What does the error "JSESSIONID not specified or invalid" mean?
When you see an invalid SESSIONID during a chat session, it is because you are not passing back the correct sessionid in the <SessionID> element.
The error you will see is "JSESSIONID not specified or invalid".
If so, be sure you are passing the SessionID that you would have received from the RequestChat call in the RequestChatResponse. It sounds like it is not in sync at some point.
When you call RequestChat, you will get a RequestChatResponse message. This response will include the SessionID that you will need for RetrieveMessages, as well as PostChatMessage, and TerminateChat. This SessionID needs to be included in the ChatClientInfoHeader.
<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:v1="urn:messages.common.chat.ws.rightnow.com/v1" xmlns:v11="urn:messages.enduser.chat.ws.rightnow.com/v1">
<AppID>Sample Chat Client</AppID>
For a more complete example, see Answer ID 8129: Chat API Example Chat Session