dropwizard

Dumping bad requests

你离开我真会死。 提交于 2019-12-25 00:27:23
问题 I have a service implemented with Dropwizard and I need to dump incorrect requests somewhere. I saw that there is a possibility to customise the error message by registering ExceptionMapper<JerseyViolationException> . But I need to have the complete request (headers, body) and not only ConstraintViolations . 回答1: You can inject ContainerRequest into the ExceptionMapper . You need to inject it as a javax.inject.Provider though, so that you can lazily retrieve it. Otherwise you will run into

Using MetricsServlet to fetch metrics in Cassandra

社会主义新天地 提交于 2019-12-24 18:13:25
问题 I want to fetch various metrics like read/write latency, disk utilisation etc. of each of my Cassandra nodes(without using JMX) as a JSON object. It seems to me that MetricsServlet, can do exactly that. However, I'm still not able to figure out, what all do I need to do in order to use it(metrics-servlets does not come with Cassandra). I'll appreciate if I can get some advice/sample code(for fetching any metric). 回答1: Cassandra is not a java web server, it doesnt support servlets. You would

How do I override all 404 pages without defining default handlers for every resource?

孤街醉人 提交于 2019-12-24 16:36:56
问题 In my Dropwizard project, I'm defining a generic ExceptionMapper<WebApplicationException> : environment.jersey().register(new WebApplicationExceptionMapper()); ...but this doesn't seem to catch any of the 404 errors for unmatched paths. Without defining five defaultHandler() methods for every single resource, how do I catch all 404s so I can return my own error page or some JSON? So, if I had a service with one resrouce, say, /docs , this is the situtation: /myservice/docs/helloworld doesn't

Jackson can't deserialize MongoDB object passed through REST

僤鯓⒐⒋嵵緔 提交于 2019-12-24 07:36:26
问题 Trying to set up an application to display MongoDB nested data (two levels of nesting and embedding) in a web application (for business analysis). I'm using Dropwizard, so I copied the dropwizard-mongo example, reduced it to the necessary parts (no delete, no insert, no metrics or anything). App.java package test; import io.dropwizard.Application; import io.dropwizard.setup.Bootstrap; import io.dropwizard.setup.Environment; import com.meltmedia.dropwizard.mongo.MongoBundle; import test.Res;

How to get String from config.yml file in Dropwizard resource?

旧城冷巷雨未停 提交于 2019-12-24 04:55:24
问题 I want to geta String in my Dropwizard config.yml and access it from a resource class. I have added the class to the configuration public class DropwizardBackendConfiguration extends Configuration { @NotEmpty private String uploadFileLocation; @JsonProperty public String getUploadFileLocation() { return uploadFileLocation; } @JsonProperty public void setUploadFileLocation(String uploadFileLocation) { this.uploadFileLocation = uploadFileLocation; } } I am able to get the content in the run

How to shutdown dropwizard application?

别来无恙 提交于 2019-12-23 22:45:51
问题 I am trying to come up with a microservice using dropwizard. The documentation tells how to start the application, but says nothing about terminating it gracefully. Fir example, apache tomcat has both startup and shutdown scripts. So does anyone know how to terminate a dropwizard application other than pressing Ctrl+C of kill ? 回答1: Dropwizard Jetty has shutdown hooks. So kill -SIGINT <pid> works out really well. 回答2: Inspired by praveenag's answer, I dug into Jetty's code. If you start

How to disable admin port in DropWizard while using gzip server mode/type

一个人想着一个人 提交于 2019-12-23 15:50:21
问题 I am trying to disable admin port in DropWizard while using 'gzip' server mode. I know this is possible in 'simple' server. Below is the .yml file configuration. - server: type: simple but I want to disable admin port in gzip server mode. server: gzip: bufferSize: 8KiB NOTE: I cant use 'simple' server as we have dependency on 'gzip'. I am out of ideas now any help is really appreciated. 回答1: The default Dropwizard config includes an admin connector. To prevent this, you will need to

dropwizard: read configuration from a non-file source

荒凉一梦 提交于 2019-12-23 10:23:31
问题 What's the right way to read configuration in dropwizard from something like a database, or a REST call? I have a use case where I cannot have a yml file with some values, and should retrieve settings/config at startup time from a preconfigured URL with REST calls. Is it right to just invoke these REST calls in the get methods of the ApplicationConfiguration class? 回答1: Similar to my answer here, you implement the ConfigurationSourceProvider interface the way you wish to implement and

How to add custom MetricFilter in GraphiteReporter to send only selected metricd

六月ゝ 毕业季﹏ 提交于 2019-12-23 02:52:54
问题 I have implemented Dropwizard metrics in my application. I am sending metrics to Graphite using below code. final Graphite graphite = new Graphite(new InetSocketAddress("xxx.xxx.xxx.xxx", xxxx)); final GraphiteReporter graphiteReporter = GraphiteReporter.forRegistry(metricRegistry) .prefixedWith(getReporterRootTagName()) .convertRatesTo(TimeUnit.SECONDS) .convertDurationsTo(TimeUnit.MILLISECONDS) .filter(MetricFilter.ALL) .build(graphite); graphiteReporter.start(Integer.parseInt(getTimePeriod

Drop-wizard request response logging

懵懂的女人 提交于 2019-12-23 01:57:39
问题 I want to log each request and response in dropwizard into different files. For example I want all the requests to be logged in /var/log/applicationname-request.log and all responses into /var/log/applicationname-response.log Is there any way in which we can achieve the same? 回答1: Unfortunately DropWizard currently doesn't support this natively. See this lively discussion for more information. Fortunately there's a workaround if you're willing to forego configuring logging with DropWizard all