Announcement Announcement Module
Collapse
No announcement yet.
Cross context forward to spring No thread-bound request found: Are you referring to.. Page Title Module
Move Remove Collapse
X
Conversation Detail Module
Collapse
  • Filter
  • Time
  • Show
Clear All
new posts

  • Cross context forward to spring No thread-bound request found: Are you referring to..

    Hello,

    I am using cocoon 2.2.0 that uses spring and also urlrewrite 3.2.0, tomcat 6.0.18 java 1.6.0_12-b04

    Two web applications are set up with crossContext="true"
    When I redirect from the context running urlrewrite to the cocoon one I get the stack traces below
    It appears that the spring filters dont get run on the cross context forward as the message "Bound request context to thread" is never printed,

    Is it true that filters do not run on a cross context forward?
    If thats true that doesnt make much sense to me.
    Is it the same request for both contexts?

    I thought of putting the springframework in a shared class loader for both applications, with the filter configuration in the originating context. I presume that would work.
    However I dont think thats the best solution.

    I also thought of putting a custom thread local class in the shared class loader just to pass the request but Id prefer to avoid that.

    Can someone explain what is happening and what the best solution is.

    Thanks in advance,

    Andy Bailey

    Ill post the stack traces in a reply to this email as this forum wont let me post them here

  • #2
    More info

    17.03.2009 00:53:14 *DEBUG* RuleBase: matched "from" (Log.java, line 210)
    catalina.out 17.03.2009 00:53:14 *DEBUG* RuleExecutionOutput: needs to be forwarded to /hazlo/strat/ChangeGov.xhtml (Log.java, line 210)
    catalina.out 17.03.2009 00:53:14 *DEBUG* UrlRewriter: got a rewritten url (Log.java, line 153)
    catalina.out 17.03.2009 00:53:14 *DEBUG* RewrittenUrl: doRewrite called (Log.java, line 153)
    localhost.2009-03-17.logMar 17, 2009 12:53:14 AM org.apache.catalina.core.ApplicationDispatcher invoke
    SEVERE: Servlet.service() for servlet DispatcherServlet threw exception


    in the web.xml
    <filter>
    <filter-name>requestContextFilter</filter-name>
    <filter-class>
    org.springframework.web.filter.RequestContextFilte r
    </filter-class>
    </filter>

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

    <!-- Changed to Request Context Filter
    <listener>
    <listener-class>org.springframework.web.context.request.Requ estContextListener</listener-class>
    </listener>
    -->

    The log shows
    2009-03-17 00:22:41,371 DEBUG http-18080-1 org.springframework.beans.factory.support.DefaultL istableBeanFactory - Returning cached instance of singleton bean 'org.apache.cocoon.servletservice.spring.BlockServ letMap'
    2009-03-17 00:22:41,376 DEBUG http-18080-1 org.springframework.beans.factory.support.DefaultL istableBeanFactory - Returning cached instance of singleton bean 'com.hazlorealidad.hazlo.service/embedded'
    2009-03-17 00:22:41,424 DEBUG http-18080-1 org.springframework.beans.factory.support.DefaultL istableBeanFactory - Returning cached instance of singleton bean 'com.hazlorealidad.hazlo.service'
    2009-03-17 00:22:41,439 DEBUG http-18080-1 org.springframework.aop.framework.JdkDynamicAopPro xy - Creating JDK dynamic proxy: target source is SingletonTargetSource for target object [org.apache.cocoon.sitemap.SitemapServlet@1734ad]
    2009-03-17 00:22:41,485 DEBUG http-18080-1 org.apache.cocoon.servletservice.DispatcherServlet - DispatcherServlet: service servlet=org.apache.cocoon.sitemap.SitemapServlet@1 734ad mountPath=/hazlo servletPath=/hazlo pathInfo=/strat/ChangeGov.xhtml
    2009-03-17 00:22:41,536 DEBUG http-18080-1 org.apache.cocoon.environment.internal.Environment Helper - Changing Cocoon context
    2009-03-17 00:22:41,536 DEBUG http-18080-1 org.apache.cocoon.environment.internal.Environment Helper - from context(/opt/apache-tomcat-6.0.18/work/Catalina/localhost/tr/blocks/hazlo/) and prefix(null)
    2009-03-17 00:22:41,536 DEBUG http-18080-1 org.apache.cocoon.environment.internal.Environment Helper - to context(/opt/apache-tomcat-6.0.18/work/Catalina/localhost/tr/blocks/hazlo/sitemap.xmap) and prefix()
    2009-03-17 00:22:41,546 DEBUG http-18080-1 org.apache.cocoon.components.source.CocoonSourceRe solver - Resolving '/opt/apache-tomcat-6.0.18/work/Catalina/localhost/tr/blocks/hazlo/' with base '/opt/apache-tomcat-6.0.18/work/Catalina/localhost/tr/blocks/hazlo/' in context '/opt/apache-tomcat-6.0.18/bin/'
    2009-03-17 00:22:41,551 DEBUG http-18080-1 org.springframework.beans.factory.support.DefaultL istableBeanFactory - Returning cached instance of singleton bean 'org.apache.avalon.framework.service.ServiceManage r'
    2009-03-17 00:22:41,551 DEBUG http-18080-1 org.springframework.beans.factory.support.DefaultL istableBeanFactory - Returning cached instance of singleton bean 'org.apache.excalibur.source.SourceFactory/file'
    2009-03-17 00:22:41,551 DEBUG http-18080-1 org.apache.cocoon.components.source.CocoonSourceRe solver - Resolved to systemID : /opt/apache-tomcat-6.0.18/work/Catalina/localhost/tr/blocks/hazlo/
    2009-03-17 00:22:41,552 DEBUG http-18080-1 org.springframework.beans.factory.support.DefaultL istableBeanFactory - Returning cached instance of singleton bean 'org.apache.avalon.framework.service.ServiceManage r'
    2009-03-17 00:22:41,552 DEBUG http-18080-1 org.springframework.beans.factory.support.DefaultL istableBeanFactory - Returning cached instance of singleton bean 'org.apache.excalibur.source.SourceFactory/file'
    2009-03-17 00:22:41,552 DEBUG http-18080-1 org.apache.cocoon.environment.internal.Environment Helper - New context is opt/apache-tomcat-6.0.18/work/Catalina/localhost/tr/blocks/hazlo/
    2009-03-17 00:22:41,552 DEBUG http-18080-1 org.apache.cocoon.components.treeprocessor.TreePro cessor - first version of the ConcreteTreeProcessor
    2009-03-17 00:22:41,555 DEBUG http-18080-1 org.springframework.beans.factory.support.DefaultL istableBeanFactory - Creating shared instance of singleton bean 'org.apache.excalibur.xmlizer.XMLizer'
    2009-03-17 00:22:41,555 DEBUG http-18080-1 org.springframework.beans.factory.support.DefaultL istableBeanFactory - Creating instance of bean 'org.apache.excalibur.xmlizer.XMLizer' with merged definition [Root bean: class [org.apache.excalibur.xmlizer.DefaultXMLizer]; scope=singleton; abstract=false; lazyInit=true; autowireCandidate=true; autowireMode=0; dependencyCheck=0; factoryBeanName=null; factoryMethodName=null; initMethodName=null; destroyMethodName=null]
    2009-03-17 00:22:41,556 DEBUG http-18080-1 org.springframework.beans.factory.support.DefaultL istableBeanFactory - Eagerly caching bean 'org.apache.excalibur.xmlizer.XMLizer' to allow for resolving potential circular references
    2009-03-17 00:22:41,556 DEBUG http-18080-1 org.springframework.beans.factory.support.DefaultL istableBeanFactory - Returning cached instance of singleton bean 'org.apache.cocoon.core.container.spring.logger.Lo g'
    2009-03-17 00:22:41,556 DEBUG http-18080-1 org.springframework.beans.factory.support.DefaultL istableBeanFactory - Returning cached instance of singleton bean 'org.apache.avalon.framework.service.ServiceManage r'
    2009-03-17 00:22:41,557 DEBUG http-18080-1 cocoon - XMLizer: Default parser is 'org.apache.excalibur.xml.sax.SAXParser'.
    2009-03-17 00:22:41,557 DEBUG http-18080-1 cocoon - No mime-type for xmlizing file:///opt/apache-tomcat-6.0.18/work/Catalina/localhost/tr/blocks/hazlo/sitemap.xmap, guessing text/xml
    2009-03-17 00:22:41,557 DEBUG http-18080-1 org.springframework.beans.factory.support.DefaultL istableBeanFactory - Returning cached instance of singleton bean 'org.apache.excalibur.xml.sax.SAXParser'
    2009-03-17 00:22:41,583 DEBUG http-18080-1 org.springframework.beans.factory.support.DefaultL istableBeanFactory - Returning cached instance of singleton bean 'org.apache.cocoon.components.treeprocessor.TreeBu ilder/sitemap-1.0'
    2009-03-17 00:22:41,598 DEBUG http-18080-1 org.springframework.beans.factory.support.DefaultL istableBeanFactory - Creating instance of bean 'org.apache.cocoon.components.treeprocessor.TreeBu ilder/sitemap-1.0Pooled' with merged definition [Root bean: class [org.apache.cocoon.components.treeprocessor.sitemap .SitemapLanguage]; scope=prototype; abstract=false; lazyInit=false; autowireCandidate=true; autowireMode=0; dependencyCheck=0; factoryBeanName=null; factoryMethodName=null; initMethodName=null; destroyMethodName=null]
    2009-03-17 00:22:41,598 DEBUG http-18080-1 org.springframework.beans.factory.support.DefaultL istableBeanFactory - Returning cached instance of singleton bean 'org.apache.avalon.framework.service.ServiceManage r'
    2009-03-17 00:22:41,602 DEBUG http-18080-1 org.apache.cocoon.environment.http.HttpEnvironment - Response successfully reset
    2009-03-17 00:22:41,605 ERROR http-18080-1 cocoon.access - Internal Cocoon Problem
    java.lang.IllegalStateException:

    see reply for the stack trace as I cant post it here in one mail....

    Comment


    • #3
      Yet more info

      Ive just seen the option to attach a file, it would be good to suggest attaching files on the message that you are over the limit of xxxx characters.

      Comment


      • #4
        Solution

        Looking at the code for DispatcherServlet it wasnt handling the case of a cross context forward. Looks like it was a cocoon problem after all. Oops sorry for posting it here!

        Here is the fix:

        package com.hazlorealidad.cocoon;

        import java.io.IOException;

        import javax.servlet.ServletException;
        import javax.servlet.http.HttpServletRequest;
        import javax.servlet.http.HttpServletResponse;

        import org.apache.commons.logging.Log;
        import org.apache.commons.logging.LogFactory;

        import org.springframework.context.i18n.LocaleContextHold er;
        import org.springframework.web.context.request.RequestCon textHolder;
        import org.springframework.web.context.request.ServletReq uestAttributes;

        public class DispatcherServlet extends org.apache.cocoon.servletservice.DispatcherServlet
        {
        /** Logger available to subclasses */
        protected final Log logger = LogFactory.getLog(getClass());

        private boolean threadContextInheritable = false;

        /**
        * Set whether to expose the LocaleContext and RequestAttributes as
        * inheritable for child threads (using an
        * {@link java.lang.InheritableThreadLocal}).
        * <p>
        * Default is "false", to avoid side effects on spawned background threads.
        * Switch this to "true" to enable inheritance for custom child threads
        * which are spawned during request processing and only used for this
        * request (that is, ending after their initial task, without reuse of the
        * thread).
        * <p>
        * <b>WARNING:</b> Do not use inheritance for child threads if you are
        * accessing a thread pool which is configured to potentially add new
        * threads on demand (e.g. a JDK
        * {@link java.util.concurrent.ThreadPoolExecutor}), since this will expose
        * the inherited context to such a pooled thread.
        */
        public void setThreadContextInheritable(boolean threadContextInheritable)
        {
        this.threadContextInheritable = threadContextInheritable;
        }

        @Override
        protected void service(HttpServletRequest request, HttpServletResponse response)
        throws ServletException, IOException
        {
        ServletRequestAttributes attributes = new ServletRequestAttributes(request);
        LocaleContextHolder.setLocale(request.getLocale(), this.threadContextInheritable);
        RequestContextHolder.setRequestAttributes(attribut es, this.threadContextInheritable);
        if (logger.isDebugEnabled())
        {
        logger.debug("Bound request context to thread: " + request);
        }
        try
        {

        super.service(request, response);
        }
        finally
        {
        RequestContextHolder.resetRequestAttributes();
        LocaleContextHolder.resetLocaleContext();
        attributes.requestCompleted();
        if (logger.isDebugEnabled())
        {
        logger.debug("Cleared thread-bound request context: " + request);
        }
        }

        }
        }

        Comment

        Working...
        X