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()
.
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.
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.
JAX-RS is a standard defined in Java Specification Request 311 (JSR-311) and Jersey / RESTEasy are implementations of it.
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With