/** * Handles requests with message handler implementation. Previously sets Http request method as * header parameter. * * @param method * @param requestEntity * @return */ private ResponseEntity<String> handleRequestInternal( HttpMethod method, HttpEntity<String> requestEntity) { Map<String, ?> httpRequestHeaders = headerMapper.toHeaders(requestEntity.getHeaders()); Map<String, String> customHeaders = new HashMap<String, String>(); for (Entry<String, List<String>> header : requestEntity.getHeaders().entrySet()) { if (!httpRequestHeaders.containsKey(header.getKey())) { customHeaders.put( header.getKey(), StringUtils.collectionToCommaDelimitedString(header.getValue())); } } HttpServletRequest request = ((ServletRequestAttributes) RequestContextHolder.getRequestAttributes()).getRequest(); UrlPathHelper pathHelper = new UrlPathHelper(); customHeaders.put(CitrusHttpMessageHeaders.HTTP_REQUEST_URI, pathHelper.getRequestUri(request)); customHeaders.put( CitrusHttpMessageHeaders.HTTP_CONTEXT_PATH, pathHelper.getContextPath(request)); String queryParams = pathHelper.getOriginatingQueryString(request); customHeaders.put( CitrusHttpMessageHeaders.HTTP_QUERY_PARAMS, queryParams != null ? queryParams : ""); customHeaders.put(CitrusHttpMessageHeaders.HTTP_REQUEST_METHOD, method.toString()); Message<?> response = messageHandler.handleMessage( MessageBuilder.withPayload(requestEntity.getBody()) .copyHeaders(convertHeaderTypes(httpRequestHeaders)) .copyHeaders(customHeaders) .build()); return generateResponse(response); }
/** * Message headers consist of standard HTTP message headers and custom headers. This method * assumes that all header entries that were not initially mapped by header mapper implementations * are custom headers. * * @param httpHeaders all message headers in their pre nature. * @param mappedHeaders the previously mapped header entries (all standard headers). * @return */ private Map<String, String> getCustomHeaders( HttpHeaders httpHeaders, Map<String, ?> mappedHeaders) { Map<String, String> customHeaders = new HashMap<String, String>(); for (Entry<String, List<String>> header : httpHeaders.entrySet()) { if (!mappedHeaders.containsKey(header.getKey())) { customHeaders.put( header.getKey(), StringUtils.collectionToCommaDelimitedString(header.getValue())); } } return customHeaders; }