You are viewing a plain text version of this content. The canonical link for it is here.
Posted to cvs@cocoon.apache.org by gi...@apache.org on 2007/06/05 14:04:43 UTC

svn commit: r544460 - in /cocoon/trunk/core/cocoon-servlet-service: cocoon-servlet-service-components/src/main/java/org/apache/cocoon/servletservice/components/ cocoon-servlet-service-impl/src/main/java/org/apache/cocoon/servletservice/

Author: giacomo
Date: Tue Jun  5 05:04:42 2007
New Revision: 544460

URL: http://svn.apache.org/viewvc?view=rev&rev=544460
Log:
attempt to fix wrong prefix for servlet-services

Modified:
    cocoon/trunk/core/cocoon-servlet-service/cocoon-servlet-service-components/src/main/java/org/apache/cocoon/servletservice/components/BlockCompletePathModule.java
    cocoon/trunk/core/cocoon-servlet-service/cocoon-servlet-service-impl/src/main/java/org/apache/cocoon/servletservice/DispatcherServlet.java

Modified: cocoon/trunk/core/cocoon-servlet-service/cocoon-servlet-service-components/src/main/java/org/apache/cocoon/servletservice/components/BlockCompletePathModule.java
URL: http://svn.apache.org/viewvc/cocoon/trunk/core/cocoon-servlet-service/cocoon-servlet-service-components/src/main/java/org/apache/cocoon/servletservice/components/BlockCompletePathModule.java?view=diff&rev=544460&r1=544459&r2=544460
==============================================================================
--- cocoon/trunk/core/cocoon-servlet-service/cocoon-servlet-service-components/src/main/java/org/apache/cocoon/servletservice/components/BlockCompletePathModule.java (original)
+++ cocoon/trunk/core/cocoon-servlet-service/cocoon-servlet-service-components/src/main/java/org/apache/cocoon/servletservice/components/BlockCompletePathModule.java Tue Jun  5 05:04:42 2007
@@ -24,6 +24,7 @@
 import org.apache.avalon.framework.configuration.ConfigurationException;
 import org.apache.cocoon.components.modules.input.InputModule;
 import org.apache.cocoon.environment.ObjectModelHelper;
+import org.apache.cocoon.servletservice.DispatcherServlet;
 
 /**
  * This module provides almost exactly the same functionality as {@link BlockPathModule}. The only difference is that
@@ -47,7 +48,12 @@
 	 * @see org.apache.cocoon.components.modules.input.InputModule#getAttribute(java.lang.String, org.apache.avalon.framework.configuration.Configuration, java.util.Map)
 	 */
 	public Object getAttribute(String name, Configuration modeConf, Map objectModel) throws ConfigurationException {
-		return ObjectModelHelper.getRequest(objectModel).getContextPath() + blockPathModule.getAttribute(name, modeConf, objectModel);
+	    final String prefix = DispatcherServlet.getDispatcherMountPrefix();
+	    if( prefix == null || prefix.length() == 0 )
+	    {
+	        return ObjectModelHelper.getRequest(objectModel).getContextPath() + blockPathModule.getAttribute(name, modeConf, objectModel);
+	    }
+        return DispatcherServlet.getDispatcherMountPrefix() + blockPathModule.getAttribute(name, modeConf, objectModel);
 	}
 
 	/* (non-Javadoc)

Modified: cocoon/trunk/core/cocoon-servlet-service/cocoon-servlet-service-impl/src/main/java/org/apache/cocoon/servletservice/DispatcherServlet.java
URL: http://svn.apache.org/viewvc/cocoon/trunk/core/cocoon-servlet-service/cocoon-servlet-service-impl/src/main/java/org/apache/cocoon/servletservice/DispatcherServlet.java?view=diff&rev=544460&r1=544459&r2=544460
==============================================================================
--- cocoon/trunk/core/cocoon-servlet-service/cocoon-servlet-service-impl/src/main/java/org/apache/cocoon/servletservice/DispatcherServlet.java (original)
+++ cocoon/trunk/core/cocoon-servlet-service/cocoon-servlet-service-impl/src/main/java/org/apache/cocoon/servletservice/DispatcherServlet.java Tue Jun  5 05:04:42 2007
@@ -54,6 +54,9 @@
     /** The servlet collector bean */
     private Map blockServletCollector;
 
+    /** Holds the mount prefix of the current request accessible by {@link DispatcherServlet.getDispatcherMountPrefix} */
+    private static ThreadLocal prefix = new ThreadLocal();
+    
     public void init() throws ServletException {
         this.log("Block dispatcher was initialized successfully.");        
     }
@@ -75,7 +78,7 @@
             throw new ServletException("No block for " + req.getPathInfo());
         }
         // Create a dynamic proxy class that overwrites the getServletPath and
-        // getPathInfo methods to privide reasonable values in the called servlet
+        // getPathInfo methods to provide reasonable values in the called servlet
         // the dynamic proxy implements all interfaces of the original request
         HttpServletRequest request = (HttpServletRequest) Proxy.newProxyInstance(
         		req.getClass().getClassLoader(), 
@@ -89,7 +92,13 @@
 	                " pathInfo=" + request.getPathInfo());
         }
         
-        servlet.service(request, res);
+        prefix.set(req.getServletPath());
+        try {
+            servlet.service(request, res);
+        }
+        finally {
+            prefix.remove();
+        }
     }
     
     private void getInterfaces(Set interfaces, Class clazz) {
@@ -115,13 +124,16 @@
 		return (Class[]) interfaces.toArray(new Class[interfaces.size()]);
 	}
 
