Print the access logs before UrlRewriteFilter

五迷三道 提交于 2019-12-08 05:14:09

问题


I have an application in which currently I am using two filters.

First one is UrlRewriteFilter which is for re-writing the url.

<filter>
    <filter-name>UrlRewriteFilter</filter-name>
    <filter-class>org.tuckey.web.filters.urlrewrite.UrlRewriteFilter</filter-class>
    <init-param>
        <param-name>logLevel</param-name>
        <param-value>DEBUG</param-value>
    </init-param>
</filter>
<filter-mapping>
    <filter-name>UrlRewriteFilter</filter-name>
    <url-pattern>/*</url-pattern>
</filter-mapping>

Second is a filter which is printing the performance of each page, along with the url.

<filter>
    <filter-name>PerfLoggingFilter</filter-name>
    <filter-class>
        com.sia.saa.common.filter.PerfLoggingFilter
        </filter-class>
</filter>
<filter-mapping>
    <filter-name>PerfLoggingFilter</filter-name>
    <url-pattern>*.form</url-pattern>
    <dispatcher>REQUEST</dispatcher>
    <dispatcher>FORWARD</dispatcher>
</filter-mapping>   

But in the logs only the re-written URL is being printed and not the original url.
Please suggest a way so that URL re-writing can continue but in the logs only the original url is printed.
Note: Post questions in case you need other details.


回答1:


Since UrlRewriteFilter uses RequestDispatcher.forward(), I guess you can obtain original request URLs in your logging filter as

request.getAttribute("javax.servlet.forward.request_uri")

so that you can log them.




回答2:


Is it not possible to have the second filter before the first one? If the second filter is executed first, you will have the original url...



来源:https://stackoverflow.com/questions/5391899/print-the-access-logs-before-urlrewritefilter

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!