dropwizard

How to log JSON responses in Dropwizard (Jersey)

匿名 (未验证) 提交于 2019-12-03 08:41:19
可以将文章内容翻译成中文,广告屏蔽插件可能会导致该功能失效(如失效,请关闭广告屏蔽插件后再试): 问题: 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 configure logger, add in your configuration file (e.g.:

Can I have multiple configuration files in DropWizard?

喜你入骨 提交于 2019-12-03 08:10:59
问题 I want to have several yaml files for DropWizard. One of them contain sensitive info and one non sensitive. Can you point me to any docs or example how to have multiple configurations in DropWizard? 回答1: ConfigurationSourceProvider is your answer. bootstrap.setConfigurationSourceProvider(new MyMultipleConfigurationSourceProvider()); The following is how dropwizard does it by default. You can easily change it to your own liking. public class FileConfigurationSourceProvider implements

Dropwizard file upload

给你一囗甜甜゛ 提交于 2019-12-03 05:46:40
问题 I have to upload a file from my site yet cnt seem to get it working with drop wizard. Here is the form from my site. <form enctype="multipart/form-data" method="POST" action="UploadFile"> <input type="file" id="fileUpload" name="file"/> <input type="hidden" id="fileName" name="fileName"/> <input type="submit" value="Upload"/> </form> How would I go about on the backend to receive the file? The solution was @POST @Consumes(MediaType.MULTIPART_FORM_DATA) public Response uploadFile(

Does Dropwizard Support Servlet 3 Asynchronous Servlets?

匿名 (未验证) 提交于 2019-12-03 03:10:03
可以将文章内容翻译成中文,广告屏蔽插件可能会导致该功能失效(如失效,请关闭广告屏蔽插件后再试): 问题: Does Dropwizard support Servlet 3 asynchronous servlets? If not, is it on the roadmap at any time in the near future? 回答1: It uses Jetty 8, which supports Servlet 3.0. Jersey (and JAX-RS) doesn't have any support for this, but it's forthcoming in JAX-RS 2.0 (and Jersey 2.0). Dropwizard doesn't add anything special, but when Jersey 2.0 ships, the next major Dropwizard release will very likely include it. 回答2: You can use https://github.com/jetty-project/jetty-eventsource-servlet . Read wiki for how to impl Servlet and EventSource In your DW

How to use swagger with dropwizard .0.7.0

匿名 (未验证) 提交于 2019-12-03 03:03:02
可以将文章内容翻译成中文,广告屏蔽插件可能会导致该功能失效(如失效,请关闭广告屏蔽插件后再试): 问题: I have the latest dropwizard setup. Now I have created a simple API and I am trying to add Swagger on top. There is a Swagger implementation for dropwizard but the sample code is against Yammer dropwizard 0.6.2 which requires addProvider and addResource. The io.dropwizard environment doesn't seem to have this function. Can you please let me know how I can do this under io.dropwizard? 回答1: For Dropwizard 0.7.0 I configure swagger like this: void configureSwagger(Environment environment) { environment.jersey().register(new

Restricting dropwizard admin page

匿名 (未验证) 提交于 2019-12-03 01:31:01
可以将文章内容翻译成中文,广告屏蔽插件可能会导致该功能失效(如失效,请关闭广告屏蔽插件后再试): 由 翻译 强力驱动 问题: How to authenticate Dropwizard admin portal, so as to restrict normal users from accessing it? Please help 回答1: In your config, you can set adminUsername and adminPassword under http like so: http : adminUsername : user1234 adminPassword : pass5678 回答2: For DW 0.7 my approach would be: public class AdminConstraintSecurityHandler extends ConstraintSecurityHandler { private static final String ADMIN_ROLE = "admin" ; public AdminConstraintSecurityHandler ( final String userName , final String password ) { final Constraint constraint =

Incompatible types, equality constraints and method not found during Java 9 Migration

匿名 (未验证) 提交于 2019-12-03 01:27:01
可以将文章内容翻译成中文,广告屏蔽插件可能会导致该功能失效(如失效,请关闭广告屏蔽插件后再试): 问题: While migrating one of our projects to Java 9(build 9+181) , I am facing a peculiar problem what looks like an incorrect implementation in some library in use related to type inference and java-module . I am using a dropwizard-core(1.1.0) and guice(4.1.0) configurations as follows: public class CustomService extends io.dropwizard.Application { public static void main(String[] args) throws Exception { new CustomService().run(args); } // other initializations @Override public void run(CustomServiceConfig config, io.dropwizard.setup.Environment

Dropwizard HK2 injection

匿名 (未验证) 提交于 2019-12-03 01:05:01
可以将文章内容翻译成中文,广告屏蔽插件可能会导致该功能失效(如失效,请关闭广告屏蔽插件后再试): 问题: im pretty new in working with dropwizard. Currently I'm trying to implement the HK2 dependency injection. That works pretty fine inside a resource but it doesn't work outside of a resource. Here is what I'm doing: Client client = new JerseyClientBuilder(environment).using(configuration.getJerseyClientConfiguration()).build("contentmoduleservice"); //DAOs ContentModuleDAO contentModuleDAO = new ContentModuleDAO(hibernate.getSessionFactory()); ModuleServedDAO moduleServedDAO = new ModuleServedDAO(hibernate.getSessionFactory()); //Manager

Dropwizard Application crashed by AbstractJAXBProvider

匿名 (未验证) 提交于 2019-12-03 01:05:01
可以将文章内容翻译成中文,广告屏蔽插件可能会导致该功能失效(如失效,请关闭广告屏蔽插件后再试): 问题: I have a server application implemented using Dropwizard and Gradle as Build System. Now I want to integrate Apache Mahout for some recommender system action. After adding the Mahout dependency and try to run, I get exceptions. My initial dependencies look like dependencies { compile 'io.dropwizard:dropwizard-core:0.9.1' compile 'io.dropwizard:dropwizard-jdbi:0.9.1' compile 'mysql:mysql-connector-java:5.1.37' compile 'redis.clients:jedis:2.8.0' compile 'com.google.guava:guava:18.0' compile 'joda-time:joda-time:2.9.1' compile 'org.apache

How to pass parameter to JsonSerializer?

大城市里の小女人 提交于 2019-12-03 00:35:18
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 correspondent content : @GET public Data getData(@QueryParam("id") Long id , @QueryParam("locale")