-    public Map getBlockServletMap()
-    {
+    public Map getBlockServletMap() {
         if(this.blockServletCollector == null) {
             final ApplicationContext applicationContext =
                 WebApplicationContextUtils.getRequiredWebApplicationContext(this.getServletContext());
             this.blockServletCollector = (Map)applicationContext.getBean( "org.apache.cocoon.servletservice.spring.BlockServletMap" );
         }
         return blockServletCollector;
+    }
+    
+    public static String getDispatcherMountPrefix() {
+        return prefix.get().toString();
     }
 }



Re: svn commit: r544460 - in /cocoon/trunk/core/cocoon-servlet-service: cocoon-servlet-service-components/src/main/java/org/apache/cocoon/servletservice/components/ cocoon-servlet-service-impl/src/main/java/org/apache/cocoon/servletservice/

Posted by Grzegorz Kossakowski <gk...@apache.org>.
Giacomo Pati pisze:
> 
> To be honest. That fix is a workaround until someone more knowledgeable than I can do it "the right
> way" which wasn't obvious to me (at least not in a reasonable time as requests get wrapped and
> proxied all over in the code).

Yeah I'm feeling the same about proxing but I guess it's the best possible design.

> Well, that's why I have not assigned myself and commented the JIRA-issue. As mentioned above it's
> only a workaround.

Ok, but putting distinct comments in the code and log message would make the situation clearer.

> Actually I might have missed the discussion you and Daniel had here on the list
> and thus I was annoyed nobody took the stab so I made this workaround to have our samples look as
> usual (and now we can fix'em, too).

Actually, there was no discussion about it because Daniel is very busy these days. I hope that it will have more free time soon so let's 
wait a little bit more for his comments.

-- 
Grzegorz Kossakowski
http://reflectingonthevicissitudes.wordpress.com/

Re: svn commit: r544460 - in /cocoon/trunk/core/cocoon-servlet-service: cocoon-servlet-service-components/src/main/java/org/apache/cocoon/servletservice/components/ cocoon-servlet-service-impl/src/main/java/org/apache/cocoon/servletservice/

Posted by Giacomo Pati <gi...@apache.org>.
-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1



Grzegorz Kossakowski wrote:
> giacomo@apache.org pisze:
>> Author: giacomo
>> Date: Tue Jun  5 05:04:42 2007
>> New Revision: 544460
>>
>> URL: http://svn.apache.org/viewvc?view=rev&rev=544460
>> Log:
>> attempt to fix wrong prefix for servlet-services
> 
> Hi Giacomo, thanks for taking care of it. However I would be grateful if
> you mention in log message the issue you are trying to fix (COCOON-2066)
> and generally it would be good that you assign the issue to yourself
> because it's sign for the others that you are willing to fix it.

To be honest. That fix is a workaround until someone more knowledgeable than I can do it "the right
way" which wasn't obvious to me (at least not in a reasonable time as requests get wrapped and
proxied all over in the code).

> Commenting the fix itself, I really hope that you consider it as
> temporary solution, do you? I talked with Daniel some time ago and he
> told me that we was going to be busy these days with his scientific work
> but he should be free soon. I really hope that he will help us to make a
> real fix - passing original request object to the
> BlockCallHttpServletRequest as it's only one reasonable option that
> covers also other issues:
> http://article.gmane.org/gmane.text.xml.cocoon.user/61154

Well, that's why I have not assigned myself and commented the JIRA-issue. As mentioned above it's
only a workaround. Actually I might have missed the discussion you and Daniel had here on the list
and thus I was annoyed nobody took the stab so I made this workaround to have our samples look as
usual (and now we can fix'em, too).

Ciao and thanks

- --
Giacomo Pati
Otego AG, Switzerland - http://www.otego.com
Orixo, the XML business alliance - http://www.orixo.com

-----BEGIN PGP SIGNATURE-----
Version: GnuPG v2.0.4 (GNU/Linux)

iD8DBQFGZkMsLNdJvZjjVZARAj3QAKCDwDndyaQd8f9J0tMGlkh1rwA4fwCfVc0S
wnqbn6kgnZXyEnZ7IzTteAA=
=HqT8
-----END PGP SIGNATURE-----

Re: svn commit: r544460 - in /cocoon/trunk/core/cocoon-servlet-service: cocoon-servlet-service-components/src/main/java/org/apache/cocoon/servletservice/components/ cocoon-servlet-service-impl/src/main/java/org/apache/cocoon/servletservice/

Posted by Grzegorz Kossakowski <gk...@apache.org>.
giacomo@apache.org pisze:
> Author: giacomo
> Date: Tue Jun  5 05:04:42 2007
> New Revision: 544460
> 
> URL: http://svn.apache.org/viewvc?view=rev&rev=544460
> Log:
> attempt to fix wrong prefix for servlet-services

Hi Giacomo, thanks for taking care of it. However I would be grateful if you mention in log message the issue you are trying to fix 
(COCOON-2066) and generally it would be good that you assign the issue to yourself because it's sign for the others that you are willing to 
fix it.

Commenting the fix itself, I really hope that you consider it as temporary solution, do you? I talked with Daniel some time ago and he told 
me that we was going to be busy these days with his scientific work but he should be free soon. I really hope that he will help us to make a 
real fix - passing original request object to the BlockCallHttpServletRequest as it's only one reasonable option that covers also other 
issues: http://article.gmane.org/gmane.text.xml.cocoon.user/61154

-- 
Grzegorz Kossakowski
http://reflectingonthevicissitudes.wordpress.com/