cocoon-cvs mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From gkossakow...@apache.org
Subject svn commit: r640476 - in /cocoon/trunk/core/cocoon-servlet-service/cocoon-servlet-service-impl/src/main: java/org/apache/cocoon/servletservice/ java/org/apache/cocoon/servletservice/spring/ resources/META-INF/cocoon/spring/
Date Mon, 24 Mar 2008 17:27:25 GMT
Author: gkossakowski
Date: Mon Mar 24 10:27:24 2008
New Revision: 640476

URL: http://svn.apache.org/viewvc?rev=640476&view=rev
Log:
Prototype integration with JNet and its usage in ServletFactoryBean.
Still lots of hacks and dirty code.

The most ugly hack here is URLStreamFactoryInstaller Spring bean that installs JNet
in its init method. ServletFactoryBean has dependency on this bean only to ensure that
init method is being called early enough.

Another problem is with usage of JNet as there is no way to release underlying Source instance.

Added:
    cocoon/trunk/core/cocoon-servlet-service/cocoon-servlet-service-impl/src/main/java/org/apache/cocoon/servletservice/URLStreamFactoryInstaller.java
Modified:
    cocoon/trunk/core/cocoon-servlet-service/cocoon-servlet-service-impl/src/main/java/org/apache/cocoon/servletservice/spring/ServletDecorator.java
    cocoon/trunk/core/cocoon-servlet-service/cocoon-servlet-service-impl/src/main/java/org/apache/cocoon/servletservice/spring/ServletFactoryBean.java
    cocoon/trunk/core/cocoon-servlet-service/cocoon-servlet-service-impl/src/main/resources/META-INF/cocoon/spring/cocoon-servlet-service-block-servlet-map.xml

Added: cocoon/trunk/core/cocoon-servlet-service/cocoon-servlet-service-impl/src/main/java/org/apache/cocoon/servletservice/URLStreamFactoryInstaller.java
URL: http://svn.apache.org/viewvc/cocoon/trunk/core/cocoon-servlet-service/cocoon-servlet-service-impl/src/main/java/org/apache/cocoon/servletservice/URLStreamFactoryInstaller.java?rev=640476&view=auto
==============================================================================
--- cocoon/trunk/core/cocoon-servlet-service/cocoon-servlet-service-impl/src/main/java/org/apache/cocoon/servletservice/URLStreamFactoryInstaller.java
(added)
+++ cocoon/trunk/core/cocoon-servlet-service/cocoon-servlet-service-impl/src/main/java/org/apache/cocoon/servletservice/URLStreamFactoryInstaller.java
Mon Mar 24 10:27:24 2008
@@ -0,0 +1,45 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.cocoon.servletservice;
+
+import java.util.Map;
+
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
+import org.apache.excalibur.sourceresolve.jnet.Installer;
+import org.apache.excalibur.sourceresolve.jnet.source.SourceFactoriesManager;
+import org.apache.excalibur.sourceresolve.jnet.source.SourceURLStreamHandlerFactory;
+
+public class URLStreamFactoryInstaller {
+    
+    private Log logger = LogFactory.getLog(getClass());
+    
+    private Map globalSourceFactories;
+    
+    public URLStreamFactoryInstaller() {}
+    
+    public void init() throws Exception {
+        Installer.setURLStreamHandlerFactory(new SourceURLStreamHandlerFactory());
+        logger.debug("SourceURLStreamHandlerFactory properly installed.");
+        SourceFactoriesManager.pushFactories(this.globalSourceFactories);
+        logger.debug("Global SourceFactories pushed on SourceFactoriesManager stack.");
+    }
+    
+    public void setGlobalSourceFactories(Map globalSourceFactories) {
+        this.globalSourceFactories = globalSourceFactories;
+    }
+}

Modified: cocoon/trunk/core/cocoon-servlet-service/cocoon-servlet-service-impl/src/main/java/org/apache/cocoon/servletservice/spring/ServletDecorator.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/ServletDecorator.java?rev=640476&r1=640475&r2=640476&view=diff
==============================================================================
--- cocoon/trunk/core/cocoon-servlet-service/cocoon-servlet-service-impl/src/main/java/org/apache/cocoon/servletservice/spring/ServletDecorator.java
(original)
+++ cocoon/trunk/core/cocoon-servlet-service/cocoon-servlet-service-impl/src/main/java/org/apache/cocoon/servletservice/spring/ServletDecorator.java
Mon Mar 24 10:27:24 2008
@@ -79,6 +79,9 @@
                         .rootBeanDefinition(ServletFactoryBean.class);
         servletFactoryDefBuilder.setSource(ctx.extractSource(source));
         servletFactoryDefBuilder.addPropertyReference("embeddedServlet", embeddedServletBeanName);
