I have been using Google Cloud Endpoints successfully. Now for custom auth, I want to use HTTPSession. The problem is that the initial session is not reused in future calls, and a new session is created (I see that from the data warehouse administrator the whole session exists, object _AH_SESSION). As stated in the docs, I included it in appengine-web.xml:
<sessions-enabled>true</sessions-enabled>
I made some code examples to narrow it down:
@Api(name = "loginService", version = "v0.1.5")
public class LoginService {
private static final Logger log = Logger.getLogger(LoginService.class.getName());
@ApiMethod(name = "login", path= "login")
public LoginResponse login(HttpServletRequest req)
{
HttpSession session = req.getSession(false);
if(session == null){
log.warning("creating new session");
session = req.getSession(true);
}
LoginResponse resp = new LoginResponse();
resp.statusCode = 200;
resp.statusMessage = "SessionId:" + session.getId();
return resp;
}
@ApiMethod(name = "show", path= "show")
public LoginResponse show(HttpServletRequest req)
{
HttpSession session = req.getSession(false);
LoginResponse resp = new LoginResponse();
resp.statusCode = 200;
resp.statusMessage = "SessionId:" + session.getId();
return resp;
}
public class LoginResponse implements Serializable{
public int statusCode;
public String statusMessage;
}
} `
, , . ( Postman - ) Chrome, API) "show", , , nullpointer.
mikO , . ? . "" appengine, Postman .. (, , , ), , , , . :
public class LoginServlet extends HttpServlet {
private static final Logger log = Logger.getLogger(LoginServlet.class.getName());
public void doGet(HttpServletRequest request,
HttpServletResponse response)
throws ServletException, IOException {
HttpSession s = request.getSession(false);
if (s == null) {
log.warning("creating new session");
s = request.getSession(true);
}
response.setContentType("text/html");
PrintWriter out = response.getWriter();
out.println("<h1>" + s.getId() + "</h1>");
}
}
!