use of org.h2.value.Transfer in project h2database by h2database.
the class SessionRemote method done.
/**
* Called to flush the output after data has been sent to the server and
* just before receiving data. This method also reads the status code from
* the server and throws any exception the server sent.
*
* @param transfer the transfer object
* @throws DbException if the server sent an exception
* @throws IOException if there is a communication problem between client
* and server
*/
public void done(Transfer transfer) throws IOException {
transfer.flush();
int status = transfer.readInt();
if (status == STATUS_ERROR) {
String sqlstate = transfer.readString();
String message = transfer.readString();
String sql = transfer.readString();
int errorCode = transfer.readInt();
String stackTrace = transfer.readString();
JdbcSQLException s = new JdbcSQLException(message, sql, sqlstate, errorCode, null, stackTrace);
if (errorCode == ErrorCode.CONNECTION_BROKEN_1) {
// allow re-connect
throw new IOException(s.toString(), s);
}
throw DbException.convert(s);
} else if (status == STATUS_CLOSED) {
transferList = null;
} else if (status == STATUS_OK_STATE_CHANGED) {
sessionStateChanged = true;
} else if (status == STATUS_OK) {
// ok
} else {
throw DbException.get(ErrorCode.CONNECTION_BROKEN_1, "unexpected status " + status);
}
}
use of org.h2.value.Transfer in project h2database by h2database.
the class SessionRemote method readLob.
@Override
public synchronized int readLob(long lobId, byte[] hmac, long offset, byte[] buff, int off, int length) {
checkClosed();
for (int i = 0, count = 0; i < transferList.size(); i++) {
Transfer transfer = transferList.get(i);
try {
traceOperation("LOB_READ", (int) lobId);
transfer.writeInt(SessionRemote.LOB_READ);
transfer.writeLong(lobId);
if (clientVersion >= Constants.TCP_PROTOCOL_VERSION_12) {
transfer.writeBytes(hmac);
}
transfer.writeLong(offset);
transfer.writeInt(length);
done(transfer);
length = transfer.readInt();
if (length <= 0) {
return length;
}
transfer.readBytes(buff, off, length);
return length;
} catch (IOException e) {
removeServer(e, i--, ++count);
}
}
return 1;
}
use of org.h2.value.Transfer in project h2database by h2database.
the class SessionRemote method setAutoCommitSend.
private synchronized void setAutoCommitSend(boolean autoCommit) {
for (int i = 0, count = 0; i < transferList.size(); i++) {
Transfer transfer = transferList.get(i);
try {
traceOperation("SESSION_SET_AUTOCOMMIT", autoCommit ? 1 : 0);
transfer.writeInt(SessionRemote.SESSION_SET_AUTOCOMMIT).writeBoolean(autoCommit);
done(transfer);
} catch (IOException e) {
removeServer(e, i--, ++count);
}
}
}
use of org.h2.value.Transfer in project h2database by h2database.
the class SessionRemote method autoCommitIfCluster.
/**
* Calls COMMIT if the session is in cluster mode.
*/
public void autoCommitIfCluster() {
if (autoCommit && cluster) {
// faster)
for (int i = 0, count = 0; i < transferList.size(); i++) {
Transfer transfer = transferList.get(i);
try {
traceOperation("COMMAND_COMMIT", 0);
transfer.writeInt(SessionRemote.COMMAND_COMMIT);
done(transfer);
} catch (IOException e) {
removeServer(e, i--, ++count);
}
}
}
}
use of org.h2.value.Transfer in project h2database by h2database.
the class WebThread method process.
@SuppressWarnings("unchecked")
private boolean process() throws IOException {
boolean keepAlive = false;
String head = readHeaderLine();
if (head.startsWith("GET ") || head.startsWith("POST ")) {
int begin = head.indexOf('/'), end = head.lastIndexOf(' ');
String file;
if (begin < 0 || end < begin) {
file = "";
} else {
file = head.substring(begin + 1, end).trim();
}
trace(head + ": " + file);
file = getAllowedFile(file);
attributes = new Properties();
int paramIndex = file.indexOf('?');
session = null;
if (paramIndex >= 0) {
String attrib = file.substring(paramIndex + 1);
parseAttributes(attrib);
String sessionId = attributes.getProperty("jsessionid");
file = file.substring(0, paramIndex);
session = server.getSession(sessionId);
}
keepAlive = parseHeader();
String hostAddr = socket.getInetAddress().getHostAddress();
file = processRequest(file, hostAddr);
if (file.length() == 0) {
// asynchronous request
return true;
}
String message;
byte[] bytes;
if (cache && ifModifiedSince != null && ifModifiedSince.equals(server.getStartDateTime())) {
bytes = null;
message = "HTTP/1.1 304 Not Modified\r\n";
} else {
bytes = server.getFile(file);
if (bytes == null) {
message = "HTTP/1.1 404 Not Found\r\n";
bytes = ("File not found: " + file).getBytes(StandardCharsets.UTF_8);
message += "Content-Length: " + bytes.length + "\r\n";
} else {
if (session != null && file.endsWith(".jsp")) {
String page = new String(bytes, StandardCharsets.UTF_8);
if (SysProperties.CONSOLE_STREAM) {
Iterator<String> it = (Iterator<String>) session.map.remove("chunks");
if (it != null) {
message = "HTTP/1.1 200 OK\r\n";
message += "Content-Type: " + mimeType + "\r\n";
message += "Cache-Control: no-cache\r\n";
message += "Transfer-Encoding: chunked\r\n";
message += "\r\n";
trace(message);
output.write(message.getBytes());
while (it.hasNext()) {
String s = it.next();
s = PageParser.parse(s, session.map);
bytes = s.getBytes(StandardCharsets.UTF_8);
if (bytes.length == 0) {
continue;
}
output.write(Integer.toHexString(bytes.length).getBytes());
output.write("\r\n".getBytes());
output.write(bytes);
output.write("\r\n".getBytes());
output.flush();
}
output.write("0\r\n\r\n".getBytes());
output.flush();
return keepAlive;
}
}
page = PageParser.parse(page, session.map);
bytes = page.getBytes(StandardCharsets.UTF_8);
}
message = "HTTP/1.1 200 OK\r\n";
message += "Content-Type: " + mimeType + "\r\n";
if (!cache) {
message += "Cache-Control: no-cache\r\n";
} else {
message += "Cache-Control: max-age=10\r\n";
message += "Last-Modified: " + server.getStartDateTime() + "\r\n";
}
message += "Content-Length: " + bytes.length + "\r\n";
}
}
message += "\r\n";
trace(message);
output.write(message.getBytes());
if (bytes != null) {
output.write(bytes);
}
output.flush();
}
return keepAlive;
}
Aggregations