private void setResponseMainHeaders(final HttpServletResponse response) { response.setHeader(HttpHeaders.SERVER, HandlerUtils.constructHeaderServerName()); response.setHeader(HttpHeaders.DATE, new Date().toString()); response.setHeader( HttpHeaders.CACHE_CONTROL, "no-cache, no-store, must-revalidate"); // HTTP 1.1. response.setHeader(HttpHeaders.PRAGMA, "no-cache"); // HTTP 1.0. response.setDateHeader(HttpHeaders.EXPIRES, 0); }
@Override public void handle( final String target, final Request baseRequest, final HttpServletRequest request, final HttpServletResponse response) throws IOException, ServletException { baseRequest.setHandled(true); String postBody = null; if (request.getMethod().equalsIgnoreCase("post")) { try { postBody = HandlerUtils.inputStreamToString(request.getInputStream()); if (postBody == null || postBody.isEmpty()) { HandlerUtils.configureErrorResponse( response, HttpStatus.BAD_REQUEST_400, BAD_POST_REQUEST_MESSAGE); return; } } catch (Exception ex) { HandlerUtils.configureErrorResponse( response, HttpStatus.BAD_REQUEST_400, BAD_POST_REQUEST_MESSAGE); return; } } final StubResponse stubResponse = dataStore.findResponseFor(constructFullURI(request), request.getMethod(), postBody); if (stubResponse instanceof NullStubResponse) { final String error = generate404ErrorMessage(request, postBody); HandlerUtils.configureErrorResponse(response, HttpStatus.NOT_FOUND_404, error); return; } try { doHandle(response, stubResponse); } catch (Exception ex) { HandlerUtils.configureErrorResponse( response, HttpStatus.INTERNAL_SERVER_ERROR_500, ex.toString()); } }