jersey-2.0

Jersey 2.6 Jackson provider registering

断了今生、忘了曾经 提交于 2019-11-30 17:37:31
I'm implementing REST web service with Jersey 2.6, I'm having troubles of registering a Jackson Provider for JSON support, I have implemented according to the jeresy documentation ( https://jersey.java.net/documentation/2.6/user-guide.html#json.jackson ). Add maven dependency - jersey-media-json-jackson Implemented a ContextResolver class. Annotated it with @Provider to enable "Auto-Discoverable Features" web.xml has the package name of the provider classes, so that Providers will be registered during the scan. ref: http://blog.dejavu.sk/2013/11/19/registering-resources-and-providers-in-jersey

Server-sent event does not work with jersey SSE

走远了吗. 提交于 2019-11-30 17:31:16
问题 I am trying to use JavaScript SSE from Jersey. I have Following code in my resource. I am hosting on Java7 and Tomcat 7. I dont get any error. But I don't see data either on page. I call /broadcast to post data. It does show message. But nothing comes on client. In Firefox, I do see /broadcast event fired multiple times. This is reference I used. https://jersey.java.net/documentation/latest/sse.html package net.jigarshah.dse.tracker; import javax.inject.Singleton; import javax.ws.rs.Consumes;

How to get list<String> as response from jersey2 client

感情迁移 提交于 2019-11-30 17:10:25
I want to know how I can extract a List<String> as response from the jersey-2.0 client. I have already tried this, List<String> list = client .target(url) .request(MediaType.APPLICATION_JSON) .get(new GenericType<List<String>>(){}); But, the above code is not working. It is not returning the expected List<String> but, a null value instead. You can get your service response as Response class object and, then parse this object using readEntity(...) method. Here is a quick code snippet: List<String> list = client .target(url) .request(MediaType.APPLICATION_JSON) .get(Response.class) .readEntity

How I return HTTP 404 JSON/XML response in JAX-RS (Jersey) on Tomcat?

别说谁变了你拦得住时间么 提交于 2019-11-30 16:50:27
I have the following code: @Path("/users/{id}") public class UserResource { @Autowired private UserDao userDao; @GET @Produces({MediaType.APPLICATION_XML, MediaType.APPLICATION_JSON}) public User getUser(@PathParam("id") int id) { User user = userDao.getUserById(id); if (user == null) { throw new NotFoundException(); } return user; } If I request for a user that doesn't exists, like /users/1234 , with " Accept: application/json ", this code returns an HTTP 404 response like one would expect, but returns Content-Type sets to text/html and a body message of html. Annotation @Produces is ignored.

How to get list<String> as response from jersey2 client

纵然是瞬间 提交于 2019-11-30 16:31:44
问题 I want to know how I can extract a List<String> as response from the jersey-2.0 client. I have already tried this, List<String> list = client .target(url) .request(MediaType.APPLICATION_JSON) .get(new GenericType<List<String>>(){}); But, the above code is not working. It is not returning the expected List<String> but, a null value instead. 回答1: You can get your service response as Response class object and, then parse this object using readEntity(...) method. Here is a quick code snippet:

How to write Unit Test for this class using Jersey 2 test framework

早过忘川 提交于 2019-11-30 16:14:23
问题 I am trying to write unit test for a Rest api call which is having a POST method for adding a video file to web based application using Jersey2. Here is the signature of the method of my class( TemplateController.java ) for which I want to write unit test: @POST @Path("/video/add") @Consumes(MediaType.APPLICATION_JSON) @Produces(MediaType.APPLICATION_JSON) public Response addVideoData( @Context HttpServletRequest request, AttachmentDTO attachmentDTO) { ... } Here is my test method of the test

Jersey custom SecurityContext on EJB jax-rs resource

独自空忆成欢 提交于 2019-11-30 15:23:44
I am trying to implement my own ContainerRequestFilter and configure SecurityContext . It works well on jax-rs resources but EJB jax-rs throws javax.ejb.AccessLocalException Only relevant thing I found is 4 years old and the workaround doesn't seem pretty. https://java.net/projects/jersey/lists/users/archive/2010-05/message/265 My custom SecurityContext: @Provider @PreMatching public class SecurityFilter implements ContainerRequestFilter { @Override public void filter(ContainerRequestContext filterContext) throws IOException { filterContext.setSecurityContext(new Authorizer()); } public class

jersey 2.7 issue while running it on apache tomcat 7.0

僤鯓⒐⒋嵵緔 提交于 2019-11-30 14:54:19
问题 I am creating a jersey application using apache tomcat 7.0 and eclipse. I have created a dynamic web project in eclipse and have defined a resource file as:- import javax.ws.rs.GET; import javax.ws.rs.Path; import javax.ws.rs.Produces; import javax.ws.rs.core.MediaType; // Plain old Java Object it does not extend as class or implements // an interface // The class registers its methods for the HTTP GET request using the @GET annotation. // Using the @Produces annotation, it defines that it

jersey 2.7 issue while running it on apache tomcat 7.0

点点圈 提交于 2019-11-30 12:33:30
I am creating a jersey application using apache tomcat 7.0 and eclipse. I have created a dynamic web project in eclipse and have defined a resource file as:- import javax.ws.rs.GET; import javax.ws.rs.Path; import javax.ws.rs.Produces; import javax.ws.rs.core.MediaType; // Plain old Java Object it does not extend as class or implements // an interface // The class registers its methods for the HTTP GET request using the @GET annotation. // Using the @Produces annotation, it defines that it can deliver several MIME types, // text, XML and HTML. // The browser requests per default the HTML MIME

Jersey version issue: MessageBodyReader not found for media type=application/xml

▼魔方 西西 提交于 2019-11-30 11:33:14
While writing a simple Jersey client that was consuming XML data, I came across this exception "MessageBodyReader not found for media type=application/xml". All of my settings, including the jersey-client as maven dependencies was just fine. The version that I was using was 2.17. Once I degraded the version to 2.15 it started working fine. Can anyone explain what dependencies that needs to be included for version 2.17 to work. Maven Dependency (works on 2.15 and lower) <dependency> <groupId>org.glassfish.jersey.core</groupId> <artifactId>jersey-client</artifactId> <version>${jersey.version}<