dropwizard

dropwizard: produce both html and json from the same class

瘦欲@ 提交于 2019-12-06 13:31:41
Is there a way to control the output format from the client side? I have a class which @Produces(MediaType.TEXT_HTML) and I want it to produce json when the client requests. I can copy the class verbatim, replacing only the @Path and @Produces annotations, but this looks like a total waste. I wonder if the client could append something like &content-type=application/json to the URL and have my server respond with json instead of html? You'll need to annotate the resources as providing both HTML and JSON: @Produces({MediaType.TEXT_HTML, MediaType.APPLICATION_JSON}) Then just make sure you have

With dropwizard validation, can I access the DB to insert a record

不羁的心 提交于 2019-12-06 12:39:58
问题 My problem is the following: I am using dropwizard for a project and I have used the validation framework happily and successfully so far. My validation works fine and it is used in the standard way. This is what I have: Request class: import javax.validation.constraints.NotNull; import MandatoryFieldLengthCheck; public class InitiatePaymentRequest implements PaymentRequest { @NotNull(message = "Mandatory input field missing") @MandatoryFieldLengthCheck(value = 32) protected String

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

淺唱寂寞╮ 提交于 2019-12-06 10:08:22
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() { FormView view = new FormView(service.getForm()); return new MainView(view); } public class FormView

Does Dropwizard Support Servlet 3 Asynchronous Servlets?

走远了吗. 提交于 2019-12-06 05:55:55
问题 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

Spring configurable, high performance, metered http client instances

谁都会走 提交于 2019-12-06 05:48:29
问题 Coming from DropWizard I am used to its HttpClientConfiguration and I am baffled that in Spring Boot I cannot find some support for controlling in a similar manner http clients instances to be used, by RestTemplates for example. To work in production the underlying client implementation should be high performance (e.g. non blocking io, with connection reuse and pooling). Then I need to set timeouts or authentication, possibly metrics gathering, cookie settings, SSL certificates settings. All

Custom Jetty Filters in Dropwizard

眉间皱痕 提交于 2019-12-06 05:28:56
问题 I'm attempting to add a custom header filter in my Dropwizard instance to check to see if the request's version is synced to the Dropwizard instance's version. I see you can use FilterBuilder to add jetty CrossOriginFilters . However, I am having trouble figuring out how to set a custom filter. Thanks 回答1: Via the Environment class. https://dropwizard.github.io/dropwizard/manual/core.html#environments @Override public void run(MyApplicationConfiguration configuration, Environment environment)

Throttling a Rest API in Java

a 夏天 提交于 2019-12-06 05:17:28
问题 I wanted to add a way to throttle the number of requests coming on each API from a certain client. So, I wanted to basically limit the number of requests per API per client. I am using DropWizard as framework. Can somebody recommend the ways to achieve this? I need something that will work for Distributed system. 回答1: A simplistic approach would be to use a Filter and wrap it around all your API calls in web.xml . Assuming your clients send an API keys identifying them in a HTTP header, you

How to create and get started with Embedded Apache Derby database in Dropwizard project (Angular 7 front-end)

六眼飞鱼酱① 提交于 2019-12-06 04:25:07
I'm reading through Derby documentation and following all the instructions. I've successfully installed it (extracted it to my Linux machine and set the DERBY_HOME path). I have a complete REST API project with Angular 7 front-end and Dropwizard backend. I hard coded some data in the backend, and created all the HTTP API methods I need (GET, POST, PATCH, DELETE). The application is fully functional, but now I need to implement the Embedded version of Derby into it. I have 0 experience with such databases, and because Dropwizard gave me enough trouble already, I cannot figure out how to get

Exception Handling/Mapping for a particular class

末鹿安然 提交于 2019-12-06 04:21:11
I have resource class which itself's talks with a internal service. This resource acts a rest API for the service. The service layer can throw unexpected exceptions, thus the resource should handle those handled unexpected exceptions and log it. I am using dropwizard framework which in turns use jersey. It goes like this. @PATH(/user) @GET public Response getUser(@QueryParam("id") String userId) { assertNotNull(userId); try { User user = service.getUser(userId); return Response.ok(user).build(); } catch (MyOwnException moe) { //basically 400's return Response.status(400).entity(moe.getMsg())

How does @JsonView annotation can be used for nested entities?

﹥>﹥吖頭↗ 提交于 2019-12-06 03:03:22
I am trying to use @JsonView annotation for my nested entities. To be more clear, assume that, we have 2 entities, each entity have its own view class. public class JsonViewAddress { //some view classes } public class Address { //fields annotated by JsonViewAddress's classes and @JsonProperty } public class JsonViewPerson { //some view classes } public class Person { //some fields (yes annotated with JsonViewPerson classes and @JsonProperty) //also assume that this is annotated with any JsonViewPerson's class. private Address address; } Let's try to achieve this Person class with Json type