Tag: dropwizard

Dropwizard仅在@POST上validation字段

我有这些只读字段需要安全,如密码。 假设我们有一个用户对象: public class User { @NotEmpty @Size(max = 100) private String name; @NotEmpty private String username; @NotEmpty @Email private String email; private String password; @JsonIgnore public String getPassword() { return password; } @JsonProperty public void setPassword(String password) { this.password = password; } } 所以,这很好用; 就像我可以得到/发布/放置任何我想要的,但我永远不会收到密码。 但我也想确保第一次发布时,密码不应为空。 如果我做 @NotEmpty private string password; 如果我不想更改此用户的密码,那么我的PUT(编辑)请求将失败,并显示validation错误。 我能想到两种解决方案: 1-inheritanceUser类,只为POST创建一个特殊的类,它可以在getter上有@NotEmpty注释。 […]

@JsonView注释如何用于嵌套实体?

我试图为我的嵌套实体使用@JsonView注释。 更清楚的是,假设我们有2个实体,每个实体都有自己的视图类。 public class JsonViewAddress { //some view classes } public class Address { //fields annotated by JsonViewAddress’s classes and @JsonProperty } public class JsonViewPerson { //some view classes } public class Person { //some fields (yes annotated with JsonViewPerson classes and @JsonProperty) //also assume that this is annotated with any JsonViewPerson’s class. private Address […]

dropwizard:从同一个类生成html和json

有没有办法从客户端控制输出格式? 我有一节课 @Produces(MediaType.TEXT_HTML) 我希望它在客户端请求时生成json 。 我可以逐字复制该类,只替换@Path和@Produces注释,但这看起来完全是浪费。 我想知道客户端是否可以将类似&content-type = application / json的内容添加到URL并让我的服务器用json而不是html响应?

不使用.YML文件的Dropwizard配置?

我是一名新手。 我想知道的是他们的任何其他方式来设置连接端口,管理端口,记录器级别和所有配置参数,而不是使用.YML文件。

如何在另一个中嵌入一个DropWizard(带有freemarker)视图?

我正在使用DropWizard和Freemarker构建一个视图,该视图根据Web服务的结果显示不同类型的表单。 我已经将表单创建为视图 – 每个都有自己的ftl。 所以,在我的资源中,我发现我需要哪种forms,然后加载main.ftl,将表单视图作为参数传递(见下文)。 这不起作用。 谁能看到我们哪里出错? 或者使用DropWizard和freemarker将视图链接在一起有一种完全不同的方式吗? @GET public Form getForm() { FormView view = new FormView(service.getForm()); return new MainView(view); } public class FormView extends View { private final Form form; public FormView(Form form) { super(“formView.ftl”); this.form = form; } public Form getForm() { return form; } } public class MainView extends View { […]

Jersey – 有没有办法用参数实例化Per-Request资源?

假设我有这个课程: @Path(“/test”) public class TestResource{ private TestService testService; public TestResource(TestService testService){ this.testService = testService; } @GET public String getMessage(){ return testService.getMessage(); } } 然后,我想在泽西岛注册。 一个会这样做: TestService testService = new TestServiceImpl(); resourceConfig.register(new TestResource(testService)); 但问题是该方法构成了TestResource的单个实例。 我想根据请求创建一个实例。 所以,泽西有一种方法可以做到这一点: TestService = new TestServiceImpl(); resourceConfig.register(TestResource.class); 那样太好了! 但它不允许我将实例化参数传递给它的构造函数。 最重要的是,我正在使用DropWizard,它也不允许我从ResourceConfig访问所有方法(但我检查了它的文档,但没有找到任何让我传递参数的方法) 所以我想知道是否有办法实现这一目标。 谢谢! PS:我知道我可以使用Spring或Guice(或我自己的实例提供程序)并注入我的类来逃避这一点,但我不想这样做(当然,如果这是唯一的方法我会这样做)

如何在Dropwizard(Jersey)中记录JSON响应

我想知道如何配置Dropwizard来记录JSON响应。

DropWizard中的Beanvalidation与自定义Json输出

我开发了一个具有各种Restfunction的web服务。 我想使用标准的@Valid注释来validation我的bean。 但我想修改输出json错误。 来自validation的错误消息目前的格式如下: { “errors”: [ “someString size must be between 0 and 140”, “anotherString cannot contain numbers” ] } 但我希望错误消息的格式如下: { “errors”: [{ “someString”: “size must be between 0 and 140” }, { “anotherString”: “cannot contain numbers” } ] } 要么 { “errors”: [{ “field”: “someString” “error”: “size must be between 0 and […]

使用Dropwizard和JDBI查询具有多个模式的数据库?

我正在使用DropWizard(使用JDBI)构建Java Rest API,我的要求是我需要使用相同的应用程序查询多个MySQL模式。 它基本上是一个包含多个模式的AWS MySQL实例 – 每个客户端一个模式。 我需要的是一种机制,它根据请求知道要查询哪个“模式” – IE:请求属于哪个客户端。 我知道如何创建DataSource,DAO等(使用本教程: https : //dropwizard.github.io/dropwizard/manual/jdbi.html ),但不知道如何查询多个模式。 有任何想法吗?

使用dropwizardvalidation,我可以访问数据库以插入记录

我的问题如下: 我正在使用dropwizard进行项目,到目前为止,我已经愉快地成功使用了validation框架。 我的validation工作正常,它以标准方式使用。 这就是我所拥有的: 请求类: import javax.validation.constraints.NotNull; import MandatoryFieldLengthCheck; public class InitiatePaymentRequest implements PaymentRequest { @NotNull(message = “Mandatory input field missing”) @MandatoryFieldLengthCheck(value = 32) protected String transactionId; } 然后是注释类: @Target({ METHOD, FIELD, ANNOTATION_TYPE }) @Retention(RUNTIME) @Constraint(validatedBy = MandatoryFieldLengthCheckValidator.class) @Documented public @interface MandatoryFieldLengthCheck { String message() default “Invalid input data”; Class[] groups() default {}; Class[] payload() […]