jax-rs

Add Response Header to JAX-RS Webservice

I am trying add some response headers to some of my webservice calls. I wrote my webservice using CXF 2.1.2 and JAX-RS. I need to return an object and I also want to add some headers to the Response. Without returning a javax.ws.rs.core.Response object, how do I add a header to the response and still return my javabean? ...

How is dispatching controlled in JAX-RS?

I'm writing a RESTful Web Service with RESTeasy. This is an implementation of JAX-RS. You annotate a class or method with a single @Path annotation. Regular expressions are used to get path parameters. For instance @Path("/foo{varname:.*}/bar") matches all patterns starting with "/foo", ending with "/bar" and having anything in be...

Which is the best Java REST API - Restlet or Jersey?

Which REST API do you prefer - Jersey or Restlet? This would encompass both the client and server API-s. We really need to just pick one and kick the tires around but I was curious what the community thinks. Restlet seems simpler and better documented to me. I've had a hard time even finding decent documentation about the Jersey clie...

cxf.jaxrs: IllegalArgumentException when using JAXRSServerFactoryBean

I ran into the following issue when setting up a JAXRS test service in a unit test. This is the code (taken from an AbstractJUnit4SpringContextTests-derived test class): JAXRSServerFactoryBean sf = new JAXRSServerFactoryBean(); sf.setServiceBeans(applicationContext.getBean("searchXY")); sf.setAddress("http://localhost:9000/"...

JAX-RS interface markup and @Context injection

Consider the following simple RESTEasy (JAX-RS) service: @Path("/example-service") public interface ExampleService { @Path("/ping") @GET public String ping(String message); } I want to define JAXRS specifics on the interface rather than the class so I can use the nice client framework, ie: ExampleService client = ProxyF...

jersey Viewable and c:import tag lib

Giver a resource class that has a method witch returns a Viewable (or generaly any jsp page). Is there a way to use the c:import or jsp:include taglib to include a Viewable response from a jaxrs anotatted class? For example given the class @Path("/some/path") public class SomeJaxrsResource { @GET public Viewable get() { return n...

How to model parent-child entities via REST and JAX-RS

I am working on a REST based API, and having some trouble figuring out what the canonical way is to represent parent / child relationships. (I am writing beans in CXF and using JAX-RS and JAXB. I started from the basic example provided by CXF) My problem is let's say you have a Foo and a Bar. There is a 1-N relationship with Foo and ...

Get ServletContext on tomcat from jax-rs / jersey

I'm playing around with jax-rs , deploying on tomcat (handling via com.sun.ws.rest.spi.container.servlet.ServletContainer). It's basically @Path("/hello") @Produces({"text/plain"}) public class Hellohandler{ @GET public String hello() { return "Hello World"; } } Is there any way I can get hold of the ServletContext w...

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

RESTEasy client framework authentication credentials

RESTEasy (a JAX-RS implementation) has a nice client framework, eg: ServiceApi client = ProxyFactory.create(ServiceApi.class, baseUri); How do you provide HTTP authentication credentials to this client? ...

JAX-RS, Map<String,String> to JSON without the overhead?

Hi! I'm using JAX-RS to create restful webservices in Java. I am getting to much overhead in the produced JSON. Data class: @XmlRootElement @XmlAccessorType(XmlAccessType.FIELD) public class Test { private Map<String,String> data; Test() {} public Test(Map<String,String> data) { this.data = data; } publ...

Marshall/Unmarshall a JSON to a Java class using JAXB

I am successfully marshaling a POJO into JSON using JAX-RS and JAXB annotations. The problem is that when I am trying to use the same for un-marshalling my request it doesn’t work. As far as I can see in the documentation JAX-RS can automatically marshal and unmarshal application/json strings back to java classes. Do I need to create m...

URL matrix parameters vs. request parameters

I'm wondering whether to use matrix or query parameters in my URLs. I found an older discussion to that topic not satisfying. Examples URL with query params: http://some.where/thing?paramA=1&amp;paramB=6542 URL with matrix params: http://some.where/thing;paramA=1;paramB=6542 At first sight matrix params seem to have only advantages:...

State of the art Java web framework for RESTful GUI apps?

Yes, I know, the old question of the best web framework ... but let me explain. I'm looking for Java Servlet based web framework that allowes RESTful interaktion and is also suitable to build web GUIs. What I want: REST support with http content negotiation and nice URL mapping data conversion from request params to domain object (an...

Does JAX-RS require data transfer objects (DTO)?

If a method of a JAX-RS application would return a domain object, the representation (say JSON) would contain all attributes of this object - right? But what if this object would contain "private" data, that shouldn't be exposed to the web? And what is about the other direction from outside in: how could be prevented that private fields...

Issue Unmarshalling Map with JAX RS using JACKSON

Hi! I have a method definition as such: @POST @Path("save") @Consumes("application/json") public void save(Map<ClientVO, Map<AssessmentVO, String>> data){ System.out.println("THIS IS THE DATA: " + data); } When I try to unmarshall on the server, I get the following exception Exception in thread "main" org.jboss.resteasy....

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)? ...

How to deploy a JAX-RS application?

The JAX-RS 1.1 specification says on page 6: If no Application subclass is present the added servlet MUST be named: javax.ws.rs.core.Application What is the added servlet? Could it be an arbitrary servlet? If an Application subclass is present and there is already a servlet defined that has a servlet initialization pa...

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 use CXF, JAX-RS and HTTP Caching

The CXF documentation mentions caching as Advanced HTTP: CXF JAXRS provides support for a number of advanced HTTP features by handling If-Match, If-Modified-Since and ETags headers. JAXRS Request context object can be used to check the preconditions. Vary, CacheControl, Cookies and Set-Cookies are also supported. I'm really interes...