Pawan
Pawan

Reputation: 32331

Restful : How to get access to Httpsession inside the Service class?

I am using Jersey restful web services . This is my below code

@Path(/test)
public class testService  {
    @POST
    public String getData(Postdata postdata) {

    }

}

My question is , is it possible to get access to httpSession Object here in this class ??

Upvotes: 33

Views: 43746

Answers (2)

Paul Vargas
Paul Vargas

Reputation: 42060

If your service is NOT singleton, you can use:

@Path("/test")
public class TestResource  {

    @Context
    private HttpServletRequest request;

    @POST
    public String getData(Postdata postdata) {
        HttpSession session = request.getSession();
    }

}

Upvotes: 22

condit
condit

Reputation: 10962

Try:

@POST
public String getData(Postdata postdata, @Context HttpServletRequest request) {
  HttpSession session = request.getSession();
}

Upvotes: 45

Related Questions