Servlet Filter is Called Twice in Embedded Jetty

classic Classic list List threaded Threaded
3 messages Options
Reply | Threaded
Open this post in threaded view
|

Servlet Filter is Called Twice in Embedded Jetty

Igal @ Lucee.org
I have written a very simple test Filter, and am running it in an embedded Jetty 9.2.18.v20160721 in debug mode in IntelliJ IDEA:

        System.out.println(TestFilter.class.getSimpleName()       // line 12
                + " > "
                + ((HttpServletRequest)servletRequest).getRequestURL()
                + ": IP "+ servletRequest.getRemoteAddr()
                + "; at "
                + new Date().toString());

        // Pass request back down the filter chain
        filterChain.doFilter(servletRequest, servletResponse);    // line 20
    }
and added it to web.xml:

<filter>
    <filter-name>TestFilter</filter-name>
    <filter-class>net.twentyonesolutions.TestFilter</filter-class>
</filter>

<filter-mapping>
    <filter-name>TestFilter</filter-name>
    <url-pattern>/*</url-pattern>
</filter-mapping>
When running in debug mode in IntelliJ IDEA, the Filter's doFilter() method is called twice, and the output from line 12 is written twice.  You can see the stack trace at the 2nd call below.

When I deploy the Filter to regular Jetty (same version), or Tomcat, the output from line 12 is only written once, as expected.

Why is this happening in debug/embedded mode?  TIA

I posted this question with a bit more detail at http://stackoverflow.com/questions/39337962/why-does-my-servlet-filter-run-twice

Stack trace at 2nd call:

[net.twentyonesolutions.TestFilter.doFilter(TestFilter.java:20)
    ,org.eclipse.jetty.servlet.ServletHandler$CachedChain.doFilter(ServletHandler.java:1652)
    ,net.twentyonesolutions.TestFilter.doFilter(TestFilter.java:20)
    ,org.eclipse.jetty.servlet.ServletHandler$CachedChain.doFilter(ServletHandler.java:1652)
    ,org.eclipse.jetty.servlet.ServletHandler.doHandle(ServletHandler.java:585)
    ,org.eclipse.jetty.server.handler.ScopedHandler.handle(ScopedHandler.java:143)
    ,org.eclipse.jetty.security.SecurityHandler.handle(SecurityHandler.java:577)
    ,org.eclipse.jetty.server.session.SessionHandler.doHandle(SessionHandler.java:223)
    ,org.eclipse.jetty.server.handler.ContextHandler.doHandle(ContextHandler.java:1127)
    ,org.eclipse.jetty.servlet.ServletHandler.doScope(ServletHandler.java:515)
    ,org.eclipse.jetty.server.session.SessionHandler.doScope(SessionHandler.java:185)
    ,org.eclipse.jetty.server.handler.ContextHandler.doScope(ContextHandler.java:1061)
    ,org.eclipse.jetty.server.handler.ScopedHandler.handle(ScopedHandler.java:141)
    ,org.eclipse.jetty.server.handler.HandlerWrapper.handle(HandlerWrapper.java:97)
    ,org.eclipse.jetty.server.Server.handle(Server.java:497)
    ,org.eclipse.jetty.server.HttpChannel.handle(HttpChannel.java:310)
    ,org.eclipse.jetty.server.HttpConnection.onFillable(HttpConnection.java:245)
    ,org.eclipse.jetty.io.AbstractConnection$2.run(AbstractConnection.java:540)
    ,org.eclipse.jetty.util.thread.QueuedThreadPool.runJob(QueuedThreadPool.java:635)
    ,org.eclipse.jetty.util.thread.QueuedThreadPool$3.run(QueuedThreadPool.java:555)
    ,java.lang.Thread.run(Thread.java:745)]


--

Igal Sapir
Lucee Core Developer
Lucee.org


_______________________________________________
jetty-users mailing list
[hidden email]
To change your delivery options, retrieve your password, or unsubscribe from this list, visit
https://dev.eclipse.org/mailman/listinfo/jetty-users
Reply | Threaded
Open this post in threaded view
|

Re: Servlet Filter is Called Twice in Embedded Jetty

Greg Wilkins
Answered on stack overflow.... you are setting the web.xml as the default descriptor, so it is being run twice.
Don't set the default descriptor.


On 6 September 2016 at 14:52, Igal @ Lucee.org <[hidden email]> wrote:
I have written a very simple test Filter, and am running it in an embedded Jetty 9.2.18.v20160721 in debug mode in IntelliJ IDEA:

        System.out.println(TestFilter.class.getSimpleName()       // line 12
                + " > "
                + ((HttpServletRequest)servletRequest).getRequestURL()
                + ": IP "+ servletRequest.getRemoteAddr()
                + "; at "
                + new Date().toString());

        // Pass request back down the filter chain
        filterChain.doFilter(servletRequest, servletResponse);    // line 20
    }
and added it to web.xml:

<filter>
    <filter-name>TestFilter</filter-name>
    <filter-class>net.twentyonesolutions.TestFilter</filter-class>
</filter>

<filter-mapping>
    <filter-name>TestFilter</filter-name>
    <url-pattern>/*</url-pattern>
</filter-mapping>
When running in debug mode in IntelliJ IDEA, the Filter's doFilter() method is called twice, and the output from line 12 is written twice.  You can see the stack trace at the 2nd call below.

When I deploy the Filter to regular Jetty (same version), or Tomcat, the output from line 12 is only written once, as expected.

Why is this happening in debug/embedded mode?  TIA

I posted this question with a bit more detail at http://stackoverflow.com/questions/39337962/why-does-my-servlet-filter-run-twice

Stack trace at 2nd call:

[net.twentyonesolutions.TestFilter.doFilter(TestFilter.java:20)
    ,org.eclipse.jetty.servlet.ServletHandler$CachedChain.doFilter(ServletHandler.java:1652)
    ,net.twentyonesolutions.TestFilter.doFilter(TestFilter.java:20)
    ,org.eclipse.jetty.servlet.ServletHandler$CachedChain.doFilter(ServletHandler.java:1652)
    ,org.eclipse.jetty.servlet.ServletHandler.doHandle(ServletHandler.java:585)
    ,org.eclipse.jetty.server.handler.ScopedHandler.handle(ScopedHandler.java:143)
    ,org.eclipse.jetty.security.SecurityHandler.handle(SecurityHandler.java:577)
    ,org.eclipse.jetty.server.session.SessionHandler.doHandle(SessionHandler.java:223)
    ,org.eclipse.jetty.server.handler.ContextHandler.doHandle(ContextHandler.java:1127)
    ,org.eclipse.jetty.servlet.ServletHandler.doScope(ServletHandler.java:515)
    ,org.eclipse.jetty.server.session.SessionHandler.doScope(SessionHandler.java:185)
    ,org.eclipse.jetty.server.handler.ContextHandler.doScope(ContextHandler.java:1061)
    ,org.eclipse.jetty.server.handler.ScopedHandler.handle(ScopedHandler.java:141)
    ,org.eclipse.jetty.server.handler.HandlerWrapper.handle(HandlerWrapper.java:97)
    ,org.eclipse.jetty.server.Server.handle(Server.java:497)
    ,org.eclipse.jetty.server.HttpChannel.handle(HttpChannel.java:310)
    ,org.eclipse.jetty.server.HttpConnection.onFillable(HttpConnection.java:245)
    ,org.eclipse.jetty.io.AbstractConnection$2.run(AbstractConnection.java:540)
    ,org.eclipse.jetty.util.thread.QueuedThreadPool.runJob(QueuedThreadPool.java:635)
    ,org.eclipse.jetty.util.thread.QueuedThreadPool$3.run(QueuedThreadPool.java:555)
    ,java.lang.Thread.run(Thread.java:745)]


--

Igal Sapir
Lucee Core Developer
Lucee.org


_______________________________________________
jetty-users mailing list
[hidden email]
To change your delivery options, retrieve your password, or unsubscribe from this list, visit
https://dev.eclipse.org/mailman/listinfo/jetty-users



--

_______________________________________________
jetty-users mailing list
[hidden email]
To change your delivery options, retrieve your password, or unsubscribe from this list, visit
https://dev.eclipse.org/mailman/listinfo/jetty-users
Reply | Threaded
Open this post in threaded view
|

Re: Servlet Filter is Called Twice in Embedded Jetty

Igal @ Lucee.org

Yep. Thanks again, Greg!


Igal Sapir
Lucee Core Developer
Lucee.org

On 9/6/2016 4:21 PM, Greg Wilkins wrote:
Answered on stack overflow.... you are setting the web.xml as the default descriptor, so it is being run twice.
Don't set the default descriptor.


On 6 September 2016 at 14:52, Igal @ Lucee.org <[hidden email]> wrote:
I have written a very simple test Filter, and am running it in an embedded Jetty 9.2.18.v20160721 in debug mode in IntelliJ IDEA:

        System.out.println(TestFilter.class.getSimpleName()       // line 12
                + " > "
                + ((HttpServletRequest)servletRequest).getRequestURL()
                + ": IP "+ servletRequest.getRemoteAddr()
                + "; at "
                + new Date().toString());

        // Pass request back down the filter chain
        filterChain.doFilter(servletRequest, servletResponse);    // line 20
    }
and added it to web.xml:
<filter>
    <filter-name>TestFilter</filter-name>
    <filter-class>net.twentyonesolutions.TestFilter</filter-class>
</filter>

<filter-mapping>
    <filter-name>TestFilter</filter-name>
    <url-pattern>/*</url-pattern>
</filter-mapping>
When running in debug mode in IntelliJ IDEA, the Filter's doFilter() method is called twice, and the output from line 12 is written twice.  You can see the stack trace at the 2nd call below. When I deploy the Filter to regular Jetty (same version), or Tomcat, the output from line 12 is only written once, as expected. Why is this happening in debug/embedded mode?  TIA I posted this question with a bit more detail at http://stackoverflow.com/questions/39337962/why-does-my-servlet-filter-run-twice Stack trace at 2nd call: [net.twentyonesolutions.TestFilter.doFilter(TestFilter.java:20)     ,org.eclipse.jetty.servlet.ServletHandler$CachedChain.doFilter(ServletHandler.java:1652)     ,net.twentyonesolutions.TestFilter.doFilter(TestFilter.java:20)     ,org.eclipse.jetty.servlet.ServletHandler$CachedChain.doFilter(ServletHandler.java:1652)     ,org.eclipse.jetty.servlet.ServletHandler.doHandle(ServletHandler.java:585)     ,org.eclipse.jetty.server.handler.ScopedHandler.handle(ScopedHandler.java:143)     ,org.eclipse.jetty.security.SecurityHandler.handle(SecurityHandler.java:577)     ,org.eclipse.jetty.server.session.SessionHandler.doHandle(SessionHandler.java:223)     ,org.eclipse.jetty.server.handler.ContextHandler.doHandle(ContextHandler.java:1127)     ,org.eclipse.jetty.servlet.ServletHandler.doScope(ServletHandler.java:515)     ,org.eclipse.jetty.server.session.SessionHandler.doScope(SessionHandler.java:185)     ,org.eclipse.jetty.server.handler.ContextHandler.doScope(ContextHandler.java:1061)     ,org.eclipse.jetty.server.handler.ScopedHandler.handle(ScopedHandler.java:141)     ,org.eclipse.jetty.server.handler.HandlerWrapper.handle(HandlerWrapper.java:97)     ,org.eclipse.jetty.server.Server.handle(Server.java:497)     ,org.eclipse.jetty.server.HttpChannel.handle(HttpChannel.java:310)     ,org.eclipse.jetty.server.HttpConnection.onFillable(HttpConnection.java:245)     ,org.eclipse.jetty.io.AbstractConnection$2.run(AbstractConnection.java:540)     ,org.eclipse.jetty.util.thread.QueuedThreadPool.runJob(QueuedThreadPool.java:635)     ,org.eclipse.jetty.util.thread.QueuedThreadPool$3.run(QueuedThreadPool.java:555)     ,java.lang.Thread.run(Thread.java:745)]
--

Igal Sapir Lucee Core Developer Lucee.org

_______________________________________________ jetty-users mailing list [hidden email] To change your delivery options, retrieve your password, or unsubscribe from this list, visit https://dev.eclipse.org/mailman/listinfo/jetty-users
--
_______________________________________________
jetty-users mailing list
[hidden email]
To change your delivery options, retrieve your password, or unsubscribe from this list, visit
https://dev.eclipse.org/mailman/listinfo/jetty-users

_______________________________________________
jetty-users mailing list
[hidden email]
To change your delivery options, retrieve your password, or unsubscribe from this list, visit
https://dev.eclipse.org/mailman/listinfo/jetty-users