cocoon-cvs mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From dani...@apache.org
Subject svn commit: r208999 - in /cocoon/whiteboard/osgi: ./ bundles/cocoon/ bundles/cocoon_servlet/ bundles/cocoon_servlet/resources/ bundles/cocoon_servlet/src/ bundles/cocoon_servlet/src/org/ bundles/cocoon_servlet/src/org/apache/ bundles/cocoon_servlet/src...
Date Sun, 03 Jul 2005 22:33:52 GMT
Author: danielf
Date: Sun Jul  3 15:33:50 2005
New Revision: 208999

URL: http://svn.apache.org/viewcvs?rev=208999&view=rev
Log:
A Cocoon servlet bundle, that try to find a sitemap bundle, create a CocoonServlet and register
it in the HTTPService. It doesn't work yet, classloading problems during initialization.

Added:
    cocoon/whiteboard/osgi/bundles/cocoon_servlet/
    cocoon/whiteboard/osgi/bundles/cocoon_servlet/build.xml
    cocoon/whiteboard/osgi/bundles/cocoon_servlet/resources/
    cocoon/whiteboard/osgi/bundles/cocoon_servlet/src/
    cocoon/whiteboard/osgi/bundles/cocoon_servlet/src/org/
    cocoon/whiteboard/osgi/bundles/cocoon_servlet/src/org/apache/
    cocoon/whiteboard/osgi/bundles/cocoon_servlet/src/org/apache/cocoon/
    cocoon/whiteboard/osgi/bundles/cocoon_servlet/src/org/apache/cocoon/service/
    cocoon/whiteboard/osgi/bundles/cocoon_servlet/src/org/apache/cocoon/service/servlet/
    cocoon/whiteboard/osgi/bundles/cocoon_servlet/src/org/apache/cocoon/service/servlet/impl/
    cocoon/whiteboard/osgi/bundles/cocoon_servlet/src/org/apache/cocoon/service/servlet/impl/Activator.java
  (with props)
    cocoon/whiteboard/osgi/jars-external/http/
    cocoon/whiteboard/osgi/jars-external/http/http_api-1.1.0.jar   (with props)
    cocoon/whiteboard/osgi/jars-external/log/
    cocoon/whiteboard/osgi/jars-external/log/log_api-1.0.0.jar   (with props)
Modified:
    cocoon/whiteboard/osgi/build.xml
    cocoon/whiteboard/osgi/bundles/cocoon/build.xml
    cocoon/whiteboard/osgi/bundles/cocoon_testcase/build.xml
    cocoon/whiteboard/osgi/init.xargs
    cocoon/whiteboard/osgi/props.xargs

Modified: cocoon/whiteboard/osgi/build.xml
URL: http://svn.apache.org/viewcvs/cocoon/whiteboard/osgi/build.xml?rev=208999&r1=208998&r2=208999&view=diff
==============================================================================
--- cocoon/whiteboard/osgi/build.xml (original)
+++ cocoon/whiteboard/osgi/build.xml Sun Jul  3 15:33:50 2005
@@ -7,6 +7,7 @@
     <ant dir="bundles/cocoon"           target="all"/>
     <ant dir="bundles/cocoon_testcase"  target="all"/>
     <ant dir="bundles/cocoon_webapp"    target="all"/>
+    <ant dir="bundles/cocoon_servlet"   target="all"/>
    </target>
  
    <target name="clean">
@@ -14,6 +15,7 @@
     <ant dir="bundles/cocoon"           target="clean"/>
     <ant dir="bundles/cocoon_testcase"  target="clean"/>
     <ant dir="bundles/cocoon_webapp"    target="clean"/>
+    <ant dir="bundles/cocoon_servlet"   target="clean"/>
    </target>
 
 </project>

Modified: cocoon/whiteboard/osgi/bundles/cocoon/build.xml
URL: http://svn.apache.org/viewcvs/cocoon/whiteboard/osgi/bundles/cocoon/build.xml?rev=208999&r1=208998&r2=208999&view=diff
==============================================================================
--- cocoon/whiteboard/osgi/bundles/cocoon/build.xml (original)
+++ cocoon/whiteboard/osgi/bundles/cocoon/build.xml Sun Jul  3 15:33:50 2005
@@ -33,7 +33,7 @@
     <mapper type="flatten"/>
   </pathconvert>
 
