Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations IamaSherpa on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Tomcat Session persistance with JDBCStore

Status
Not open for further replies.

JavaTomcatNewbie

Programmer
Jul 16, 2002
2
US
Win 2000
Jakarta Tomcat 4.0.3
JDK 1.3


I'm getting an exception in Tomcat 4.0.3 that I don't know what to do with. I'm reading James Goodwill's book "Apache Jakarta-Tomcat" and I'm trying to run the example
On page page 128. I'm using Mysql and session data shows up in the database some of the time, other times Tomcat throws the exception. It seems like Tomcat checks the database every 60 seconds to see which sessions have timed out and everytime it throws the exception. I'm new to this, sorry for posting all the code, but I have been working on this for 3 days. I'm new to mysql also.

The books says that Tomcat will manage sessions in a database for you. I see the data in the database but then.. I get this and all of the session information isn't in the database.
Tim


The exception I'm getting is

java.io.IOException: Stream closed
at java.io.BufferedInputStream.ensureOpen(BufferedInputStream.java:123)
at java.io.BufferedInputStream.read(BufferedInputStream.java:273)
at java.io_ObjectInputStream.readFullyInternal(ObjectInputStream.java:1780)
at java.io_ObjectInputStream.bufferData(ObjectInputStream.java:1750)
at java.io_ObjectInputStream.readShort(ObjectInputStream.java:1935)
at java.io_ObjectInputStream.readStreamHeader(ObjectInputStream.java:842)
at java.io_ObjectInputStream.<init>(ObjectInputStream.java:168)
at org.apache.catalina.util.CustomObjectInputStream.<init>(CustomObjectInputStream.java:103)
at org.apache.catalina.session.JDBCStore.load(JDBCStore.java:518)
at org.apache.catalina.session.StoreBase.processExpires(StoreBase.java:295)
at org.apache.catalina.session.StoreBase.run(StoreBase.java:350)
at java.lang.Thread.run(Thread.java:484)

The relative portion of the server.xml file is...

<Context path=&quot;/library2&quot; docBase=&quot;library2&quot; debug=&quot;0&quot; reloadable=&quot;true&quot;>
<Manager className=&quot;org.apache.catalina.session.PersistentManager&quot;
debug=&quot;0&quot;
saveOnRestart=&quot;true&quot;
maxActiveSessions=&quot;-1&quot;
minIdleSwap=&quot;-1&quot;
maxIdleSwap=&quot;-1&quot;
maxIdleBackup=&quot;-1&quot;>
<Store className=&quot;org.apache.catalina.session.JDBCStore&quot;
driverName=&quot;org.gjt.mm.mysql.Driver&quot;
connectionURL=&quot;jdbc:mysql://localhost/tomcatsessions?user=SessionTracking;password=tracking&quot;
sessionTable=&quot;sessions&quot;
sessionIdCol=&quot;id&quot;
sessionDataCol=&quot;data&quot;
sessionValidCol=&quot;valid&quot;
sessionMaxInactiveCol=&quot;maxinactive&quot;
sessionLastAccessedCol=&quot;lastaccess&quot;
checkInterval=&quot;60&quot;
debug=&quot;99&quot; />

</Manager>


</Context>



The servlet is straight from the book and it looks like this....

package chapter7;

import java.io.*;
import java.text.*;
import java.util.*;
import javax.servlet.*;
import javax.servlet.http.*;

public class SessionServlet extends HttpServlet {

public void doGet(HttpServletRequest request,
HttpServletResponse response)
throws IOException, ServletException {

response.setContentType(&quot;text/html&quot;);

PrintWriter out = response.getWriter();
out.println(&quot;<html>&quot;);
out.println(&quot;<body bgcolor=\&quot;white\&quot;>&quot;);
out.println(&quot;<head>&quot;);

out.println(&quot;<title>Session Servlet</title>&quot;);
out.println(&quot;</head>&quot;);
out.println(&quot;<body>&quot;);

// Get a reference to the HttpSession Object
HttpSession session = request.getSession();

// Print the current Session's ID
out.println(&quot;Session ID:&quot; + &quot; &quot; + session.getId());
out.println(&quot;<br>&quot;);

// Print the current Session's Creation Time
out.println(&quot;Session Created:&quot; + &quot; &quot; +
new Date(session.getCreationTime()) + &quot;<br>&quot;);

// Print the current Session's Last Access Time
out.println(&quot;Session Last Accessed&quot; + &quot; &quot; +
new Date(session.getLastAccessedTime()));

// Get the name/value pair to be placed in the HttpSession
String dataName = request.getParameter(&quot;name&quot;);
String dataValue = request.getParameter(&quot;value&quot;);

if ( dataName != null && dataValue != null ) {

// If the Parameter Values are not null
// then add the name/value pair to the HttpSession
session.setAttribute(dataName, dataValue);
}

out.println(&quot;<P>&quot;);
out.println(&quot;Sessions Attributes&quot; + &quot;<br>&quot;);

// Get all of the Attribute Names from the HttpSession
Enumeration names = session.getAttributeNames();

while ( names.hasMoreElements() ) {

String name = (String) names.nextElement();
// Get the Attribute Value with the matching name
String value = session.getAttribute(name).toString();
// Print the name/value pair
out.println(name + &quot; = &quot; + value + &quot;<br>&quot;);
}

// Create a Form to Add name/value pairs to the HttpSession
out.println(&quot;<P>GET based form:<br>&quot;);
out.print(&quot;<form action=\&quot;&quot;);
out.print(response.encodeURL(&quot;chapter7.SessionServlet&quot;));
out.print(&quot;\&quot; &quot;);
out.println(&quot;method=GET>&quot;);
out.println(&quot;Session Attribute:&quot;);
out.println(&quot;<input type=text size=20 name=name>&quot;);
out.println(&quot;<br>&quot;);
out.println(&quot;Session Value:&quot;);
out.println(&quot;<input type=text size=20 name=value>&quot;);
out.println(&quot;<br>&quot;);
out.println(&quot;<input type=submit>&quot;);
out.println(&quot;</form>&quot;);

out.println(&quot;</body>&quot;);
out.println(&quot;</html>&quot;);
}
}

 
I need a real expert. Please refer me to a an expert or a book if you can't help. It must have good information about the JDBCStore in Tomcat.

The servlet that was using JDBCStore was also using a JDBC Realm for user Basic User authentication. I had the web.xml file coded for this authentication. With the JDBC Realm it was suppose to look up the user information in a database.

when I took this portion out of the servlet I stopped getting the Stream closed exception for the JDBCStore.

I monitored the database controlling sessions and it did write session data to the table when tomcat was shutdown. Then I created some session what are supposse to expire after 10 seconds. They neve left the database.
Has anyone used this stuff in tomcat with successs?


HelP
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top