Search code examples
restsessionliferay-7

Liferay 7.2 Api Rest Session parameter


I have Liferay 7.2.

I created a module rest.

It is possibile to save a variable in session ad use it in other method?

My idea of code is:

@GET
@Path("/save/paramt")
            
public String jsonSaveParamRequest() throws Exception {

String json = "xx";

//SAVE IN SESSION json

return "ok";
}

@GET
@Path("/get/paramt")        
public String jsonGetParamRequest() throws Exception {
String xx= SESSION VARIABLE json

return xx;
}

Solution

  • Saving state in a HTTP session in a REST API is not recommended and should be avoided. Please refer to the discussions here SO:how-to-understand-restful-api-is-stateless.

    Technically, I guess this is possible as you can inject the HttpServletRequest as a method param via @Context HttpServletRequest request to your annotated method and use getSession(). But I am not sure if you can rely on that.