-  <property name="export.package"        value="org.apache.avalon.framework.context,org.apache.avalon.framework.logger,org.apache.avalon.framework.service,org.apache.cocoon,org.apache.cocoon.components.blocks,org.apache.cocoon.components.classloader,org.apache.cocoon.components.fam,org.apache.cocoon.components.modules.input,org.apache.cocoon.components.pipeline.impl,org.apache.cocoon.components.source.impl,org.apache.cocoon.components.treeprocessor,org.apache.cocoon.components.treeprocessor.sitemap,org.apache.cocoon.core,org.apache.cocoon.core.container,org.apache.cocoon.environment,org.apache.cocoon.environment.impl,org.apache.cocoon.generation,org.apache.cocoon.matching,org.apache.cocoon.reading,org.apache.cocoon.serialization,org.apache.cocoon.components.source,org.apache.cocoon.transformation,org.apache.cocoon.util,org.apache.cocoon.util.log,org.apache.avalon.excalibur.logger,org.apache.excalibur.source,org.apache.excalibur.source.impl,org.apache.excalibur.xml.impl,org.apache.excalibur.xml.xslt,org.apache.excalibur.xmlizer,org.apache.log"/>
+  <property name="export.package"        value="javax.servlet,javax.servlet.http,org.apache.avalon.framework.context,org.apache.avalon.framework.logger,org.apache.avalon.framework.service,org.apache.cocoon,org.apache.cocoon.components.blocks,org.apache.cocoon.components.classloader,org.apache.cocoon.components.fam,org.apache.cocoon.components.modules.input,org.apache.cocoon.components.pipeline.impl,org.apache.cocoon.components.source,org.apache.cocoon.components.source.impl,org.apache.cocoon.components.treeprocessor,org.apache.cocoon.components.treeprocessor.sitemap,org.apache.cocoon.core,org.apache.cocoon.core.container,org.apache.cocoon.environment,org.apache.cocoon.environment.impl,org.apache.cocoon.generation,org.apache.cocoon.matching,org.apache.cocoon.reading,org.apache.cocoon.serialization,org.apache.cocoon.servlet,org.apache.cocoon.transformation,org.apache.cocoon.util,org.apache.cocoon.util.log,org.apache.avalon.excalibur.logger,org.apache.excalibur.source,org.apache.excalibur.source.impl,org.apache.excalibur.xml.impl,org.apache.excalibur.xml.xslt,org.apache.excalibur.xmlizer,org.apache.log"/>
 
   <property name = "bundle.build.lib"    value = "false"/>
   <property name = "bundle.build.api"    value = "false"/>

Added: cocoon/whiteboard/osgi/bundles/cocoon_servlet/build.xml
URL: http://svn.apache.org/viewcvs/cocoon/whiteboard/osgi/bundles/cocoon_servlet/build.xml?rev=208999&view=auto
==============================================================================
--- cocoon/whiteboard/osgi/bundles/cocoon_servlet/build.xml (added)
+++ cocoon/whiteboard/osgi/bundles/cocoon_servlet/build.xml Sun Jul  3 15:33:50 2005
@@ -0,0 +1,55 @@
+<?xml version="1.0"?>
+
+<!DOCTYPE project [
+  <!ENTITY bundlebuild_include  SYSTEM "../../ant/bundlebuild_include.xml">
+]>
+
+<project name="cocoon_servlet" default="all">
+
+  <property name="cocoon.trunk"          location="../../../trunk"/>
+  <property name="topdir"                location="../.."/>
+
+  <path id="bundle.compile.path">
+   <pathelement location="lib/cocoon.jar"/>
+   <pathelement location="lib/servlet-2_3.jar"/>
+   <pathelement location="${topdir}/jars-external/http/http_api-1.1.0.jar"/>
+   <pathelement location="${topdir}/jars-external/log/log_api-1.0.0.jar"/>
+  </path>
+
+  <property name="bundle.description"    value="Cocoon servlet bundle"/>
+  <property name="bundle.vendor"         value="Apache"/>
+  <property name="bundle.category"       value="servlet"/>
+  <property name="bundle.version"        value="1.0.0"/>
+
+  <property name="impl.pattern"          value="org/apache/cocoon/service/servlet/impl/**"/>
+  <property name="import.package"        value="javax.servlet,javax.servlet.http,org.apache.cocoon.servlet,org.osgi.framework,org.osgi.service.http,org.osgi.service.log,org.osgi.util.tracker"/>
+
+  <property name="do.bundle.custom.pre"  value="true"/>
+
+  <target name="bundle.custom.pre">
+    <mkdir dir="lib"/>
+    <unzip src="${topdir}/jars/cocoon/cocoon_all-1.0.0.jar"
+           dest="lib">
+      <fileset dir=".">
+        <include name="cocoon.jar"/>
+        <include name="servlet-2_3.jar"/>
+      </fileset>
+    </unzip>
+  </target>
+
+  <property name="do.bundle.custom.post"  value="true"/>
+
+  <target name="bundle.custom.post">
+    <delete dir="lib"/>
+  </target>
+
+  &bundlebuild_include;
+
+</project>
+
+
+
+
+
+
+

