@Test
  public void testFormParameters() throws Exception {
    final Map<String, String[]> patternMap = new HashMap<String, String[]>();
    patternMap.put("title", new String[] {"Developing PaaS Components"});
    patternMap.put("authors", new String[] {"Shalini M"});
    patternMap.put("price", new String[] {"100$"});

    final NetworkListener listener = httpServer.getListener(LISTENER_NAME);

    startHttpServer(
        new HttpHandler() {

          @Override
          public void service(Request request, Response response) throws Exception {
            final Map<String, String[]> paramMap = request.getParameterMap();
            boolean isOk = paramMap.size() == patternMap.size();

            if (isOk) {
              // if sizes are equal - compare content
              for (Map.Entry<String, String[]> patternEntry : patternMap.entrySet()) {
                final String key = patternEntry.getKey();
                final String[] value = patternEntry.getValue();
                isOk = paramMap.containsKey(key) && Arrays.equals(value, paramMap.get(key));

                if (!isOk) break;
              }
            }

            if (isOk) {
              response.setStatus(200, "FINE");
            } else {
              response.setStatus(500, "Attributes don't match");
            }
          }
        },
        "/bookstore/BookStoreServlet");

    final MemoryManager mm = listener.getTransport().getMemoryManager();
    final Buffer requestPart1 =
        Buffers.wrap(mm, Utils.loadResourceFile("form-params-payload1.dat"));
    final Buffer requestPart2 =
        Buffers.wrap(mm, Utils.loadResourceFile("form-params-payload2.dat"));

    Buffer responseBuffer =
        send("localhost", PORT, Buffers.appendBuffers(mm, requestPart1, requestPart2))
            .get(10, TimeUnit.SECONDS);

    // Successful response length is 37 bytes.  This includes the status
    // line and a content-length
    boolean isFailure = responseBuffer.remaining() != 37;

    if (isFailure) {
      byte[] response = new byte[responseBuffer.remaining()];
      responseBuffer.get(response);
      String hex = toHexString(response);
      fail("unexpected response length=" + response.length + " content=[" + hex + "]");
    }
  }
  @Test
  public void testSslParams() throws Exception {
    final NetworkListener listener = httpServer.getListener(LISTENER_NAME);

    startHttpServer(
        new HttpHandler() {

          @Override
          public void service(Request request, Response response) throws Exception {
            boolean isOk = request.isSecure();
            String error = "unknown";

            if (isOk) {
              try {
                assertEquals(
                    (Integer) 256, (Integer) request.getAttribute(SSLSupport.KEY_SIZE_KEY));
                assertNotNull(request.getAttribute(SSLSupport.SESSION_ID_KEY));
                assertNotNull(request.getAttribute(SSLSupport.CIPHER_SUITE_KEY));
                assertNotNull(request.getAttribute(SSLSupport.CERTIFICATE_KEY));
              } catch (Exception e) {
                error = e.getClass().getName() + ": " + e.getMessage();
                isOk = false;
              }
            }

            if (isOk) {
              response.setStatus(200, "FINE");
            } else {
              response.setStatus(500, error);
            }
          }
        });

    final MemoryManager mm = listener.getTransport().getMemoryManager();
    final Buffer request = Buffers.wrap(mm, Utils.loadResourceFile("get-secured.dat"));

    Buffer responseBuffer = send("localhost", PORT, request).get(10, TimeUnit.SECONDS);

    // Successful response length is 37 bytes.  This includes the status
    // line and a content-length
    boolean isFailure = responseBuffer.remaining() != 37;

    if (isFailure) {
      byte[] response = new byte[responseBuffer.remaining()];
      responseBuffer.get(response);
      String hex = toHexString(response);
      fail("unexpected response length=" + response.length + " content=[" + hex + "]");
    }
  }
  @Test
  public void testNullAttribute() throws Exception {
    final NetworkListener listener = httpServer.getListener(LISTENER_NAME);

    startHttpServer(
        new HttpHandler() {

          @Override
          public void service(Request request, Response response) throws Exception {
            final Set<String> attributeNames = request.getAttributeNames();
            final boolean isOk =
                attributeNames.contains("JK_LB_ACTIVATION")
                    && request.getAttribute("JK_LB_ACTIVATION") == null
                    && attributeNames.contains("AJP_REMOTE_PORT")
                    && "60955".equals(request.getAttribute("AJP_REMOTE_PORT"));

            if (isOk) {
              response.setStatus(200, "FINE");
            } else {
              response.setStatus(500, "Attributes don't match");
            }
          }
        },
        "/SimpleWebApp/SimpleServlet");

    final MemoryManager mm = listener.getTransport().getMemoryManager();
    final Buffer request = Buffers.wrap(mm, Utils.loadResourceFile("null-attr-payload.dat"));

    Buffer responseBuffer = send("localhost", PORT, request).get(10, TimeUnit.SECONDS);

    // Successful response length is 37 bytes.  This includes the status
    // line and a content-length
    boolean isFailure = responseBuffer.remaining() != 37;

    if (isFailure) {
      byte[] response = new byte[responseBuffer.remaining()];
      responseBuffer.get(response);
      String hex = toHexString(response);
      fail("unexpected response length=" + response.length + " content=[" + hex + "]");
    }
  }
  @Test
  public void testAddresses() throws Exception {
    final String expectedRemoteAddr = "10.163.27.8";
    final String expectedLocalAddr = "10.163.25.1";
    final NetworkListener listener = httpServer.getListener(LISTENER_NAME);

    startHttpServer(
        new HttpHandler() {

          @Override
          public void service(Request request, Response response) throws Exception {
            boolean isOk = false;
            final StringBuilder errorBuilder = new StringBuilder();
            try {
              String result = request.getRemoteAddr();
              isOk = expectedRemoteAddr.equals(result);
              if (!isOk) {
                errorBuilder
                    .append("Remote host don't match. Expected ")
                    .append(expectedRemoteAddr)
                    .append(" but was ")
                    .append(result)
                    .append('\n');
              }

              String localName = request.getLocalName();
              String localAddr = request.getLocalAddr();
              isOk = expectedLocalAddr.equals(localName) && localName.equals(localAddr);
              if (!isOk) {
                errorBuilder
                    .append("Local address and host don't match. Expected=")
                    .append(expectedLocalAddr)
                    .append(" Addr=")
                    .append(localAddr)
                    .append(" name=")
                    .append(localName)
                    .append('\n');
              }
            } catch (Exception e) {
              errorBuilder.append(e.toString());
            }

            if (isOk) {
              response.setStatus(200, "FINE");
            } else {
              LOGGER.warning(errorBuilder.toString());
              response.setStatus(500, "ERROR");
            }
          }
        });

    final MemoryManager mm = listener.getTransport().getMemoryManager();
    final Buffer request = Buffers.wrap(mm, Utils.loadResourceFile("peer-addr-check.dat"));

    Buffer responseBuffer = send("localhost", PORT, request).get(60, TimeUnit.SECONDS);

    // Successful response length is 37 bytes.  This includes the status
    // line and a content-length
    boolean isFailure = responseBuffer.remaining() != 37;

    if (isFailure) {
      byte[] response = new byte[responseBuffer.remaining()];
      responseBuffer.get(response);
      String hex = toHexString(response);
      fail("unexpected response length=" + response.length + " content=[" + hex + "]");
    }
  }