AJPConnectionHandler implements ConnectionHandler { public void handleConnection(Socket socket) throws IOException { socket.setSoTimeout(timeout); InputStream in = socket.getInputStream(); OutputStream out = socket.getOutputStream(); AJPMessage ajpRequest = new AJPMessage(8192); final StateHolder holder = new StateHolder(); do { if (!holder.state.equals(State.READY)) throw new IllegalStateException( "Trying to read a new request in state " + holder.state); ajpRequest.readMessage(in); int type = ajpRequest.peekByte(); switch (type) { case AJPConstants.JK_AJP13_CPING_REQUEST: out.write(PONG); out.flush(); case AJPConstants.JK_AJP13_FORWARD_REQUEST: doForwardRequest(socket, ajpRequest, holder); } } while (true); } AJPConnectionHandler(AJPRequestHandler handler); int getTimeout(); void setTimeout(int timeout); void handleConnection(Socket socket);  }
@Test public void testHandleConnection() throws Exception { AJPClient client = new AJPClient(); client.connect(ajp); StreamingRequest req = new StreamingRequest.Impl(); req.setTarget(new InetSocketAddress("www.target.com", 443)); req.setSsl(true); req.setHeader(AsciiString.getBytes("GET /test/?a=b HTTP/1.0\r\n" + "Host: www.target.com\r\n\r\n")); StreamingResponse response = client.fetchResponse(req); MutableBufferedResponse resp = new MutableBufferedResponse.Impl(); MessageUtils.buffer(response, resp, Integer.MAX_VALUE); System.out.println(resp); }