4

I need to redirect to a specific external url in my jersey web service

and I am using this method:

    public static Response redirectTo(String path) {
    URI uri;
    try {
        uri = new URI(path);
        return Response.seeOther(uri).build();
    } catch (URISyntaxException e) {
        e.printStackTrace();
        return null;
    }
}

But it navigates to a white screen page and not to stackoverflow.com.

Why is it happening and how to fix it?

This method is called inside this method

@GET
    @Path("/login")
    @Consumes({MediaType.APPLICATION_XML, MediaType.APPLICATION_JSON})
    public Response login(@Context UriInfo info, @Context HttpServletRequest request) {
...
String url = "http://stackoverflow.com";
redirectTo(url); 
}

the url of login method is called when triggering an event from AppDirect (via browser)

alexbt
  • 16,415
  • 6
  • 78
  • 87
eeadev
  • 3,662
  • 8
  • 47
  • 100
  • You probably need to provide more details. What do you mean by a white screen? Which client you use to access the REST resource which is supposed to return 303 with the `Location` header? How do you use this client to call this resource? Have you tried `curl` and checked whether it returns 303 with the `Location` header as expected? – Stepan Vavra May 27 '16 at 10:02
  • I edited the question, no I didnt try the curl – eeadev May 27 '16 at 12:17

1 Answers1

1

I ended up in adding the @Context HttpServletResponse res parameter to my method and calling this method res.sendRedirect(urlApp);

This is working as expected.

eeadev
  • 3,662
  • 8
  • 47
  • 100