activemq-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From jstrac...@apache.org
Subject svn commit: r521846 - in /activemq/camel/trunk: camel-core/src/main/java/org/apache/camel/impl/ camel-jbi/src/main/java/org/apache/camel/component/jbi/ camel-jbi/src/test/java/org/apache/camel/component/jbi/
Date Fri, 23 Mar 2007 18:22:40 GMT
Author: jstrachan
Date: Fri Mar 23 11:22:39 2007
New Revision: 521846

URL: http://svn.apache.org/viewvc?view=rev&rev=521846
Log:
more tinkering on the JBI test case

Modified:
    activemq/camel/trunk/camel-core/src/main/java/org/apache/camel/impl/DefaultCamelContext.java
    activemq/camel/trunk/camel-jbi/src/main/java/org/apache/camel/component/jbi/JbiBinding.java
    activemq/camel/trunk/camel-jbi/src/test/java/org/apache/camel/component/jbi/JbiTest.java

Modified: activemq/camel/trunk/camel-core/src/main/java/org/apache/camel/impl/DefaultCamelContext.java
URL: http://svn.apache.org/viewvc/activemq/camel/trunk/camel-core/src/main/java/org/apache/camel/impl/DefaultCamelContext.java?view=diff&rev=521846&r1=521845&r2=521846
==============================================================================
--- activemq/camel/trunk/camel-core/src/main/java/org/apache/camel/impl/DefaultCamelContext.java
(original)
+++ activemq/camel/trunk/camel-core/src/main/java/org/apache/camel/impl/DefaultCamelContext.java
Fri Mar 23 11:22:39 2007
@@ -21,11 +21,12 @@
 import org.apache.camel.builder.RouteBuilder;
 
 import java.util.ArrayList;
+import java.util.Collection;
 import java.util.HashMap;
 import java.util.List;
 import java.util.Map;
-import java.util.Collection;
 import java.util.concurrent.Callable;
+import java.util.concurrent.CopyOnWriteArrayList;
 
 /**
  * Represents the context used to configure routes and the policies to use.
@@ -36,6 +37,7 @@
 public class DefaultCamelContext implements CamelContext {
     private Map<String, Endpoint> endpoints = new HashMap<String, Endpoint>();
     private Map<String, Component> components = new HashMap<String, Component>();
+    private List<EndpointResolver> resolvers = new CopyOnWriteArrayList<EndpointResolver>();
     private List<Route> routes;
     private TypeConverter typeConverter;
     private EndpointResolver endpointResolver;
@@ -51,6 +53,9 @@
             }
             component.setContext(this);
             components.put(componentName, component);
+            if (component instanceof EndpointResolver) {
+                resolvers.add((EndpointResolver) component);
+            }
         }
     }
 
@@ -116,15 +121,37 @@
         Endpoint answer;
         synchronized (endpoints) {
             answer = endpoints.get(uri);
-        }
-        if (answer == null) {
-            EndpointResolver er = getEndpointResolver();
-            try {
-                answer = er.resolveEndpoint(this, uri);
-            }
-            catch (Exception e) {
-                throw new ResolveEndpointFailedException(uri, e);
+            if (answer == null) {
+                try {
+                    for (EndpointResolver resolver : resolvers) {
+                        answer = resolver.resolveEndpoint(this, uri);
+                        if (answer != null) {
+                            break;
+                        }
+                    }
+                    if (answer == null) {
+                        EndpointResolver er = getEndpointResolver();
+                        answer = er.resolveEndpoint(this, uri);
+                    }
+                    if (answer != null) {
+                        endpoints.put(uri, answer);
+                    }
+                }
+                catch (Exception e) {
+                    throw new ResolveEndpointFailedException(uri, e);
+                }
             }
+        }
+        return answer;
+    }
+
+    /**
+     * Looks up the current active endpoint by URI without auto-creating it.
+     */
+    public Endpoint getEndpoint(String uri) {
+        Endpoint answer;
+        synchronized (endpoints) {
+            answer = endpoints.get(uri);
         }
         return answer;
     }

Modified: activemq/camel/trunk/camel-jbi/src/main/java/org/apache/camel/component/jbi/JbiBinding.java
URL: http://svn.apache.org/viewvc/activemq/camel/trunk/camel-jbi/src/main/java/org/apache/camel/component/jbi/JbiBinding.java?view=diff&rev=521846&r1=521845&r2=521846
==============================================================================
--- activemq/camel/trunk/camel-jbi/src/main/java/org/apache/camel/component/jbi/JbiBinding.java
(original)
+++ activemq/camel/trunk/camel-jbi/src/main/java/org/apache/camel/component/jbi/JbiBinding.java
Fri Mar 23 11:22:39 2007
@@ -25,8 +25,10 @@
 import javax.jbi.messaging.NormalizedMessage;
 import javax.jbi.messaging.MessageExchangeFactory;
 import javax.xml.transform.Source;
+import javax.xml.transform.stream.StreamSource;
 import java.util.Map;
 import java.util.Set;
