Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How can I retrieve the session ID from within a JAX-RS webservice?

I cannot figure out how to retrieve the session ID from a given JAX-RS webservice request. I assume it is available, but I do not know how to retrieve it.

I am NOT using CXF. I would be grateful for any assistance.

like image 359
TimC Avatar asked Jan 27 '11 17:01

TimC


1 Answers

You can use the @Context annotation to get the current instance of the HttpServletRequest.

@Path("/session-id.txt")
public class SessionIdResource {

    @GET
    @Produces(MediaType.TEXT_PLAIN)
    public String getSessionId(@Context HttpServletRequest request) {
        return request.getSession(true).getId();
    }
}
like image 60
sdorra Avatar answered Nov 04 '22 01:11

sdorra