jersey

Getting JSON from Jersey with circular dependencies

。_饼干妹妹 提交于 2019-12-11 00:34:03
问题 I am writing a service that uses Jersey and JAXB. My classes are annotated with @XMLRootElement, @XMLElement, etc. I have a circular dependency between two classes, so I have annotated the circular dependent property with @XMLTransient. So when I call my service I get xml as the default, which works perfectly. However, when I try using JSON, I get repeated lines like: {"name":"dere","entries":[{"points":0,"wins":0,"losses":0,"ties":0,"leaderboard":{"name":"dere","entries":[{"points":0,"wins"

Processing same concurrent request in REST

谁说胖子不能爱 提交于 2019-12-11 00:22:54
问题 Greetings SO community! I have a REST, jersey based, application. This application(due to nature of it's clients) receives same http requests (3-6 of them) at roughly the same time (~2-5s apart). Each request takes around 10s to process and brings back a ton of data (hitting DB, doing data massaging etc). In an ideal world I'd like to avoid having to process the same request multiple times and was thinking of coding some sort of request filter that would only allow unique requests go through,

Applying interceptor to Jersey RESTful service wired as Spring @Component

我的梦境 提交于 2019-12-11 00:22:17
问题 Is it possible to apply a Spring handler interceptor or something similar to a Jersey Restful service? The Jersey service is built with Spring and is inside a Spring @Component? I noticed that Spring allows the use of handler interceptors for controllers but cant find anything to work with my Jersey-Rest component Thanks 回答1: Jersey comes with its own servlet and therefore is pretty much outside of Spring MVC, which the Interceptors are part of. You can either: Use a Spring HTTP Filter to

Spring transactional dont rollback when exception is mapped by ExceptionMapper

守給你的承諾、 提交于 2019-12-11 00:11:54
问题 I have a RESTFul service (implemented by jersey) . The service is marked with @Transactional. I declared an ExceptionMapper like this: @Provider public class ThrowableMapper implements ExceptionMapper<Throwable> { private static final Logger log = Logger.getLogger(ThrowableMapper.class); public Response toResponse(Throwable ex) { log.error("throwable", ex); return Response.status(500).entity("Internal Error").type("text/plain").build(); } } when exceptionmapper is not declared than

How do I define a “default” implementation in HK2?

萝らか妹 提交于 2019-12-10 23:59:49
问题 I am using HK2 to resolve dependencies of services in my Jersey / Jetty web service. I have a situation where for one particular interface, I want to use a specific implementation as a "default" implementation. By "default" I mean no names or qualifiers - it is what you get if you do not specify any annotations on top of the field or argument. However, in a few very specific situations, I want to provide an alternative implementation that will be qualified with an annotation. As a result of

CXF/Jetty equivalent of the following Jersey/Jetty code

廉价感情. 提交于 2019-12-10 23:39:19
问题 I've got some test code with Jersey (2.7) and Jetty (9.2.5.v2014112) that I'm trying to port to CXF (3.0.x) and Jetty (same version). There's one part that I can't figure out, the equivalent of the rc.register(resource) line below: ServletContextHandler sch = new ServletContextHandler(); sch.setContextPath("/xxx"); resource = new TheResource(); ResourceConfig rc = new ResourceConfig(); rc.register(resource); ServletContainer sc = new ServletContainer(rc); ServletHolder holder = new

use Jersey Library in a Android project

六月ゝ 毕业季﹏ 提交于 2019-12-10 22:22:56
问题 I try to implement a restful client on android via Jersey library. It works pretty well in a Java project. But when I do it in a android project, always come up an exception: could not find class "com.sun.jersey.api.client.config...." It seems that the library cannot be found even I have added it in the build path. 回答1: I believe Jersey currently is not ported to Android. But for example Restlet does explicitly support Android and also implements the same API (JAX-RS). 回答2: The jar file needs

HTTP Status 500 - Servlet.init() for servlet jersey-serlvet threw exception?

纵饮孤独 提交于 2019-12-10 22:00:40
问题 I'm trying create a Web Service RESTFUL using Jersey with Maven and Tomcat. When I do execute my webservice, does throws some exceptions and doesn't works. How could I solve it ? URL http://localhost:8080/FerpaWS/ws/cliente Service package br.com.ferpa.ws; import javax.ws.rs.Consumes; import javax.ws.rs.GET; import javax.ws.rs.Path; import javax.ws.rs.core.MediaType; import javax.ws.rs.core.Response; import org.json.JSONObject; @Path("/") public class Cliente { @GET @Path("/cliente")

How to access wicket session from Jersey-2 request filter?

一曲冷凌霜 提交于 2019-12-10 20:39:47
问题 In Jersey 1.x we accessed the Wicket session from a (Jersey) session attribute, as described here https://stackoverflow.com/a/15767824/1399659. In moving to Jersey 2.x it seems the proper pattern to use a ContainerRequestFilter, which also allows Spring bean injection as well. We have this working successfully by including <param-name>jersey.config.server.provider.packages</param-name> as an init-param to the ServletContainer and using the @Provider annotation on a ContainerRequestFilter

JacksonFeature breaks JsonIgnoreProperties

試著忘記壹切 提交于 2019-12-10 20:34:09
问题 I have pojo's like these: @JsonIgnoreProperties(ignoreUnknown = true) public class SNAPIResponse { public String status; public String message; public int errorCode; public ConsumerProfile consumerProfile; @JsonIgnoreProperties(ignoreUnknown = true) public static class ConsumerProfile { public String accountId; } } and my Jersey client works just fine even though the ConsumerProfile responses contain a lot of extra fields. Then I add a line: client.register(JacksonFeature.class); to my Jersey