@Test public void testDumpRequest() { HttpServletRequest req = mock(HttpServletRequest.class); when(req.getMethod()).thenReturn("GET"); Vector<String> headerNames = new Vector<>(2); headerNames.add("Content-Type"); when (req.getHeaderNames()).thenReturn(headerNames.elements()); Vector<String> headers = new Vector<>(2); headers.add("application/xml"); when (req.getHeaders("Content-Type")).thenReturn(headers.elements()); Vector<String> attributes = new Vector<>(1); attributes.add("attribute1"); when (req.getAttributeNames()).thenReturn(attributes.elements()); when (req.getAttribute("attribute1")).thenReturn("value1"); assertThatCode(() -> XACMLRest.dumpRequest(req)).doesNotThrowAnyException(); Map<String, String[]> params = new HashMap<>(); String[] vals = new String[2]; vals[0] = "v1"; vals[1] = "v2"; params.put("param1", vals); when (req.getParameter("type")).thenReturn("hb"); when (req.getParameterMap()).thenReturn(params); assertThatCode(() -> XACMLRest.dumpRequest(req)).doesNotThrowAnyException(); when(req.getMethod()).thenReturn("PUT"); assertThatCode(() -> XACMLRest.dumpRequest(req)).doesNotThrowAnyException(); }
public static void dumpRequest(HttpServletRequest request) { if (! logger.isDebugEnabled()) { return; } if (request.getMethod().equals("GET") && "hb".equals(request.getParameter("type")) ) { logger.debug("GET type=hb : heartbeat received"); return; } logger.debug("{}:{} {} {}", request.getMethod(), request.getRemoteAddr(), request.getRemoteHost(), request.getRemotePort()); logger.debug("{} {} {}", request.getLocalAddr(), request.getLocalName(), request.getLocalPort()); Enumeration<String> en = request.getHeaderNames(); logger.debug("Headers:"); while (en.hasMoreElements()) { String element = en.nextElement(); Enumeration<String> values = request.getHeaders(element); while (values.hasMoreElements()) { String value = values.nextElement(); logger.debug("{}:{}", element, value); } } logger.debug("Attributes:"); en = request.getAttributeNames(); while (en.hasMoreElements()) { String element = en.nextElement(); logger.debug("{}:{}", element, request.getAttribute(element)); } logger.debug("ContextPath: {}", request.getContextPath()); if (request.getMethod().equals("PUT") || request.getMethod().equals("POST")) { logger.debug("Query String: {}", request.getQueryString()); try { if (request.getInputStream() == null) { logger.debug("Content: No content inputStream"); } else { logger.debug("Content available: {}", request.getInputStream().available()); } } catch (Exception e) { logger.debug("Content: inputStream exception: {}", e.getMessage(), e); } } else { logger.debug("Parameters:"); Map<String, String[]> params = request.getParameterMap(); Set<String> keys = params.keySet(); for (String key : keys) { String[] values = params.get(key); logger.debug("{}({}): {}", key, values.length, values); } } logger.debug("Request URL {}", request.getRequestURL()); }
XACMLRest { public static void dumpRequest(HttpServletRequest request) { if (! logger.isDebugEnabled()) { return; } if (request.getMethod().equals("GET") && "hb".equals(request.getParameter("type")) ) { logger.debug("GET type=hb : heartbeat received"); return; } logger.debug("{}:{} {} {}", request.getMethod(), request.getRemoteAddr(), request.getRemoteHost(), request.getRemotePort()); logger.debug("{} {} {}", request.getLocalAddr(), request.getLocalName(), request.getLocalPort()); Enumeration<String> en = request.getHeaderNames(); logger.debug("Headers:"); while (en.hasMoreElements()) { String element = en.nextElement(); Enumeration<String> values = request.getHeaders(element); while (values.hasMoreElements()) { String value = values.nextElement(); logger.debug("{}:{}", element, value); } } logger.debug("Attributes:"); en = request.getAttributeNames(); while (en.hasMoreElements()) { String element = en.nextElement(); logger.debug("{}:{}", element, request.getAttribute(element)); } logger.debug("ContextPath: {}", request.getContextPath()); if (request.getMethod().equals("PUT") || request.getMethod().equals("POST")) { logger.debug("Query String: {}", request.getQueryString()); try { if (request.getInputStream() == null) { logger.debug("Content: No content inputStream"); } else { logger.debug("Content available: {}", request.getInputStream().available()); } } catch (Exception e) { logger.debug("Content: inputStream exception: {}", e.getMessage(), e); } } else { logger.debug("Parameters:"); Map<String, String[]> params = request.getParameterMap(); Set<String> keys = params.keySet(); for (String key : keys) { String[] values = params.get(key); logger.debug("{}({}): {}", key, values.length, values); } } logger.debug("Request URL {}", request.getRequestURL()); } }
XACMLRest { public static void dumpRequest(HttpServletRequest request) { if (! logger.isDebugEnabled()) { return; } if (request.getMethod().equals("GET") && "hb".equals(request.getParameter("type")) ) { logger.debug("GET type=hb : heartbeat received"); return; } logger.debug("{}:{} {} {}", request.getMethod(), request.getRemoteAddr(), request.getRemoteHost(), request.getRemotePort()); logger.debug("{} {} {}", request.getLocalAddr(), request.getLocalName(), request.getLocalPort()); Enumeration<String> en = request.getHeaderNames(); logger.debug("Headers:"); while (en.hasMoreElements()) { String element = en.nextElement(); Enumeration<String> values = request.getHeaders(element); while (values.hasMoreElements()) { String value = values.nextElement(); logger.debug("{}:{}", element, value); } } logger.debug("Attributes:"); en = request.getAttributeNames(); while (en.hasMoreElements()) { String element = en.nextElement(); logger.debug("{}:{}", element, request.getAttribute(element)); } logger.debug("ContextPath: {}", request.getContextPath()); if (request.getMethod().equals("PUT") || request.getMethod().equals("POST")) { logger.debug("Query String: {}", request.getQueryString()); try { if (request.getInputStream() == null) { logger.debug("Content: No content inputStream"); } else { logger.debug("Content available: {}", request.getInputStream().available()); } } catch (Exception e) { logger.debug("Content: inputStream exception: {}", e.getMessage(), e); } } else { logger.debug("Parameters:"); Map<String, String[]> params = request.getParameterMap(); Set<String> keys = params.keySet(); for (String key : keys) { String[] values = params.get(key); logger.debug("{}({}): {}", key, values.length, values); } } logger.debug("Request URL {}", request.getRequestURL()); } private  XACMLRest(); }
XACMLRest { public static void dumpRequest(HttpServletRequest request) { if (! logger.isDebugEnabled()) { return; } if (request.getMethod().equals("GET") && "hb".equals(request.getParameter("type")) ) { logger.debug("GET type=hb : heartbeat received"); return; } logger.debug("{}:{} {} {}", request.getMethod(), request.getRemoteAddr(), request.getRemoteHost(), request.getRemotePort()); logger.debug("{} {} {}", request.getLocalAddr(), request.getLocalName(), request.getLocalPort()); Enumeration<String> en = request.getHeaderNames(); logger.debug("Headers:"); while (en.hasMoreElements()) { String element = en.nextElement(); Enumeration<String> values = request.getHeaders(element); while (values.hasMoreElements()) { String value = values.nextElement(); logger.debug("{}:{}", element, value); } } logger.debug("Attributes:"); en = request.getAttributeNames(); while (en.hasMoreElements()) { String element = en.nextElement(); logger.debug("{}:{}", element, request.getAttribute(element)); } logger.debug("ContextPath: {}", request.getContextPath()); if (request.getMethod().equals("PUT") || request.getMethod().equals("POST")) { logger.debug("Query String: {}", request.getQueryString()); try { if (request.getInputStream() == null) { logger.debug("Content: No content inputStream"); } else { logger.debug("Content available: {}", request.getInputStream().available()); } } catch (Exception e) { logger.debug("Content: inputStream exception: {}", e.getMessage(), e); } } else { logger.debug("Parameters:"); Map<String, String[]> params = request.getParameterMap(); Set<String> keys = params.keySet(); for (String key : keys) { String[] values = params.get(key); logger.debug("{}({}): {}", key, values.length, values); } } logger.debug("Request URL {}", request.getRequestURL()); } private  XACMLRest(); static void xacmlInit(ServletConfig config); static void loadXacmlProperties(Properties policyProperties, Properties pipProperties); static void dumpRequest(HttpServletRequest request); }
XACMLRest { public static void dumpRequest(HttpServletRequest request) { if (! logger.isDebugEnabled()) { return; } if (request.getMethod().equals("GET") && "hb".equals(request.getParameter("type")) ) { logger.debug("GET type=hb : heartbeat received"); return; } logger.debug("{}:{} {} {}", request.getMethod(), request.getRemoteAddr(), request.getRemoteHost(), request.getRemotePort()); logger.debug("{} {} {}", request.getLocalAddr(), request.getLocalName(), request.getLocalPort()); Enumeration<String> en = request.getHeaderNames(); logger.debug("Headers:"); while (en.hasMoreElements()) { String element = en.nextElement(); Enumeration<String> values = request.getHeaders(element); while (values.hasMoreElements()) { String value = values.nextElement(); logger.debug("{}:{}", element, value); } } logger.debug("Attributes:"); en = request.getAttributeNames(); while (en.hasMoreElements()) { String element = en.nextElement(); logger.debug("{}:{}", element, request.getAttribute(element)); } logger.debug("ContextPath: {}", request.getContextPath()); if (request.getMethod().equals("PUT") || request.getMethod().equals("POST")) { logger.debug("Query String: {}", request.getQueryString()); try { if (request.getInputStream() == null) { logger.debug("Content: No content inputStream"); } else { logger.debug("Content available: {}", request.getInputStream().available()); } } catch (Exception e) { logger.debug("Content: inputStream exception: {}", e.getMessage(), e); } } else { logger.debug("Parameters:"); Map<String, String[]> params = request.getParameterMap(); Set<String> keys = params.keySet(); for (String key : keys) { String[] values = params.get(key); logger.debug("{}({}): {}", key, values.length, values); } } logger.debug("Request URL {}", request.getRequestURL()); } private  XACMLRest(); static void xacmlInit(ServletConfig config); static void loadXacmlProperties(Properties policyProperties, Properties pipProperties); static void dumpRequest(HttpServletRequest request);  }