Togglz filter IllegalStateException

725 views
Skip to first unread message

Marcin Grzejszczak

unread,
Sep 27, 2013, 7:09:25 AM9/27/13
to togglz...@googlegroups.com

Hi!

Sorry for spamming you again ;) but there is an exception being thrown constantly when we deployed the app:

java.lang.IllegalStateException: HttpServletRequestHolder.bind() called for a thread that already has a request associated with it. It's likely that the request was not correctly removed from the thread before it is put back into the thread pool.

        at org.togglz.servlet.util.HttpServletRequestHolder.bind(HttpServletRequestHolder.java:22) ~[togglz-servlet-2.0.0.Final.jar:na]

        at org.togglz.servlet.util.HttpServletRequestHolderListener.begin(HttpServletRequestHolderListener.java:25) ~[togglz-servlet-2.0.0.Final.jar:na]

        at org.togglz.servlet.CompositeRequestListener.begin(CompositeRequestListener.java:36) ~[togglz-servlet-2.0.0.Final.jar:na]

        at org.togglz.servlet.TogglzFilter.doFilter(TogglzFilter.java:97) [togglz-servlet-2.0.0.Final.jar:na]

        at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:256) [web-core.jar:3.1.2.1-SNAPSHOT]

        at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:217) [web-core.jar:3.1.2.1-SNAPSHOT]

        at org.togglz.servlet.TogglzFilter.doFilter(TogglzFilter.java:100) [togglz-servlet-2.0.0.Final.jar:na]

        at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:256) [web-core.jar:3.1.2.1-SNAPSHOT]

        at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:217) [web-core.jar:3.1.2.1-SNAPSHOT]

Our configuraiton is shown here (https://groups.google.com/forum/#!topic/togglz-users/1dicN_4nYr0)

Any idea what is wrong? it's happening for every request

BR,

Marcin

Christian Kaltepoth

unread,
Sep 27, 2013, 7:38:47 AM9/27/13
to togglz...@googlegroups.com
Hey Marcin,

Togglz stores the current request in a ThreadLocal. This exception tells you that the ThreadLocal which Togglz uses for this already has a value set, which may happen if the ThreadLocal isn't cleaned correctly before the thread is put back into the worker pool.

In your case it seems like the TogglzFilter is registered twice (see stacktrace, there are two occurrences of the TogglzFilter). The first run of the filter stores the request in the ThreadLocal and therefore the second run fails with this exception. You should double check your configuration for duplicated entries. In Servlet 3.0 environments you don't need to register the filter at all, because it is automatically registered.

Christian


2013/9/27 Marcin Grzejszczak <marcin.gr...@gmail.com>

Marcin Grzejszczak

unread,
Sep 27, 2013, 7:42:46 AM9/27/13
to togglz...@googlegroups.com
Thx for the update.

We have servlet 2.5 environment and this is the Togglz Part (web.xml):

....

    <filter>
        <filter-name>togglzFilter</filter-name>
        <filter-class>org.togglz.servlet.TogglzFilter</filter-class>
    </filter>
....

  <filter-mapping>
        <filter-name>togglzFilter</filter-name>
        <url-pattern>/*</url-pattern>
    </filter-mapping>

....

    <servlet>
        <servlet-name>TogglzConsoleServlet</servlet-name>
        <servlet-class>org.togglz.console.TogglzConsoleServlet</servlet-class>
    </servlet>

Have I made a mistake with such config?

Christian Kaltepoth

unread,
Sep 27, 2013, 7:49:05 AM9/27/13
to togglz...@googlegroups.com
Hey Marcin,

looks very good. But as you saw in the stacktrace, the filter is executed twice. Is there anything special about your setup? So you have version="2.5" in your <web-app> XML root element?

See here:

        at org.togglz.servlet.util.HttpServletRequestHolder.bind(HttpServletRequestHolder.java:22) ~[togglz-servlet-2.0.0.Final.jar:na]
        at org.togglz.servlet.util.HttpServletRequestHolderListener.begin(HttpServletRequestHolderListener.java:25) ~[togglz-servlet-2.0.0.Final.jar:na]
        at org.togglz.servlet.CompositeRequestListener.begin(CompositeRequestListener.java:36) ~[togglz-servlet-2.0.0.Final.jar:na]
        at org.togglz.servlet.TogglzFilter.doFilter(TogglzFilter.java:97) [togglz-servlet-2.0.0.Final.jar:na]
        at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:256) [web-core.jar:3.1.2.1-SNAPSHOT]
        at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:217) [web-core.jar:3.1.2.1-SNAPSHOT]
        at org.togglz.servlet.TogglzFilter.doFilter(TogglzFilter.java:100) [togglz-servlet-2.0.0.Final.jar:na]
        at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:256) [web-core.jar:3.1.2.1-SNAPSHOT]




2013/9/27 Marcin Grzejszczak <marcin.gr...@gmail.com>

Marcin Grzejszczak

unread,
Sep 27, 2013, 7:54:17 AM9/27/13
to togglz...@googlegroups.com

Christian Kaltepoth

unread,
Sep 27, 2013, 8:04:18 AM9/27/13
to togglz...@googlegroups.com
Which container are you using? And which version?


2013/9/27 Marcin Grzejszczak <marcin.gr...@gmail.com>
Message has been deleted

Sean Adkinson

unread,
Dec 30, 2013, 7:33:15 PM12/30/13
to togglz...@googlegroups.com

This was happening to me as well, and I found the cause.

I haven't figured out the best way to fix it yet, but this is happening because you are registering the TogglzFilter like normal, but it is also being registered via META-INF/web-fragment.xml in togglz-servlet.jar.  My application needs to run on both Tomcat 6 (which doesn't read web-fragment.xml) and Tomcat 7 (which does), so I'll have to figure out what to do about this.

Any suggestions?

Sean Adkinson

unread,
Dec 30, 2013, 7:34:14 PM12/30/13
to togglz...@googlegroups.com

Christian Kaltepoth

unread,
Dec 31, 2013, 2:54:34 AM12/31/13
to togglz...@googlegroups.com
Hey Sean,

you can let Tomcat ignore the web-fragment.xml file by adding an empty <absolute-ordering/> element in your web.xml. But this is a Servlet 3.0 feature, so you have to set the version in your web.xml to 3.0. Not sure if Tomcat 6.0 will like this. But it's worth a try.

Christian

Christian Kaltepoth

unread,
Dec 31, 2013, 3:26:48 AM12/31/13
to togglz...@googlegroups.com
After thinking about this a bit more, actually Tomcat 7 _should_ ignore web-fragment.xml if the version in web.xml is set to 2.5. Can you confirm this?


2013/12/31 Christian Kaltepoth <chri...@kaltepoth.de>

Sean Adkinson

unread,
Dec 31, 2013, 10:49:02 AM12/31/13
to togglz...@googlegroups.com
Adding <absolute-ordering/> does indeed solve the issue.  Thanks!

Actually, my servlet version is set to 2.4 (which is strange, I didn't expect that).  I work on a large application that's been around a number of years, so I won't update to 2.5 or 3.0 right now.

Thanks for the fix,
Sean

--
Sean Adkinson
Senior Software Engineer - Jama Software
  
Reply all
Reply to author
Forward
0 new messages