You are viewing a plain text version of this content. The canonical link for it is here.
Posted to cvs@cocoon.apache.org by re...@apache.org on 2008/03/11 11:58:48 UTC

svn commit: r635881 - /cocoon/trunk/core/cocoon-servlet-service/cocoon-servlet-service-impl/src/main/java/org/apache/cocoon/servletservice/spring/ServletFactoryBean.java

Author: reinhard
Date: Tue Mar 11 03:58:38 2008
New Revision: 635881

URL: http://svn.apache.org/viewvc?rev=635881&view=rev
Log:
the context attribute might not exist

Modified:
    cocoon/trunk/core/cocoon-servlet-service/cocoon-servlet-service-impl/src/main/java/org/apache/cocoon/servletservice/spring/ServletFactoryBean.java

Modified: cocoon/trunk/core/cocoon-servlet-service/cocoon-servlet-service-impl/src/main/java/org/apache/cocoon/servletservice/spring/ServletFactoryBean.java
URL: http://svn.apache.org/viewvc/cocoon/trunk/core/cocoon-servlet-service/cocoon-servlet-service-impl/src/main/java/org/apache/cocoon/servletservice/spring/ServletFactoryBean.java?rev=635881&r1=635880&r2=635881&view=diff
==============================================================================
--- cocoon/trunk/core/cocoon-servlet-service/cocoon-servlet-service-impl/src/main/java/org/apache/cocoon/servletservice/spring/ServletFactoryBean.java (original)
+++ cocoon/trunk/core/cocoon-servlet-service/cocoon-servlet-service-impl/src/main/java/org/apache/cocoon/servletservice/spring/ServletFactoryBean.java Tue Mar 11 03:58:38 2008
@@ -93,39 +93,41 @@
         if (this.parentContainer == null) {
             this.parentContainer = WebApplicationContextUtils.getRequiredWebApplicationContext(this.servletContext);
         }
-        
+
         String contextPath = this.contextPath;
-        
+
         //FIXME: I'm not sure if there is any better place for this code (GK)
         //-----------------------------------------------------
         // hack for getting a file protocol or other protocols that can be used as context
         // path in the getResource method in the servlet context
