FAQ Database Discussion Community


Authorization in dropwizard

java,jersey,dropwizard
I want to make an small application using dropwizard in 0.8.0-rc3-SNAPSHOT. In that I want if any user will call my api user should pass an authtoken in the header part.What I have done till now is--- @Override public void run(HelloWorldConfigurationhelloWorldConfiguration,Environment environment) throws Exception{ environment.jersey().register(new ViewResource()); environment.servlets().addFilter("MyCustomRequestFilter", new MyCustomRequestFilter()) .addMappingForUrlPatterns(EnumSet.of(DispatcherType.REQUEST),false,...

Mockito always return null when testing dropwizard resources

unit-testing,junit,mockito,dropwizard
I am trying to test dropwizard resources and followed http://www.dropwizard.io/manual/testing.html to do so. However, I always get a null object from the mocked class/method. The resource method @GET @Path("/id") @ApiOperation("Find property by id") @Produces(MediaType.APPLICATION_JSON) public Property findById(@QueryParam("id") int id) { return propertyDAO.findById(id); } And the test class public class PropertiesResourceTest...

Jersey 2.x Custom Injection Annotation With Attributes

java,jersey,jersey-2.0,dropwizard,hk2
I am in the process of migrating from DropWizard 0.7.1 to 0.8.1. This includes migrating from Jersey 1.x to 2.x. In my implementation that uses Jersey 1.18.1, I had a MyProvider (changed all class names for simplicity's sake) that implements InjectableProvider. This class would create MyInjectable objects, containing the custom...

Dropwizard 0.8.0: serve static assets from /

path,assets,dropwizard
I want my server to serve the static html files from /. Furthermore, css and js files should be served from /css respectively, /js. All json data should be accessible at /api. However, I get a 404 for http://localhost:8080/ or any other path. I use the following setting in the...

HTTP 204 error in REST (Dropwizard)

java,rest,dropwizard
I have problem with http 204 error. Always, when I try to use a POST command, and push data into dropwizard, I have 204. I don't know why, I tried solve it but code looks like okey. public class POIDefinition { // int id; String description; // String location; }...

Dropwizard. Send Json and make jersey + jackson recognize class

java,json,jersey,jackson,dropwizard
i am farley new to jackson and jersey. Have done some programs that uses those libraries. But i have a problem that i cant find a solution for. @POST @Path("/submit") @Consumes(MediaType.APPLICATION_JSON) public void submitTicket(Ticket ticket) { System.out.println("*** SUBMIT A NEW TICKET ***"); System.out.println("Ticket: " + ticket); } This is in...

Customize Dropwizard's /ping

java,rest,dropwizard
Dropwizard provides a /ping endpoint on it's admin port (7001) that responds with a "pong" string. Is it possible to customize the behavior of this call? What I'm looking for is to be able to control the response of the call based on application code....

Dropwizard Hibernate Configuration

mysql,hibernate,dropwizard,java-ee-7
I am new to Dropwizard and so far everything was going well till I started messing with Hibernate and MySQL. My problem is: Hibernate won't create tables and consequently no columns in my DB. The only warning I get when running my jar file is: org.hibernate.cfg.environment hibernate.properties not found But...

confused about base64 encoding of BLOBs when using dropwizard

json,blob,dropwizard
I have a dropwizard app running against postgres and a table. I define the BLOB column in the entity class as byte[]: @Entity @Table(name = "document") @NamedQueries({ @NamedQuery( name = "my.documents.model.Document.findAll", query = "SELECT d FROM Document d" ) }) public class Document { @Id @GeneratedValue(strategy = GenerationType.IDENTITY) private long...

How to [de]serialize to pojo objects from JSON when there is mixed camel case in names

java,jackson,dropwizard
I'm using Dropwizard (which uses Jackson under the hood) to create a bridging API service. It connects to two other API's that are very similar (API1 and API2). I have my own POJO library that contains the request and response POJO's for API1 and API2. The only difference between those...

CodeSource on Liberty Profile 8.5.5.5

java,websphere,dropwizard,websphere-liberty
I'm trying to deploy a dropwizard (dw) application using wizard-in-a-box (wiab) on IBM Liberty Profile 8.5.5.5, but I'm encountering som issues with the io.dropwizard.util.JarLocation class. wiab will try to get the location of the Listener class wrapping the dw application but fails to do so since the CodeSource object in...

Catch json processing exception with dropwizard?

java,json,jackson,jersey-2.0,dropwizard
I have a dropwizard application with a global exception handler registered that implements ExceptionMapper<Throwable>. If I throw any runtime exception from within a resource the mapper gets hit. However, in a test I am posting JSON to to a resource with a missing type discriminator for a jackson polymorphic type....

Routing requests to multiple backend servers Dropwizard and Elasticsearch

http,nginx,elasticsearch,frontend,dropwizard
I have to backend servers : A dropwizard server that serves as a mainly application server. This server is used by the frontend for all operations except searching. An elasticsearch server feeded by the dropwizard server which serves the frontend for all search queries. Knowing that dropwizard is running on...

Options for custom serializers / deserializers with Dropwizard?

jersey,jackson,dropwizard,jersey-client
What's a good way to have custom (de)serializers that can be registered externally with dropwizard? I was having problems with (de)serializing a composite object. I tried using @JsonUnwrapped to get the JSON I wanted, but had problems with it for deserializing - it needs special constructors that take strings and...

Unable to view Hystrix metrics in Dropwizard app via hystrix-metrics-event-stream servlet

java,dropwizard,hystrix
I have a Dropwizard 0.8.1 app to which I have added a number of HystrixCommand classes for calling out to various external services. I now want to visualize stats related to calls to those services, but I can't seem to get my app to play nice with the Hystrix Dashboard....

How To deploy Dropwizard Web Services in Tomcat Server

java,eclipse,web-services,tomcat,dropwizard
I am facing a problem to deploy drop wizard services in tomcat server, I have created my web services in drop wizard framework which use jetty server in default, but here I want to deploy my web services in tomcat server so is there any way that how to deploy...

Why am I getting a 500 response for my POST on my Jersey REST API?

java,jersey,dropwizard,postman
I have just begun implementing my first Drowizard project. Here's my first resource class: @Path("/bill") public class CommandResource { //... @POST @Consumes(MediaType.APPLICATION_JSON) @Path("/createBillForStudy") public Response handleCreateBillForStudyCommand(CreateBillForStudyCommand cmd, @Context UriInfo uriInfo) { System.out.println("Creating bill for command: " + cmd); UUID newId = billCreator.handle(cmd); URI location = uriInfo.getBaseUriBuilder().path(CommandResource.class).path("/" + newId).build(); return...

Dropwizard / Jackson returns HTTP code 200 from function but AJAX POST gets error

java,jquery,ajax,jackson,dropwizard
I am new to Dropwizard and am having a little trouble with the conversion from POJO to Json. I am using jQuery at the frontend where I am calling the ajax function with the type POST. I am trying to validate a login against data in a MySQL database. I...

Spring - Programmatically generate a set of beans

java,spring,spring-mvc,dropwizard
I have a Dropwizard application that needs to generate a dozen or so beans for each of the configs in a configuration list. Things like health checks, quartz schedulers, etc. Something like this: @Component class MyModule { @Inject private MyConfiguration configuration; @Bean @Lazy public QuartzModule quartzModule() { return new QuartzModule(quartzConfiguration());...

MultiException when custom jersey param throws exception

java,jax-rs,jersey-2.0,dropwizard
NOTE: All code to reproduce this problem is available at https://gist.github.com/SrikanthRao/c9fc35e6fe22a74ab40c http://localhost:8080/date/bean?date=2014-13-23 (using BeanParam) produces "{"code":500,"message":"There was an error processing your request. It has been logged (ID 48be9aa43bd49547)."}" without adding MultiExceptionMapper to jersey. If I add MultiExceptionMapper to jersey, the above url results in "Date is either not in YYYY-MM-DD...

Implementing custom logging for Dropwizard resources

java,jetty,dropwizard
I have a dropwizard application with multiple resources. I need to implement some custom logging which should be the same for all resources and should contain things like URL, response time, response size and some data extracted from the request header. Generally, I would like to be able to specify...

Dropwizard 0.8 and GuiceBundle Governator: Forcing Resources class to be Singleton

java,guice,dropwizard
I'm using Dropwizard 0.8.1 and I have observed that resource object is created each time a belonging path is called. I think this done because the resource are registered by class when the application is bootstraped. Is there anyway to force the resources to be Singleton? I have tried to...

How to avoid dependency conflict when using dropwizard + jersey client

java,maven-2,dropwizard,jersey-client
I have a DropWizard REST API written and works. One of the resource endpoints actually writes an email, however as soon as I add the following dependencies DropWizard starts to fail on start up <dependency> <groupId>com.sun.jersey</groupId> <artifactId>jersey-client</artifactId> <version>1.18.1</version> </dependency> <dependency> <groupId>com.sun.jersey</groupId> <artifactId>jersey-core</artifactId> <version>1.18.1</version> </dependency>...

Dropwizard upgrade from 0.7 to 0.8.0 release error

maven,dropwizard
I recently upgraded from 0.7 to 0.8 release version of dropwizard. Right out-of-the-box, I get the following error when I am trying to start my application. I have cleaned my maven repository and started fresh but still no luck. INFO [2015-03-11 20:03:45,144] io.dropwizard.server.ServerFactory: Starting CoreApplication Exception in thread "main" java.lang.NoClassDefFoundError:...

Why ever use CachedGauage in Dropwizard Metrics?

java,metrics,dropwizard,codahale-metrics
I see there is the CachedGauge in the DropWizard Metrics (formerly Coda Hale Metrics) lib. I'm wondering why anyone would ever use this?!? My understanding of the value of a metric is that it is real-time, accurate and relevant. If a metric is reporting a stale/cached value, of what purpose...

Handling managed Hibernate DAO exceptions in Dropwizard

java,hibernate,jersey,dropwizard
I'm having a problem with Dropwizard where I can't catch the exception thrown by the Hibernate DAO object within my resource. I have the following DAO object public class ApplicantDAO extends AbstractDAO<Applicant> { public ApplicantDAO(SessionFactory factory) { super(factory); } public long create(Applicant person) { return persist(person).getApplicantId(); } } I am...

Dropwizard 0.8.0 WADL support

jersey-2.0,dropwizard,wadl
Wadl can be configured in Dropwizard 0.7.1 like this: environment .jersey() .getResourceConfig() .getProperties() .put(ResourceConfig.FEATURE_DISABLE_WADL, Boolean.FALSE);//Create WADL How can I set it in Dropwizard 0.8.0...

@Path annotation: abstract resource in dropwizard

java,groovy,annotations,jetty,dropwizard
I had an idea to build abstract resource class for my application: abstract class MyAbstractResource<A> { MyAbstractDao dao; public MyAbstractResource(MyAbstractDao dao) { this.dao = dao; } @Path("/") @POST @Produces(MediaType.APPLICATION_JSON) @Timed public A create(A account) { return dao.create(account); } @Path("/{id}") @PUT @Produces(MediaType.APPLICATION_JSON) @Timed public A update(A account) { return dao.change(account); }...

Atmosphere, dropwizard and jersey injection error

compiler-errors,jersey,dropwizard,atmosphere
Here is my gradle file: compile group: 'io.dropwizard', name: 'dropwizard-core', version: '0.8.0' compile group: 'io.dropwizard', name: 'dropwizard-auth', version: '0.8.0' compile group: 'io.dropwizard', name: 'dropwizard-client', version: '0.8.0' compile group: 'org.glassfish.jersey.media', name: 'jersey-media-multipart', version: '2.16' compile group: 'org.glassfish.jersey.core', name: 'jersey-client', version: '2.16' compile group: 'org.atmosphere', name: 'atmosphere-jersey', version: '2.1.10' After adding atmosphere-jursey...

Maven and Intellij builds differently

java,maven,intellij-idea,dropwizard
I have a parent pom. When I am on the parent and write mvn clean install my dropwizard application builds fine. However, in Intellij it fails because it cannot find my config.yml file. The problem is that I need to include my module directory in Intellij, but not in Maven....

Resource query parameter validation on jersey-dropwizard

java,jersey,dropwizard
I have a dropwizard application and in one resource i would like to have a required query parameter. I know jersey supports bean validation so i tried to use @NotNull annotation but it didn't work. Here's the code to resource: @Path("/resource/{id}") @Produces(MediaType.APPLICATION_JSON) public class MyResource { //....constructor... @GET public String...

Use custom where condition with JDBI dropwizard

java,sql,dropwizard,jdbi
I am trying to explore JDBI with dropwizard, my custome code is as below. public interface UserDao { @SqlQuery("SELECT FROM `t_user` :cond") @Mapper(UserMapper.class) List<User> fetch(@Bind("cond") String cond); } and trying to call with below code Application.getJdbi().onDemand(UserDao.class).fetch("where logon_id="+p.getEmail()+"'"); and getting below issue Caused by: com.mysql.jdbc.exceptions.jdbc4.MySQLSyntaxErrorException: You have an error in your...

Timeout for Dropwizard's health checks?

java,dropwizard,jdbi
I have two sql database connections for which health checks are automatically added by dropwizard. But when the application loses connection to one of them, the /healthcheck endpoint takes indefinitely long to respond, where I would want it to timeout after a few seconds. I've already set the maxWaitForConnection setting,...

Override DropWizard ConstrainViolation message

java,jax-rs,dropwizard
So I want to change the validation messages used to validate a model through a DropWizard resource. I'm using java bean validation annotations. For example here is one of the fields I want to validate: @NotEmpty(message = "Password must not be empty.") I can test this works as expected using...

Dropwizard: Passing custom type query parameter

java,rest,jersey,jax-rs,dropwizard
How can I accept custom type query parameter? public String detail(@QueryParam("request") final MYRequest request) { Above line gives error while starting the server jersey.server.model.ModelValidationException: Validation of the application resource model has failed during application initialization. ...

EHCache and DropWizard: Returning no response

jersey,ehcache,dropwizard
I have successfully integrated SimplePageCachingFilter with DropWizard. However, there is one thing standing in my way. Whenever an exception in my application is thrown, instead of being routed to my ExceptionMapper I get "Response contains no data" in my API Browser. I also happen to see this pass by in...