I'm trying to archieve the following:
1) end user will post to a servlet(lets call it GW) - the GW will store his session for the following requests to come.
2) for every request received by the GW , The GW will post to another servlet(will call it API)
3) only the GW can post to the API (SSL secured), and both will have a fixed IP(though it has nothing to do with this issue)
4) for every request posted to the API, the API must also maintain a session for future requests.
5) GW is posting to API using the following implemetation:
try {
HttpPost httppost = new HttpPost(uri);
CookieStore cookieStore = new BasicCookieStore();
HttpContext httpContext = new BasicHttpContext();
httpContext.setAttribute(ClientContext.COOKIE_STORE, cookieStore);
HttpResponse response = httpclient.execute(httppost, httpContext);
} finally {
httpclient.getConnectionManager().shutdown();
}
6) API will receive requests as follows:
public void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
HttpSession session = req.getSession(false);
// isSessionValidFromURL = req.isRequestedSessionIdFromURL();
// isSessionValidFromCookie = req.isRequestedSessionIdFromCookie();
isSessionValid = req.isRequestedSessionIdValid();
if (isSessionValid) {
...
...
}
...
}
7) in API, if the request is a new request it will create a new session, will store parameters in DB and build the globals and more..
The problem is: after login (GW sends login to API) command sent,the API create new session so far so good. On the second command it fails to validate the session on the following lines of code:
isSessionValid = req.isRequestedSessionIdValid();
isSessionValidFromURL = req.isRequestedSessionIdFromURL();
isSessionValidFromCookie = req.isRequestedSessionIdFromCookie();
all returns false. I tried to send the session id using a cookie mechanism as shown above, and tried sending the received session id from the url without a success.
In addition,I've tried this and this without success. Thanx
EDIT : Solution: This wonderful Post passes it via url (Its SSL so its won't be a security breach)