>Date: Tue, 30 May 2000 00:24:34 +0100
>From: "Nic Ferrier" <[EMAIL PROTECTED]>
>To: [EMAIL PROTECTED]
>Subject: Re: session invalidation
>Mime-Version: 1.0
>Content-Disposition: inline
>
>>>> slb <[EMAIL PROTECTED]> 29-May-00 11:23:49 PM >>>
>
>>If my servlet opens a socket to another host while in an
>>active session with a user from a browser, the http session
>>is invalidated - at least that seems to be the result of my
>>testing so far with Tomcat 3.1. Why is that so? Is it just
>>opening a socket? Writing to it? Some other magic?
>
>This shouldn't happen.
>
>Post the relevant part of your code and I (or someone else) may be
>able to help.
>
>
>Nic
Ok, I'll try to put in enough snippets to demonstrate:
first, in the controlling servlet, some beans are put into
the session. Once all the beans are filled, I create
another thread and start it going to process a transaction.
I log the session create time just before the thread gets
kicked off, so I know it's valid at that point.
-------
HttpSession mySession = request.getSession(true);
.....
mySession.setAttribute("DeptInputBean",dib);
mySession.setAttribute("CCBean",cb);
mySession.setAttribute("AddressBean",ab);
ServletContext context = getServletContext();
if (dib.isGoodDeptInput()) {
if (cb.isGoodCCBean() &&
(!dib.getDoAVS() || ab.isGoodAddress())) {
myEnv.getLogWriter().log("Session in control " +
mySession.getCreationTime(),LogWriter.DEBUG);
Charge charge = new Charge(mySession,myEnv);
Thread chargeThread = new Thread(charge);
chargeThread.start();
rd = context.getRequestDispatcher(response.encodeURL("/Done.jsp"));
} else {
if (dib.getDoAVS())
rd = context.getRequestDispatcher(response.encodeURL("/GetCCAddr
ess.jsp"));
---------
Then in the thread, I am building an XML transaction that I want
to send along to an external gateway. I get the builder class,
build the transaction, and then call on the builder to send
itself like this (I've left out some of the try/catch lines
they just log errors for now (and I'm not getting anything in
the log from them anyway). The second call to getCreationTime
below always throws an invalid state exception saying
the session is already invalidated, so something happens
in cgw.sendRequest to invalidate the session.
-------
gatewayClass = Class.forName(deptBean.getGatewayClass());
cgw = (ChargeGW)(gatewayClass.newInstance());
myEnv.getLogWriter().log("Session in start " +
mySession.getCreationTime(),
LogWriter.DEBUG);
GWResponse gwResponse =
cgw.sendRequest(ccBean, deptBean, addressBean,myEnv);
myEnv.getLogWriter().log("Session in start2 " +
mySession.getCreationTime(),
LogWriter.DEBUG);
if ((gwResponse != null) && deptBean.getSendEmail())
sendEmail(gwResponse);
......
---------
SOoo, in cgw.sendRequest, here is the meat (there are some
lines to test values for some fields, but nothing that should
affect session. The logged transaction looks as I expect it
to look, and the gateway does get the request. The last
exception is never thrown.
----------
Request request = new Request();
buildRequest(ccBean,deptBean,addressBean,request);
myEnv.getLogWriter().log("tran " + request.toString(),LogWriter.DEBUG);
try {
Socket socket = this.getSocket(testCharge,myEnv);
response = request.send(socket,(testCharge? testURLFile : URLFile));
}
catch (Exception e) {....
--------
Here's how the socket gets built, and it logs as I expect it to.
In the log, it looks like this -
[Mon May 29 18:00:23 EDT 2000] info: ccgate: returning socket
Socket[addr=xxxxx.com/nnn.nnn.nnn.nnn,port=80,localport=32943]
except with a good host name and IP address.
--------
if (testCharge && testMode)
socket = new Socket(testURLHost,testURLPort);
else ......
myEnv.getLogWriter().log("returning socket " +
socket.toString(),LogWriter.INFO);
return socket;
---------
The actual send is part of a vendor library, but here is the
relevant part of that call:
----------
java.io.OutputStream out = socket.getOutputStream();
String ccc = "POST " + file + " HTTP/1.0\n"
+ "Content-type: application/octet-stream\n"
+ "Content-length: " + len + "\n"
+ "\n"
+ data
+ "\n";
out.write(ccc.getBytes());
StringBuffer resultbuffer = new StringBuffer();
java.io.BufferedReader in = new java.io.BufferedReader(new java.io.Input
StreamReader(socket.getInputStream()));
----------
I know this is long and disjoint. If you've read this far, and have
explanations to help me, thanks a lot.
sandy
[EMAIL PROTECTED]
___________________________________________________________________________
To unsubscribe, send email to [EMAIL PROTECTED] and include in the body
of the message "signoff SERVLET-INTEREST".
Archives: http://archives.java.sun.com/archives/servlet-interest.html
Resources: http://java.sun.com/products/servlet/external-resources.html
LISTSERV Help: http://www.lsoft.com/manuals/user/user.html