我试图坚持dropwizard应用程序启动的时间.
public class Main Application extends Application<MainConfiguration> {
private final HibernateBundle<DeployerConfiguration> hibernate = new HibernateBundle<AppConfiguration>(App.class) {
public DataSourceFactory getDataSourceFactory(
AppConfiguration configuration) {
return configuration.getDataSourceFactory();
}
@Override
public void initialize(Bootstrap<AppConfiguration> bootstrap) {
bootstrap.addBundle(hibernate);
public static void main() {
final AppDAO ddao = new AppDAO(hibernate.getSessionFactory());
App app = new App(new Date());
adao.create(app);
Run Code Online (Sandbox Code Playgroud)
物体:
JsonIgnoreProperties(ignoreUnknown = true)
@Entity
@Table(name = "app")
@NamedQuery(name = "App.findAll", query = "SELECT d FROM App d")
public class App implements Serializable{
private static final long serialVersionUID = 1L; …Run Code Online (Sandbox Code Playgroud) 在RESTful API中,很典型的做法是查看可以支持多种序列化格式的端点:
// Sends back "fizz" resource that has an id=34 as a JSON object
http://api.example.com/v2/fizz/34.json
// Sends back "fizz" resource that has an id=34 as an XML object
http://api.example.com/v2/fizz/34.xml
// Sends back "fizz" resource that has an id=34 as a binary object,
// say, using Google Protocol Buffers
http://api.example.com/v2/fizz/34.bin
Run Code Online (Sandbox Code Playgroud)
我正在设计一个Dropwizard服务,并试图弄清楚如何实现多种格式支持,但是在这方面文档很贫乏。有任何想法吗?
我是 dropwizard 的新手。我正在使用 dropwizard 的 0.8.5 版。我有一个 dropwizard REST 服务,它在调用成功时返回 JSON,在调用不成功时返回 HTTL,例如 HTTP 状态代码 500 或 404。
幸福之路
LOGGER.info("Cached userinfo for '{}'",username);
JSONObject json = new JSONObject();
json.put("ticketId",created.getTicketId());
json.put("token", token);
return Response.ok(json.toString()).build();
Run Code Online (Sandbox Code Playgroud)
不幸的道路
if (created.getTicketId() == null) {
LOGGER.error("Email not sent, ticket not created");
return Response.status(Response.Status.INTERNAL_SERVER_ERROR).type(MediaType.APPLICATION_JSON).build();
}
Run Code Online (Sandbox Code Playgroud)
这是卷曲:
curl -H "Content-Type: application/json" -X POST -d '{"username":"WPf3s0G1M"}' http://localhost:7777/ids-rest-api/password/reset
Run Code Online (Sandbox Code Playgroud)
这是那个 curl 的回复,我想要 JSON 格式的回复:
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8"/>
<title>Error 500 Request failed.</title>
</head>
<body><h2>HTTP ERROR 500</h2>
<p>Problem accessing /ids-rest-api/password/reset. Reason: …Run Code Online (Sandbox Code Playgroud) 我有一个.ftl资源文件,用于通过 RESTful 端点显示它,我还想通过电子邮件将此表示发送给用户。Dropwizard 对视图做了一些魔术,允许将填充的模板主体返回到我的 REST 端点(我假设为 aString或类似 a 的更高级的东西StringBuilder)。
有没有办法在View不使用其余客户端的情况下请求 a 的主体?我也不想让我的电子邮件表示依赖于HTMLREST 客户端中使用的内容,所以没有建议只将电子邮件路由到wget点击端点的内容。
从dropwizard source来看,似乎我需要ViewRenderer从某个地方获取 a ,可能是通过使用ServiceLoader.load()- 因为这是ViewBundle获取副本的方式(如果您不提供任何副本)。
我想知道在 dropwizard 中是否可以从不同的资源类调用另一个资源方法类。
我查看了其他帖子,使用 ResourceContext 允许从另一个资源类调用 get 方法,但也可以使用来自另一个资源类的 post 方法。
假设我们有两个资源类 A 和 B。在类 A 中,我创建了一些 JSON,我想使用 B 的 post 方法将该 JSON 发布到 B 类。那可能吗?
问题
无法将swagger 2.0转换为受 Postman 导入功能影响的格式
通过生成 /swagger.json|yaml
Swagger 端点使用 swagger 通过 dropwizard 码头暴露
尝试
尝试通过导入屏幕手动导入 JSON 或 YAML 版本
尝试使用以下方法转换为不同的格式:api-spec-converter和swagger2-postman-generator
结果
导入错误: Must contain an info object
题
有没有人设法解决这个问题,允许导入
在我的 config.yml 中我有这样的配置
myObject:
key1: value1
key2:value2
key3: value3
Run Code Online (Sandbox Code Playgroud)
然后我有一个 Dropwizard Configuration 类
public class MyObject {
String key1;
String value1;
String key2;
.. so on
}
Run Code Online (Sandbox Code Playgroud)
如何读取 yml 文件,使其仅作为一个哈希图读取?这可能吗?
假设我有一个自定义 ConstraintValidator:
public class FooValidator implements ConstraintValidator<ValidFoo, String> {
@Override
public void initialize(final ValidFoo foo) {
// No-op
}
@Override
public boolean isValid(final String foo, final ConstraintValidatorContext context) {
}
}
Run Code Online (Sandbox Code Playgroud)
我希望能够通过从ServiceConfigurationDropwizardrun或initialize.
这可能吗?
我目前正在使用 dropwizard 处理我的 java 应用程序。
它工作正常,我运行它并发送完整的 yml 文件或参数。
例如,其中之一是:
reporting:
enabled: false
Run Code Online (Sandbox Code Playgroud)
所以,我想做的就是将此 yml 文件设置为默认值,并在需要时(用于将来的功能)发送此值var
所以我想做这样的事情
reporting:
enabled: ${REPORTING_FLAG:false}
Run Code Online (Sandbox Code Playgroud)
然后我可以将 REPORTING_FLAG 作为环境参数(docker)发送,并且应该可以正常工作......
问题是我发现我的应用程序无法识别该模型。
我有什么办法可以做到这一点吗?是否需要考虑额外的配置?我之前用 Spring 应用程序做过,但这似乎有所不同。
现在我收到一个错误,预期的布尔值无效(将整行作为字符串)
有想法吗?
我正在尝试制作一个测试用例来检查 Dropwizard Metric Meter 名称:这是代码:
@Test
public void getMeterName(){
String metricsPrefix = "com.company.team";
String tagSupplied = "tenant.db.table";
String expectedMeterName = "com.company.team.tenant.db.table";
assertSame(expectedMeterName,MetricRegistry.name(metricsPrefix,tagSupplied));
}
Run Code Online (Sandbox Code Playgroud)
这是我得到的错误:
java.lang.AssertionError: expected same:<com.company.team.tenant.db.table> was not:<com.company.team.tenant.db.table>
Expected :com.company.team.tenant.db.table
Actual :com.company.team.tenant.db.table
Run Code Online (Sandbox Code Playgroud)
我在这里缺少什么?