I created a web service on which I used @Stateless annotation i.e
@Stateless
@Path("/boo/too")
public class RestController {
@Context
private HttpServletRequest request;
@Context
private ServletContext context;
@GET
@Path("/coo")
@Consumes({MediaType.APPLICATION_JSON})
@Produces({MediaType.APPLICATION_JSON})
public GetResObj getFuncName(
@HeaderParam("foo") String foo,
@QueryParam("boo") String boo
) throws Exception{
MyClass className =(ClassCast) request.getSession().getAttribute("myClassInstance");
}
Now from some reading i have done and the accurate answer to this question : question
, I understand that a Stateless object is an object which can have variables but it's immutable (can't hold any state). When using the @Stateless annotation the request.getSession()
part of code throws a nullPointerException . When i remove the @Stateless annotation the request.getSession()
works fine .
Can you see why is this happening ?