jersey-2.0

Specify Custom Application Context

时光毁灭记忆、已成空白 提交于 2019-12-04 01:41:55
We are migrating some of our data services from Jersey 1.x using jersey-spring to Jersey 2.x using jersey-spring3. We have a few test classes that inherit from JerseyTest. Some of these classes use custom applicationContext.xml files that are not specified in the web.xml file. In Jersey 1.x the test classes that extended JerseyTest could call the super constructor with a WebappDescriptor.Builder to which a context parameter could be passed to set or override the application context path. E.g. public MyTestClassThatExtendsJerseyTest() { super(new WebAppDescriptor.Builder("com.helloworld")

WARNING: The (sub)resource method contains empty path annotation

只谈情不闲聊 提交于 2019-12-03 22:16:46
I have configured rest path like "/v1/" and the endpoint configured in servlet like '/test/'. Now I removed the "/v1" from the java class "Test". org.glassfish.jersey.internal.Errors logErrors WARNING: The following warnings have been detected: WARNING: The (sub)resource method test in com.abc.services.Test contains empty path annotation. I got the above warning after make this change. How to handle this warning? And I want this "/v1" removing changes for across 10 rest paths. So anyone help me to run without warnings? The warning means you have a resource method annotated with @Path("/") or

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,

Connection reset on Jersey with Java 7

别来无恙 提交于 2019-12-03 20:30:32
I'm trying to call an https link with the webTarget of jersey 2.22.2. The code is that: Client client = ClientBuilder.newBuilder().build(); WebTarget target = client.target(uri); MultivaluedMap<String, Object> headers = new MultivaluedHashMap<String, Object>(); headers.add("Content-Type", "application/json"); headers.add("id", id); headers.add("key", key); Response response = target.request().headers(headers).get(Response.class); In Java 8 it's work great, but in Java 7 it's give me this Connection reset Exception. javax.ws.rs.ProcessingException: java.net.SocketException: Connection reset at

Register ServletContainer programmatically in Osgi

﹥>﹥吖頭↗ 提交于 2019-12-03 16:48:11
I'm developing a JAX-RS application with OSGI where resources are loaded dynamically. For this, I need to register the ServletContainer programmatically, then I can call the method ServletContainer.reload (ResourceConfig). I'm running on OSGI environment with support for servlet 3.x, using PAX-WEB 3.0.2 and Jersey 2.4. The problem is when I want to access a resource that implements Server Sent Event, Jersey raises an error that does not support asynchrony because it runs in a Servlet 2.x. Here the exception: 2013-11-05 00:22:37,675 | WARN | qtp27902282-62 | ServletHandler | pse.jetty.servlet

How can I cleanly override the default ServiceLocator used by Jersey?

流过昼夜 提交于 2019-12-03 16:41:15
I am developing an application that uses Jersey (2.5) as its REST front-end, and Jetty as embedded HTTP(S) server, both in a so-called "embedded" way, eg. without resorting to making .war and deploying it but through programmatic configuration of handlers, resources, injections... I would like to somehow override the HK2 ServiceLocator that is used on the server side by Jersey, or possibly provide this service locator with a parent for resolving dependencies that are defined outside of the REST part of the application. From what I see of the code, this does not seem possible: The

Jersey 2.7 - setting retry handler

Deadly 提交于 2019-12-03 15:38:40
I would like to set a retry handler for Jersey client utilizing ApacheConnector . I wish to do it, because I want it to retry on timeout (my HAProxy will switch it to another server). I have no clue how to do this in Jersey 2.7 . Example code: public static void Example() { ClientConfig clientConfig = new ClientConfig(); clientConfig.connectorProvider(new ApacheConnectorProvider()); clientConfig.property(ApacheClientProperties.CONNECTION_MANAGER, new PoolingHttpClientConnectionManager()); RequestConfig reqConfig = RequestConfig.custom().build(); clientConfig.property(ApacheClientProperties

Jackson not consuming the JSON root element

核能气质少年 提交于 2019-12-03 15:27:08
I'm using JAX-RS + Jersey to consume the web-service request and Jackson to translate JSON data: @Path("/") public class JAXRSRestController { @Path("/jsonRequest") @POST @Consumes(MediaType.APPLICATION_JSON) public Response submitJsonRequest(SampleObject sampleObject, @Context HttpHeaders headers) { Ack ack = new Ack(); ack.setUniqueId(sampleObject.getId()); ack.setType(sampleObject.getName()); return Response.ok().entity(ack).build(); } } Here if the request is in the below format, it would not be consumed: { "sampleObject": { "id": "12345", "name": "somename" } } But if the request is in

Jersey 2.1 + JBoss 7.1 NoSuchMethodError: getProperties

懵懂的女人 提交于 2019-12-03 14:59:45
I am trying to run Jersey 2.1 REST service on JBoss 7.1 AS. I am getting the NoSuchMethodError: javax.ws.rs.core.Application.getProperties error during deployment: ERROR [org.apache.catalina.core.ContainerBase.[jboss.web].[default-host].[/RESTService]] (MSC service thread 1-9) StandardWrapper.Throwable: java.lang.NoSuchMethodError: javax.ws.rs.core.Application.getProperties()Ljava/util/Map; at org.glassfish.jersey.server.ApplicationHandler.<init>(ApplicationHandler.java:271) [jersey-server-2.1.jar:] at org.glassfish.jersey.servlet.WebComponent.<init>(WebComponent.java:283) [jersey-container

Registering JacksonJsonProvider with ObjectMapper + JavaTimeModule to Jersey 2 Client

∥☆過路亽.° 提交于 2019-12-03 12:34:58
I'm trying to marshal response containing ISO formatted timestamp like that: { ... "time" : "2014-07-02T04:00:00.000000Z" ... } into ZonedDateTime field in my domain model object. Eventually it works if I use solution that is commented in following snippet.There are many similar questions on SO but I would like to get a specific answer what is wrong with another approach which uses JacksonJsonProvider with ObjectMapper + JavaTimeModule ? ObjectMapper mapper = new ObjectMapper(); mapper.registerModule(new JavaTimeModule()); JacksonJsonProvider provider = new JacksonJsonProvider(mapper); Client