Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Jersey URL forwarding

Inside a Jersey REST method I would like to forward to an another website. How can I achieve that?

@Path("/")
public class News {

    @GET
    @Produces(MediaType.TEXT_HTML)
    @Path("go/{news_id}")
    public String getForwardNews(
        @PathParam("news_id") String id) throws Exception {

        //how can I make here a forward to "http://somesite.com/news/id" (not redirect)?

        return "";
    }
}

EDIT:

I'm getting the No thread local value in scope for proxy of class $Proxy78 error when trying to do something like this:

@Context
HttpServletRequest request;
@Context
HttpServletResponse response;
@Context
ServletContext context;

...

RequestDispatcher dispatcher =  context.getRequestDispatcher("url");
dispatcher.forward(request, response);
like image 382
Don Grem Avatar asked Nov 23 '11 13:11

Don Grem


2 Answers

public Response foo()
{
    URI uri = UriBuilder.fromUri(<ur url> ).build();
    return Response.seeOther( uri ).build();
}

I used above code in my application and it works.

like image 162
Ajai S Avatar answered Oct 21 '22 12:10

Ajai S


Try this, it worked for me:

public String getForwardNews(

@Context final HttpServletRequest request,

@Context final HttpServletResponse response) throws Exception

{

System.out.println("CMSredirecting... ");

response.sendRedirect("YourUrlSite");

return "";

}
like image 25
user2167877 Avatar answered Oct 21 '22 12:10

user2167877