servicemix-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From gno...@apache.org
Subject svn commit: r750406 - in /servicemix/components/engines/servicemix-camel/trunk: ./ src/main/java/org/apache/servicemix/camel/ src/main/java/org/apache/servicemix/camel/osgi/ src/main/resources/META-INF/services/ src/main/resources/META-INF/services/org...
Date Thu, 05 Mar 2009 10:06:08 GMT
Author: gnodet
Date: Thu Mar  5 10:06:07 2009
New Revision: 750406

URL: http://svn.apache.org/viewvc?rev=750406&view=rev
Log:
SMXCOMP-471: Deploying camel routes involving JBI endpoints in ServiceMix 4 does not work
anymore

Added:
    servicemix/components/engines/servicemix-camel/trunk/src/main/java/org/apache/servicemix/camel/CamelComponent.java
    servicemix/components/engines/servicemix-camel/trunk/src/main/java/org/apache/servicemix/camel/osgi/OsgiCamelJbiComponent.java
    servicemix/components/engines/servicemix-camel/trunk/src/main/java/org/apache/servicemix/camel/osgi/OsgiJbiComponent.java
    servicemix/components/engines/servicemix-camel/trunk/src/main/resources/META-INF/services/
    servicemix/components/engines/servicemix-camel/trunk/src/main/resources/META-INF/services/org/
    servicemix/components/engines/servicemix-camel/trunk/src/main/resources/META-INF/services/org/apache/
    servicemix/components/engines/servicemix-camel/trunk/src/main/resources/META-INF/services/org/apache/camel/
    servicemix/components/engines/servicemix-camel/trunk/src/main/resources/META-INF/services/org/apache/camel/component/
    servicemix/components/engines/servicemix-camel/trunk/src/main/resources/META-INF/services/org/apache/camel/component/jbi
Removed:
    servicemix/components/engines/servicemix-camel/trunk/src/main/java/org/apache/servicemix/camel/osgi/CamelComponentFactoryBean.java
Modified:
    servicemix/components/engines/servicemix-camel/trunk/pom.xml
    servicemix/components/engines/servicemix-camel/trunk/src/main/java/org/apache/servicemix/camel/CamelJbiComponent.java
    servicemix/components/engines/servicemix-camel/trunk/src/main/java/org/apache/servicemix/camel/JbiComponent.java
    servicemix/components/engines/servicemix-camel/trunk/src/main/resources/META-INF/spring/servicemix-camel.xml

Modified: servicemix/components/engines/servicemix-camel/trunk/pom.xml
URL: http://svn.apache.org/viewvc/servicemix/components/engines/servicemix-camel/trunk/pom.xml?rev=750406&r1=750405&r2=750406&view=diff
==============================================================================
--- servicemix/components/engines/servicemix-camel/trunk/pom.xml (original)
+++ servicemix/components/engines/servicemix-camel/trunk/pom.xml Thu Mar  5 10:06:07 2009
@@ -60,7 +60,6 @@
       META-INF.services.org.apache.xbean.spring.http.servicemix.apache.org.camel
     </servicemix.osgi.export>
     <servicemix.osgi.bundles>
-        org.apache.servicemix.bundles.jaxp-ri,
         org.springframework.core,
         org.springframework.beans,
         org.springframework.context

Added: servicemix/components/engines/servicemix-camel/trunk/src/main/java/org/apache/servicemix/camel/CamelComponent.java
URL: http://svn.apache.org/viewvc/servicemix/components/engines/servicemix-camel/trunk/src/main/java/org/apache/servicemix/camel/CamelComponent.java?rev=750406&view=auto
==============================================================================
--- servicemix/components/engines/servicemix-camel/trunk/src/main/java/org/apache/servicemix/camel/CamelComponent.java
(added)
+++ servicemix/components/engines/servicemix-camel/trunk/src/main/java/org/apache/servicemix/camel/CamelComponent.java
Thu Mar  5 10:06:07 2009
@@ -0,0 +1,39 @@
+/*
+ * 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.camel;
+
+import org.apache.servicemix.common.ServiceMixComponent;
+import org.apache.servicemix.common.ServiceUnit;
+import org.apache.servicemix.common.Endpoint;
+
+/**
+ */
+public interface CamelComponent extends ServiceMixComponent {
+
+    void addJbiComponent(JbiComponent jbiComponent);
+
+    ServiceUnit getServiceUnit();
+
+    void addEndpoint(Endpoint endpoint) throws Exception;
+
+    void removeEndpoint(Endpoint endpoint) throws Exception;
+
+    void activateJbiEndpoint(CamelProviderEndpoint jbiEndpoint) throws Exception;
+
+    void deactivateJbiEndpoint(CamelProviderEndpoint jbiEndpoint) throws Exception;
+
+}

