Uploaded image for project: 'Undertow'
  1. Undertow
  2. UNDERTOW-327

%r and %U in access log output forwarded URL

XMLWordPrintable

    • Hide

      Case 1. Servlet request forward.
      Create servlet filter.

      import java.io.IOException;
      
      import javax.servlet.Filter;
      import javax.servlet.FilterChain;
      import javax.servlet.FilterConfig;
      import javax.servlet.RequestDispatcher;
      import javax.servlet.ServletException;
      import javax.servlet.ServletRequest;
      import javax.servlet.ServletResponse;
      import javax.servlet.annotation.WebFilter;
      import javax.servlet.http.HttpServletRequest;
      
      @WebFilter(servletNames = "Faces Servlet")
      public class Forwarder implements Filter {
      
      	@Override
      	public void init(FilterConfig filterConfig) throws ServletException {
      	}
      
      	@Override
      	public void doFilter(ServletRequest request, ServletResponse response, FilterChain chain) throws IOException,
      			ServletException {
      		if (((HttpServletRequest) request).getRequestURI().endsWith("forward-me.xhtml")) {
      			RequestDispatcher dispatcher = request
      					.getRequestDispatcher("forward-target.xhtml");
      			dispatcher.forward(request, response);
      		} else {
      			chain.doFilter(request, response);
      		}
      	}
      
      	@Override
      	public void destroy() {
      	}
      
      }
      

      Request "forward-me.xhtml". Observe "GET forward-target.xhtml" being written to access log.

      Case 2. Servler error handling.
      Create error page, register it in web.xml.

      <error-page>
      	<location>/error.xhtml</location>
      </error-page>
      

      Request some page, that throws a error on GET. Observe "GET error.xhtml" being written to access log.

      Show
      Case 1. Servlet request forward. Create servlet filter. import java.io.IOException; import javax.servlet.Filter; import javax.servlet.FilterChain; import javax.servlet.FilterConfig; import javax.servlet.RequestDispatcher; import javax.servlet.ServletException; import javax.servlet.ServletRequest; import javax.servlet.ServletResponse; import javax.servlet.annotation.WebFilter; import javax.servlet.http.HttpServletRequest; @WebFilter(servletNames = "Faces Servlet" ) public class Forwarder implements Filter { @Override public void init(FilterConfig filterConfig) throws ServletException { } @Override public void doFilter(ServletRequest request, ServletResponse response, FilterChain chain) throws IOException, ServletException { if (((HttpServletRequest) request).getRequestURI().endsWith( "forward-me.xhtml" )) { RequestDispatcher dispatcher = request .getRequestDispatcher( "forward-target.xhtml" ); dispatcher.forward(request, response); } else { chain.doFilter(request, response); } } @Override public void destroy() { } } Request "forward-me.xhtml". Observe "GET forward-target.xhtml" being written to access log. Case 2. Servler error handling. Create error page, register it in web.xml. <error-page> <location>/error.xhtml</location> </error-page> Request some page, that throws a error on GET. Observe "GET error.xhtml" being written to access log.

      Noticed this happening in two cases.

      1. Servlet request forward (javax.servlet.DispatcherType.FORWARD).
      2. Servlet error handling (javax.servlet.DispatcherType.ERROR).

      In both cases %r and %U result in a rewritten URL being written to access log, not the original. This was not the case in JBoss Web at least for forwarding (didn't use servlet error handling then). The rewritten URL could be useful too, but it should be available as a separate token.

      Didn't test javax.servlet.DispatcherType.INCLUDE.

              sdouglas1@redhat.com Stuart Douglas (Inactive)
              vsevolodgol Vsevolod Golovanov (Inactive)
              Votes:
              0 Vote for this issue
              Watchers:
              2 Start watching this issue

                Created:
                Updated:
                Resolved: