jersey

JAX-RS get entity as JAXB object and as String

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 origin...

Jersey implementing ContextResolver<JAXBContext> in Spring

So I am writing a Spring(2.5( + Jersey(1.1.4.1) and trying to create a JSONConfiguration using a ContextResolver. Here is the code: package com.rhigdon.jersey.config; import com.sun.jersey.api.json.JSONConfiguration; import com.sun.jersey.api.json.JSONJAXBContext; import javax.ws.rs.ext.ContextResolver; import javax.ws.rs.ext.Provide...

Passing an object to a REST Web Service using Jersey

I have a simple WS that is a @PUT and takes in an object @Path("test") public class Test { @PUT @Path("{nid}"} @Consumes("application/xml") @Produces({"application/xml", "application/json"}) public WolResponse callWol(@PathParam("nid") WolRequest nid) { WolResponse response = new WolResponse(); respo...

Java Async REST web service using Jersey?

Hi, I need to implement a Java REST Web Service (we use Jersey framework) which can basically either a. block waiting for some event (or poll for the event), before returning the response b. provide some kind of aysnc behaviour to notify the client when the request has been processed. I was thinking of returning a transationID, and ha...

How to fix Jersey POST request parameters warning?

I'm building a very simple REST API using Jersey, and I've got a warning in my log files that I'm not sure about. WARNING: A servlet POST request, to the URI http://myserver/mycontext/myapi/users/12345?action=delete, contains form parameters in the request body but the request body has been consumed by the servlet or a se...

JAX/Jersey Custom error code in Response

In Jersey, how can we 'replace' the status string associated with a known status code? e.g. return Response.status(401).build(); generates a HTTP response that contains: HTTP/1.1 401 Unauthorized I (not me, but the client application) would like to see the response as: HTTP/1.1 401 Authorization Required I tried the following a...

Multiple return type in Jersey Client request

Hi, I'm using Jersey Client API in the following way :- User user = webRsrc.accept(MediaType.APPLICATION_XML).post(User.class, usr); So I'm expecting the response in object of User class which is a JAXB annotated class. However, at times I might also get an error xml and for that I've created a JAXB class ErrorResponse. Now the pro...

Minimum Servlet API version for JAX-RS 1.1

What minimum version of the Servlet API is required to run JAX-RS 1.1 (for example Jersey 1.1)? ...

Jersey client not sending UTF-8 characters

Hi guys, We're using Jersey 1.0.3 to implement a REST client. This client needs to post an XML envelope containing UTF-8 characters. When debugging, we can clearly see that the entity that is being sent is correct. However, the request that is being sent changes the entity and garbles non-ASCII characters. We've dug into the Jersey sour...

How to generate JSON from a Jersey resource?

I'm using Jersy and want to output the following JSON with only the fields listed: [ { "name": "Holidays", "value": "http://www.google.com/calendar/feeds/usa__en%40holiday.calendar.google.com/public/basic" }, { "name": "Personal", "value": "http://www.google.com/calendar/feeds/myprivatefeed/basic" ...

Jesey Oauth client and "%20" spaces

HI all. I am trying to use the Sun Jersey Client API with Jesey Oauth to connect to twitter. Lets say I already have the oauth token and token secret. String accessToken = MY_TOKEN; String accessTokenSecret = MY_TOKEN_SECRET; String url = "http://twitter.com/statuses/update.xml"; // initialize the params and secret. OAuthParameters p...

Using the Jersey client to do a POST operation

Hello, In a Java method, I'd like to use a Jersey client object to do a POST operation on a RESTful web service (also written using Jersey) but am not sure how to use the client to send the values that will be used as FormParam's on the server. I'm able to send query params just fine. Thanks in advance. ...

HTTPS using Jersey Client

How do I send GET requests using the Jersey Client API to a server which runs on the HTTPS protocol. Is there any sample code that I can use ? ...

How do you return multipart content from a JAX-RS web service?

I'd like to avoid embedding HTML in XML returned from my JAX-RS web service, but still be able to return both XML and HTML in the response to a single GET. Is there a way to do this? Is it a bad idea? Right now I am doing 2 separate GET's for different resources one XML one HTML - however since both resources are always retrieved toget...

Parameters not added in Uri

Hi, i want to build an Uri for an Webservice. I use the UriBuilder and want to add the parameters to the URI. The paramameters are saved in an MultivaluedMap. @GET @PathParam("/{callUrl}/{parameters}") public static String buildGetUri(@PathParam("callUrl") String callUrl, @PathParam("parameters"...

Jersey w/ Spring 3.0?

I see some are using Jersey w/ Spring. With Spring 3.0 there are now annotations available to make RESTful APIs directly in a controller. Why should I consider using Jersey w/ Spring? ...

RESTful resource not found. 404 or 204? Jersey returns 204 on null being returned from handler.

If you are looking for /Resource/Id and that resource does not exist, I had always though that 404 was the appropriate response. However, when returning "null" from a Jersey handler, I get back a "204 No Content". I can likely work with either one, but am curious to others thoughts on this. To answer my own next question. To get jersey ...

Jersey Resource class interaction?

So, I'm coming up to speed on Jersey and have a "best practice" question. How strict should keep the resources self contained in one file. Should one resource class reference another class if needed? An example: I have a Person resource and an Appointment Resource. (ie: /Person/1 & /appointment/12345). I can also do something like /Per...

How can I customize serialization of a list of JAXB objects to JSON?

I'm using Jersey to create a REST web service for a server component. The JAXB-annotated object I want to serialize in a list looks like this: @XmlRootElement(name = "distribution") @XmlType(name = "tDistribution", propOrder = { "id", "name" }) public class XMLDistribution { private String id; private String name; // no...

JAXB and Jersey list resolution?

I have the following XSD defined to generate some jaxb objects. It works well. <xsd:element name="Person" type="Person" /> <xsd:complexType name="Person"> <xsd:sequence> <xsd:element name="Id" type="xsd:int" /> <xsd:element name="firstName" type="xsd:string" /> <xsd:element name="lastName" type="xsd:string" ...