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.
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();
}
}
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