+        //FIXME: it's a dirty hack here, this dependency is added in order to assure that
URLHandlerFactory is installed before
+        //ServletFactoryBean is used.
+        servletFactoryDefBuilder.addPropertyReference("URLHandlerFactoryInstaller", "org.apache.cocoon.servletservice.URLStreamFactoryInstaller");
         servletFactoryDefBuilder.setInitMethodName("init");
         servletFactoryDefBuilder.setDestroyMethodName("destroy");
         servletFactoryDefBuilder.addPropertyValue("serviceName", holder.getBeanName());

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=640476&r1=640475&r2=640476&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
Mon Mar 24 10:27:24 2008
@@ -18,6 +18,7 @@
 
 import java.io.IOException;
 import java.net.MalformedURLException;
+import java.net.URL;
 import java.util.Enumeration;
 import java.util.Map;
 
@@ -32,6 +33,7 @@
 import org.aopalliance.intercept.MethodInvocation;
 import org.apache.cocoon.servletservice.Mountable;
 import org.apache.cocoon.servletservice.ServletServiceContext;
+import org.apache.cocoon.servletservice.URLStreamFactoryInstaller;
 import org.apache.excalibur.source.Source;
 import org.apache.excalibur.source.SourceResolver;
 import org.springframework.aop.framework.ProxyFactory;
@@ -101,18 +103,14 @@
         // hack for getting a file protocol or other protocols that can be used as context
         // path in the getResource method in the servlet context
         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);
+                URL url = new URL(contextPath);
+                source = (Source)url.getContent(new Class[] {Source.class});
                 contextPath = source.getURI();
+                //FIXME: obtained source is *NOT* released!!!
             } catch (IOException e) {
                 throw new MalformedURLException("Could not resolve " + contextPath + " due
to " + e);
-            } finally {
-                if (resolver != null) {
-                    resolver.release(source);
-                }
             }
         }
         //----------------------------------------------------
@@ -226,6 +224,10 @@
 
     public void setServiceName(String name) {
         this.serviceName = name;
+    }
+    
+    public void setURLHandlerFactoryInstaller(URLStreamFactoryInstaller installer ) {
+        //we don't need this dependency
     }
 
     public Object getObject() throws Exception {

Modified: cocoon/trunk/core/cocoon-servlet-service/cocoon-servlet-service-impl/src/main/resources/META-INF/cocoon/spring/cocoon-servlet-service-block-servlet-map.xml
URL: http://svn.apache.org/viewvc/cocoon/trunk/core/cocoon-servlet-service/cocoon-servlet-service-impl/src/main/resources/META-INF/cocoon/spring/cocoon-servlet-service-block-servlet-map.xml?rev=640476&r1=640475&r2=640476&view=diff
==============================================================================
--- cocoon/trunk/core/cocoon-servlet-service/cocoon-servlet-service-impl/src/main/resources/META-INF/cocoon/spring/cocoon-servlet-service-block-servlet-map.xml
(original)
+++ cocoon/trunk/core/cocoon-servlet-service/cocoon-servlet-service-impl/src/main/resources/META-INF/cocoon/spring/cocoon-servlet-service-block-servlet-map.xml
Mon Mar 24 10:27:24 2008
@@ -29,4 +29,15 @@
                            type="javax.servlet.Servlet"
                            has-properties="mountPath"
                            key-property="mountPath"/>
+                           
+    <bean id="org.apache.cocoon.servletservice.URLStreamFactoryInstaller" class="org.apache.cocoon.servletservice.URLStreamFactoryInstaller"
+          scope="singleton" init-method="init">
+      <property name="globalSourceFactories">
+        <!-- only blockcontext and file protocols are supported by SSF -->
+        <map>
+            <entry key="file" value-ref="org.apache.excalibur.source.SourceFactory/file"/>
+            <entry key="blockcontext" value-ref="org.apache.excalibur.source.SourceFactory/blockcontext"/>
+        </map>
+      </property>
+    </bean>
 </beans>



Mime
View raw message