Added: cocoon/whiteboard/osgi/bundles/cocoon_servlet/src/org/apache/cocoon/service/servlet/impl/Activator.java
URL: http://svn.apache.org/viewcvs/cocoon/whiteboard/osgi/bundles/cocoon_servlet/src/org/apache/cocoon/service/servlet/impl/Activator.java?rev=208999&view=auto
==============================================================================
--- cocoon/whiteboard/osgi/bundles/cocoon_servlet/src/org/apache/cocoon/service/servlet/impl/Activator.java
(added)
+++ cocoon/whiteboard/osgi/bundles/cocoon_servlet/src/org/apache/cocoon/service/servlet/impl/Activator.java
Sun Jul  3 15:33:50 2005
@@ -0,0 +1,178 @@
+/*
+ * Copyright 1999-2005 The Apache Software Foundation.
+ *
+ * Licensed 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.service.servlet.impl;
+
+import java.util.Hashtable;
+import java.net.URL;
+import java.io.InputStream;
+import javax.servlet.http.HttpServletRequest;
+import javax.servlet.http.HttpServletResponse;
+
+import org.apache.cocoon.servlet.CocoonServlet;
+import org.osgi.framework.Bundle;
+import org.osgi.framework.BundleActivator;
+import org.osgi.framework.BundleContext;
+import org.osgi.framework.BundleException;
+import org.osgi.framework.Constants;
+import org.osgi.framework.ServiceEvent;
+import org.osgi.framework.ServiceListener;
+import org.osgi.framework.ServiceReference;
+import org.osgi.service.http.HttpContext;
+import org.osgi.service.http.HttpService;
+import org.osgi.service.log.LogService;
+import org.osgi.util.tracker.ServiceTracker;
+
+/**
+ * Activator which register a Cocoon servlet
+ */
+
+public class Activator implements BundleActivator {
+
+    static BundleContext bc;
+    static ServiceTracker logTracker;
+    static final String  SERVLET_ALIAS = "/";     // the http server root
+    static final String  SITEMAP = "sitemap";
+
+    private Hashtable registrations = new Hashtable();
+    private Bundle sitemapBundle;
+    
+    public void start(BundleContext bc) throws BundleException {
+
+        this.bc  = bc;
+        this.logTracker = new ServiceTracker(bc, LogService.class.getName(), null);
+        this.logTracker.open();
+
+        // FIXME: Add a BundleListener to detect if a sitemap bundle
+        // is installed, updated or uninstalled.
+        this.sitemapBundle = getSitemapBundle();
+        ((LogService)this.logTracker.getService()).log(LogService.LOG_INFO, "set sitemap
bundle " + this.sitemapBundle);
+
+        ServiceListener listener = new ServiceListener() {
+                public void serviceChanged(ServiceEvent ev) {
+                    ServiceReference sr = ev.getServiceReference();
+                    
+                    switch(ev.getType()) {
+                    case ServiceEvent.REGISTERED:
+                        setRoot(sr);
+                        break;
+                    case ServiceEvent.UNREGISTERING:
+                        unsetRoot(sr);
+                        break;
+                    }
+                }
+            };
+        
+        String filter = "(objectclass=" + HttpService.class.getName() + ")";
+        
+        try {
+            bc.addServiceListener(listener, filter);
+            
+            ServiceReference[] srl = bc.getServiceReferences(null, filter);
+            for(int i = 0; srl != null && i < srl.length; i++) {
+                listener.serviceChanged(new ServiceEvent(ServiceEvent.REGISTERED,
+                                                         srl[i]));
+            }
+        } catch (Exception e) {
+            ((LogService)this.logTracker.getService()).log(LogService.LOG_ERROR,
+                                                           "Failed to set up listener for
http service", e);
+        }
+    }
+  
+    public void stop(BundleContext bc) throws BundleException {
+    }
+
+    private Bundle getSitemapBundle() {
+        Bundle[] bundles = this.bc.getBundles();
+        for (int i = 0; i < bundles.length; i++) {
+            Bundle bundle = bundles[i];
+            try {
+                ((LogService)this.logTracker.getService()).log(LogService.LOG_INFO, "checking
bundle " + bundle + " name=" + bundle.getHeaders().get(Constants.BUNDLE_NAME) + " category="
+ bundle.getHeaders().get(Constants.BUNDLE_CATEGORY) + " state=" + bundle.getState());
+                if ((bundle.getState() == Bundle.INSTALLED ||
+                     bundle.getState() == Bundle.RESOLVED ||
+                     bundle.getState() == Bundle.ACTIVE)) {
+                    ((LogService)this.logTracker.getService()).log(LogService.LOG_INFO, "ok
state");
+                    if (SITEMAP.equals(bundle.getHeaders().get(Constants.BUNDLE_CATEGORY)))
{
+                        ((LogService)this.logTracker.getService()).log(LogService.LOG_INFO,
"sitemap");
+                        return bundle;
+                    }
+                }
+            } catch (NullPointerException e) {
+                // BUNDLE_CATEGORY not present in the headers of the
+                // bundle, nothing to do.
+            }
+        }
+        return null;
+    }
+
+    private void setRoot(ServiceReference sr) {
+        
+        if(registrations.containsKey(sr)) {
+            return; // already done
+        }
+        
+        ((LogService)this.logTracker.getService()).log(LogService.LOG_INFO, "set root for
" + sr);
+
+        HttpService http = (HttpService)bc.getService(sr);
+
+        HttpContext context = new HttpContext() {
+                public boolean handleSecurity(HttpServletRequest  request,
+                                              HttpServletResponse response) 
+                    throws java.io.IOException {
+                    return true;
+                }
+        
+                public URL getResource(String name) {
+                    if (sitemapBundle != null) {
+                        return sitemapBundle.getResource(name);
+                    } else {
+                        return null;
+                    }
+                }
+        
+                public String getMimeType(String reqEntry) {
+                    return null; // server decides type
+                }
+            };
+    
+        try {
+            Hashtable parameters = new Hashtable();
+            parameters.put("work-directory", "work");
+            http.registerServlet(SERVLET_ALIAS, new CocoonServlet(), parameters, context);
+
+            registrations.put(sr, context);
+        } catch (Exception e) {
+            ((LogService)this.logTracker.getService()).log(LogService.LOG_ERROR,
+                                                           "Failed to register resource",
e);
+        }
+    } 
+
+    private void unsetRoot(ServiceReference sr) {
+        if(!registrations.containsKey(sr)) {
+            return; // nothing to do
+        }
+
+        ((LogService)this.logTracker.getService()).log(LogService.LOG_INFO, "unset root for
" + sr);
+    
+        HttpService http = (HttpService)bc.getService(sr);
+    
+        if(http != null) {
+            http.unregister(SERVLET_ALIAS);
+            bc.ungetService(sr);
+        }
+        registrations.remove(sr);
+    }
+
+}

Propchange: cocoon/whiteboard/osgi/bundles/cocoon_servlet/src/org/apache/cocoon/service/servlet/impl/Activator.java
------------------------------------------------------------------------------
    svn:eol-style = native

Modified: cocoon/whiteboard/osgi/bundles/cocoon_testcase/build.xml
URL: http://svn.apache.org/viewcvs/cocoon/whiteboard/osgi/bundles/cocoon_testcase/build.xml?rev=208999&r1=208998&r2=208999&view=diff
==============================================================================
--- cocoon/whiteboard/osgi/bundles/cocoon_testcase/build.xml (original)
+++ cocoon/whiteboard/osgi/bundles/cocoon_testcase/build.xml Sun Jul  3 15:33:50 2005
@@ -27,7 +27,7 @@
 
   <property name="impl.pattern"          value="org/apache/cocoon/**"/>
   <property name="bundle.classpath"      value=".,cocoon-testcase.jar"/>
-  <property name="import.package"        value="junit.framework,org.knopflerfish.service.junit,org.apache.avalon.framework.context,org.apache.avalon.framework.logger,org.apache.avalon.framework.service,org.apache.cocoon,org.apache.cocoon.components.blocks,org.apache.cocoon.components.fam,org.apache.cocoon.components.modules.input,org.apache.cocoon.components.pipeline.impl,org.apache.cocoon.components.source.impl,org.apache.cocoon.components.treeprocessor,org.apache.cocoon.core,org.apache.cocoon.core.container,org.apache.cocoon.environment,org.apache.cocoon.environment.impl,org.apache.cocoon.generation,org.apache.cocoon.matching,org.apache.cocoon.reading,org.apache.cocoon.serialization,org.apache.cocoon.components.source,org.apache.cocoon.transformation,org.apache.cocoon.util,org.apache.cocoon.util.log,org.apache.avalon.excalibur.logger,org.apache.excalibur.source,org.apache.excalibur.source.impl,org.apache.excalibur.xml.impl,org.apache.excalibur.xmlizer,org.apache.log"/>
+  <property name="import.package"        value="junit.framework,org.knopflerfish.service.junit,org.apache.avalon.framework.context,org.apache.avalon.framework.logger,org.apache.avalon.framework.service,org.apache.cocoon,org.apache.cocoon.components.blocks,org.apache.cocoon.components.classloader,org.apache.cocoon.components.fam,org.apache.cocoon.components.modules.input,org.apache.cocoon.components.pipeline.impl,org.apache.cocoon.components.source.impl,org.apache.cocoon.components.treeprocessor,org.apache.cocoon.components.treeprocessor.sitemap,org.apache.cocoon.core,org.apache.cocoon.core.container,org.apache.cocoon.environment,org.apache.cocoon.environment.impl,org.apache.cocoon.generation,org.apache.cocoon.matching,org.apache.cocoon.reading,org.apache.cocoon.serialization,org.apache.cocoon.components.source,org.apache.cocoon.transformation,org.apache.cocoon.util,org.apache.cocoon.util.log,org.apache.avalon.excalibur.logger,org.apache.excalibur.source,org.apache.excalibur.source.impl,org.apache.excalibur.xml.impl,org.apache.excalibur.xml.xslt,org.apache.excalibur.xmlizer,org.apache.log"/>
 
   <property name="do.bundle.custom.pre"  value="true"/>
 

Modified: cocoon/whiteboard/osgi/init.xargs
URL: http://svn.apache.org/viewcvs/cocoon/whiteboard/osgi/init.xargs?rev=208999&r1=208998&r2=208999&view=diff
==============================================================================
--- cocoon/whiteboard/osgi/init.xargs (original)
+++ cocoon/whiteboard/osgi/init.xargs Sun Jul  3 15:33:50 2005
@@ -18,7 +18,7 @@
 
 ## Some library bundles
 -initlevel 2
--install http://www.knopflerfish.org/releases/1.3.3/jars/jsdk/jsdk-2.2.jar
+-install cocoon/cocoon_all-1.0.0.jar
 
 ## HTTP Service
 -initlevel 4
@@ -33,11 +33,12 @@
 # JUnit
 -install ../jars-external/junit/junit_all-1.0.0.jar
 
--initlevel 8
--install cocoon/cocoon_all-1.0.0.jar
-
--initlevel 9
+-initlevel 7
 -install cocoon_testcase/cocoon_testcase-1.0.0.jar
+-install cocoon_webapp/cocoon_webapp-1.0.0.jar
+
+-initlevel 8
+-install cocoon_servlet/cocoon_servlet-1.0.0.jar
 
 -startlevel 9
 

Added: cocoon/whiteboard/osgi/jars-external/http/http_api-1.1.0.jar
URL: http://svn.apache.org/viewcvs/cocoon/whiteboard/osgi/jars-external/http/http_api-1.1.0.jar?rev=208999&view=auto
==============================================================================
Binary file - no diff available.

Propchange: cocoon/whiteboard/osgi/jars-external/http/http_api-1.1.0.jar
------------------------------------------------------------------------------
    svn:mime-type = application/octet-stream

Added: cocoon/whiteboard/osgi/jars-external/log/log_api-1.0.0.jar
URL: http://svn.apache.org/viewcvs/cocoon/whiteboard/osgi/jars-external/log/log_api-1.0.0.jar?rev=208999&view=auto
==============================================================================
Binary file - no diff available.

Propchange: cocoon/whiteboard/osgi/jars-external/log/log_api-1.0.0.jar
------------------------------------------------------------------------------
    svn:mime-type = application/octet-stream

Modified: cocoon/whiteboard/osgi/props.xargs
URL: http://svn.apache.org/viewcvs/cocoon/whiteboard/osgi/props.xargs?rev=208999&r1=208998&r2=208999&view=diff
==============================================================================
--- cocoon/whiteboard/osgi/props.xargs (original)
+++ cocoon/whiteboard/osgi/props.xargs Sun Jul  3 15:33:50 2005
@@ -16,7 +16,7 @@
 # Various debug flags
 -Dorg.knopflerfish.framework.debug.packages=false
 -Dorg.knopflerfish.framework.debug.errors=true
--Dorg.knopflerfish.framework.debug.classloader=false
+-Dorg.knopflerfish.framework.debug.classloader=true
 -Dorg.knopflerfish.framework.debug.startlevel=false
 -Dorg.knopflerfish.framework.debug.ldap=false
 



Mime
View raw message