You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@servicemix.apache.org by ff...@apache.org on 2009/02/19 08:49:23 UTC

svn commit: r745769 - in /servicemix/components/engines/servicemix-camel/trunk: ./ src/main/java/org/apache/servicemix/camel/ src/test/java/org/apache/servicemix/camel/

Author: ffang
Date: Thu Feb 19 07:49:23 2009
New Revision: 745769

URL: http://svn.apache.org/viewvc?rev=745769&view=rev
Log:
[SMXCOMP-455]Create JbiComponent per SU (camel context)

Added:
    servicemix/components/engines/servicemix-camel/trunk/src/main/java/org/apache/servicemix/camel/JbiComponent.java   (with props)
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/CamelProviderEndpoint.java
    servicemix/components/engines/servicemix-camel/trunk/src/main/java/org/apache/servicemix/camel/CamelSpringDeployer.java
    servicemix/components/engines/servicemix-camel/trunk/src/main/java/org/apache/servicemix/camel/JbiEndpoint.java
    servicemix/components/engines/servicemix-camel/trunk/src/main/java/org/apache/servicemix/camel/JbiException.java
    servicemix/components/engines/servicemix-camel/trunk/src/test/java/org/apache/servicemix/camel/JbiEndpointWithMepSpecifiedTest.java
    servicemix/components/engines/servicemix-camel/trunk/src/test/java/org/apache/servicemix/camel/JbiTestSupport.java
    servicemix/components/engines/servicemix-camel/trunk/src/test/java/org/apache/servicemix/camel/SendFromCamelToJbiAndBackToCamelTest.java
    servicemix/components/engines/servicemix-camel/trunk/src/test/java/org/apache/servicemix/camel/TwoServicemixCamelSusTest.java

Modified: servicemix/components/engines/servicemix-camel/trunk/pom.xml
URL: http://svn.apache.org/viewvc/servicemix/components/engines/servicemix-camel/trunk/pom.xml?rev=745769&r1=745768&r2=745769&view=diff
==============================================================================
--- servicemix/components/engines/servicemix-camel/trunk/pom.xml (original)
+++ servicemix/components/engines/servicemix-camel/trunk/pom.xml Thu Feb 19 07:49:23 2009
@@ -210,7 +210,7 @@
       </plugin>
       <plugin>
         <artifactId>maven-surefire-plugin</artifactId>
-        <configuration>
+        <configuration>          
           <childDelegation>false</childDelegation>
           <useFile>true</useFile>
           <excludes>

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=745769&r1=745768&r2=745769&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 Feb 19 07:49:23 2009
@@ -25,42 +25,32 @@
 import java.util.concurrent.ScheduledThreadPoolExecutor;
 
 import javax.jbi.servicedesc.ServiceEndpoint;
-import javax.xml.namespace.QName;
 
-import org.apache.camel.CamelContext;
-import org.apache.camel.Component;
 import org.apache.camel.Endpoint;
-import org.apache.camel.Exchange;
-import org.apache.camel.FailedToCreateProducerException;
 import org.apache.camel.Processor;
 import org.apache.servicemix.common.BaseServiceUnitManager;
 import org.apache.servicemix.common.DefaultComponent;
 import org.apache.servicemix.common.Deployer;
 import org.apache.servicemix.common.util.IntrospectionSupport;
-import org.apache.servicemix.common.util.URIResolver;
 import org.apache.servicemix.common.util.URISupport;
-import org.apache.servicemix.id.IdGenerator;
 
 /**
  * Deploys the camel endpoints within JBI
- * 
+ *
  * @version $Revision: 426415 $
  */