Modified: servicemix/components/engines/servicemix-camel/trunk/src/main/java/org/apache/servicemix/camel/CamelJbiComponent.java
URL: http://svn.apache.org/viewvc/servicemix/components/engines/servicemix-camel/trunk/src/main/java/org/apache/servicemix/camel/CamelJbiComponent.java?rev=750406&r1=750405&r2=750406&view=diff
==============================================================================
--- servicemix/components/engines/servicemix-camel/trunk/src/main/java/org/apache/servicemix/camel/CamelJbiComponent.java
(original)
+++ servicemix/components/engines/servicemix-camel/trunk/src/main/java/org/apache/servicemix/camel/CamelJbiComponent.java
Thu Mar  5 10:06:07 2009
@@ -39,7 +39,7 @@
  *
  * @version $Revision: 426415 $
  */
-public class CamelJbiComponent extends DefaultComponent {
+public class CamelJbiComponent extends DefaultComponent implements CamelComponent {
 
     protected CamelSpringDeployer deployer;
 

Modified: servicemix/components/engines/servicemix-camel/trunk/src/main/java/org/apache/servicemix/camel/JbiComponent.java
URL: http://svn.apache.org/viewvc/servicemix/components/engines/servicemix-camel/trunk/src/main/java/org/apache/servicemix/camel/JbiComponent.java?rev=750406&r1=750405&r2=750406&view=diff
==============================================================================
--- servicemix/components/engines/servicemix-camel/trunk/src/main/java/org/apache/servicemix/camel/JbiComponent.java
(original)
+++ servicemix/components/engines/servicemix-camel/trunk/src/main/java/org/apache/servicemix/camel/JbiComponent.java
Thu Mar  5 10:06:07 2009
@@ -28,17 +28,21 @@
 import org.apache.servicemix.id.IdGenerator;
 
 public class JbiComponent implements Component<Exchange> {
-    private final CamelJbiComponent camelJbiComponent;
+
+    private CamelComponent camelJbiComponent;
     private JbiBinding binding;
     private CamelContext camelContext;
     private IdGenerator idGenerator;
     private String suName;
 
-    public JbiComponent(CamelJbiComponent component) {
-        camelJbiComponent = component;
-        camelJbiComponent.addJbiComponent(this);
+    public JbiComponent(CamelComponent component) {
+        setCamelJbiComponent(component);
+    }
+
+    protected JbiComponent() {
     }
 
+
     public CamelContext getCamelContext() {
         return camelContext;
     }
@@ -47,7 +51,13 @@
         camelContext = context;
     }
 
-    public CamelJbiComponent getCamelJbiComponent() {
+    public void setCamelJbiComponent(CamelComponent component) {
+        this.camelJbiComponent = component;
+        this.camelJbiComponent.addJbiComponent(this);
+
+    }
+
+    public CamelComponent getCamelJbiComponent() {
         return camelJbiComponent;
     }
 

Added: servicemix/components/engines/servicemix-camel/trunk/src/main/java/org/apache/servicemix/camel/osgi/OsgiCamelJbiComponent.java
URL: http://svn.apache.org/viewvc/servicemix/components/engines/servicemix-camel/trunk/src/main/java/org/apache/servicemix/camel/osgi/OsgiCamelJbiComponent.java?rev=750406&view=auto
==============================================================================
--- servicemix/components/engines/servicemix-camel/trunk/src/main/java/org/apache/servicemix/camel/osgi/OsgiCamelJbiComponent.java
(added)
+++ servicemix/components/engines/servicemix-camel/trunk/src/main/java/org/apache/servicemix/camel/osgi/OsgiCamelJbiComponent.java
Thu Mar  5 10:06:07 2009
@@ -0,0 +1,95 @@
+/*
+ * 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.camel.osgi;
+
+import java.util.List;
+import java.util.Collections;
+import java.util.ArrayList;
+import java.io.File;
+import java.net.URL;
+
+import org.apache.servicemix.camel.CamelJbiComponent;
+import org.apache.servicemix.camel.CamelSpringDeployer;
+import org.apache.servicemix.common.BaseServiceUnitManager;
+import org.apache.servicemix.common.Deployer;
+import org.apache.servicemix.common.ServiceMixComponent;
+import org.apache.servicemix.common.xbean.ClassLoaderXmlPreprocessor;
+import org.apache.xbean.spring.context.SpringApplicationContext;
+import org.apache.xbean.classloader.JarFileClassLoader;
+import org.springframework.osgi.context.BundleContextAware;
+import org.springframework.osgi.util.BundleDelegatingClassLoader;
+import org.osgi.framework.BundleContext;
+import org.osgi.framework.Bundle;
+
+/**
+ * When deploying a JBI packaged SU to camel component, camel-spring can not be found
+ * by Spring/XBean, thus leading to an exception about the spring namespace not being
+ * found.  We need to hack the clasloader for SUs to force a reference to camel-spring
+ * in the SU classloader parents.
+ *
+ * This does not completely solve the problem, as converters can not be found because
+ * camel-core ResolverUtil does not work well
+ */
+public class OsgiCamelJbiComponent extends CamelJbiComponent implements BundleContextAware
{
+
+    private BundleContext bundleContext;
+
+    public void setBundleContext(BundleContext bundleContext) {
+        this.bundleContext = bundleContext;
+    }
+
+    public BaseServiceUnitManager createServiceUnitManager() {
+        CamelSpringDeployer deployer = new OsgiCamelSpringDeployer(this);
+        return new BaseServiceUnitManager(this, new Deployer[] {deployer});
+    }
+
+    public class OsgiCamelSpringDeployer extends CamelSpringDeployer {
+        public OsgiCamelSpringDeployer(CamelJbiComponent component) {
+            super(component);
+        }
+        protected List getXmlPreProcessors(String serviceUnitRootPath) {
+            ClassLoaderXmlPreprocessor classLoaderXmlPreprocessor =
+                    new OsgiClassLoaderXmlPreprocessor(new File(serviceUnitRootPath),
+                                                       component);
+            return Collections.singletonList(classLoaderXmlPreprocessor);
+        }
+    }
+
+    public class OsgiClassLoaderXmlPreprocessor extends ClassLoaderXmlPreprocessor {
+        public OsgiClassLoaderXmlPreprocessor(File root, ServiceMixComponent component) {
+            super(root, component);
+        }
+
+        protected ClassLoader getParentClassLoader(SpringApplicationContext applicationContext)
{
+            List<ClassLoader> parents = new ArrayList<ClassLoader>();
+            parents.add(super.getParentClassLoader(applicationContext));
+            for (Bundle bundle : bundleContext.getBundles()) {
+                try {
+                    if (bundle.getSymbolicName().contains("camel-spring")) {
+                        parents.add(BundleDelegatingClassLoader.createBundleClassLoaderFor(bundle));
+                    }
+                } catch (Throwable e) {
+                    // Do nothing
+                }
+            }
+            return new JarFileClassLoader("SU parent class loader",
+                                          new URL[0],
+                                          parents.toArray(new ClassLoader[parents.size()]));
+        }
+    }
+
+}

Added: servicemix/components/engines/servicemix-camel/trunk/src/main/java/org/apache/servicemix/camel/osgi/OsgiJbiComponent.java
URL: http://svn.apache.org/viewvc/servicemix/components/engines/servicemix-camel/trunk/src/main/java/org/apache/servicemix/camel/osgi/OsgiJbiComponent.java?rev=750406&view=auto
==============================================================================
--- servicemix/components/engines/servicemix-camel/trunk/src/main/java/org/apache/servicemix/camel/osgi/OsgiJbiComponent.java
(added)
+++ servicemix/components/engines/servicemix-camel/trunk/src/main/java/org/apache/servicemix/camel/osgi/OsgiJbiComponent.java
Thu Mar  5 10:06:07 2009
@@ -0,0 +1,56 @@
+/*
+ * 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.camel.osgi;
+
+import org.springframework.osgi.context.BundleContextAware;
+import org.springframework.beans.factory.InitializingBean;
+import org.springframework.beans.factory.DisposableBean;
+import org.apache.servicemix.camel.JbiComponent;
+import org.apache.servicemix.camel.CamelComponent;
+import org.osgi.framework.BundleContext;
+import org.osgi.framework.ServiceReference;
+
+/**
+ */
+public class OsgiJbiComponent extends JbiComponent implements BundleContextAware, InitializingBean,
DisposableBean {
+
+    private BundleContext bundleContext;
+    private ServiceReference reference;
+
+    public BundleContext getBundleContext() {
+        return bundleContext;
+    }
+
+    public void setBundleContext(BundleContext bundleContext) {
+        this.bundleContext = bundleContext;
+    }
+
+    public void afterPropertiesSet() throws Exception {
+        reference = bundleContext.getServiceReference(CamelComponent.class.getName());
+        if (reference == null) {
+            throw new IllegalStateException(CamelComponent.class.getName() + " not found
in the OSGi registry");
+        }
+        CamelComponent component = (CamelComponent) bundleContext.getService(reference);
+        setCamelJbiComponent(component);
+    }
+
+    public void destroy() throws Exception {
+        if (reference != null) {
+            bundleContext.ungetService(reference);
+        }
+    }
+}

Added: servicemix/components/engines/servicemix-camel/trunk/src/main/resources/META-INF/services/org/apache/camel/component/jbi
URL: http://svn.apache.org/viewvc/servicemix/components/engines/servicemix-camel/trunk/src/main/resources/META-INF/services/org/apache/camel/component/jbi?rev=750406&view=auto
==============================================================================
--- servicemix/components/engines/servicemix-camel/trunk/src/main/resources/META-INF/services/org/apache/camel/component/jbi
(added)
+++ servicemix/components/engines/servicemix-camel/trunk/src/main/resources/META-INF/services/org/apache/camel/component/jbi
Thu Mar  5 10:06:07 2009
@@ -0,0 +1,18 @@
+#
+# 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.
+#
+
+class=org.apache.servicemix.camel.osgi.OsgiJbiComponent
\ No newline at end of file

Modified: servicemix/components/engines/servicemix-camel/trunk/src/main/resources/META-INF/spring/servicemix-camel.xml
URL: http://svn.apache.org/viewvc/servicemix/components/engines/servicemix-camel/trunk/src/main/resources/META-INF/spring/servicemix-camel.xml?rev=750406&r1=750405&r2=750406&view=diff
==============================================================================
--- servicemix/components/engines/servicemix-camel/trunk/src/main/resources/META-INF/spring/servicemix-camel.xml
(original)
+++ servicemix/components/engines/servicemix-camel/trunk/src/main/resources/META-INF/spring/servicemix-camel.xml
Thu Mar  5 10:06:07 2009
@@ -29,12 +29,13 @@
   http://www.springframework.org/schema/osgi
   http://www.springframework.org/schema/osgi/spring-osgi.xsd">
 
-    <bean id="servicemix-camel" class="org.apache.servicemix.camel.osgi.CamelComponentFactoryBean">
+    <bean id="servicemix-camel" class="org.apache.servicemix.camel.osgi.OsgiCamelJbiComponent">
     </bean>
 
     <osgi:service ref="servicemix-camel">
         <osgi:interfaces>
             <value>javax.jbi.component.Component</value>
+            <value>org.apache.servicemix.camel.CamelComponent</value>
         </osgi:interfaces>
         <osgi:service-properties>
             <entry key="NAME" value="servicemix-camel" />



Mime
View raw message