session.removeAttribute(DISABLE_ENCRYPTION_ONCE);
handler.scheduleFilterWrite(nextFilter,
writeRequest);
} else {
// Otherwise, encrypt the buffer.
ByteBuffer buf = (ByteBuffer) writeRequest.getMessage();
if (SessionLog.isDebugEnabled(session)) {
SessionLog.debug(session, " Filtered Write: " + handler);
}
if (handler.isWritingEncryptedData()) {
// data already encrypted; simply return buffer
if (SessionLog.isDebugEnabled(session)) {
SessionLog.debug(session, " already encrypted: "
+ buf);
}
handler.scheduleFilterWrite(nextFilter,
writeRequest);
} else if (handler.isHandshakeComplete()) {
// SSL encrypt
if (SessionLog.isDebugEnabled(session)) {
SessionLog.debug(session, " encrypt: " + buf);
}
int pos = buf.position();
handler.encrypt(buf.buf());
buf.position(pos);
ByteBuffer encryptedBuffer = new EncryptedBuffer(SSLHandler
.copy(handler.getOutNetBuffer()), buf);
if (SessionLog.isDebugEnabled(session)) {
SessionLog.debug(session, " encrypted buf: "
+ encryptedBuffer);