-public class CamelJbiComponent extends DefaultComponent implements Component<Exchange> {
+public class CamelJbiComponent extends DefaultComponent {
 
     protected CamelSpringDeployer deployer;
 
-    private JbiBinding binding;
-
-    private CamelContext camelContext;
-
     private ScheduledExecutorService executorService;
 
-    private IdGenerator idGenerator;
+    private List<JbiComponent> jbiComponents = new ArrayList<JbiComponent>();
+
 
     /*
      * (non-Javadoc)
-     * 
+     *
      * @see org.servicemix.common.BaseComponent#createServiceUnitManager()
      */
     @Override
@@ -87,24 +77,6 @@
         return new Class[] {CamelProviderEndpoint.class, CamelConsumerEndpoint.class};
     }
 
-    /**
-     * @return the binding
-     */
-    public JbiBinding getBinding() {
-        if (binding == null) {
-            binding = new JbiBinding();
-        }
-        return binding;
-    }
-
-    /**
-     * @param binding
-     *            the binding to set
-     */
-    public void setBinding(JbiBinding binding) {
-        this.binding = binding;
-    }
-
     @Override
     protected String[] getEPRProtocols() {
         return new String[] {"camel"};
@@ -112,17 +84,44 @@
 
     @Override
     protected org.apache.servicemix.common.Endpoint getResolvedEPR(ServiceEndpoint ep) throws Exception {
-        CamelProviderEndpoint endpoint = createEndpoint(ep);
+        org.apache.servicemix.common.Endpoint endpoint = null;
+        // extract the su name camel:su1:seda:queque
+        JbiComponent jbiComponent = null;
+        String uriString = "";
+        String endpointName = ep.getEndpointName();
+        String names[] = endpointName.split(":");
+        if (names.length > 2) {
+            jbiComponent = getJbiComponent(names[1]);
+
+        } else {
+            throw new IllegalStateException("Can't find the su name from the endpoint name");
+        }
+        if (jbiComponent != null) {
+            // skip the su-name part
+            int index = 0;
+            for(String name : names) {
+                if (index == 0) {
+                    uriString = name;
+                }
+                if (index > 1) {
+                    uriString += ":" + name;
+                }
+                index ++;
+            }
+            endpoint = createEndpoint(uriString, jbiComponent);
+        } else {
+            throw new IllegalStateException("Can't find the JbiComponent");
+        }
         return endpoint;
     }
 
-    public CamelProviderEndpoint createEndpoint(ServiceEndpoint ep) throws URISyntaxException {
-        URI uri = new URI(ep.getEndpointName());
+    public CamelProviderEndpoint createEndpoint(String uriString, JbiComponent jbiComponent) throws URISyntaxException {
+        URI uri = new URI(uriString);
         Map map = URISupport.parseQuery(uri.getQuery());
         String camelUri = uri.getSchemeSpecificPart();
-        Endpoint camelEndpoint = getCamelContext().getEndpoint(camelUri);
-        Processor processor = createCamelProcessor(camelEndpoint);
-        CamelProviderEndpoint endpoint = new CamelProviderEndpoint(getServiceUnit(), camelEndpoint, getBinding(), processor);
+        Endpoint camelEndpoint = jbiComponent.getCamelContext().getEndpoint(camelUri);
+        Processor processor = jbiComponent.createCamelProcessor(camelEndpoint);
+        CamelProviderEndpoint endpoint = new CamelProviderEndpoint(getServiceUnit(), camelEndpoint, jbiComponent.getBinding(), processor);
 
         IntrospectionSupport.setProperties(endpoint, map);
 
@@ -132,22 +131,26 @@
         return endpoint;
     }
 
-    // Resolve Camel Endpoints
-    // -------------------------------------------------------------------------
-    public Endpoint<Exchange> createEndpoint(String uri) {
-        if (uri.startsWith("jbi:")) {
-            uri = uri.substring("jbi:".length());
-            return new JbiEndpoint(this, uri);
-        }
-        return null;
+    public synchronized void addJbiComponent(JbiComponent jbiComponent) {
+        jbiComponents.add(jbiComponent);
     }
 
-    public CamelContext getCamelContext() {
-        return camelContext;
+    public synchronized void removeJbiComponent(String suName) {
+        JbiComponent component = getJbiComponent(suName);
+        if (component != null) {
+            jbiComponents.remove(component);
+        }
     }
 
-    public void setCamelContext(CamelContext camelContext) {
-        this.camelContext = camelContext;
+    public synchronized JbiComponent getJbiComponent(String suName) {
+        JbiComponent result = null;
+        for (JbiComponent component: jbiComponents) {
+            if (suName.equals(component.getSuName())) {
+                result = component;
+                break;
+            }
+        }
+        return result;
     }
 
     public ScheduledExecutorService getExecutorService() {
@@ -159,11 +162,9 @@
 
     /**
      * Activating a JBI endpoint created by a camel consumer.
-     * 
-     * @returns a JBI endpoint created for the given Camel endpoint
+     *
      */
-    public CamelProviderEndpoint activateJbiEndpoint(Endpoint camelEndpoint, Processor processor) throws Exception {
-        CamelProviderEndpoint jbiEndpoint = createJbiEndpointFromCamel(camelEndpoint, processor);
+    public void activateJbiEndpoint(CamelProviderEndpoint jbiEndpoint) throws Exception {
 
         // the following method will activate the new dynamic JBI endpoint
         if (deployer != null) {
@@ -172,7 +173,7 @@
         } else {
             addEndpoint(jbiEndpoint);
         }
-        return jbiEndpoint;
+
     }
 
     public void deactivateJbiEndpoint(CamelProviderEndpoint jbiEndpoint) throws Exception {
@@ -182,86 +183,11 @@
         }
     }
 
-    protected CamelProviderEndpoint createJbiEndpointFromCamel(Endpoint camelEndpoint, Processor processor) {
-        CamelProviderEndpoint jbiEndpoint;
-        String endpointUri = camelEndpoint.getEndpointUri();
-        if (camelEndpoint instanceof JbiEndpoint) {
-            QName service = null;
-            String endpoint = null;
-            if (endpointUri.startsWith("name:")) {
-                endpoint = endpointUri.substring("name:".length());
-                service = CamelProviderEndpoint.SERVICE_NAME;
-            } else if (endpointUri.startsWith("endpoint:")) {
-                String uri = endpointUri.substring("endpoint:".length());
-                // lets decode "serviceNamespace sep serviceName sep
-                // endpointName
-                String[] parts;
-                try {
-                    parts = URIResolver.split3(uri);
-                } catch (IllegalArgumentException e) {
-                    throw new IllegalArgumentException(
-                            "Expected syntax jbi:endpoint:[serviceNamespace][sep][serviceName][sep][endpointName] " 
-                            + "where sep = '/' or ':' depending on the serviceNamespace, but was given: "
-                                    + endpointUri + ". Cause: " + e, e);
-                }
-                service = new QName(parts[0], parts[1]);
-                endpoint = parts[2];
-            } else if (endpointUri.startsWith("service:")) {
-                String uri = endpointUri.substring("service:".length());
-                // lets decode "serviceNamespace sep serviceName
-                String[] parts;
-                try {
-                    parts = URIResolver.split2(uri);
-                } catch (IllegalArgumentException e) {
-                    throw new IllegalArgumentException(
-                            "Expected syntax jbi:endpoint:[serviceNamespace][sep][serviceName] " 
-                            + "where sep = '/' or ':' depending on the serviceNamespace, but was given: "
-                                    + endpointUri + ". Cause: " + e, e);
-                }
-                service = new QName(parts[0], parts[1]);
-                endpoint = createEndpointName();
-            } else {
-                throw new IllegalArgumentException(
-                        "Expected syntax jbi:endpoint:[serviceNamespace][sep][serviceName][sep][endpointName] " 
-                        + "or jbi:service:[serviceNamespace][sep][serviceName or jbi:name:[endpointName] but was given: "
-                                + endpointUri);
-            }
-            jbiEndpoint = new CamelProviderEndpoint(getServiceUnit(), service, endpoint, camelEndpoint, getBinding(), processor);
-        } else {
-            jbiEndpoint = new CamelProviderEndpoint(getServiceUnit(), camelEndpoint, getBinding(), processor);
-        }
-        return jbiEndpoint;
-    }
-
-    protected String createEndpointName() {
-        if (idGenerator == null) {
-            idGenerator = new IdGenerator("camel");
-        }
-        return idGenerator.generateSanitizedId();
-    }
-
-    /**
-     * Returns a JBI endpoint created for the given Camel endpoint
-     */
-    public CamelProviderEndpoint createJbiEndpointFromCamel(Endpoint camelEndpoint) {
-        Processor processor = createCamelProcessor(camelEndpoint);
-        return createJbiEndpointFromCamel(camelEndpoint, processor);
-    }
-
-    protected Processor createCamelProcessor(Endpoint camelEndpoint) {
-        Processor processor = null;
-        try {
-            processor = camelEndpoint.createProducer();
-        } catch (Exception e) {
-            throw new FailedToCreateProducerException(camelEndpoint, e);
-        }
-        return processor;
-    }
 
     /**
      * Should we expose the Camel JBI onto the NMR. <p/> We may wish to add some
      * policy stuff etc.
-     * 
+     *
      * @param endpoint
      *            the camel endpoint
      * @return true if the endpoint should be exposed in the NMR

Modified: servicemix/components/engines/servicemix-camel/trunk/src/main/java/org/apache/servicemix/camel/CamelProviderEndpoint.java
URL: http://svn.apache.org/viewvc/servicemix/components/engines/servicemix-camel/trunk/src/main/java/org/apache/servicemix/camel/CamelProviderEndpoint.java?rev=745769&r1=745768&r2=745769&view=diff
==============================================================================
--- servicemix/components/engines/servicemix-camel/trunk/src/main/java/org/apache/servicemix/camel/CamelProviderEndpoint.java (original)
+++ servicemix/components/engines/servicemix-camel/trunk/src/main/java/org/apache/servicemix/camel/CamelProviderEndpoint.java Thu Feb 19 07:49:23 2009
@@ -134,7 +134,7 @@
                     }
                 }
             }
-        // This is not compliant with the default MEPs
+        // This is not complaint with the default MEPs
         } else {
             throw new IllegalStateException("Provider exchange is ACTIVE, but no in or fault is provided");
         }

Modified: servicemix/components/engines/servicemix-camel/trunk/src/main/java/org/apache/servicemix/camel/CamelSpringDeployer.java
URL: http://svn.apache.org/viewvc/servicemix/components/engines/servicemix-camel/trunk/src/main/java/org/apache/servicemix/camel/CamelSpringDeployer.java?rev=745769&r1=745768&r2=745769&view=diff
==============================================================================
--- servicemix/components/engines/servicemix-camel/trunk/src/main/java/org/apache/servicemix/camel/CamelSpringDeployer.java (original)
+++ servicemix/components/engines/servicemix-camel/trunk/src/main/java/org/apache/servicemix/camel/CamelSpringDeployer.java Thu Feb 19 07:49:23 2009
@@ -53,6 +53,12 @@
         return "camel-context";
     }
 
+    public void undeploy(ServiceUnit su) throws DeploymentException {
+        // Remove the jbiComponent form CamelJbiComponent
+        component.removeJbiComponent(su.getName());
+        super.undeploy(su);
+    }
+
     /*
      * (non-Javadoc)
      *
@@ -69,7 +75,7 @@
 
         // lets install the context class loader
         ServiceUnit serviceUnit = super.deploy(suName, serviceUnitRootPath);
-//        Thread.currentThread().setContextClassLoader(serviceUnit.getConfigurationClassLoader());
+        // Thread.currentThread().setContextClassLoader(serviceUnit.getConfigurationClassLoader());
         return serviceUnit;
     }
 
@@ -85,27 +91,34 @@
 
         SpringCamelContext camelContext = SpringCamelContext.springCamelContext(applicationContext);
 
+        JbiComponent jbiComponent = camelContext.getComponent("jbi", JbiComponent.class);
         // now lets iterate through all the endpoints
         Collection<Endpoint> endpoints = camelContext.getSingletonEndpoints();
 
-        for (Endpoint endpoint : endpoints) {
-            if (component.isEndpointExposedOnNmr(endpoint)) {
-                services.add(component.createJbiEndpointFromCamel(endpoint));
+        if (jbiComponent != null) {
+            // set the SU Name
+            jbiComponent.setSuName(serviceUnitName);
+            for (Endpoint endpoint : endpoints) {
+                if (component.isEndpointExposedOnNmr(endpoint)) {
+                    services.add(jbiComponent.createJbiEndpointFromCamel(endpoint));
+                }
             }
+            // lets add a control bus endpoint to ensure we have at least one endpoint to deploy
+            BeanComponent beanComponent = camelContext.getComponent("bean", BeanComponent.class);
+            Endpoint endpoint = beanComponent.createEndpoint(new CamelControlBus(camelContext),
+                                                             "camel:" + serviceUnitName + "-controlBus");
+            services.add(jbiComponent.createJbiEndpointFromCamel(endpoint));
         }
 
-        // lets add a control bus endpoint to ensure we have at least one endpoint to deploy
-        BeanComponent beanComponent = camelContext.getComponent("bean", BeanComponent.class);
-        Endpoint endpoint = beanComponent.createEndpoint(new CamelControlBus(camelContext),
-                                                         "camel:" + serviceUnitName + "-controlBus");
-        services.add(component.createJbiEndpointFromCamel(endpoint));
+
 
         return services;
     }
 
     protected Map getParentBeansMap() {
         Map beans =  super.getParentBeansMap();
-        beans.put("jbi", component);
+        beans.put("servicemix-camel", component);
+        beans.put("jbi", new JbiComponent(component));
         return beans;
     }
 

Added: 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=745769&view=auto
==============================================================================
--- servicemix/components/engines/servicemix-camel/trunk/src/main/java/org/apache/servicemix/camel/JbiComponent.java (added)
+++ servicemix/components/engines/servicemix-camel/trunk/src/main/java/org/apache/servicemix/camel/JbiComponent.java Thu Feb 19 07:49:23 2009
@@ -0,0 +1,174 @@
+/*
+ * 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 javax.xml.namespace.QName;
+
+import org.apache.camel.CamelContext;
+import org.apache.camel.Component;
+import org.apache.camel.Endpoint;
+import org.apache.camel.Exchange;
+import org.apache.camel.FailedToCreateProducerException;
+import org.apache.camel.Processor;
+import org.apache.servicemix.common.util.URIResolver;
+import org.apache.servicemix.id.IdGenerator;
+
+public class JbiComponent implements Component<Exchange> {
+    private final CamelJbiComponent camelJbiComponent;
+    private JbiBinding binding;
+    private CamelContext camelContext;
+    private IdGenerator idGenerator;
+    private String suName;
+
+    public JbiComponent(CamelJbiComponent component) {
+        camelJbiComponent = component;
+        camelJbiComponent.addJbiComponent(this);
+    }
+
+    public CamelContext getCamelContext() {
+        return camelContext;
+    }
+
+    public void setCamelContext(CamelContext context) {
+        camelContext = context;
+    }
+
+    public CamelJbiComponent getCamelJbiComponent() {
+        return camelJbiComponent;
+    }
+
+    public void setSuName(String su) {
+        suName = su;
+    }
+
+    public String getSuName() {
+        return suName;
+    }
+
+    /**
+     * @return the binding
+     */
+    public JbiBinding getBinding() {
+        if (binding == null) {
+            binding = new JbiBinding();
+        }
+        return binding;
+    }
+
+    /**
+     * @param binding
+     *            the binding to set
+     */
+    public void setBinding(JbiBinding binding) {
+        this.binding = binding;
+    }
+
+    // Resolve Camel Endpoints
+    // -------------------------------------------------------------------------
+    public Endpoint<Exchange> createEndpoint(String uri) {
+        if (uri.startsWith("jbi:")) {
+            uri = uri.substring("jbi:".length());
+            return new JbiEndpoint(this, uri);
+        }
+        return null;
+    }
+
+
+    protected CamelProviderEndpoint createJbiEndpointFromCamel(
+            Endpoint camelEndpoint, Processor processor) {
+        CamelProviderEndpoint jbiEndpoint;
+        String endpointUri = camelEndpoint.getEndpointUri();
+        if (camelEndpoint instanceof JbiEndpoint) {
+            QName service = null;
+            String endpoint = null;
+            if (endpointUri.startsWith("name:")) {
+                endpoint = endpointUri.substring("name:".length());
+                service = CamelProviderEndpoint.SERVICE_NAME;
+            } else if (endpointUri.startsWith("endpoint:")) {
+                String uri = endpointUri.substring("endpoint:".length());
+                // lets decode "serviceNamespace sep serviceName sep
+                // endpointName
+                String[] parts;
+                try {
+                    parts = URIResolver.split3(uri);
+                } catch (IllegalArgumentException e) {
+                    throw new IllegalArgumentException(
+                            "Expected syntax jbi:endpoint:[serviceNamespace][sep][serviceName][sep][endpointName] "
+                                    + "where sep = '/' or ':' depending on the serviceNamespace, but was given: "
+                                    + endpointUri + ". Cause: " + e, e);
+                }
+                service = new QName(parts[0], parts[1]);
+                endpoint = parts[2];
+            } else if (endpointUri.startsWith("service:")) {
+                String uri = endpointUri.substring("service:".length());
+                // lets decode "serviceNamespace sep serviceName
+                String[] parts;
+                try {
+                    parts = URIResolver.split2(uri);
+                } catch (IllegalArgumentException e) {
+                    throw new IllegalArgumentException(
+                            "Expected syntax jbi:endpoint:[serviceNamespace][sep][serviceName] "
+                                    + "where sep = '/' or ':' depending on the serviceNamespace, but was given: "
+                                    + endpointUri + ". Cause: " + e, e);
+                }
+                service = new QName(parts[0], parts[1]);
+                endpoint = createEndpointName();
+            } else {
+                throw new IllegalArgumentException(
+                        "Expected syntax jbi:endpoint:[serviceNamespace][sep][serviceName][sep][endpointName] "
+                                + "or jbi:service:[serviceNamespace][sep][serviceName or jbi:name:[endpointName] but was given: "
+                                + endpointUri);
+            }
+            jbiEndpoint = new CamelProviderEndpoint(getCamelJbiComponent()
+                    .getServiceUnit(), service, endpoint, camelEndpoint,
+                    getBinding(), processor);
+        } else {
+            jbiEndpoint = new CamelProviderEndpoint(getCamelJbiComponent()
+                    .getServiceUnit(), camelEndpoint, getBinding(), processor);
+        }
+        return jbiEndpoint;
+    }
+
+     protected String createEndpointName() {
+            if (idGenerator == null) {
+                idGenerator = new IdGenerator("camel");
+            }
+            return idGenerator.generateSanitizedId();
+        }
+
+    /**
+     * Returns a JBI endpoint created for the given Camel endpoint
+     */
+    public CamelProviderEndpoint createJbiEndpointFromCamel(
+            Endpoint camelEndpoint) {
+        Processor processor = createCamelProcessor(camelEndpoint);
+        return createJbiEndpointFromCamel(camelEndpoint, processor);
+    }
+
+    protected Processor createCamelProcessor(Endpoint camelEndpoint) {
+        Processor processor = null;
+        try {
+            processor = camelEndpoint.createProducer();
+        } catch (Exception e) {
+            throw new FailedToCreateProducerException(camelEndpoint, e);
+        }
+        return processor;
+    }
+
+
+
+}

Propchange: servicemix/components/engines/servicemix-camel/trunk/src/main/java/org/apache/servicemix/camel/JbiComponent.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: servicemix/components/engines/servicemix-camel/trunk/src/main/java/org/apache/servicemix/camel/JbiComponent.java
------------------------------------------------------------------------------
    svn:keywords = Rev Date

Modified: servicemix/components/engines/servicemix-camel/trunk/src/main/java/org/apache/servicemix/camel/JbiEndpoint.java
URL: http://svn.apache.org/viewvc/servicemix/components/engines/servicemix-camel/trunk/src/main/java/org/apache/servicemix/camel/JbiEndpoint.java?rev=745769&r1=745768&r2=745769&view=diff
==============================================================================
--- servicemix/components/engines/servicemix-camel/trunk/src/main/java/org/apache/servicemix/camel/JbiEndpoint.java (original)
+++ servicemix/components/engines/servicemix-camel/trunk/src/main/java/org/apache/servicemix/camel/JbiEndpoint.java Thu Feb 19 07:49:23 2009
@@ -48,9 +48,9 @@
 
     private JbiProducer producer;
 
-    private final CamelJbiComponent jbiComponent;
+    private final JbiComponent jbiComponent;
 
-    public JbiEndpoint(CamelJbiComponent jbiComponent, String uri) {
+    public JbiEndpoint(JbiComponent jbiComponent, String uri) {
         super(uri, jbiComponent);
         this.jbiComponent = jbiComponent;
         parseUri(uri);
@@ -76,7 +76,7 @@
         @Override
         public void start() throws Exception {
             consumer = new CamelConsumerEndpoint(jbiComponent.getBinding(), JbiEndpoint.this);
-            jbiComponent.addEndpoint(consumer);
+            jbiComponent.getCamelJbiComponent().addEndpoint(consumer);
             super.start();
         }
         @Override
@@ -85,7 +85,7 @@
                 log.debug("Camel producer for " + super.getEndpoint() + " has already been stopped");
             } else {
                 log.debug("Stopping Camel producer for " + super.getEndpoint());
-                jbiComponent.removeEndpoint(consumer);
+                jbiComponent.getCamelJbiComponent().removeEndpoint(consumer);
                 super.stop();
             }
         }
@@ -148,13 +148,14 @@
             @Override
             protected void doStart() throws Exception {
                 super.doStart();
-                jbiEndpoint = jbiComponent.activateJbiEndpoint(JbiEndpoint.this, processor);
+                jbiEndpoint = jbiComponent.createJbiEndpointFromCamel(JbiEndpoint.this, processor);
+                jbiComponent.getCamelJbiComponent().activateJbiEndpoint(jbiEndpoint);
             }
 
             @Override
             protected void doStop() throws Exception {
                 if (jbiEndpoint != null) {
-                    jbiComponent.deactivateJbiEndpoint(jbiEndpoint);
+                    jbiComponent.getCamelJbiComponent().deactivateJbiEndpoint(jbiEndpoint);
                 }
                 super.doStop();
             }

Modified: servicemix/components/engines/servicemix-camel/trunk/src/main/java/org/apache/servicemix/camel/JbiException.java
URL: http://svn.apache.org/viewvc/servicemix/components/engines/servicemix-camel/trunk/src/main/java/org/apache/servicemix/camel/JbiException.java?rev=745769&r1=745768&r2=745769&view=diff
==============================================================================
--- servicemix/components/engines/servicemix-camel/trunk/src/main/java/org/apache/servicemix/camel/JbiException.java (original)
+++ servicemix/components/engines/servicemix-camel/trunk/src/main/java/org/apache/servicemix/camel/JbiException.java Thu Feb 19 07:49:23 2009
@@ -22,6 +22,9 @@
  * @version $Revision: 563665 $
  */
 public class JbiException extends RuntimeCamelException {
+
+    private static final long serialVersionUID = -939254443652090476L;
+
     public JbiException(Throwable cause) {
         super(cause);
     }

Modified: servicemix/components/engines/servicemix-camel/trunk/src/test/java/org/apache/servicemix/camel/JbiEndpointWithMepSpecifiedTest.java
URL: http://svn.apache.org/viewvc/servicemix/components/engines/servicemix-camel/trunk/src/test/java/org/apache/servicemix/camel/JbiEndpointWithMepSpecifiedTest.java?rev=745769&r1=745768&r2=745769&view=diff
==============================================================================
--- servicemix/components/engines/servicemix-camel/trunk/src/test/java/org/apache/servicemix/camel/JbiEndpointWithMepSpecifiedTest.java (original)
+++ servicemix/components/engines/servicemix-camel/trunk/src/test/java/org/apache/servicemix/camel/JbiEndpointWithMepSpecifiedTest.java Thu Feb 19 07:49:23 2009
@@ -52,7 +52,7 @@
             }
             
         });
-        assertEquals(1, component.count);
+        assertEquals(1, component.getCount());
     }
 
     @Override
@@ -78,6 +78,10 @@
         
         private int count;
         
+        public int getCount() {
+        	return count;
+        }
+        
         @Override
         public void onMessageExchange(MessageExchange exchange) throws MessagingException {
             if (exchange instanceof InOnly) {

Modified: servicemix/components/engines/servicemix-camel/trunk/src/test/java/org/apache/servicemix/camel/JbiTestSupport.java
URL: http://svn.apache.org/viewvc/servicemix/components/engines/servicemix-camel/trunk/src/test/java/org/apache/servicemix/camel/JbiTestSupport.java?rev=745769&r1=745768&r2=745769&view=diff
==============================================================================
--- servicemix/components/engines/servicemix-camel/trunk/src/test/java/org/apache/servicemix/camel/JbiTestSupport.java (original)
+++ servicemix/components/engines/servicemix-camel/trunk/src/test/java/org/apache/servicemix/camel/JbiTestSupport.java Thu Feb 19 07:49:23 2009
@@ -47,7 +47,7 @@
  * @version $Revision: 563665 $
  */
 public abstract class JbiTestSupport extends TestSupport {
-    
+
     protected Exchange receivedExchange;
 
     protected CamelContext camelContext = new DefaultCamelContext();
@@ -63,7 +63,7 @@
     protected String startEndpointUri = "jbi:endpoint:serviceNamespace:serviceA:endpointA";
 
     protected ProducerTemplate<Exchange> client = camelContext.createProducerTemplate();
-    
+
     protected ServiceMixClient servicemixClient;
 
     /**
@@ -117,7 +117,7 @@
     protected void setUp() throws Exception {
         configureContainer(jbiContainer);
         List<ActivationSpec> activationSpecList = new ArrayList<ActivationSpec>();
-        
+
         // lets add the Camel endpoint
         CamelJbiComponent component = new CamelJbiComponent();
         activationSpecList.add(createActivationSpec(component, new QName("camel", "camel"), "camelEndpoint"));
@@ -125,15 +125,15 @@
         // and provide a callback method for adding more services
         appendJbiActivationSpecs(activationSpecList);
         jbiContainer.setActivationSpecs(activationSpecList.toArray(new ActivationSpec[activationSpecList.size()]));
-        
+
         jbiContainer.afterPropertiesSet();
-        
+
         exchangeCompletedListener = new ExchangeCompletedListener();
         jbiContainer.addListener(exchangeCompletedListener);
 
         // allow for additional configuration of the compenent (e.g. deploying SU)
         configureComponent(component);
-        
+
         // lets add some routes
         RouteBuilder builder = createRoutes();
         if (builder != null) {
@@ -146,24 +146,24 @@
 
     protected void configureComponent(CamelJbiComponent component) throws Exception {
         // add the ServiceMix Camel component to the CamelContext
-        camelContext.addComponent("jbi", component);
+        camelContext.addComponent("jbi", new JbiComponent(component));
     }
 
     protected void configureContainer(final JBIContainer container) throws Exception {
         container.setEmbedded(true);
     }
-    
+
     public ServiceMixClient getServicemixClient() throws JBIException {
         if (servicemixClient == null) {
             servicemixClient = new DefaultServiceMixClient(jbiContainer);
         }
         return servicemixClient;
     }
-    
+
     protected ActivationSpec createActivationSpec(Object component, QName service) {
         return createActivationSpec(component, service, "endpoint");
     }
-    
+
     protected ActivationSpec createActivationSpec(Object component, QName service, String endpoint) {
         ActivationSpec spec = new ActivationSpec(component);
         spec.setService(service);
@@ -178,7 +178,7 @@
         camelContext.stop();
         super.tearDown();
     }
-    
+
     protected MockEndpoint getMockEndpoint(String uri) {
         return (MockEndpoint)camelContext.getEndpoint(uri);
     }

Modified: servicemix/components/engines/servicemix-camel/trunk/src/test/java/org/apache/servicemix/camel/SendFromCamelToJbiAndBackToCamelTest.java
URL: http://svn.apache.org/viewvc/servicemix/components/engines/servicemix-camel/trunk/src/test/java/org/apache/servicemix/camel/SendFromCamelToJbiAndBackToCamelTest.java?rev=745769&r1=745768&r2=745769&view=diff
==============================================================================
--- servicemix/components/engines/servicemix-camel/trunk/src/test/java/org/apache/servicemix/camel/SendFromCamelToJbiAndBackToCamelTest.java (original)
+++ servicemix/components/engines/servicemix-camel/trunk/src/test/java/org/apache/servicemix/camel/SendFromCamelToJbiAndBackToCamelTest.java Thu Feb 19 07:49:23 2009
@@ -62,6 +62,13 @@
         };
     }
 
+    protected void configureComponent(CamelJbiComponent component) throws Exception {
+        // add the ServiceMix Camel component to the CamelContext
+        JbiComponent jbiComponent = new JbiComponent(component);
+        jbiComponent.setSuName("su_test");
+        camelContext.addComponent("jbi", jbiComponent);
+    }
+
     @Override
     protected void appendJbiActivationSpecs(
             List<ActivationSpec> activationSpecList) {
@@ -73,7 +80,7 @@
         activationSpec.setEndpoint("endpointA");
 
         // lets setup the sender to talk directly to camel
-        senderComponent.setResolver(new URIResolver("camel:seda:receiver"));
+        senderComponent.setResolver(new URIResolver("camel:su_test:seda:receiver"));
         activationSpec.setComponent(senderComponent);
 
         activationSpecList.add(activationSpec);

Modified: servicemix/components/engines/servicemix-camel/trunk/src/test/java/org/apache/servicemix/camel/TwoServicemixCamelSusTest.java
URL: http://svn.apache.org/viewvc/servicemix/components/engines/servicemix-camel/trunk/src/test/java/org/apache/servicemix/camel/TwoServicemixCamelSusTest.java?rev=745769&r1=745768&r2=745769&view=diff
==============================================================================
--- servicemix/components/engines/servicemix-camel/trunk/src/test/java/org/apache/servicemix/camel/TwoServicemixCamelSusTest.java (original)
+++ servicemix/components/engines/servicemix-camel/trunk/src/test/java/org/apache/servicemix/camel/TwoServicemixCamelSusTest.java Thu Feb 19 07:49:23 2009
@@ -25,57 +25,61 @@
 import org.apache.commons.logging.LogFactory;
 
 public class TwoServicemixCamelSusTest extends
-		NonJbiCamelEndpointsIntegrationTest {
-	private static final transient Log LOG = LogFactory
-			.getLog(TwoServicemixCamelSusTest.class);
-
-	private void deploySu(CamelJbiComponent component, String suName)
-			throws Exception {
-		String serviceUnitConfiguration = suName + "-src/camel-context.xml";
-		URL url = getClass().getResource(serviceUnitConfiguration);
-		File path = new File(new URI(url.toString()));
-		path = path.getParentFile();
-
-		// Deploy and start su
-		component.getServiceUnitManager()
-				.deploy(suName, path.getAbsolutePath());
-		component.getServiceUnitManager().init(suName, path.getAbsolutePath());
-		component.getServiceUnitManager().start(suName);
-	}
-
-	private void undeploySu(CamelJbiComponent component, String suName)
-			throws Exception {
-		String serviceUnitConfiguration = suName + "-src/camel-context.xml";
-		URL url = getClass().getResource(serviceUnitConfiguration);
-		File path = new File(new URI(url.toString()));
-		path = path.getParentFile();
-
-		// Stop and undeploy
-		component.getServiceUnitManager().stop(suName);
-		component.getServiceUnitManager().shutDown(suName);
-		component.getServiceUnitManager().undeploy(suName,
-				path.getAbsolutePath());
-	}
-
-	public void testComponentInstallation() throws Exception {
-
-		CamelJbiComponent component = new CamelJbiComponent();
-		container.activateComponent(component, "#ServiceMixComponent#");
-
-		// deploy two sus here
-		deploySu(component, "su3");
-		CamelContext su3CamelContext = component.getCamelContext();
-		assertNotNull("We should get a camel context here ", su3CamelContext);
-		deploySu(component, "su6");
-		CamelContext su6CamelContext = component.getCamelContext();
-		assertNotNull("We should get a camel context here ", su6CamelContext);
-		assertTrue("Here should be two different camel contexts",
-				!su3CamelContext.equals(su6CamelContext));
-
-		// deploy two sus here
-		undeploySu(component, "su3");
-		undeploySu(component, "su6");
+        NonJbiCamelEndpointsIntegrationTest {
+    private static final transient Log LOG = LogFactory
+            .getLog(TwoServicemixCamelSusTest.class);
+
+    private void deploySu(CamelJbiComponent component, String suName)
+            throws Exception {
+        String serviceUnitConfiguration = suName + "-src/camel-context.xml";
+        URL url = getClass().getResource(serviceUnitConfiguration);
+        File path = new File(new URI(url.toString()));
+        path = path.getParentFile();
+
+        // Deploy and start su
+        component.getServiceUnitManager()
+                .deploy(suName, path.getAbsolutePath());
+        component.getServiceUnitManager().init(suName, path.getAbsolutePath());
+        component.getServiceUnitManager().start(suName);
+    }
+
+    private void undeploySu(CamelJbiComponent component, String suName)
+            throws Exception {
+        String serviceUnitConfiguration = suName + "-src/camel-context.xml";
+        URL url = getClass().getResource(serviceUnitConfiguration);
+        File path = new File(new URI(url.toString()));
+        path = path.getParentFile();
+
+        // Stop and undeploy
+        component.getServiceUnitManager().stop(suName);
+        component.getServiceUnitManager().shutDown(suName);
+        component.getServiceUnitManager().undeploy(suName,
+                path.getAbsolutePath());
+    }
+
+    public void testComponentInstallation() throws Exception {
+
+        CamelJbiComponent component = new CamelJbiComponent();
+        container.activateComponent(component, "#ServiceMixComponent#");
+
+        // deploy two sus here
+        deploySu(component, "su3");
+        JbiComponent jbiComponent = component.getJbiComponent("su3");
+        assertNotNull("JbiComponent should not be null ", jbiComponent);
+        CamelContext su3CamelContext = jbiComponent.getCamelContext();
+        assertNotNull("We should get a camel context here ", su3CamelContext);
+        deploySu(component, "su6");
+        jbiComponent = component.getJbiComponent("su6");
+        assertNotNull("JbiComponent should not be null ", jbiComponent);
+        CamelContext su6CamelContext = jbiComponent.getCamelContext();
+        assertNotNull("We should get a camel context here ", su6CamelContext);
+        assertTrue("Here should be two different camel contexts",
+                !su3CamelContext.equals(su6CamelContext));
+
+        // deploy two sus here
+        undeploySu(component, "su3");
+        undeploySu(component, "su6");
 
-	}
+    }
 
 }