Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Jersey (JSR311-Implementation) & Redirections

Tags:

java

rest

jersey

Is there a way to redirect the user-agent in a Jersey Resource?

In Spring MVC there's the "redirect:"-syntax but I didn't find anything comparable in Jersey's Viewable class. The only method I found working was using HttpServletResponse.sendRedirect().

like image 587
fasseg Avatar asked Jul 27 '10 08:07

fasseg


People also ask

What is Jersey implementation?

Jersey is Sun's production quality reference implementation for JSR 311: JAX-RS: The Java API for RESTful Web Services. Jersey implements support for the annotations defined in JSR-311, making it easy for developers to build RESTful web services with Java and the Java JVM.

Why is Jersey framework used?

RESTful service development (on Jersey) is an architecture, which inherently uses servlets. JAX-RS compliant tools like Jersey provide easy marshalling-unmarshalling of XML/JSON data, helping the developers. REST helps us use GET/POST/PUT/DELETE in a fashion that is far efficient than normal servlets.

What is the name of the reference implementation of the JAX-RS specification?

JAX-RS is a standard defined in Java Specification Request 311 (JSR-311) and Jersey / RESTEasy are implementations of it.


1 Answers

You have to return a Response object containing your status code and Location-header. The easiest way is to use javax.ws.rs.core.Response.temporaryRedirect(URI).

When using Viewable you might need to throw a WebApplicationException containing that Response object.

like image 145
Moritz Avatar answered Oct 06 '22 10:10

Moritz