jersey

Jersey client async POST request to not wait for response

断了今生、忘了曾经 提交于 2019-12-07 10:39:13
问题 I have created a simple Jersey client and it is able to successfully do a POST request with a payload. But right now it waits for a response from the http endpoint: public void callEndpoint(String endpoint, String payload) { try { ClientConfig config = new DefaultClientConfig(); Client client = Client.create(config); WebResource webResource = client.resource(getBaseURI(endpoint)); log.debug("Sending payload [" + payload + "] to URL - [" + getBaseURI(endpoint) + "]"); // POST method - Is this

JAX-RS and Long Polling

强颜欢笑 提交于 2019-12-07 10:36:16
问题 I'm trying to use long polling with JAX-RS (Jersey implementation) and it doesn't work as I expect. Maybe I'm misunderstanding something. I would appreciate any advice. Please note that using a reverse connection (something like Atmosphere, Comet, etc) is not a option for security reason. Not that I'm currently developing with Tomcat 7. The following method is invoked from a JQuery Ajax call (using $.ajax ). @Path("/poll") @GET public void poll(@Suspended final AsyncResponse asyncResponse)

JAX-RS get entity as JAXB object and as String

十年热恋 提交于 2019-12-07 10:33:03
问题 I have a JAX-RS web service (using jersey) that accepts a JAXB object as the request entity. When we get an error, we want to log the original xml string that was sent to us. Currently, I am just re-marshalling the JAXB object, but since we have several java enums in those classes, enum values that are not spelled correctly in the original xml string are lost, which is not acceptable for our purposes. Does anyone know a way to get the request entity as both a string and JABX object? I would

Why is injecting a SecurityContext into a Jersey Singleton thread safe?

丶灬走出姿态 提交于 2019-12-07 10:29:36
问题 In the Jersey documentation, Example 16.2 shows an example of injecting a SecurityContext into a Jersey resource singleton. Surely the docs are correct, and the example given is indeed thread safe. I suspect that the injection of the SecurityContext happens exactly once, and when getUserPrincipal() is called, perhaps it picks up user data from some structure that is attached to the thread itself (maybe a ThreadLocal object?). That's the only way I can see that the correct user info be served

Access Jersey based RESTful service using jQuery

纵饮孤独 提交于 2019-12-07 10:27:05
问题 I am trying to access RESTful service, created on Java and deployed with help of Jersey using jQuery. If I access it using browser I will get the result, but from jQuery, I am getting an error and can not see any results on the page. Page with the script is hosting on local Apache server and the Service is running separately using Jersey/Grizzly on the same machine. I can see that service is sending the response and it has 200 code, but I keep getting error from .ajax, without any details and

Cross domain REST/Jersey web services with CORS

喜夏-厌秋 提交于 2019-12-07 10:22:14
问题 I want to make Cross domain REST web services with CORS(Cross-Origin Resource Sharing). I am using Jersey Libraries for making services. I need to know What code/configuration changes i need to do from server side perspective? How to invoke this services from HTML5/js. Thanks 回答1: All the information for your server side configuration can be found at enable-cors.org. There is no need to change any code clientside, but I would recommend checking the Browsers capability for CORS before using it

Moxy ignore invalid fields in json

不打扰是莪最后的温柔 提交于 2019-12-07 10:08:15
问题 When I send this request: {"invalidField": "value", "date": "value"} to my rest service: @PUT @Consumes("application/json") public void putJson(Test content) { System.out.println(content.toString()); } I expected to get an exception because: There is no invalidField in my domain model. Date format is not valid. But really I get test object with null values. My dmain model is: public class Test { private String name; private Date date; //getters and setters here } I think this is not a valid

JAX-RS REST Services as a library

核能气质少年 提交于 2019-12-07 09:17:25
Is it possible to package my rest resource classes in a .jar library so that when they are included in someone's app that app gets the services? i am currently using jersey (jersey.dev.java.net) Well, I don't see why it won't work GRANTED that person defines the rest servlet in their web.xml to locate your REST package from the jar... like this:- <servlet> <servlet-name>Jersey Rest Web Service</servlet-name> <servlet-class>com.sun.jersey.spi.spring.container.servlet.SpringServlet</servlet-class> <init-param> <param-name>com.sun.jersey.config.property.resourceConfigClass</param-name> <param

Authentication in Jersey

一世执手 提交于 2019-12-07 09:16:21
问题 I want to implement authentication for my Jersey0based server/client REST but I'm not sure how exactly to lay out the code. Basically for every operation I have 2 methods - 1 from the server side, 1 from the client side. I've narrowed down the algorithm - I'm going to use the amazon strategy with HMAC. The question is how to lay out this in the code - should I add the authentication (encryption/decryption code) into every method - both server/client side or should I have one "dispatch" method

Jersey GenericEntity Not Working

孤街醉人 提交于 2019-12-07 08:47:32
问题 I am using Jersey's GenericEntity to return a list as json. However I'm getting the exception A message body writer for Java type, class java.util.Arrays$ArrayList, and MIME media type, application/xml, was not found 16-May-2011 11:16:31 com.sun.jersey.spi.container.ContainerResponse traceException SEVERE: Mapped exception to response: 500 (Internal Server Error).... I know this means that Jersey is not setup to map to json properly. Where do I need to give more information to jersey. I am