servicemix-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From gno...@apache.org
Subject svn commit: r643087 - in /servicemix/smx4/features/trunk: assembly/ assembly/src/main/descriptors/ assembly/src/main/filtered-resources/etc/ ejb3/ ejb3/cxf-transport-osgi/ ejb3/cxf-transport-osgi/src/ ejb3/cxf-transport-osgi/src/main/ ejb3/cxf-transpor...
Date Mon, 31 Mar 2008 18:09:56 GMT
Author: gnodet
Date: Mon Mar 31 11:09:44 2008
New Revision: 643087

URL: http://svn.apache.org/viewvc?rev=643087&view=rev
Log:
Add a CXF transport based on osgi

Added:
    servicemix/smx4/features/trunk/ejb3/cxf-transport-osgi/   (with props)
    servicemix/smx4/features/trunk/ejb3/cxf-transport-osgi/pom.xml
    servicemix/smx4/features/trunk/ejb3/cxf-transport-osgi/src/
    servicemix/smx4/features/trunk/ejb3/cxf-transport-osgi/src/main/
    servicemix/smx4/features/trunk/ejb3/cxf-transport-osgi/src/main/java/
    servicemix/smx4/features/trunk/ejb3/cxf-transport-osgi/src/main/java/org/
    servicemix/smx4/features/trunk/ejb3/cxf-transport-osgi/src/main/java/org/apache/
    servicemix/smx4/features/trunk/ejb3/cxf-transport-osgi/src/main/java/org/apache/servicemix/
    servicemix/smx4/features/trunk/ejb3/cxf-transport-osgi/src/main/java/org/apache/servicemix/cxf/
    servicemix/smx4/features/trunk/ejb3/cxf-transport-osgi/src/main/java/org/apache/servicemix/cxf/transport/
    servicemix/smx4/features/trunk/ejb3/cxf-transport-osgi/src/main/java/org/apache/servicemix/cxf/transport/http_osgi/
    servicemix/smx4/features/trunk/ejb3/cxf-transport-osgi/src/main/java/org/apache/servicemix/cxf/transport/http_osgi/OsgiDestination.java
    servicemix/smx4/features/trunk/ejb3/cxf-transport-osgi/src/main/java/org/apache/servicemix/cxf/transport/http_osgi/OsgiDestinationRegistry.java
    servicemix/smx4/features/trunk/ejb3/cxf-transport-osgi/src/main/java/org/apache/servicemix/cxf/transport/http_osgi/OsgiServlet.java
    servicemix/smx4/features/trunk/ejb3/cxf-transport-osgi/src/main/java/org/apache/servicemix/cxf/transport/http_osgi/OsgiTransportFactory.java
    servicemix/smx4/features/trunk/ejb3/cxf-transport-osgi/src/main/resources/
    servicemix/smx4/features/trunk/ejb3/cxf-transport-osgi/src/main/resources/META-INF/
    servicemix/smx4/features/trunk/ejb3/cxf-transport-osgi/src/main/resources/META-INF/cxf/
    servicemix/smx4/features/trunk/ejb3/cxf-transport-osgi/src/main/resources/META-INF/cxf/osgi/
    servicemix/smx4/features/trunk/ejb3/cxf-transport-osgi/src/main/resources/META-INF/cxf/osgi/cxf-extension-osgi.xml
    servicemix/smx4/features/trunk/ejb3/cxf-transport-osgi/src/main/resources/META-INF/spring/
    servicemix/smx4/features/trunk/ejb3/cxf-transport-osgi/src/main/resources/META-INF/spring/cxf-transport-osgi.xml
Modified:
    servicemix/smx4/features/trunk/assembly/pom.xml
    servicemix/smx4/features/trunk/assembly/src/main/descriptors/unix-bin.xml
    servicemix/smx4/features/trunk/assembly/src/main/descriptors/windows-bin.xml
    servicemix/smx4/features/trunk/assembly/src/main/filtered-resources/etc/startup.properties
    servicemix/smx4/features/trunk/ejb3/pom.xml

Modified: servicemix/smx4/features/trunk/assembly/pom.xml
URL: http://svn.apache.org/viewvc/servicemix/smx4/features/trunk/assembly/pom.xml?rev=643087&r1=643086&r2=643087&view=diff
==============================================================================
--- servicemix/smx4/features/trunk/assembly/pom.xml (original)
+++ servicemix/smx4/features/trunk/assembly/pom.xml Mon Mar 31 11:09:44 2008
@@ -239,6 +239,11 @@
         </dependency>
         <dependency>
             <groupId>org.apache.servicemix.ejb3</groupId>
+            <artifactId>org.apache.servicemix.cxf.transport.osgi</artifactId>
+            <version>1.0-SNAPSHOT</version>
+        </dependency>
+        <dependency>
+            <groupId>org.apache.servicemix.ejb3</groupId>
             <artifactId>org.apache.servicemix.ejb3.deployer</artifactId>
             <version>1.0-SNAPSHOT</version>
         </dependency>
@@ -335,6 +340,11 @@
         <dependency>
             <groupId>org.ops4j.pax.web-extender</groupId>
             <artifactId>pax-web-ex-war</artifactId>
