@Test public void sessionAttributesWithNoSession() { when(httpServletRequest.getSession(false)).thenReturn(null); Map<String, String> result = extractor.getSessionAttributes(httpServletRequest.getClass(), httpServletRequest); assertThat(result, is(nullValue())); }
public Map<String, String> getSessionAttributes(Class<?> httpServletRequestClass, Object httpServletRequest) { Method getSessionMethod = retrieveMethod(HttpMethods.SERVLET_GET_SESSION, httpServletRequestClass); if (null == getSessionMethod) { return null; } Object httpSession; Class<?> httpSessionClass; try { httpSession = getSessionMethod.invoke(httpServletRequest, new Object[] { Boolean.FALSE }); if (httpSession == null) { if (LOG.isDebugEnabled()) { LOG.debug("No session can be found"); } return null; } httpSessionClass = httpSession.getClass(); } catch (Exception e) { LOG.error("Invocation of to get attributes on given object failed.", e); return null; } Method getAttributeNamesSession = retrieveMethod(HttpMethods.SESSION_GET_ATTRIBUTE_NAMES, httpSessionClass); if (null == getAttributeNamesSession) { return null; } Method getAttributeValueSession = retrieveMethod(HttpMethods.SESSION_GET_ATTRIBUTE, httpSessionClass); if (null == getAttributeValueSession) { return null; } try { @SuppressWarnings("unchecked") Enumeration<String> sessionAttr = (Enumeration<String>) getAttributeNamesSession.invoke(httpSession, (Object[]) null); Map<String, String> sessionAttributes = new HashMap<String, String>(); if (null != sessionAttr) { while (sessionAttr.hasMoreElements()) { String sessionAtt = sessionAttr.nextElement(); Object sessionValue = getAttributeValueSession.invoke(httpSession, sessionAtt); sessionAttributes.put(sessionAtt, strConstraint.crop(getAttributeValue(sessionValue))); } return sessionAttributes; } } catch (Exception e) { LOG.error("Invocation of to get attributes on given object failed.", e); } return null; }
HttpInformationExtractor { public Map<String, String> getSessionAttributes(Class<?> httpServletRequestClass, Object httpServletRequest) { Method getSessionMethod = retrieveMethod(HttpMethods.SERVLET_GET_SESSION, httpServletRequestClass); if (null == getSessionMethod) { return null; } Object httpSession; Class<?> httpSessionClass; try { httpSession = getSessionMethod.invoke(httpServletRequest, new Object[] { Boolean.FALSE }); if (httpSession == null) { if (LOG.isDebugEnabled()) { LOG.debug("No session can be found"); } return null; } httpSessionClass = httpSession.getClass(); } catch (Exception e) { LOG.error("Invocation of to get attributes on given object failed.", e); return null; } Method getAttributeNamesSession = retrieveMethod(HttpMethods.SESSION_GET_ATTRIBUTE_NAMES, httpSessionClass); if (null == getAttributeNamesSession) { return null; } Method getAttributeValueSession = retrieveMethod(HttpMethods.SESSION_GET_ATTRIBUTE, httpSessionClass); if (null == getAttributeValueSession) { return null; } try { @SuppressWarnings("unchecked") Enumeration<String> sessionAttr = (Enumeration<String>) getAttributeNamesSession.invoke(httpSession, (Object[]) null); Map<String, String> sessionAttributes = new HashMap<String, String>(); if (null != sessionAttr) { while (sessionAttr.hasMoreElements()) { String sessionAtt = sessionAttr.nextElement(); Object sessionValue = getAttributeValueSession.invoke(httpSession, sessionAtt); sessionAttributes.put(sessionAtt, strConstraint.crop(getAttributeValue(sessionValue))); } return sessionAttributes; } } catch (Exception e) { LOG.error("Invocation of to get attributes on given object failed.", e); } return null; } }
HttpInformationExtractor { public Map<String, String> getSessionAttributes(Class<?> httpServletRequestClass, Object httpServletRequest) { Method getSessionMethod = retrieveMethod(HttpMethods.SERVLET_GET_SESSION, httpServletRequestClass); if (null == getSessionMethod) { return null; } Object httpSession; Class<?> httpSessionClass; try { httpSession = getSessionMethod.invoke(httpServletRequest, new Object[] { Boolean.FALSE }); if (httpSession == null) { if (LOG.isDebugEnabled()) { LOG.debug("No session can be found"); } return null; } httpSessionClass = httpSession.getClass(); } catch (Exception e) { LOG.error("Invocation of to get attributes on given object failed.", e); return null; } Method getAttributeNamesSession = retrieveMethod(HttpMethods.SESSION_GET_ATTRIBUTE_NAMES, httpSessionClass); if (null == getAttributeNamesSession) { return null; } Method getAttributeValueSession = retrieveMethod(HttpMethods.SESSION_GET_ATTRIBUTE, httpSessionClass); if (null == getAttributeValueSession) { return null; } try { @SuppressWarnings("unchecked") Enumeration<String> sessionAttr = (Enumeration<String>) getAttributeNamesSession.invoke(httpSession, (Object[]) null); Map<String, String> sessionAttributes = new HashMap<String, String>(); if (null != sessionAttr) { while (sessionAttr.hasMoreElements()) { String sessionAtt = sessionAttr.nextElement(); Object sessionValue = getAttributeValueSession.invoke(httpSession, sessionAtt); sessionAttributes.put(sessionAtt, strConstraint.crop(getAttributeValue(sessionValue))); } return sessionAttributes; } } catch (Exception e) { LOG.error("Invocation of to get attributes on given object failed.", e); } return null; } HttpInformationExtractor(StringConstraint strConstraint); }
HttpInformationExtractor { public Map<String, String> getSessionAttributes(Class<?> httpServletRequestClass, Object httpServletRequest) { Method getSessionMethod = retrieveMethod(HttpMethods.SERVLET_GET_SESSION, httpServletRequestClass); if (null == getSessionMethod) { return null; } Object httpSession; Class<?> httpSessionClass; try { httpSession = getSessionMethod.invoke(httpServletRequest, new Object[] { Boolean.FALSE }); if (httpSession == null) { if (LOG.isDebugEnabled()) { LOG.debug("No session can be found"); } return null; } httpSessionClass = httpSession.getClass(); } catch (Exception e) { LOG.error("Invocation of to get attributes on given object failed.", e); return null; } Method getAttributeNamesSession = retrieveMethod(HttpMethods.SESSION_GET_ATTRIBUTE_NAMES, httpSessionClass); if (null == getAttributeNamesSession) { return null; } Method getAttributeValueSession = retrieveMethod(HttpMethods.SESSION_GET_ATTRIBUTE, httpSessionClass); if (null == getAttributeValueSession) { return null; } try { @SuppressWarnings("unchecked") Enumeration<String> sessionAttr = (Enumeration<String>) getAttributeNamesSession.invoke(httpSession, (Object[]) null); Map<String, String> sessionAttributes = new HashMap<String, String>(); if (null != sessionAttr) { while (sessionAttr.hasMoreElements()) { String sessionAtt = sessionAttr.nextElement(); Object sessionValue = getAttributeValueSession.invoke(httpSession, sessionAtt); sessionAttributes.put(sessionAtt, strConstraint.crop(getAttributeValue(sessionValue))); } return sessionAttributes; } } catch (Exception e) { LOG.error("Invocation of to get attributes 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> getSessionAttributes(Class<?> httpServletRequestClass, Object httpServletRequest) { Method getSessionMethod = retrieveMethod(HttpMethods.SERVLET_GET_SESSION, httpServletRequestClass); if (null == getSessionMethod) { return null; } Object httpSession; Class<?> httpSessionClass; try { httpSession = getSessionMethod.invoke(httpServletRequest, new Object[] { Boolean.FALSE }); if (httpSession == null) { if (LOG.isDebugEnabled()) { LOG.debug("No session can be found"); } return null; } httpSessionClass = httpSession.getClass(); } catch (Exception e) { LOG.error("Invocation of to get attributes on given object failed.", e); return null; } Method getAttributeNamesSession = retrieveMethod(HttpMethods.SESSION_GET_ATTRIBUTE_NAMES, httpSessionClass); if (null == getAttributeNamesSession) { return null; } Method getAttributeValueSession = retrieveMethod(HttpMethods.SESSION_GET_ATTRIBUTE, httpSessionClass); if (null == getAttributeValueSession) { return null; } try { @SuppressWarnings("unchecked") Enumeration<String> sessionAttr = (Enumeration<String>) getAttributeNamesSession.invoke(httpSession, (Object[]) null); Map<String, String> sessionAttributes = new HashMap<String, String>(); if (null != sessionAttr) { while (sessionAttr.hasMoreElements()) { String sessionAtt = sessionAttr.nextElement(); Object sessionValue = getAttributeValueSession.invoke(httpSession, sessionAtt); sessionAttributes.put(sessionAtt, strConstraint.crop(getAttributeValue(sessionValue))); } return sessionAttributes; } } catch (Exception e) { LOG.error("Invocation of to get attributes 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);  }