HttpServletResponse response)
throws IOException, ServletException {
synchronized (this) {
DataInputStream inStream = null;
DataOutputStream dataOut = null;
try {
// fredt@users - the servlet container, Resin does not return all
// the bytes with one call to input.read(b,0,len) when len > 8192
// bytes, the loop in the Result.read() method handles this
inStream = new DataInputStream(request.getInputStream());
int databaseID = inStream.readInt();
long sessionID = inStream.readLong();
int mode = inStream.readByte();
Session session = DatabaseManager.getSession(databaseID,
sessionID);
Result resultIn = Result.newResult(session, mode, inStream,
rowIn);
resultIn.setDatabaseId(databaseID);
resultIn.setSessionId(sessionID);
Result resultOut;
int type = resultIn.getType();
if (type == ResultConstants.CONNECT) {
try {
session = DatabaseManager.newSession(
dbType, dbPath, resultIn.getMainString(),
resultIn.getSubString(), new HsqlProperties(),
resultIn.getZoneString(),
resultIn.getUpdateCount());
resultIn.readAdditionalResults(null, inStream, rowIn);
resultOut = Result.newConnectionAcknowledgeResponse(
session.getDatabase(), session.getId(),
session.getDatabase().getDatabaseID());
} catch (HsqlException e) {
resultOut = Result.newErrorResult(e);
}
} else if (type == ResultConstants.DISCONNECT
|| type == ResultConstants.RESETSESSION) {
// Upon DISCONNECT 6 bytes are read by the ClientConnectionHTTP": mode (1 byte), a length (int), and an 'additional results (1 byte)
response.setHeader("Cache-Control", "no-cache"); // DB-traffic should not be cached by proxy's
response.setContentType("application/octet-stream");
response.setContentLength(6);
// Only acquire output-stream after headers are set
dataOut = new DataOutputStream(response.getOutputStream());
dataOut.writeByte(ResultConstants.DISCONNECT); // Mode
dataOut.writeInt(4); //Length Int of first result is always read! Minvalue is 4: It is the number of bytes of the current result (it includes the length of this Int itself)
dataOut.writeByte(ResultConstants.NONE); // No Additional results
dataOut.close();
return;
} else {
int dbId = resultIn.getDatabaseId();
long sessionId = resultIn.getSessionId();
session = DatabaseManager.getSession(dbId, sessionId);
resultIn.readLobResults(session, inStream, rowIn);
resultOut = session.execute(resultIn);
}
HsqlByteArrayOutputStream memStream =
new HsqlByteArrayOutputStream();
DataOutputStream tempOutput = new DataOutputStream(memStream);
resultOut.write(session, tempOutput, rowOut);
response.setHeader("Cache-Control", "no-cache"); // DB-traffic should not be cached by proxy's
response.setContentType("application/octet-stream");
response.setContentLength(memStream.size());
// Only acquire output-stream after headers are set
dataOut = new DataOutputStream(response.getOutputStream());
memStream.writeTo(dataOut);
iQueries++;
} catch (HsqlException e) {}