+            <version>${pax.web.extender.version}</version>
+        </dependency>
+        <dependency>
+            <groupId>org.ops4j.pax.web-extender</groupId>
+            <artifactId>pax-web-ex-whiteboard</artifactId>
             <version>${pax.web.extender.version}</version>
         </dependency>
         <dependency>

Modified: servicemix/smx4/features/trunk/assembly/src/main/descriptors/unix-bin.xml
URL: http://svn.apache.org/viewvc/servicemix/smx4/features/trunk/assembly/src/main/descriptors/unix-bin.xml?rev=643087&r1=643086&r2=643087&view=diff
==============================================================================
--- servicemix/smx4/features/trunk/assembly/src/main/descriptors/unix-bin.xml (original)
+++ servicemix/smx4/features/trunk/assembly/src/main/descriptors/unix-bin.xml Mon Mar 31 11:09:44
2008
@@ -149,7 +149,9 @@
                 <include>org.ops4j.pax.web:pax-web-bundle</include>
                 <include>org.ops4j.pax.web:pax-web-jsp</include>
                 <include>org.ops4j.pax.web-extender:pax-web-ex-war</include>
+                <include>org.ops4j.pax.web-extender:pax-web-ex-whiteboard</include>
                 <include>org.ops4j.pax.url:pax-url-war</include>
+                <include>org.apache.servicemix.war:org.apache.servicemix.war.deployer</include>
 
                 <!-- EJB3 / CXF -->
                 <include>org.apache.xbean:xbean-finder</include>
@@ -188,6 +190,7 @@
                 <include>org.apache.servicemix.bundles:org.apache.servicemix.bundles.xmlschema-1.3.2</include>
                 <include>org.apache.servicemix.bundles:org.apache.servicemix.bundles.xmlresolver-1.2</include>
                 <include>org.apache.servicemix.ejb3:org.apache.servicemix.cxf.transport.nmr</include>
+                <include>org.apache.servicemix.ejb3:org.apache.servicemix.cxf.transport.osgi</include>
                 <include>org.apache.servicemix.ejb3:org.apache.servicemix.cxf.binding.nmr</include>
                 <include>org.apache.servicemix.ejb3:org.apache.servicemix.ejb3.deployer</include>
 

Modified: servicemix/smx4/features/trunk/assembly/src/main/descriptors/windows-bin.xml
URL: http://svn.apache.org/viewvc/servicemix/smx4/features/trunk/assembly/src/main/descriptors/windows-bin.xml?rev=643087&r1=643086&r2=643087&view=diff
==============================================================================
--- servicemix/smx4/features/trunk/assembly/src/main/descriptors/windows-bin.xml (original)
+++ servicemix/smx4/features/trunk/assembly/src/main/descriptors/windows-bin.xml Mon Mar 31
11:09:44 2008
@@ -140,7 +140,9 @@
                 <include>org.ops4j.pax.web:pax-web-bundle</include>
                 <include>org.ops4j.pax.web:pax-web-jsp</include>
                 <include>org.ops4j.pax.web-extender:pax-web-ex-war</include>
+                <include>org.ops4j.pax.web-extender:pax-web-ex-whiteboard</include>
                 <include>org.ops4j.pax.url:pax-url-war</include>
+                <include>org.apache.servicemix.war:org.apache.servicemix.war.deployer</include>
 
                 <!-- EJB3 / CXF -->
                 <include>org.apache.xbean:xbean-finder</include>
@@ -179,6 +181,7 @@
                 <include>org.apache.servicemix.bundles:org.apache.servicemix.bundles.xmlschema-1.3.2</include>
                 <include>org.apache.servicemix.bundles:org.apache.servicemix.bundles.xmlresolver-1.2</include>
                 <include>org.apache.servicemix.ejb3:org.apache.servicemix.cxf.transport.nmr</include>
+                <include>org.apache.servicemix.ejb3:org.apache.servicemix.cxf.transport.osgi</include>
                 <include>org.apache.servicemix.ejb3:org.apache.servicemix.cxf.binding.nmr</include>
                 <include>org.apache.servicemix.ejb3:org.apache.servicemix.ejb3.deployer</include>
 

Modified: servicemix/smx4/features/trunk/assembly/src/main/filtered-resources/etc/startup.properties
URL: http://svn.apache.org/viewvc/servicemix/smx4/features/trunk/assembly/src/main/filtered-resources/etc/startup.properties?rev=643087&r1=643086&r2=643087&view=diff
==============================================================================
--- servicemix/smx4/features/trunk/assembly/src/main/filtered-resources/etc/startup.properties
(original)
+++ servicemix/smx4/features/trunk/assembly/src/main/filtered-resources/etc/startup.properties
Mon Mar 31 11:09:44 2008
@@ -92,6 +92,7 @@
 pax-web-bundle-${pax.web.version}.jar=50
 pax-web-jsp-${pax.web.version}.jar=50
 pax-web-ex-war-${pax.web.extender.version}.jar=50
+pax-web-ex-whiteboard-${pax.web.extender.version}.jar=50
 pax-url-war-${pax.url.version}.jar=50
 
 org.apache.servicemix.bundles.asm-2.2.3-${servicemix.kernel.version}.jar=50
