I have run into a problem with my code, in that after I rearranged it
into neat little packages it no longer works. Gotta love that.
What happens is that I have a servlet that is serializing an object and
sending it to my applet. This has been working just fine until I moved
stuff around into packages.
The object being serialized extends AbsTableModel, which is identical to
AbstractTableModel with the exception that I was forced to compile it
locally due to serial number differences between versions of java.
Again, up to this point everything worked fine.
Here is the error I get:
java.io.StreamCorruptedException: Caught EOFException while reading the
stream header
at
java.io.ObjectInputStream.readStreamHeader(ObjectInputStream.java:845)
at java.io.ObjectInputStream.<init>(ObjectInputStream.java:168)
at com.sequenom.realsnp.query.ExecQuery.<init>(ExecQuery.java:48)
at com.sequenom.realsnp.query.ExecQuery.<init>(ExecQuery.java:64)
at com.sequenom.realsnp.graphics.DrawGlobal.run(DrawGlobal.java:78)
Where com.sequenom.realsnp is my local package. In ExecQuery on the
client (applet) side, I send via URL and receive the AbsTableModel back:
try {
// Make the connection
URL queryServlet = new URL( s_url );
connection = queryServlet.openConnection();
connection.setDoOutput( true );
connection.setDoInput( true );
connection.setUseCaches( false );
connection.setDefaultUseCaches( false );
connection.setRequestProperty ( "Content-Type",
"application/x-java-serialized-object" );
sendQuery( connection, qc );
// Get TableModel back from servlet
ObjectInputStream ois = new ObjectInputStream(
connection.getInputStream() );
if( queryType.equals( "query" ) ) {
model = readTableModel( ois );
} else {
ois.close();
}
}
catch ( Exception ex ) {
System.out.println("ExecQuery: Problem reading object from
servlet");
ex.printStackTrace();
}
// Here is readTableModel
public static TableModel readTableModel( ObjectInputStream ois ) {
TableModel tableModel = null;
try {
tableModel = ( TableModel )ois.readObject();
ois.close();
}
catch ( Exception e ) {
e.printStackTrace();
System.out.println("ExecQuery: Error reading file from servlet");
}
return tableModel;
}
On the servlet side, here is the code (SQLAdapter extends
AbsTableModel):
try {
// Read object from stream
ois = new ObjectInputStream( request.getInputStream() );
QueryContainer qc = ( QueryContainer ) ois.readObject();
query = qc.getQuery();
queryType = qc.getQuerytype();
database = qc.getDatabase();
remote_host = qc.getRemoteHost();
//s = ( String ) ois.readObject();
ois.close();
address = "jdbc:mysql://" + remote_host + ":3306/" + database +
"?user=root&password=dbl0k3d.";
sqla = new SQLAdapter( address, driver );
// If this is a query, generate a model... else just insert it
if ( queryType.equals( "query" ) ) {
genTableModel( query , response );
} else {
sqla.insertQuery( query );
closeStream( response );
}
return;
}
catch ( IOException ie ) {
dumpError("QueryServlet: IOError from application");
ie.printStackTrace();
}
catch ( Exception e ) {
dumpError("QueryServlet: Error reading object from application");
}
}
public void genTableModel( String s, HttpServletResponse response ) {
try {
// Create db connection object
//SQLAdapter sqla = new SQLAdapter( address, driver );
// Execute the query from the string received in input stream
sqla.executeQuery( s );
// Post response back to client
sendToApp( response, sqla );
}
catch ( Exception e ) {
dumpError("QueryServlet: Error in genTableModel");
}
}
What am I missing now?
Thanks,
Bryan