-        int tmp = contextPath.indexOf(':');
-        boolean tmp2 = !(contextPath.startsWith("file:") || contextPath.startsWith("/") || contextPath.indexOf(':') == -1);
-        if (!(contextPath.startsWith("file:") || contextPath.startsWith("/") || contextPath.indexOf(':') == -1)) {
-            SourceResolver resolver = null;
-            Source source = null;
-            try {
-                resolver = (SourceResolver) parentContainer.getBean(SourceResolver.ROLE);
-                source = resolver.resolveURI(contextPath);
-                contextPath = source.getURI();
-            } catch (IOException e) {
-                throw new MalformedURLException("Could not resolve " + contextPath + " due to " + e);
-            } finally {
-                if (resolver != null) {
-                    resolver.release(source);
+        if(contextPath != null) {
+            int tmp = contextPath.indexOf(':');
+            boolean tmp2 = !(contextPath.startsWith("file:") || contextPath.startsWith("/") || contextPath.indexOf(':') == -1);
+            if (!(contextPath.startsWith("file:") || contextPath.startsWith("/") || contextPath.indexOf(':') == -1)) {
+                SourceResolver resolver = null;
+                Source source = null;
+                try {
+                    resolver = (SourceResolver) parentContainer.getBean(SourceResolver.ROLE);
+                    source = resolver.resolveURI(contextPath);
+                    contextPath = source.getURI();
+                } catch (IOException e) {
+                    throw new MalformedURLException("Could not resolve " + contextPath + " due to " + e);
+                } finally {
+                    if (resolver != null) {
+                        resolver.release(source);
+                    }
                 }
             }
-        }
-        //----------------------------------------------------
-        
+            //----------------------------------------------------
 
-        if (contextPath.length() != 0 && contextPath.charAt(0) != '/' && !contextPath.startsWith("file:")) {
-            throw new MalformedURLException("The contextPath must be empty or start with '/' " +
-                                            contextPath);
+
+            if (contextPath.length() != 0 && contextPath.charAt(0) != '/' && !contextPath.startsWith("file:")) {
+                throw new MalformedURLException("The contextPath must be empty or start with '/' " +
+                                                contextPath);
+            }
+
+            this.servletServiceContext.setContextPath(contextPath);
         }
-        
-        this.servletServiceContext.setContextPath(contextPath);
 
         GenericWebApplicationContext container = new GenericWebApplicationContext();
         container.setParent(this.parentContainer);
@@ -246,7 +248,7 @@
         if (this.embeddedServlet == null) {
             return null;
         }
-        
+
         return this.embeddedServlet != null ? this.embeddedServlet.getClass() : null;
     }
 



Re: [ssf] context path

Posted by Grzegorz Kossakowski <gr...@tuffmail.com>.
Reinhard Poetz pisze:
>>
>> This is not a solution IMHO. I forgot to bring this issue to mailing
>> list, my fault. Actually, I
>> think we should disallow empty context-path and mount-path attributes
>> because there is no sane way
>> to handle such cases. If you don't set contextPath, then you break a
>> contract in ServletContext
>> class because getResource() method no longer works.
>>
>> I think we should just change our schema and throw an exception when
>> any of attributes is null.
> 
> after thinking about it again, it makes sense to me.

Done in r636472.

-- 
Grzegorz Kossakowski

[ssf] context path

Posted by Reinhard Poetz <re...@apache.org>.
Grzegorz Kossakowski wrote:
> reinhard@apache.org pisze:
>> Author: reinhard
>> Date: Tue Mar 11 03:58:38 2008
>> New Revision: 635881
>>
>> URL: http://svn.apache.org/viewvc?rev=635881&view=rev
>> Log:
>> the context attribute might not exist
>>
> [...]
> 
>> +        if(contextPath != null) {
>> +            int tmp = contextPath.indexOf(':');
>> +            boolean tmp2 = !(contextPath.startsWith("file:") || contextPath.startsWith("/") || contextPath.indexOf(':') == -1);
> 
> This is not a solution IMHO. I forgot to bring this issue to mailing list, my fault. Actually, I
> think we should disallow empty context-path and mount-path attributes because there is no sane way
> to handle such cases. If you don't set contextPath, then you break a contract in ServletContext
> class because getResource() method no longer works.
> 
> I think we should just change our schema and throw an exception when any of attributes is null.

after thinking about it again, it makes sense to me.

-- 
Reinhard Pötz                            Managing Director, {Indoqa} GmbH
                           http://www.indoqa.com/en/people/reinhard.poetz/

Member of the Apache Software Foundation
Apache Cocoon Committer, PMC member, PMC Chair        reinhard@apache.org
_________________________________________________________________________

Re: svn commit: r635881 - /cocoon/trunk/core/cocoon-servlet-service/cocoon-servlet-service-impl/src/main/java/org/apache/cocoon/servletservice/spring/ServletFactoryBean.java

Posted by Grzegorz Kossakowski <gr...@tuffmail.com>.
reinhard@apache.org pisze:
> Author: reinhard
> Date: Tue Mar 11 03:58:38 2008
> New Revision: 635881
> 
> URL: http://svn.apache.org/viewvc?rev=635881&view=rev
> Log:
> the context attribute might not exist
> 
[...]

> +        if(contextPath != null) {
> +            int tmp = contextPath.indexOf(':');
> +            boolean tmp2 = !(contextPath.startsWith("file:") || contextPath.startsWith("/") || contextPath.indexOf(':') == -1);

This is not a solution IMHO. I forgot to bring this issue to mailing list, my fault. Actually, I
think we should disallow empty context-path and mount-path attributes because there is no sane way
to handle such cases. If you don't set contextPath, then you break a contract in ServletContext
class because getResource() method no longer works.

I think we should just change our schema and throw an exception when any of attributes is null.

WDYT?

-- 
Grzegorz Kossakowski