@@ -132,6 +133,7 @@
 org.apache.servicemix.bundles.xmlschema-1.3.2-${version}.jar=50
 org.apache.servicemix.bundles.xmlresolver-1.2-${version}.jar=50
 org.apache.servicemix.cxf.transport.nmr-${version}.jar=50
+org.apache.servicemix.cxf.transport.osgi-${version}.jar=50
 org.apache.servicemix.cxf.binding.nmr-${version}.jar=50
 org.apache.servicemix.ejb3.deployer-${version}.jar=50
 

Propchange: servicemix/smx4/features/trunk/ejb3/cxf-transport-osgi/
------------------------------------------------------------------------------
--- svn:ignore (added)
+++ svn:ignore Mon Mar 31 11:09:44 2008
@@ -0,0 +1,7 @@
+target
+*.iml
+*.ipr
+*.iws
+.classpath
+.project
+.settings

Added: servicemix/smx4/features/trunk/ejb3/cxf-transport-osgi/pom.xml
URL: http://svn.apache.org/viewvc/servicemix/smx4/features/trunk/ejb3/cxf-transport-osgi/pom.xml?rev=643087&view=auto
==============================================================================
--- servicemix/smx4/features/trunk/ejb3/cxf-transport-osgi/pom.xml (added)
+++ servicemix/smx4/features/trunk/ejb3/cxf-transport-osgi/pom.xml Mon Mar 31 11:09:44 2008
@@ -0,0 +1,123 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+         xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
+
+    <!--
+
+        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.
+    -->
+
+    <modelVersion>4.0.0</modelVersion>
+
+    <parent>
+	    <groupId>org.apache.servicemix.ejb3</groupId>
+	    <artifactId>ejb3</artifactId>
+        <version>1.0-SNAPSHOT</version>
+    </parent>
+
+    <groupId>org.apache.servicemix.ejb3</groupId>
+    <artifactId>org.apache.servicemix.cxf.transport.osgi</artifactId>
+    <packaging>bundle</packaging>
+    <version>1.0-SNAPSHOT</version>
+    <name>ServiceMix CXF Transport for OSGi</name>
+
+    <dependencies>
+        <dependency>
+            <groupId>org.apache.servicemix.bundles</groupId>
+            <artifactId>org.apache.servicemix.bundles.cxf-2.0.4</artifactId>
+            <version>${pom.version}</version>
+        </dependency>
+        <dependency>
+            <groupId>org.apache.felix</groupId>
+            <artifactId>org.osgi.compendium</artifactId>
+            <version>${felix.compendium.version}</version>
+            <scope>provided</scope>
+        </dependency>
+        <dependency>
+            <groupId>org.apache.cxf</groupId>
+            <artifactId>cxf-bundle</artifactId>
+            <version>${cxf.version}</version>
+            <optional>true</optional>
+        </dependency>
+    </dependencies>
+
+    <build>
+        <plugins>
+            <!-- Bundle generation -->
+            <plugin>
+                <groupId>org.apache.felix</groupId>
+                <artifactId>maven-bundle-plugin</artifactId>
+                <configuration>
+                    <instructions>
+                        <Bundle-SymbolicName>${pom.artifactId}</Bundle-SymbolicName>
+                        <Import-Package>
+                            javax.xml.rpc*;resolution:=optional,
+                            javax.xml.soap,
+                            com.ctc.wstx.stax;resolution:=optional,
+                            org.apache.axis.soap;resolution:=optional,
+                            org.apache.axis2.saaj;resolution:=optional,
+                            com.sun.xml.messaging.saaj.soap.ver1_1;resolution:=optional,
+                            com.sun.xml.messaging.saaj.client.p2p;resolution:=optional,
+                            com.sun.xml.messaging.saaj.soap;resolution:=optional,
+                            *
+                        </Import-Package>
+                        <Export-Package>
+                            org.apache.servicemix.cxf.transport.http_osgi,
+                            '=META-INF.cxf.osgi'
+                        </Export-Package>
+                        <_failok>true</_failok>
+                    </instructions>
+                </configuration>
+            </plugin>
+            <!-- generate dependencies versions -->
+            <plugin>
+		        <groupId>org.apache.servicemix.kernel.testing</groupId>
+		        <artifactId>depends-maven-plugin</artifactId>
+                <version>${servicemix.kernel.version}</version>
+                <executions>
+                    <execution>
+                        <id>generate-depends-file</id>
+                        <goals>
+                            <goal>generate-depends-file</goal>
+                        </goals>
+                    </execution>
+                </executions>
+            </plugin>
+            <plugin>
+                <groupId>org.apache.maven.plugins</groupId>
+                <artifactId>maven-surefire-plugin</artifactId>
+                <configuration>
+                    <forkMode>pertest</forkMode>
+                    <systemProperties>
+                        <property>
+                            <name>javax.xml.parsers.DocumentBuilderFactory</name>
+                            <value>com.sun.org.apache.xerces.internal.jaxp.DocumentBuilderFactoryImpl</value>
+                        </property>
+                        <property>
+                            <name>javax.xml.datatype.DatatypeFactory</name>
+                            <value>com.sun.org.apache.xerces.internal.jaxp.datatype.DatatypeFactoryImpl</value>
+                        </property>
+                        <property>
+                            <name>javax.xml.parsers.SAXParserFactory</name>
+                            <value>com.sun.org.apache.xerces.internal.jaxp.SAXParserFactoryImpl</value>
+                        </property>
+                    </systemProperties>
+                </configuration>
+            </plugin>
+        </plugins>
+    </build>
+
+</project>

