public TesterAjpMessage sendMessage(TesterAjpMessage headers, TesterAjpMessage body) throws IOException { // Send the headers socket.getOutputStream().write(headers.getBuffer(), 0, headers.getLen()); if (body != null) { // Send the body of present socket.getOutputStream().write(body.getBuffer(), 0, body.getLen()); } // Read the response return readMessage(); }
/** Reads a message from the server. */ public TesterAjpMessage readMessage() throws IOException { InputStream is = socket.getInputStream(); TesterAjpMessage message = new TesterAjpMessage(packetSize); byte[] buf = message.getBuffer(); int headerLength = message.getHeaderLength(); read(is, buf, 0, headerLength); int messageLength = message.processHeader(false); if (messageLength < 0) { throw new IOException("Invalid AJP message length"); } else if (messageLength == 0) { return message; } else { if (messageLength > buf.length) { throw new IllegalArgumentException( "Message too long [" + Integer.valueOf(messageLength) + "] for buffer length [" + Integer.valueOf(buf.length) + "]"); } read(is, buf, headerLength, messageLength); return message; } }
static { TesterAjpMessage ajpCping = new TesterAjpMessage(16); ajpCping.reset(); ajpCping.appendByte(Constants.JK_AJP13_CPING_REQUEST); ajpCping.end(); AJP_CPING = new byte[ajpCping.getLen()]; System.arraycopy(ajpCping.getBuffer(), 0, AJP_CPING, 0, ajpCping.getLen()); }
public TesterAjpMessage createBodyMessage(byte[] data) { TesterAjpMessage message = new TesterAjpMessage(packetSize); message.reset(); // Set the header bytes message.getBuffer()[0] = 0x12; message.getBuffer()[1] = 0x34; message.appendBytes(data, 0, data.length); message.end(); return message; }
/** Create a message to request the given URL. */ public TesterAjpMessage createForwardMessage() { TesterAjpMessage message = new TesterAjpMessage(packetSize); message.reset(); // Set the header bytes message.getBuffer()[0] = 0x12; message.getBuffer()[1] = 0x34; // Code 2 for forward request message.appendByte(Constants.JK_AJP13_FORWARD_REQUEST); // HTTP method, GET = 2 message.appendByte(method); // Protocol message.appendString(protocol); // Request URI message.appendString(uri); // Client address message.appendString(remoteAddr); // Client host message.appendString(remoteHost); // Server name message.appendString(serverName); // Server port message.appendInt(serverPort); // Is ssl message.appendByte(ssl ? 0x01 : 0x00); return message; }