@Test
 public void clientCanCallServer() {
   // then
   // - in http
   assertEquals(
       new HttpResponse()
           .withStatusCode(HttpStatusCode.OK_200.code())
           .withBody("test_initializer_response_body"),
       makeRequest(
           new HttpRequest()
               .withMethod("POST")
               .withPath("/test_initializer_path")
               .withBody("test_initializer_request_body"),
           headersToIgnore));
   // - in https
   assertEquals(
       new HttpResponse()
           .withStatusCode(HttpStatusCode.OK_200.code())
           .withBody("test_initializer_response_body"),
       makeRequest(
           new HttpRequest()
               .withMethod("POST")
               .withPath("/test_initializer_path")
               .withBody("test_initializer_request_body"),
           headersToIgnore));
 }
示例#2
0
  @Override
  protected void doPut(
      HttpServletRequest httpServletRequest, HttpServletResponse httpServletResponse) {

    try {
      String requestPath =
          httpServletRequest.getPathInfo() != null && httpServletRequest.getContextPath() != null
              ? httpServletRequest.getPathInfo()
              : httpServletRequest.getRequestURI();
      if (requestPath.equals("/status")) {

        httpServletResponse.setStatus(HttpStatusCode.OK_200.code());

      } else if (requestPath.equals("/clear")) {

        requestLogFilter.clear(
            httpRequestSerializer.deserialize(
                IOStreamUtils.readInputStreamToString(httpServletRequest)));
        httpServletResponse.setStatus(HttpStatusCode.ACCEPTED_202.code());

      } else if (requestPath.equals("/reset")) {

        requestLogFilter.reset();
        httpServletResponse.setStatus(HttpStatusCode.ACCEPTED_202.code());

      } else if (requestPath.equals("/dumpToLog")) {

        requestResponseLogFilter.dumpToLog(
            httpRequestSerializer.deserialize(
                IOStreamUtils.readInputStreamToString(httpServletRequest)),
            "java".equals(httpServletRequest.getParameter("type")));
        httpServletResponse.setStatus(HttpStatusCode.ACCEPTED_202.code());

      } else if (requestPath.equals("/retrieve")) {

        HttpRequest[] requests =
            requestLogFilter.retrieve(
                httpRequestSerializer.deserialize(
                    IOStreamUtils.readInputStreamToString(httpServletRequest)));
        httpServletResponse.setStatus(HttpStatusCode.OK_200.code());
        httpServletResponse.setHeader(CONTENT_TYPE, MediaType.JSON_UTF_8.toString());
        IOStreamUtils.writeToOutputStream(
            httpRequestSerializer.serialize(requests).getBytes(), httpServletResponse);

      } else if (requestPath.equals("/verify")) {

        String result =
            requestLogFilter.verify(
                verificationSerializer.deserialize(
                    IOStreamUtils.readInputStreamToString(httpServletRequest)));
        if (result.isEmpty()) {
          httpServletResponse.setStatus(HttpStatusCode.ACCEPTED_202.code());
        } else {
          httpServletResponse.setStatus(HttpStatusCode.NOT_ACCEPTABLE_406.code());
          httpServletResponse.setHeader(CONTENT_TYPE, MediaType.JSON_UTF_8.toString());
          IOStreamUtils.writeToOutputStream(result.getBytes(), httpServletResponse);
        }

      } else if (requestPath.equals("/verifySequence")) {

        String result =
            requestLogFilter.verify(
                verificationSequenceSerializer.deserialize(
                    IOStreamUtils.readInputStreamToString(httpServletRequest)));
        if (result.isEmpty()) {
          httpServletResponse.setStatus(HttpStatusCode.ACCEPTED_202.code());
        } else {
          httpServletResponse.setStatus(HttpStatusCode.NOT_ACCEPTABLE_406.code());
          httpServletResponse.setHeader(CONTENT_TYPE, MediaType.JSON_UTF_8.toString());
          IOStreamUtils.writeToOutputStream(result.getBytes(), httpServletResponse);
        }

      } else if (requestPath.equals("/stop")) {

        httpServletResponse.setStatus(HttpStatusCode.NOT_IMPLEMENTED_501.code());

      } else {
        forwardRequest(httpServletRequest, httpServletResponse);
      }
    } catch (Exception e) {
      logger.error("Exception processing " + httpServletRequest, e);
      httpServletResponse.setStatus(HttpStatusCode.BAD_REQUEST_400.code());
    }
  }