dropwizard

Logging into different files based on some condition

一个人想着一个人 提交于 2019-12-04 05:52:00
问题 We have an application. In which we have a condition.Based on the condition, if it is true then we will write some log messages to one file else we will log the messages to another file. And logging should be happened based on the condition and not based on log level. How it is possible in dropwizard using yaml file? 回答1: This is supported out of the box. Here is my example: server: rootPath: /api/* requestLog: appenders: [] applicationConnectors: - type: http port: 9085 logging: level: INFO

How do I get the JSON body in Jersey?

懵懂的女人 提交于 2019-12-04 03:15:40
问题 Is there a @RequestBody equivalent in Jersey? @POST() @Path("/{itemId}") @Consumes(MediaType.APPLICATION_JSON) public void addVote(@PathParam("itemId") Integer itemId, @RequestBody body) { voteDAO.create(new Vote(body)); } I want to be able to fetch the POSTed JSON somehow. 回答1: You don't need any annotation. The only parameter without annotation will be a container for request body: @POST() @Path("/{itemId}") @Consumes(MediaType.APPLICATION_JSON) public void addVote(@PathParam("itemId")

Dropwizard deserializing generic list from JerseyClient

落爺英雄遲暮 提交于 2019-12-04 01:38:42
问题 I wanted to implement a generic class to use for caching results from a REST API in a local MongoDB-instance. For this to work, I need to deserialize a collection I get from JerseyClient: Response response = this.source.request().get(); List<T> list = response.readEntity( new GenericType<List<T>>() {} ); // ... do stuff with the list Let's say I'm using this piece of code in a context of T relating to a class Foo . The really weird thing is, after the readEntity call, list is not a List<Foo>

No session currently bound to execution context

风流意气都作罢 提交于 2019-12-04 00:20:12
I got below exception when I used session.getCurrentSession() . I have mentioned hibernate.current_session_context_class: managed org.hibernate.HibernateException: No session currently bound to execution context at org.hibernate.context.internal.ManagedSessionContext.currentSession(ManagedSessionContext.java:75) at org.hibernate.internal.SessionFactoryImpl.getCurrentSession(SessionFactoryImpl.java:1014) at io.dropwizard.hibernate.AbstractDAO.currentSession(AbstractDAO.java:36) at io.dropwizard.hibernate.AbstractDAO.persist(AbstractDAO.java:149) I use this with dropwizard . Can anyone help me

How to change the Validation Error behaviour for Dropwizard?

三世轮回 提交于 2019-12-03 22:15:05
In Dropwizard I use @Valid annotations for my resource methods: public class Address { @NotNull String street ... } @Path("/address") @Produces(MediaType.APPLICATION_JSON) public class AddressResource { @POST public MyResponse addAddress(@Valid Address address) { if (address == null) { throw new WebApplicationException("address was null"); } ... } } On application start I register a custom WebApplicationExceptionMapper which handles WebApplicationExceptions . Thus, for addresses with the value null, the exception is thrown and handled in the mapper which generates a useful response. However,

How can I reset timer of dropwizard metrics?

时间秒杀一切 提交于 2019-12-03 21:48:36
问题 We are processing messages that comes in periodically. We use codahale dropwizard metrics' "Timer" for measuring the time it takes to process them. I found someone had the same issue here: "problem with exponentially decaying reservoir is that if no new data comes in, it will keep on giving the same numbers all the times. For example, let say you update a timer with 5 and 7 (then don't put anything at all) , then no matter when you see (even after x hours), timer will still show the average

Dropwizard and Guice: injecting Environment

大城市里の小女人 提交于 2019-12-03 13:20:59
I am currently building a Dropwizard + Guice + Jersey-based application where the database access is being handled by JDBI for the time being. What I am trying to achieve is to have your typical enterprise architecture, where Resources access Service classes accessing a DAO class that in turn accesses the database. It would be nice to get all this wired up in a proper DI way, although I guess I can build my object graph in the run() method of the application if all else fails. So, I'm running into this problem that has been mentioned here before : Getting a DBIFactory requires both the

Dropwizard hot deployment

岁酱吖の 提交于 2019-12-03 12:40:19
I'm looking for a simple to use system in Java which creates a REST service for me. So I found dropwizard but as far as I can use google it turns out it lacks hot deployment although jetty is able to do so. When using the maven-shade-plugin it takes at least 10 seconds to build the thing. Also my IDE reports that it cannot use compile on save feature (aka hot deployment) when the shade-plugin is involved. Can I use hotdeployment somehow? Or what can I use instead? Update : If nothing will fix this I'll probably use a combination of jersey&guice etc which is explained in this post You don't

How to make @JsonSnakeCase the default for configuration in Dropwizard

萝らか妹 提交于 2019-12-03 11:31:38
How will I configure jackson to use snake case in dropwizard instead of putting @JsonSnakeCase in every class ? And finally am able to find the answer.. Just add below cofiguration. environment.getObjectMapperFactory().setPropertyNamingStrategy(PropertyNamingStrategy.CAMEL_CASE_TO_LOWER_CASE_WITH_UNDERSCORES) Just add this following line in your run() method environment.getObjectMapper().setPropertyNamingStrategy( PropertyNamingStrategy.CAMEL_CASE_TO_LOWER_CASE_WITH_UNDERSCORES); environment.jersey().register(new JacksonMessageBodyProvider(mapper)); 来源: https://stackoverflow.com/questions

How to pass parameter to JsonSerializer?

让人想犯罪 __ 提交于 2019-12-03 10:05:19
问题 I have a simple data service : @GET public Data getData(@QueryParam("id") Long id) { Data data = dataService.getData(id); return data; } And a matching DataSerializer that implements JsonSerializer<Data> : The DataSerializer is registered to Jackson via : simpleModule.addSerializer(Data.class , dataSerializer); ObjectMapper mapper = new ObjectMapper(); mapper.registerModule(simpleModule); It works well. But today , I want to add another Locale parameter , and hope the DataSerializer to output