CachingHttpServletRequestWrapper extends HttpServletRequestWrapper { @Override public Map<String, String[]> getParameterMap() { final Map<String, String[]> params = new HashMap<>(super.getParameterMap()); MediaType contentType = Optional.ofNullable(getContentType()) .map(mediaType -> { try { return MediaType.valueOf(mediaType); } catch (InvalidMediaTypeException e) { log.warn(String.format("Failed to parse content type '%s' - using default media type '%s'", getContentType(), MediaType.ALL_VALUE), e); return MediaType.ALL; } }) .orElse(MediaType.ALL); Charset charset = Optional.ofNullable(contentType.getCharset()) .orElse(Charset.forName(CitrusSettings.CITRUS_FILE_ENCODING)); if (RequestMethod.POST.name().equals(getMethod()) || RequestMethod.PUT.name().equals(getMethod())) { if (new MediaType(contentType.getType(), contentType.getSubtype()).equals(MediaType.APPLICATION_FORM_URLENCODED)) { try { fillParams(params, new String(FileCopyUtils.copyToByteArray(getInputStream()), charset), charset); } catch (IOException e) { throw new CitrusRuntimeException("Failed to read request body", e); } } } else { fillParams(params, getQueryString(), charset); } return params; } @SuppressWarnings("WeakerAccess")  CachingHttpServletRequestWrapper(final HttpServletRequest request); @Override Map<String, String[]> getParameterMap(); @Override ServletInputStream getInputStream();  }
@Test public void testDelegateGetParameterIfBodyIsNull() { final String expectedKey = "foobar"; when(serverRequestMock.getParameterMap()).thenReturn(Collections.singletonMap(expectedKey, new String[]{})); final Map<String, String[]> parameterMap = wrapper.getParameterMap(); assertEquals(parameterMap.keySet().size(),1); assertTrue(parameterMap.containsKey(expectedKey)); }