From 6cae8148dacbda89bf52704bf405a753562ba9ad Mon Sep 17 00:00:00 2001 From: batthp Date: Wed, 15 Jul 2020 14:02:42 -0400 Subject: [PATCH] Fixing headers --- .../admin/service/HttpClientServiceImpl.java | 2 +- .../engine/MockedRestServerEngineUtils.java | 30 +++++++++++++++---- 2 files changed, 26 insertions(+), 6 deletions(-) diff --git a/src/main/java/com/smockin/admin/service/HttpClientServiceImpl.java b/src/main/java/com/smockin/admin/service/HttpClientServiceImpl.java index 02772375..25d7da5f 100644 --- a/src/main/java/com/smockin/admin/service/HttpClientServiceImpl.java +++ b/src/main/java/com/smockin/admin/service/HttpClientServiceImpl.java @@ -55,7 +55,7 @@ public HttpClientResponseDTO handleCall(final HttpClientCallDTO dto, boolean jus return new HttpClientResponseDTO(HttpStatus.NOT_FOUND.value()); } String url = dto.getUrl(); - dto.setUrl(redirectUrl + url); + dto.setUrl((redirectUrl + url).replaceAll("(? getHeadersInfo(HttpServletRequest request) { + Map map = new HashMap(); + + Enumeration headerNames = request.getHeaderNames(); + while (headerNames.hasMoreElements()) { + + String key = (String) headerNames.nextElement(); + String value = request.getHeader(key); + System.out.println(key + ": " + value); + + if(!(key.equalsIgnoreCase("Content-Length") || key.equalsIgnoreCase("Host"))) + map.put(key, value); + } + + return map; + } + public Optional loadMockedResponse(final Request request, final Response response, final boolean isMultiUserMode) { @@ -86,7 +103,9 @@ public Optional loadMockedResponse(final Request request, HttpClientCallDTO http = new HttpClientCallDTO(); http.setUrl(request.pathInfo()); http.setMethod(RestMethodEnum.findByName(request.requestMethod())); - http.setHeaders(request.params()); + http.setHeaders(getHeadersInfo(request.raw())); +// http.setHeaders(request.params()); + http.setBody(request.body()); HttpClientResponseDTO responseDto = null; try @@ -99,7 +118,8 @@ public Optional loadMockedResponse(final Request request, } if(responseDto != null && responseDto.getStatus() != 404) { - return Optional.of(new ResponseEntity(responseDto, HttpStatus.OK).getBody().getBody()); + response.status(responseDto.getStatus()); + return Optional.of(new ResponseEntity(responseDto, HttpStatus.resolve(responseDto.getStatus())).getBody().getBody()); } try {