/** * Read an AJP message. * * @return The number of bytes read * @throws IOException any other failure, including incomplete reads */ protected int readMessage(AjpMessage message, boolean blockFirstRead) throws IOException { byte[] buf = message.getBuffer(); int headerLength = message.getHeaderLength(); int bytesRead = read(buf, 0, headerLength, blockFirstRead); if (bytesRead == 0) { return 0; } int messageLength = message.processHeader(true); if (messageLength < 0) { // Invalid AJP header signature throw new IOException( sm.getString("ajpmessage.invalidLength", Integer.valueOf(messageLength))); } else if (messageLength == 0) { // Zero length message. return bytesRead; } else { if (messageLength > buf.length) { // Message too long for the buffer // Need to trigger a 400 response throw new IllegalArgumentException( sm.getString( "ajpprocessor.header.tooLong", Integer.valueOf(messageLength), Integer.valueOf(buf.length))); } bytesRead += read(buf, headerLength, messageLength, true); return bytesRead; } }
/** * Read an AJP message. * * @param first is true if the message is the first in the request, which will cause a short * duration blocking read * @return true if the message has been read, false if the short read didn't return anything * @throws IOException any other failure, including incomplete reads */ protected boolean readMessage(AjpMessage message, boolean first, boolean useAvailableData) throws IOException { int headerLength = message.getHeaderLength(); if (first) { if (!readt(headerLength, useAvailableData)) { return false; } } else { read(headerLength); } inputBuffer.get(message.getBuffer(), 0, headerLength); int messageLength = message.processHeader(true); if (messageLength < 0) { // Invalid AJP header signature // TODO: Throw some exception and close the connection to frontend. return false; } else if (messageLength == 0) { // Zero length message. return true; } else { if (messageLength > message.getBuffer().length) { // Message too long for the buffer // Need to trigger a 400 response throw new IllegalArgumentException( getSm() .getString( "ajpprocessor.header.tooLong", Integer.valueOf(messageLength), Integer.valueOf(message.getBuffer().length))); } read(messageLength); inputBuffer.get(message.getBuffer(), headerLength, messageLength); return true; } }