Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Jersey: redirect outside of Jersey root

I've been writing a prototype Jersey (JAX-RS) application and wanted to try handling application/x-www-form-urlencoded posts with a redirect-after-POST methodology.

I want to redirect to an html page hosted at the application root on success, however I can't seem to escape out of Jersey's servlet root.

Here's an example of a resource which allows you to create a new user:

URI I want: /jersey-test/user.html

URI I get: /jersey-test/r/user.html

@POST
@Consumes({MediaType.APPLICATION_FORM_URLENCODED})
public Response putUser(@Context UriInfo uriInfo, 
    MultivaluedMap<String, String> formParams) {

    // snip... do work and insert user here...

    URI uri = uriInfo.getBaseUriBuilder().path("user.html").build();
    return Response.seeOther(uri).build();
}

Relevant snippets from my web.xml:

<web-app ...>
  <display-name>jersey-test</display-name>
  ...
  <servlet>
    <servlet-name>Jersey REST Service</servlet-name>
    <servlet-class>com.sun.jersey.spi.container.servlet.ServletContainer</servlet-class>
    ...
  </servlet>
  ...
  <servlet-mapping>
    <servlet-name>Jersey REST Service</servlet-name>
    <url-pattern>/r/*</url-pattern>
  </servlet-mapping>
</web-app>
like image 331
JavadocMD Avatar asked Feb 28 '13 20:02

JavadocMD


1 Answers

Assign the path like this:

URI uri = uriInfo.getBaseUriBuilder().path("../user.html").build();
like image 165
Valeh Hajiyev Avatar answered Oct 31 '22 21:10

Valeh Hajiyev