Added: servicemix/smx4/features/trunk/ejb3/cxf-transport-osgi/src/main/java/org/apache/servicemix/cxf/transport/http_osgi/OsgiDestination.java
URL: http://svn.apache.org/viewvc/servicemix/smx4/features/trunk/ejb3/cxf-transport-osgi/src/main/java/org/apache/servicemix/cxf/transport/http_osgi/OsgiDestination.java?rev=643087&view=auto
==============================================================================
--- servicemix/smx4/features/trunk/ejb3/cxf-transport-osgi/src/main/java/org/apache/servicemix/cxf/transport/http_osgi/OsgiDestination.java
(added)
+++ servicemix/smx4/features/trunk/ejb3/cxf-transport-osgi/src/main/java/org/apache/servicemix/cxf/transport/http_osgi/OsgiDestination.java
Mon Mar 31 11:09:44 2008
@@ -0,0 +1,105 @@
+/**
+ * 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.servicemix.cxf.transport.http_osgi;
+
+import java.io.IOException;
+import java.util.logging.Level;
+import java.util.logging.Logger;
+
+
+import org.apache.cxf.Bus;
+import org.apache.cxf.common.logging.LogUtils;
+import org.apache.cxf.message.MessageImpl;
+import org.apache.cxf.service.model.EndpointInfo;
+import org.apache.cxf.transport.ConduitInitiator;
+import org.apache.cxf.transport.MessageObserver;
+import org.apache.cxf.transport.http.AbstractHTTPDestination;
+
+
+public class OsgiDestination extends AbstractHTTPDestination {
+
+    static final Logger LOG = LogUtils.getL7dLogger(OsgiDestination.class);
+
+    private static final long serialVersionUID = 1L;
+
+    final OsgiDestinationRegistry factory;
+    final String path;
+
+    /**
+     * Constructor, allowing subsititution of configuration.
+     *
+     * @param b the associated Bus
+     * @param ci the associated conduit initiator
+     * @param ei the endpoint info of the destination
+     * @param fact the transport factory
+     * @param p the path
+     * @throws IOException
+     */
+    public OsgiDestination(Bus b,
+                           ConduitInitiator ci,
+                           EndpointInfo ei,
+                           OsgiDestinationRegistry fact,
+                           String p)
+        throws IOException {
+        // would add the default port to the address
+        super(b, ci, ei, false);
+        factory = fact;
+        path = p;
+    }
+
+
+    protected Logger getLogger() {
+        return LOG;
+    }
+
+    protected Bus getBus() {
+        return bus;
+    }
+
+
+    protected void doMessage(MessageImpl inMessage) throws IOException {
+        try {
+
+            setHeaders(inMessage);
+
+            inMessage.setDestination(this);
+
+            incomingObserver.onMessage(inMessage);
+
+        } finally {
+            if (LOG.isLoggable(Level.FINE)) {
+                LOG.fine("Finished servicing http request on thread: " + Thread.currentThread());
+            }
+        }
+    }
+
+    @Override
+    public void shutdown() {
+        factory.removeDestination(path);
+        super.shutdown();
+    }
+
+    public MessageObserver getMessageObserver() {
+        return this.incomingObserver;
+    }
+
+    public EndpointInfo getEndpointInfo() {
+        return endpointInfo;
+    }
+}

