/** * Forwards the request to the next filter in the chain and delegates down to the subclasses * to perform the actual request logging both before and after the request is processed. * @see #beforeRequest * @see #afterRequest */ @Override protected void doFilterInternal(HttpServletRequest request, HttpServletResponse response, FilterChain filterChain) throws ServletException, IOException { boolean isFirstRequest = !isAsyncDispatch(request); HttpServletRequest requestToUse = request; if (isIncludePayload() && isFirstRequest && !(request instanceof ContentCachingRequestWrapper)) { requestToUse = new ContentCachingRequestWrapper(request, getMaxPayloadLength()); } boolean shouldLog = shouldLog(requestToUse); if (shouldLog && isFirstRequest) { beforeRequest(requestToUse, getBeforeMessage(requestToUse)); } try { filterChain.doFilter(requestToUse, response); } finally { if (shouldLog && !isAsyncStarted(requestToUse)) { afterRequest(requestToUse, getAfterMessage(requestToUse)); } } }
/** * Get the message to write to the log before the request. * @see #createMessage */ private String getBeforeMessage(HttpServletRequest request) { return createMessage(request, this.beforeMessagePrefix, this.beforeMessageSuffix); }
msg.append("uri=").append(request.getRequestURI()); if (isIncludeQueryString()) { String queryString = request.getQueryString(); if (queryString != null) { if (isIncludeClientInfo()) { String client = request.getRemoteAddr(); if (StringUtils.hasLength(client)) { if (isIncludeHeaders()) { msg.append(";headers=").append(new ServletServerHttpRequest(request).getHeaders()); if (isIncludePayload()) { String payload = getMessagePayload(request); if (payload != null) { msg.append(";payload=").append(payload);
/** * Forwards the request to the next filter in the chain and delegates down to the subclasses * to perform the actual request logging both before and after the request is processed. * @see #beforeRequest * @see #afterRequest */ @Override protected void doFilterInternal(HttpServletRequest request, HttpServletResponse response, FilterChain filterChain) throws ServletException, IOException { boolean isFirstRequest = !isAsyncDispatch(request); HttpServletRequest requestToUse = request; if (isIncludePayload() && isFirstRequest && !(request instanceof ContentCachingRequestWrapper)) { requestToUse = new ContentCachingRequestWrapper(request, getMaxPayloadLength()); } boolean shouldLog = shouldLog(requestToUse); if (shouldLog && isFirstRequest) { beforeRequest(requestToUse, getBeforeMessage(requestToUse)); } try { filterChain.doFilter(requestToUse, response); } finally { if (shouldLog && !isAsyncStarted(requestToUse)) { afterRequest(requestToUse, getAfterMessage(requestToUse)); } } }
/** * Forwards the request to the next filter in the chain and delegates * down to the subclasses to perform the actual request logging both * before and after the request is processed. * @see #beforeRequest * @see #afterRequest */ protected void doFilterInternal( HttpServletRequest request, HttpServletResponse response, FilterChain filterChain) throws ServletException, IOException { beforeRequest(request, getBeforeMessage(request)); try { filterChain.doFilter(request, response); } finally { afterRequest(request, getAfterMessage(request)); } }
/** * Extracts the message payload portion of the message created by * {@link #createMessage(HttpServletRequest, String, String)} when * {@link #isIncludePayload()} returns true. * @since 5.0.3 */ @Nullable protected String getMessagePayload(HttpServletRequest request) { ContentCachingRequestWrapper wrapper = WebUtils.getNativeRequest(request, ContentCachingRequestWrapper.class); if (wrapper != null) { byte[] buf = wrapper.getContentAsByteArray(); if (buf.length > 0) { int length = Math.min(buf.length, getMaxPayloadLength()); try { return new String(buf, 0, length, wrapper.getCharacterEncoding()); } catch (UnsupportedEncodingException ex) { return "[unknown]"; } } } return null; }
/** * Create a log message for the given request, prefix and suffix. * <p>If <code>includeQueryString</code> is <code>true</code> then * the inner part of the log message will take the form * <code>request_uri?query_string</code> otherwise the message will * simply be of the form <code>request_uri</code>. * <p>The final message is composed of the inner part as described * and the supplied prefix and suffix. */ protected String createMessage(HttpServletRequest request, String prefix, String suffix) { StringBuffer buffer = new StringBuffer(); buffer.append(prefix); buffer.append(request.getRequestURI()); if (isIncludeQueryString()) { buffer.append('?'); buffer.append(request.getQueryString()); } buffer.append(suffix); return buffer.toString(); }
/** * Extracts the message payload portion of the message created by * {@link #createMessage(HttpServletRequest, String, String)} when * {@link #isIncludePayload()} returns true. * @since 5.0.3 */ @Nullable protected String getMessagePayload(HttpServletRequest request) { ContentCachingRequestWrapper wrapper = WebUtils.getNativeRequest(request, ContentCachingRequestWrapper.class); if (wrapper != null) { byte[] buf = wrapper.getContentAsByteArray(); if (buf.length > 0) { int length = Math.min(buf.length, getMaxPayloadLength()); try { return new String(buf, 0, length, wrapper.getCharacterEncoding()); } catch (UnsupportedEncodingException ex) { return "[unknown]"; } } } return null; }
/** * Forwards the request to the next filter in the chain and delegates down to the subclasses * to perform the actual request logging both before and after the request is processed. * @see #beforeRequest * @see #afterRequest */ @Override protected void doFilterInternal(HttpServletRequest request, HttpServletResponse response, FilterChain filterChain) throws ServletException, IOException { boolean isFirstRequest = !isAsyncDispatch(request); HttpServletRequest requestToUse = request; if (isIncludePayload() && isFirstRequest && !(request instanceof ContentCachingRequestWrapper)) { requestToUse = new ContentCachingRequestWrapper(request, getMaxPayloadLength()); } boolean shouldLog = shouldLog(requestToUse); if (shouldLog && isFirstRequest) { beforeRequest(requestToUse, getBeforeMessage(requestToUse)); } try { filterChain.doFilter(requestToUse, response); } finally { if (shouldLog && !isAsyncStarted(requestToUse)) { afterRequest(requestToUse, getAfterMessage(requestToUse)); } } }
msg.append("uri=").append(request.getRequestURI()); if (isIncludeQueryString()) { String queryString = request.getQueryString(); if (queryString != null) { if (isIncludeClientInfo()) { String client = request.getRemoteAddr(); if (StringUtils.hasLength(client)) { if (isIncludeHeaders()) { msg.append(";headers=").append(new ServletServerHttpRequest(request).getHeaders()); if (isIncludePayload()) { String payload = getMessagePayload(request); if (payload != null) { msg.append(";payload=").append(payload);
/** * Get the message to write to the log after the request. * @see #createMessage */ private String getAfterMessage(HttpServletRequest request) { return createMessage(request, this.afterMessagePrefix, this.afterMessageSuffix); }
/** * Extracts the message payload portion of the message created by * {@link #createMessage(HttpServletRequest, String, String)} when * {@link #isIncludePayload()} returns true. * @since 5.0.3 */ @Nullable protected String getMessagePayload(HttpServletRequest request) { ContentCachingRequestWrapper wrapper = WebUtils.getNativeRequest(request, ContentCachingRequestWrapper.class); if (wrapper != null) { byte[] buf = wrapper.getContentAsByteArray(); if (buf.length > 0) { int length = Math.min(buf.length, getMaxPayloadLength()); try { return new String(buf, 0, length, wrapper.getCharacterEncoding()); } catch (UnsupportedEncodingException ex) { return "[unknown]"; } } } return null; }
/** * Forwards the request to the next filter in the chain and delegates down to the subclasses * to perform the actual request logging both before and after the request is processed. * @see #beforeRequest * @see #afterRequest */ @Override protected void doFilterInternal(HttpServletRequest request, HttpServletResponse response, FilterChain filterChain) throws ServletException, IOException { boolean isFirstRequest = !isAsyncDispatch(request); HttpServletRequest requestToUse = request; if (isIncludePayload() && isFirstRequest && !(request instanceof ContentCachingRequestWrapper)) { requestToUse = new ContentCachingRequestWrapper(request, getMaxPayloadLength()); } boolean shouldLog = shouldLog(requestToUse); if (shouldLog && isFirstRequest) { beforeRequest(requestToUse, getBeforeMessage(requestToUse)); } try { filterChain.doFilter(requestToUse, response); } finally { if (shouldLog && !isAsyncStarted(requestToUse)) { afterRequest(requestToUse, getAfterMessage(requestToUse)); } } }
msg.append("uri=").append(request.getRequestURI()); if (isIncludeQueryString()) { String queryString = request.getQueryString(); if (queryString != null) { if (isIncludeClientInfo()) { String client = request.getRemoteAddr(); if (StringUtils.hasLength(client)) { if (isIncludeHeaders()) { msg.append(";headers=").append(new ServletServerHttpRequest(request).getHeaders()); if (isIncludePayload()) { String payload = getMessagePayload(request); if (payload != null) { msg.append(";payload=").append(payload);
/** * Get the message to write to the log after the request. * @see #createMessage */ private String getAfterMessage(HttpServletRequest request) { return createMessage(request, this.afterMessagePrefix, this.afterMessageSuffix); }
msg.append("uri=").append(request.getRequestURI()); if (isIncludeQueryString()) { String queryString = request.getQueryString(); if (queryString != null) { if (isIncludeClientInfo()) { String client = request.getRemoteAddr(); if (StringUtils.hasLength(client)) { if (isIncludeHeaders()) { msg.append(";headers=").append(new ServletServerHttpRequest(request).getHeaders()); String payload = getMessagePayload(request); if (payload != null) { msg.append(";payload=").append(payload);
/** * Get the message to write to the log before the request. * @see #createMessage */ private String getBeforeMessage(HttpServletRequest request) { return createMessage(request, this.beforeMessagePrefix, this.beforeMessageSuffix); }
/** * Get the message to write to the log before the request. * @see #createMessage */ private String getBeforeMessage(HttpServletRequest request) { return createMessage(request, this.beforeMessagePrefix, this.beforeMessageSuffix); }
/** * Get the message to write to the log after the request. * @see #createMessage */ private String getAfterMessage(HttpServletRequest request) { return createMessage(request, this.afterMessagePrefix, this.afterMessageSuffix); }
/** * Get the message to write to the log after the request. * @see #createMessage */ private String getAfterMessage(HttpServletRequest request) { return createMessage(request, this.afterMessagePrefix, this.afterMessageSuffix); }