public void doPut( HttpServletRequest httpServletRequest, HttpServletResponse httpServletResponse) { String requestPath = httpServletRequest.getPathInfo() != null && httpServletRequest.getContextPath() != null ? httpServletRequest.getPathInfo() : httpServletRequest.getRequestURI(); if (requestPath.equals("/dumpToLog")) { mockServer.dumpToLog( httpRequestSerializer.deserialize( IOStreamUtils.readInputStreamToString(httpServletRequest))); httpServletResponse.setStatus(HttpStatusCode.ACCEPTED_202.code()); } else if (requestPath.equals("/reset")) { mockServer.reset(); httpServletResponse.setStatus(HttpStatusCode.ACCEPTED_202.code()); } else if (requestPath.equals("/clear")) { mockServer.clear( httpRequestSerializer.deserialize( IOStreamUtils.readInputStreamToString(httpServletRequest))); httpServletResponse.setStatus(HttpStatusCode.ACCEPTED_202.code()); } else { Expectation expectation = expectationSerializer.deserialize( IOStreamUtils.readInputStreamToString(httpServletRequest)); mockServer .when(expectation.getHttpRequest(), expectation.getTimes()) .thenRespond(expectation.getHttpResponse()); httpServletResponse.setStatus(HttpStatusCode.CREATED_201.code()); } }
@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()); } }