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()); } }
private void handlePOSTorGET( HttpServletRequest httpServletRequest, HttpServletResponse httpServletResponse) { HttpRequest httpRequest = httpServletRequestMapper.mapHttpServletRequestToHttpRequest(httpServletRequest); HttpResponse httpResponse = mockServer.handle(httpRequest); if (httpResponse != null) { httpServletResponseMapper.mapHttpResponseToHttpServletResponse( httpResponse, httpServletResponse); } else { httpServletResponse.setStatus(HttpStatusCode.NOT_FOUND_404.code()); } }