@Test public void readParameters() { final String param1 = "p1"; final String param2 = "p2"; final String param1VReal = "I am a really long string that should be cropped in an meaningful way."; final String param2VReal1 = "value5"; final String param2VReal2 = "value6"; final String[] param1V = new String[] { param1VReal }; final String[] param2V = new String[] { param2VReal1, param2VReal2 }; final Map<String, String[]> parameterMap = new HashMap<String, String[]>(); MapUtils.putAll(parameterMap, new Object[][] { { param1, param1V }, { param2, param2V } }); when(httpServletRequest.getParameterMap()).thenReturn(parameterMap); Map<String, String[]> result = extractor.getParameterMap(httpServletRequest.getClass(), httpServletRequest); assertThat(result.size(), is(parameterMap.size())); assertThat(result, hasKey(param1)); assertThat(result, hasKey(param2)); assertThat("Value should be cropped!", result.get(param1), is(not(param1V))); assertThat(result.get(param2), is(param2V)); }
public Map<String, String[]> getParameterMap(Class<?> httpServletRequestClass, Object httpServletRequest) { Method m = retrieveMethod(HttpMethods.SERVLET_GET_PARAMETER_MAP, httpServletRequestClass); if (null == m) { return null; } try { @SuppressWarnings("unchecked") Map<String, String[]> parameterMap = (Map<String, String[]>) m.invoke(httpServletRequest, (Object[]) null); if ((null == parameterMap) || parameterMap.isEmpty()) { return null; } return strConstraint.crop(parameterMap); } catch (Exception e) { LOG.error("Invocation on given object failed.", e); return null; } }
HttpInformationExtractor { public Map<String, String[]> getParameterMap(Class<?> httpServletRequestClass, Object httpServletRequest) { Method m = retrieveMethod(HttpMethods.SERVLET_GET_PARAMETER_MAP, httpServletRequestClass); if (null == m) { return null; } try { @SuppressWarnings("unchecked") Map<String, String[]> parameterMap = (Map<String, String[]>) m.invoke(httpServletRequest, (Object[]) null); if ((null == parameterMap) || parameterMap.isEmpty()) { return null; } return strConstraint.crop(parameterMap); } catch (Exception e) { LOG.error("Invocation on given object failed.", e); return null; } } }
HttpInformationExtractor { public Map<String, String[]> getParameterMap(Class<?> httpServletRequestClass, Object httpServletRequest) { Method m = retrieveMethod(HttpMethods.SERVLET_GET_PARAMETER_MAP, httpServletRequestClass); if (null == m) { return null; } try { @SuppressWarnings("unchecked") Map<String, String[]> parameterMap = (Map<String, String[]>) m.invoke(httpServletRequest, (Object[]) null); if ((null == parameterMap) || parameterMap.isEmpty()) { return null; } return strConstraint.crop(parameterMap); } catch (Exception e) { LOG.error("Invocation on given object failed.", e); return null; } } HttpInformationExtractor(StringConstraint strConstraint); }
HttpInformationExtractor { public Map<String, String[]> getParameterMap(Class<?> httpServletRequestClass, Object httpServletRequest) { Method m = retrieveMethod(HttpMethods.SERVLET_GET_PARAMETER_MAP, httpServletRequestClass); if (null == m) { return null; } try { @SuppressWarnings("unchecked") Map<String, String[]> parameterMap = (Map<String, String[]>) m.invoke(httpServletRequest, (Object[]) null); if ((null == parameterMap) || parameterMap.isEmpty()) { return null; } return strConstraint.crop(parameterMap); } catch (Exception e) { LOG.error("Invocation on given object failed.", e); return null; } } HttpInformationExtractor(StringConstraint strConstraint); String getRequestUri(Class<?> httpServletRequestClass, Object httpServletRequest); String getRequestMethod(Class<?> httpServletRequestClass, Object httpServletRequest); Map<String, String[]> getParameterMap(Class<?> httpServletRequestClass, Object httpServletRequest); Map<String, String> getAttributes(Class<?> httpServletRequestClass, Object httpServletRequest); Map<String, String> getHeaders(Class<?> httpServletRequestClass, Object httpServletRequest); Map<String, String> getSessionAttributes(Class<?> httpServletRequestClass, Object httpServletRequest); int getResponseStatus(Class<?> httpServletResponseClass, Object httpServletResponse); String getScheme(Class<?> httpServletRequestClass, Object httpServletRequest); String getServerName(Class<?> httpServletRequestClass, Object httpServletRequest); int getServerPort(Class<?> httpServletRequestClass, Object httpServletRequest); String getQueryString(Class<?> httpServletRequestClass, Object httpServletRequest); }
HttpInformationExtractor { public Map<String, String[]> getParameterMap(Class<?> httpServletRequestClass, Object httpServletRequest) { Method m = retrieveMethod(HttpMethods.SERVLET_GET_PARAMETER_MAP, httpServletRequestClass); if (null == m) { return null; } try { @SuppressWarnings("unchecked") Map<String, String[]> parameterMap = (Map<String, String[]>) m.invoke(httpServletRequest, (Object[]) null); if ((null == parameterMap) || parameterMap.isEmpty()) { return null; } return strConstraint.crop(parameterMap); } catch (Exception e) { LOG.error("Invocation on given object failed.", e); return null; } } HttpInformationExtractor(StringConstraint strConstraint); String getRequestUri(Class<?> httpServletRequestClass, Object httpServletRequest); String getRequestMethod(Class<?> httpServletRequestClass, Object httpServletRequest); Map<String, String[]> getParameterMap(Class<?> httpServletRequestClass, Object httpServletRequest); Map<String, String> getAttributes(Class<?> httpServletRequestClass, Object httpServletRequest); Map<String, String> getHeaders(Class<?> httpServletRequestClass, Object httpServletRequest); Map<String, String> getSessionAttributes(Class<?> httpServletRequestClass, Object httpServletRequest); int getResponseStatus(Class<?> httpServletResponseClass, Object httpServletResponse); String getScheme(Class<?> httpServletRequestClass, Object httpServletRequest); String getServerName(Class<?> httpServletRequestClass, Object httpServletRequest); int getServerPort(Class<?> httpServletRequestClass, Object httpServletRequest); String getQueryString(Class<?> httpServletRequestClass, Object httpServletRequest);  }