dropwizard

How to log JSON responses in Dropwizard (Jersey)

久未见 提交于 2019-12-10 02:43:54
问题 I would like to know how one would configure Dropwizard to log the JSON response. 回答1: In dropwizard 0.8.1 (also tried in 0.9.0-SNAPSHOT), add to Application.run(...) : import java.util.logging.Logger; import org.glassfish.jersey.filter.LoggingFilter; ... public void run(MyApplicationConfiguration conf, Environment env) throws Exception { // do your stuff and then add LoggingFilter env.jersey().register(new LoggingFilter( Logger.getLogger(LoggingFilter.class.getName()), true) ); } To

Getting resource annotations in Jersey 1.18.1 request filter

纵饮孤独 提交于 2019-12-10 00:10:23
问题 I'm implementing a user authorization module that will be applied on a resource method using a (new) annotation. In order to do so, I created a Jersey (request) filter in which I need to get the annotation in order to allow / disallow the resource operation. I'm using Dropwizard 0.7.1 with Jersey 1.18.1 The resource class: @Path("/v1/users/registration") @Produces(MediaType.APPLICATION_JSON) @Api(value = "/users/registration") public class UserRegistrationResource { @POST @AuthorizedFor(Realm

JDBI How can I dynamically create a WHERE clause while preventing SQL Injection?

ⅰ亾dé卋堺 提交于 2019-12-09 00:45:51
问题 I want to dynamically filter a JDBI query. The a list of parameters is passed from the UI via REST e.g. http://localhost/things?foo=bar&baz=taz http://localhost/things?foo=buz Which is (clumsily) built (Jersey @Context UriInfo::getQueryParameters -> StringBuilder) to something like this: WHERE foo=bar AND baz=taz And passed to JDBI which looks like this: @UseStringTemplate3StatementLocator public interface ThingDAO { @SqlQuery("SELECT * FROM things <where>) List<Thing> findThingsWhere(@Define

Getting error in jackson library code

馋奶兔 提交于 2019-12-08 17:03:47
问题 We are using dropwizard version 0.6.3. When we try to upgrade version 0.7.0, we are getting this error on service start. Exception in thread "main" java.lang.VerifyError: class com.fasterxml.jackson.module.afterburner.deser.SuperSonicBeanDeserializer overrides final method deserialize.(Lcom/fasterxml/jackson/core/JsonParser;Lcom/fasterxml/jackson/databind/DeserializationContext;)Ljava/lang/Object; Tried searching, didn't get any solution. When i looked into SuperSonicBeanDeserializer class,

Add jetty servlet into dropwizard

旧巷老猫 提交于 2019-12-08 16:49:06
问题 I need to add jetty servlet into my already existing server implemented using dropwizard framework. To be more specific: I have a restful resource Foo mapped to url "localhost:8080/foo" with CRUD operations. Now I need a jetty servlet mapped to url "localhost:8080/bar" and handles all requests to this url (mainly GET and POST). I could not get a clue how to do this after some googlings. Could someone please give me a direction or a snippet? Thanks! 回答1: If you're using Dropwizard 0.6.2 you

Dropwizard resource classes calling another resource method classes?

生来就可爱ヽ(ⅴ<●) 提交于 2019-12-08 12:50:06
问题 I was wondering if it was possible in dropwizard to call another resource method class from a different resource class. I looked around other posts and using ResourceContext allows one to call a get method from another resource class, but it also possible to use a post method from another resource class. Let say we have two resource classes A and B. In class A, I have created some JSON and I want to post that JSON to B class using B's post method. Would that be possible? 回答1: Yes, Resource

Removing a specific element of a list which is an element of another list using PATCH method. Written using dropwizard

♀尐吖头ヾ 提交于 2019-12-08 09:12:27
问题 I'm trying to write a PATCH api method which removes one specific element from a list of items. Note that the list of items is part of the Menu class. There aren't a lot of dropwizard resources out there, so I'm kinda stuck. Here's all the important pieces of code – https://pastebin.com/Y9mAVZJk Any help would mean a lot. I am a beginner when it comes to restul apis, but i've grasped the concept of Angular easily. I'm having issues with the backend, especially because it is dropwizard. It has

Dropwizard validate a field only on @POST

≯℡__Kan透↙ 提交于 2019-12-08 08:23:19
问题 I have these read-only fields which needs to be secure, like passwords. Say we have a user object: 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; } } So, this works nicely; as in I can get/post/put whatever I want, but I will never

How to find the size of a file uploaded via Dropwizard REST API

风格不统一 提交于 2019-12-08 05:34:09
问题 I am using Dropwizard 0.7.0 to build an API for file upload. Ran into trouble validating the uploaded file size limit. I want to check the size before writing the file to disk @POST @Consumes(MediaType.MULTIPART_FORM_DATA) @Produces(MediaType.TEXT_PLAIN) public Response uploadFile(@Context final HttpServletRequest request, @FormDataParam("file") FormDataBodyPart fileBodyPart) { /* * Check the request size */ request.getPart("file").getSize(); ......... } it throws an error: java.lang

How can I embed one DropWizard (with freemarker) View in another one?

依然范特西╮ 提交于 2019-12-08 01:12:44
问题 I am using DropWizard and Freemarker to build up a view which displays different types of forms based on results from a webservice. I have created the forms as views - each with their own ftl. So, in my resource, I discover which form I need, then load the main.ftl, passing the form view as a parameter (see below). This doesn't work. Can anyone see where we're going wrong? Or is there a completely different way to chain views together using DropWizard and freemarker? @GET public Form getForm(