+import java.io.StringReader;
 
 /**
  * The binding of how Camel messages get mapped to JBI and back again
@@ -57,6 +59,10 @@
     public MessageExchange makeJbiMessageExchange(Exchange camelExchange, MessageExchangeFactory
exchangeFactory) throws MessagingException {
         MessageExchange jbiExchange = createJbiMessageExchange(camelExchange, exchangeFactory);
         NormalizedMessage normalizedMessage = jbiExchange.getMessage("in");
+        if (normalizedMessage == null) {
+            normalizedMessage = jbiExchange.createMessage();
+            jbiExchange.setMessage(normalizedMessage, "in");
+        }
         normalizedMessage.setContent(getJbiInContent(camelExchange));
         addJbiHeaders(jbiExchange, normalizedMessage, camelExchange);
         return jbiExchange;
@@ -73,6 +79,11 @@
     }
 
     protected Source getJbiInContent(Exchange camelExchange) {
+        // TODO this should be more smart
+        Object value = camelExchange.getIn().getBody();
+        if (value instanceof String) {
+            return new StreamSource(new StringReader(value.toString()));
+        }
         return camelExchange.getIn().getBody(Source.class);
     }
 

Modified: activemq/camel/trunk/camel-jbi/src/test/java/org/apache/camel/component/jbi/JbiTest.java
URL: http://svn.apache.org/viewvc/activemq/camel/trunk/camel-jbi/src/test/java/org/apache/camel/component/jbi/JbiTest.java?view=diff&rev=521846&r1=521845&r2=521846
==============================================================================
--- activemq/camel/trunk/camel-jbi/src/test/java/org/apache/camel/component/jbi/JbiTest.java
(original)
+++ activemq/camel/trunk/camel-jbi/src/test/java/org/apache/camel/component/jbi/JbiTest.java
Fri Mar 23 11:22:39 2007
@@ -20,6 +20,7 @@
 import junit.framework.TestCase;
 import org.apache.servicemix.jbi.container.JBIContainer;
 import org.apache.servicemix.jbi.container.ActivationSpec;
+import org.apache.servicemix.jbi.container.SpringJBIContainer;
 import org.apache.commons.logging.Log;
 import org.apache.commons.logging.LogFactory;
 import org.apache.camel.CamelContext;
@@ -46,7 +47,7 @@
 
     protected Exchange receivedExchange;
     protected CamelContext camelContext = new DefaultCamelContext();
-    protected JBIContainer jbiContainer = new JBIContainer();
+    protected SpringJBIContainer jbiContainer = new SpringJBIContainer();
     protected CountDownLatch latch = new CountDownLatch(1);
     protected Endpoint<Exchange> endpoint;
 
@@ -78,13 +79,32 @@
         jbiContainer.setEmbedded(true);
 
         CamelJbiComponent component = new CamelJbiComponent();
+
+        /*
+
+        <bean class="org.apache.servicemix.jbi.container.ActivationSpec">
+          <property name="id" value="receiver"/>
+          <property name="service" ref="receiverServiceName"/>
+          <property name="endpoint" value="receiver"/>
+          <!-- no need to specify service on this POJO as it is hard coded -->
+          <property name="component">
+            <bean class="org.apache.servicemix.tck.ReceiverComponent"/>
+          </property>
+        </bean>
+
+         */
         ActivationSpec activationSpec = new ActivationSpec();
-        activationSpec.setComponentName("camel");
+        activationSpec.setId("camel");
         activationSpec.setService(new QName("camel"));
-        activationSpec.setComponent(component);
         activationSpec.setEndpoint("camelEndpoint");
-        activationSpec.setId("camel");
-        jbiContainer.activateComponent(component, activationSpec);
+        activationSpec.setComponent(component);
+
+        //activationSpec.setComponentName("camel");
+
+        jbiContainer.setActivationSpecs(new ActivationSpec[] {activationSpec});
+        jbiContainer.afterPropertiesSet();
+
+        //jbiContainer.activateComponent(component, "camel");
 
         // lets configure some componnets
         camelContext.addComponent("jbi", component);
@@ -92,8 +112,8 @@
         // lets add some routes
         camelContext.setRoutes(new RouteBuilder() {
             public void configure() {
-                from("jbi:service:test.a").to("jbi:service:test.b");
-                from("jbi:service:test.b").process(new Processor<Exchange>() {
+                from("jbi:service:test:a").to("jbi:service:test:b");
+                from("jbi:service:test:b").process(new Processor<Exchange>() {
                     public void onExchange(Exchange e) {
                         System.out.println("Received exchange: " + e.getIn());
                         receivedExchange = e;
@@ -102,7 +122,7 @@
                 });
             }
         });
-        endpoint = camelContext.resolveEndpoint("jbi:service:test.a");
+        endpoint = camelContext.resolveEndpoint("jbi:service:test:a");
         assertNotNull("No endpoint found!", endpoint);
 
         camelContext.activateEndpoints();



Mime
View raw message