Added: servicemix/smx4/features/trunk/ejb3/cxf-transport-osgi/src/main/java/org/apache/servicemix/cxf/transport/http_osgi/OsgiDestinationRegistry.java
URL: http://svn.apache.org/viewvc/servicemix/smx4/features/trunk/ejb3/cxf-transport-osgi/src/main/java/org/apache/servicemix/cxf/transport/http_osgi/OsgiDestinationRegistry.java?rev=643087&view=auto
==============================================================================
--- servicemix/smx4/features/trunk/ejb3/cxf-transport-osgi/src/main/java/org/apache/servicemix/cxf/transport/http_osgi/OsgiDestinationRegistry.java
(added)
+++ servicemix/smx4/features/trunk/ejb3/cxf-transport-osgi/src/main/java/org/apache/servicemix/cxf/transport/http_osgi/OsgiDestinationRegistry.java
Mon Mar 31 11:09:44 2008
@@ -0,0 +1,75 @@
+/**
+ * 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.servicemix.cxf.transport.http_osgi;
+
+import java.util.Collection;
+import java.util.Collections;
+import java.util.Set;
+import java.util.concurrent.ConcurrentHashMap;
+import java.util.concurrent.ConcurrentMap;
+
+public class OsgiDestinationRegistry {
+
+    private ConcurrentMap<String, OsgiDestination> destinations = new ConcurrentHashMap<String,
OsgiDestination>();
+
+    public OsgiDestinationRegistry() {
+    }
+
+    public void addDestination(String path, OsgiDestination destination) {
+        String p = getTrimmedPath(path);
+        destinations.putIfAbsent(path, destination);
+    }
+
+    public void removeDestination(String path) {
+        destinations.remove(path);
+    }
+
+    public OsgiDestination getDestinationForPath(String path) {
+        // to use the url context match
+        return destinations.get(getTrimmedPath(path));
+    }
+
+    public Collection<OsgiDestination> getDestinations() {
+        return Collections.unmodifiableCollection(destinations.values());
+    }
+
+    public Set<String> getDestinationsPaths() {
+        return Collections.unmodifiableSet(destinations.keySet());
+    }
+
+    static String getTrimmedPath(String path) {
+        if (path == null) {
+            return "/";
+        }
+        final String lh = "http://localhost/";
+        final String lhs = "https://localhost/";
+
+        if (path.startsWith(lh)) {
+            path = path.substring(lh.length());
+        } else if (path.startsWith(lhs)) {
+            path = path.substring(lhs.length());
+        }
+        if (!path.startsWith("/")) {
+            path = "/" + path;
+
+        }
+        return path;
+    }
+
+}

Added: servicemix/smx4/features/trunk/ejb3/cxf-transport-osgi/src/main/java/org/apache/servicemix/cxf/transport/http_osgi/OsgiServlet.java
URL: http://svn.apache.org/viewvc/servicemix/smx4/features/trunk/ejb3/cxf-transport-osgi/src/main/java/org/apache/servicemix/cxf/transport/http_osgi/OsgiServlet.java?rev=643087&view=auto
==============================================================================
--- servicemix/smx4/features/trunk/ejb3/cxf-transport-osgi/src/main/java/org/apache/servicemix/cxf/transport/http_osgi/OsgiServlet.java
(added)
+++ servicemix/smx4/features/trunk/ejb3/cxf-transport-osgi/src/main/java/org/apache/servicemix/cxf/transport/http_osgi/OsgiServlet.java
Mon Mar 31 11:09:44 2008
@@ -0,0 +1,294 @@
+/**
+ * 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.servicemix.cxf.transport.http_osgi;
+
+import java.io.IOException;
+import java.io.OutputStream;
+import java.io.InputStream;
+import java.util.logging.Logger;
+import java.util.logging.Level;
+import java.util.Set;
+import java.util.Collection;
+import java.security.Principal;
+
+import javax.servlet.ServletException;
+import javax.servlet.http.HttpServlet;
+import javax.servlet.http.HttpServletRequest;
+import javax.servlet.http.HttpServletResponse;
+
+import org.apache.cxf.Bus;
+import org.apache.cxf.helpers.HttpHeaderHelper;
+import org.apache.cxf.security.SecurityContext;
+import org.apache.cxf.transport.http.AbstractHTTPDestination;
+import org.apache.cxf.transport.http.HTTPSession;
+import org.apache.cxf.transport.https.SSLUtils;
+import org.apache.cxf.message.MessageImpl;
+import org.apache.cxf.message.Message;
+import org.apache.cxf.message.ExchangeImpl;
+import org.apache.cxf.transports.http.QueryHandlerRegistry;
+import org.apache.cxf.transports.http.QueryHandler;
+import org.apache.cxf.service.model.EndpointInfo;
+import org.apache.cxf.common.logging.LogUtils;
+import org.apache.cxf.common.util.StringUtils;
+import org.xmlsoap.schemas.wsdl.http.AddressType;
+
+public class OsgiServlet extends HttpServlet {
+
+    private static final Logger LOG = LogUtils.getL7dLogger(OsgiServlet.class);
+
+    private OsgiDestinationRegistry transport;
+    private String lastBase = "";
+    private boolean isHideServiceList;
+    private boolean disableAddressUpdates;
+    private String forcedBaseAddress;
+
+    public OsgiServlet(OsgiDestinationRegistry transport) {
+        this.transport = transport;
+    }
+
+    @Override
+    public void destroy() {
+    }
+
+    @Override
+    protected void doPost(HttpServletRequest request, HttpServletResponse response) throws
ServletException {
+        invoke(request, response);
+    }
+
+    @Override
+    protected void doGet(HttpServletRequest request, HttpServletResponse response) throws
ServletException {
+        invoke(request, response);
+    }
+
+    @Override
+    protected void doDelete(HttpServletRequest request, HttpServletResponse response) throws
ServletException, IOException {
+        invoke(request, response);
+    }
+
+    @Override
+    protected void doPut(HttpServletRequest request, HttpServletResponse response) throws
ServletException, IOException {
+        invoke(request, response);
+    }
+
+    public void setHideServiceList(boolean generate) {
+        isHideServiceList = generate;
+    }
+
+    public void setDisableAddressUpdates(boolean noupdates) {
+        disableAddressUpdates = noupdates;
+    }
+
+    public void setForcedBaseAddress(String s) {
+        forcedBaseAddress = s;
+    }
+
+    private synchronized void updateDests(HttpServletRequest request) {
+        if (disableAddressUpdates) {
+            return;
+        }
+        String base = forcedBaseAddress == null ? getBaseURL(request) : forcedBaseAddress;
+
+        if (base.equals(lastBase)) {
+            return;
+        }
+        Set<String> paths = transport.getDestinationsPaths();
+        for (String path : paths) {
+            OsgiDestination d2 = transport.getDestinationForPath(path);
+            String ad = d2.getEndpointInfo().getAddress();
+            if (ad.equals(path)
+                || ad.equals(lastBase + path)) {
+                d2.getEndpointInfo().setAddress(base + path);
+                if (d2.getEndpointInfo().getExtensor(AddressType.class) != null) {
+                    d2.getEndpointInfo().getExtensor(AddressType.class).setLocation(base
+ path);
+                }
+            }
+        }
+        lastBase = base;
+    }
+
+    public void invoke(HttpServletRequest request, HttpServletResponse res) throws ServletException
{
+        try {
+            EndpointInfo ei = new EndpointInfo();
+            String address = request.getPathInfo() == null ? "" : request.getPathInfo();
+
+            ei.setAddress(address);
+            OsgiDestination d = (OsgiDestination) transport.getDestinationForPath(ei.getAddress());
+
+            if (d == null) {
+                if (request.getRequestURI().endsWith("/services")
+                    || request.getRequestURI().endsWith("/services/")
+                    || StringUtils.isEmpty(request.getPathInfo())
+                    || "/".equals(request.getPathInfo())) {
+                    updateDests(request);
+                    generateServiceList(request, res);
+                } else {
+                    d = checkRestfulRequest(request);
+                    if (d == null || d.getMessageObserver() == null) {
+                        LOG.warning("Can't find the the request for "
+                                    + request.getRequestURL() + "'s Observer ");
+                        generateNotFound(request, res);
+                    }  else { // the request should be a restful service request
+                        updateDests(request);
+                        invokeDestination(request, res, d);
+                    }
+                }
+            } else {
+                ei = d.getEndpointInfo();
+                Bus bus = d.getBus();
+                if (null != request.getQueryString()
+                    && request.getQueryString().length() > 0
+                    && bus.getExtension(QueryHandlerRegistry.class) != null) {
+
+                    String ctxUri = request.getPathInfo();
+                    String baseUri = request.getRequestURL().toString()
+                        + "?" + request.getQueryString();
+                    // update the EndPoint Address with request url
+                    if ("GET".equals(request.getMethod())) {
+                        updateDests(request);
+                    }
+
+                    for (QueryHandler qh : bus.getExtension(QueryHandlerRegistry.class).getHandlers())
{
+                        if (qh.isRecognizedQuery(baseUri, ctxUri, ei)) {
+
+                            res.setContentType(qh.getResponseContentType(baseUri, ctxUri));
+                            OutputStream out = res.getOutputStream();
+                            try {
+                                qh.writeResponse(baseUri, ctxUri, ei, out);
+                                out.flush();
+                                return;
+                            } catch (Exception e) {
+                                //throw new ServletException(e);
+                                LOG.warning(qh.getClass().getName()
+                                    + " Exception caught writing response: "
+                                    + e.getMessage());
+                            }
+                        }
+                    }
+                }
+
+                invokeDestination(request, res, d);
+            }
+        } catch (IOException e) {
+            throw new ServletException(e);
+        }
+    }
+
+    private OsgiDestination checkRestfulRequest(HttpServletRequest request) throws IOException
{
+
+        String address = request.getPathInfo() == null ? "" : request.getPathInfo();
+
+        for (String path : transport.getDestinationsPaths()) {
+            if (address.startsWith(path)) {
+                return transport.getDestinationForPath(path);
+            }
+        }
+        return null;
+    }
+
+    private void generateServiceList(HttpServletRequest request, HttpServletResponse response)
+        throws IOException {
+        Collection<OsgiDestination> destinations = transport.getDestinations();
+        response.setContentType("text/html");
+        response.getWriter().write("<html><body>");
+        if (!isHideServiceList) {
+            if (destinations.size() > 0) {
+                for (OsgiDestination sd : destinations) {
+                    if (null != sd.getEndpointInfo().getName()) {
+                        String address = sd.getEndpointInfo().getAddress();
+                        response.getWriter().write("<p> <a href=\"" + address +
"?wsdl\">");
+                        response.getWriter().write(sd.getEndpointInfo().getName() + "</a>
</p>");
+                    }
+                }
+            } else {
+                response.getWriter().write("No service was found.");
+            }
+        }
+        response.getWriter().write("</body></html>");
+    }
+
+    private String getBaseURL(HttpServletRequest request) {
+        String reqPrefix = request.getRequestURL().toString();
+        String pathInfo = request.getPathInfo() == null ? "" : request.getPathInfo();
+        //fix for CXF-898
+        if (!"/".equals(pathInfo) || reqPrefix.endsWith("/")) {
+            reqPrefix = reqPrefix.substring(0, reqPrefix.length() - pathInfo.length());
+        }
+        return reqPrefix;
+    }
+
+    protected void generateNotFound(HttpServletRequest request, HttpServletResponse res)
throws IOException {
+        res.setStatus(404);
+        res.setContentType("text/html");
+        res.getWriter().write("<html><body>No service was found.</body></html>");
+    }
+
+    public void invokeDestination(final HttpServletRequest request, HttpServletResponse response,
OsgiDestination d) throws ServletException {
+        if (LOG.isLoggable(Level.FINE)) {
+            LOG.fine("Service http request on thread: " + Thread.currentThread());
+        }
+
+        try {
+            MessageImpl inMessage = new MessageImpl();
+            inMessage.setContent(InputStream.class, request.getInputStream());
+            inMessage.put(AbstractHTTPDestination.HTTP_REQUEST, request);
+            inMessage.put(AbstractHTTPDestination.HTTP_RESPONSE, response);
+            inMessage.put(AbstractHTTPDestination.HTTP_CONTEXT, getServletContext());
+            inMessage.put(Message.HTTP_REQUEST_METHOD, request.getMethod());
+            inMessage.put(Message.PATH_INFO, request.getPathInfo());
+            inMessage.put(Message.QUERY_STRING, request.getQueryString());
+            inMessage.put(Message.CONTENT_TYPE, request.getContentType());
+            inMessage.put(Message.BASE_PATH, d.getAddress().getAddress().getValue());
+            inMessage.put(SecurityContext.class, new SecurityContext() {
+                public Principal getUserPrincipal() {
+                    return request.getUserPrincipal();
+                }
+                public boolean isUserInRole(String role) {
+                    return request.isUserInRole(role);
+                }
+            });
+
+            // work around a bug with Jetty which results in the character
+            // encoding not being trimmed correctly.
+            String enc = request.getCharacterEncoding();
+            if (enc != null && enc.endsWith("\"")) {
+                enc = enc.substring(0, enc.length() - 1);
+            }
+
+            String normalizedEncoding = HttpHeaderHelper.mapCharset(enc);
+            if (normalizedEncoding == null) {
+                String m = new org.apache.cxf.common.i18n.Message("INVALID_ENCODING_MSG",
+                                                                  LOG, enc).toString();
+                LOG.log(Level.WARNING, m);
+                throw new IOException(m);
+            }
+
+            inMessage.put(Message.ENCODING, normalizedEncoding);
+            SSLUtils.propogateSecureSession(request, inMessage);
+
+            ExchangeImpl exchange = new ExchangeImpl();
+            exchange.setInMessage(inMessage);
+            exchange.setSession(new HTTPSession(request));
+
+            d.doMessage(inMessage);
+        } catch (IOException e) {
+            throw new ServletException(e);
+        }
+
+    }
+}

Added: servicemix/smx4/features/trunk/ejb3/cxf-transport-osgi/src/main/java/org/apache/servicemix/cxf/transport/http_osgi/OsgiTransportFactory.java
URL: http://svn.apache.org/viewvc/servicemix/smx4/features/trunk/ejb3/cxf-transport-osgi/src/main/java/org/apache/servicemix/cxf/transport/http_osgi/OsgiTransportFactory.java?rev=643087&view=auto
==============================================================================
--- servicemix/smx4/features/trunk/ejb3/cxf-transport-osgi/src/main/java/org/apache/servicemix/cxf/transport/http_osgi/OsgiTransportFactory.java
(added)
+++ servicemix/smx4/features/trunk/ejb3/cxf-transport-osgi/src/main/java/org/apache/servicemix/cxf/transport/http_osgi/OsgiTransportFactory.java
Mon Mar 31 11:09:44 2008
@@ -0,0 +1,70 @@
+/**
+ * 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.servicemix.cxf.transport.http_osgi;
+
+import java.io.IOException;
+import java.net.URI;
+
+import org.apache.cxf.service.model.EndpointInfo;
+import org.apache.cxf.transport.Destination;
+import org.apache.cxf.transport.DestinationFactory;
+import org.apache.cxf.transport.DestinationFactoryManager;
+import org.apache.cxf.transport.http.AbstractHTTPTransportFactory;
+
+public class OsgiTransportFactory extends AbstractHTTPTransportFactory
+    implements DestinationFactory {
+
+    private OsgiDestinationRegistry registry;
+
+    public void setRegistry(OsgiDestinationRegistry registry) {
+        this.registry = registry;
+    }
+
+    public void init() {
+        if (bus == null) {
+            throw new IllegalStateException("bus should not be null");
+        }
+        if (registry == null) {
+            throw new IllegalStateException("registry should not be null");
+        }
+        if (activationNamespaces == null) {
+            activationNamespaces = getTransportIds();
+        }
+        DestinationFactoryManager dfm = bus.getExtension(DestinationFactoryManager.class);
+        if (dfm != null && activationNamespaces != null) {
+            for (String ns : activationNamespaces) {
+                dfm.registerDestinationFactory(ns, this);
+            }
+        }
+    }
+
+    public Destination getDestination(EndpointInfo endpointInfo) throws IOException {
+        if (URI.create(endpointInfo.getAddress()).isAbsolute()) {
+            throw new IllegalStateException("Endpoint address should be a relative URI wrt
to the servlet address (use '/xxx' for example)");
+        }
+        OsgiDestination d = registry.getDestinationForPath(endpointInfo.getAddress());
+        if (d == null) {
+            String path = OsgiDestinationRegistry.getTrimmedPath(endpointInfo.getAddress());
+            d = new OsgiDestination(getBus(), null, endpointInfo, registry, path);
+            registry.addDestination(path, d);
+        }
+        return d;
+    }
+
+}

Added: servicemix/smx4/features/trunk/ejb3/cxf-transport-osgi/src/main/resources/META-INF/cxf/osgi/cxf-extension-osgi.xml
URL: http://svn.apache.org/viewvc/servicemix/smx4/features/trunk/ejb3/cxf-transport-osgi/src/main/resources/META-INF/cxf/osgi/cxf-extension-osgi.xml?rev=643087&view=auto
==============================================================================
--- servicemix/smx4/features/trunk/ejb3/cxf-transport-osgi/src/main/resources/META-INF/cxf/osgi/cxf-extension-osgi.xml
(added)
+++ servicemix/smx4/features/trunk/ejb3/cxf-transport-osgi/src/main/resources/META-INF/cxf/osgi/cxf-extension-osgi.xml
Mon Mar 31 11:09:44 2008
@@ -0,0 +1,48 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!--
+  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.
+-->
+<beans xmlns="http://www.springframework.org/schema/beans"
+       xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+       xmlns:osgi="http://www.springframework.org/schema/osgi"
+       xsi:schemaLocation="
+http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd
+http://www.springframework.org/schema/osgi  http://www.springframework.org/schema/osgi/spring-osgi.xsd">
+
+    <bean id="org.apache.servicemix.cxf.transport.http_osgi.OsgiTransportFactory"
+          class="org.apache.servicemix.cxf.transport.http_osgi.OsgiTransportFactory"
+          init-method="init">
+
+        <property name="bus" ref="cxf"/>
+        <property name="registry" ref="osgiDestinationRegistry" />
+        <property name="transportIds">
+            <set>
+                <value>http://cxf.apache.org/bindings/xformat</value>
+                <value>http://schemas.xmlsoap.org/soap/http</value>
+                <value>http://schemas.xmlsoap.org/wsdl/http/</value>
+                <value>http://schemas.xmlsoap.org/wsdl/soap/http</value>
+ 	            <value>http://www.w3.org/2003/05/soap/bindings/HTTP/</value>
+                <value>http://cxf.apache.org/transports/http/configuration</value>
+            </set>
+        </property>
+    </bean>
+
+    <osgi:reference id="osgiDestinationRegistry"
+                    interface="org.apache.servicemix.cxf.transport.http_osgi.OsgiDestinationRegistry"
/>
+
+</beans>

Added: servicemix/smx4/features/trunk/ejb3/cxf-transport-osgi/src/main/resources/META-INF/spring/cxf-transport-osgi.xml
URL: http://svn.apache.org/viewvc/servicemix/smx4/features/trunk/ejb3/cxf-transport-osgi/src/main/resources/META-INF/spring/cxf-transport-osgi.xml?rev=643087&view=auto
==============================================================================
--- servicemix/smx4/features/trunk/ejb3/cxf-transport-osgi/src/main/resources/META-INF/spring/cxf-transport-osgi.xml
(added)
+++ servicemix/smx4/features/trunk/ejb3/cxf-transport-osgi/src/main/resources/META-INF/spring/cxf-transport-osgi.xml
Mon Mar 31 11:09:44 2008
@@ -0,0 +1,42 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!--
+  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.
+-->
+<beans xmlns="http://www.springframework.org/schema/beans"
+       xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+       xmlns:osgi="http://www.springframework.org/schema/osgi"
+       xsi:schemaLocation="
+http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd
+http://www.springframework.org/schema/osgi  http://www.springframework.org/schema/osgi/spring-osgi.xsd">
+
+    <bean id="destinationRegistry" class="org.apache.servicemix.cxf.transport.http_osgi.OsgiDestinationRegistry"
/>
+
+    <bean id="osgiServlet" class="org.apache.servicemix.cxf.transport.http_osgi.OsgiServlet">
+        <constructor-arg ref="destinationRegistry"/>
+    </bean>
+
+    <osgi:service ref="osgiServlet" interface="javax.servlet.Servlet">
+        <osgi:service-properties>
+            <entry key="alias" value="/cxf" />
+        </osgi:service-properties>
+    </osgi:service>
+
+    <osgi:service ref="destinationRegistry" interface="org.apache.servicemix.cxf.transport.http_osgi.OsgiDestinationRegistry">
+    </osgi:service>
+
+</beans>

Modified: servicemix/smx4/features/trunk/ejb3/pom.xml
URL: http://svn.apache.org/viewvc/servicemix/smx4/features/trunk/ejb3/pom.xml?rev=643087&r1=643086&r2=643087&view=diff
==============================================================================
--- servicemix/smx4/features/trunk/ejb3/pom.xml (original)
+++ servicemix/smx4/features/trunk/ejb3/pom.xml Mon Mar 31 11:09:44 2008
@@ -37,6 +37,7 @@
     <modules>
         <module>bundles</module>
         <module>cxf-transport-nmr</module>
+        <module>cxf-transport-osgi</module>
         <module>cxf-binding-nmr</module>
         <module>deployer</module>
     </modules>



Mime
View raw message