Hello,
I have read that I can create an implementation of javax.ws.rs.ext.ExceptionMapper that will map a thrown application exception to a Response object.
I've created a simple example which throws an exception if the phone length is greater than 20 characters when persisting the object. I am expecting the exception to be mapped to...
I have a JAX-RS webservice that makes use of JPA entity classes. I have a resource class like this:
@Path("/entity")
public class MyEntityResource
{
@GET
@Produces(MediaType.APPLICATION_XML)
@Path("/{entity}")
public MyEntity getMyEntity(@PathParam("entity") String entity)
{
log.debug("Entering getMyEntity w...
The JAX-RS implementation Jersey supports MVC style web applications through the Viewable class, which is a container for a template name and a model object. It is used like this:
@GET
public Viewable get() {
return new Viewable("/index", "FOO");
}
I wonder how a status code could be returned with this approach. The above would impl...
There are examples on the web showing how to use the JAX-RS implementation Jersey with custom template engines like FreeMarker. But these examples are looking a bit improvised or dated. There is also one example relying only on JAX-RS and not Jersy specific classes. Is there a mature ViewProcessor implementation for FreeMarker or do I ha...
Spring MVC names objects that contain a logical view name and the payload to render ModelAndView, the JAX-RS implementation Jersey names them Viewable. I like Viewable a bit better, but maybe you have a better suggestion.
Example:
return new Viewable("index", payload);
How would you name a class, that combines a view (template) name ...
I am using @PathParam and the request format is like this,
@Path("/XXX/XXX/{testvariable:[\\s\\S]+}")
Here, testvariable can take values like http://google.com/myname.txt, 191.123.122.333 or in short a String with any special characters.
The regex that I used doesn't seem to allow the value "http://google.com/myname.txt" for this.
...
I would like to check in a JAX-RS webservice request that valid XML was included in the body. However, this code:
@PUT
@Produces(MediaType.TEXT_XML)
@Consumes(MediaType.TEXT_XML)
@Path("/{objectID}")
public MyObject updateMyObject(@PathParam("objectID") String existingObjectID, JAXBElement<MyObject> object)
{
MyObject udpatedObject...
How can I set the charset with JAX-RS? I've tried @Produces("text/html; charset=UTF-8") but that was ignored and only text/html was send with the HTTP header. I want to set the charset within a MessageBodyWriter, but don't want to extract the media type by analysing the @Produces annotation via reflection by myself.
...
Hi All,
I am using the JAX-RS REST service on a GlassFIsh server (JDK6 application). I secured my REST application with @RolesAllowed() annotations. I have a Dojo web client that need access to the REST resources. I am using FORM authentication on the REST server but happy to change it if there is a better way. When I access my resource...
How do I set the xml namespace when using Jersey, jaxb & jax-rs
...
I just heard about Apache Wink, and I was wondering what differences it had compared to Jersey or JBoss RESTEasy. What can be done in one that the other two can't?
We've been using Jersey for some of our internal projects mostly for it's simplicity, but I can't really figure out what makes these other two any better that I would consid...
I am going to build a many web services using weblogic and JAX-RS. To keep things simple I was going to place each service in its own project. But the problem I seem to be having is with setting the context-root for each project.
Can multiple projects that are deployed on the save weblogic server have the same context-root?
...
I'm using Jersey to implement a RESTful API that is primarily retrieve and serve JSON encoded data. But I have some situations where I need to accomplish the following:
Export downloadable documents, such as PDF, XLS, ZIP, or other binary files.
Retrieve multipart data, such some JSON plus an uploaded XLS file
I have a single-page JQ...
Hi all,
I've used a regular expression in @Path to achieve overloading and at first I thought it was really neat, but overloading methods is usually not good practice. Does the same apply to RESTful web services? Is there a better way to achieve this using JAX-RS?
So I can now call my getProject REST service by /project/ProjectNumber10...
Hi,
when serializing my resources on Jersey, I want to use namespaces in some cases.
Is there any way to customize the namespace prefixes on jersey?
Default:
<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<order xmlns:ns2="http://www.w3.org/2005/Atom">
<price>123</price>
<ns2:link rel="duh" href="/abc/123"/>
<ns2:l...
Hi,
is it possible to configure GET method to read variable number of URI parameters and interpret them either as variable argument (array) or collection? I know query parameters can be read as list/set but I can't go for them in my case.
E.g.:
@GET
@Produces("text/xml")
@Path("list/{taskId}")
public String getTaskCheckLists(@PathPara...
I read that the HTTP way to pass an array in a request is to set a parameter multiple times:
1) GET /users?orderBy=last_name&orderBy=first_name
However, I've also seen the comma-delimited parameter (and I feel this is "cleaner"):
2) GET /users?orderBy=last_name,first_name
I want to implement multi-sorting (ordering users by last_na...
Jersey identifies requests by looking at the accept header. I have a request which accepts only text/* - How can i force the response to be for example application/json?
@POST
@Path("/create")
@Produces(MediaType.APPLICATION_JSON)
public MyResponseObject create() {
return new MyResponseObject();
}
If a request is directed to creat...
I've got a Resource class that attempts to return an interface type, say "Shape":
public interface Shape {...}
@XmlRootElement
public class Circle implements Shape {...}
@Path("/api/shapes")
public class ShapeResource {
@GET
@Path("/{shapeId}")
public Shape get(@PathParam("shapeId") String shapeId) {
....
r...
The Java EE REST specifaction, JAX-RS, describes the translation of path variables to regexes, like in /customer/{id}.
From JAX-RS 1.1 Spec, page 19:
Replace each URI template variable with a capturing group containing the specified regular expression or ‘([ˆ/]+?)’ if no regular expression is specified.
The Java API doc of java.ut...