예제 #1
0
  @Test
  public void testPingPong() throws Exception {
    startHttpServer(
        new HttpHandler() {

          @Override
          public void service(Request request, Response response) throws Exception {
            response.setStatus(200, "FINE");
          }
        },
        "/");

    final MemoryManager mm =
        httpServer.getListener(LISTENER_NAME).getTransport().getMemoryManager();
    final Buffer request = mm.allocate(512);
    request.put((byte) 0x12);
    request.put((byte) 0x34);
    request.putShort((short) 1);
    request.put(AjpConstants.JK_AJP13_CPING_REQUEST);
    request.flip();

    final Future<Buffer> responseFuture = send("localhost", PORT, request);
    Buffer response = responseFuture.get(10, TimeUnit.SECONDS);

    assertEquals('A', response.get());
    assertEquals('B', response.get());
    assertEquals((short) 1, response.getShort());
    assertEquals(AjpConstants.JK_AJP13_CPONG_REPLY, response.get());

    final AjpForwardRequestPacket headersPacket =
        new AjpForwardRequestPacket("GET", "/TestServlet/normal", 80, PORT);
    headersPacket.addHeader("Host", "localhost:80");
    send(headersPacket.toByteArray());

    AjpResponse ajpResponse = Utils.parseResponse(readAjpMessage());
    Assert.assertEquals("FINE", ajpResponse.getResponseMessage());
  }
 static int readShort(final Buffer buffer, final int offset) {
   return buffer.getShort(offset) & 0xFFFF;
 }