servicemix-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From gno...@apache.org
Subject svn commit: r572700 - in /incubator/servicemix/trunk/deployables/serviceengines/servicemix-camel: ./ src/main/java/org/apache/servicemix/camel/ src/test/java/org/apache/servicemix/camel/ src/test/resources/org/apache/servicemix/camel/su5-src/
Date Tue, 04 Sep 2007 14:57:48 GMT
Author: gnodet
Date: Tue Sep  4 07:57:46 2007
New Revision: 572700

URL: http://svn.apache.org/viewvc?rev=572700&view=rev
Log:
Improve camel support for InOut

Added:
    incubator/servicemix/trunk/deployables/serviceengines/servicemix-camel/src/test/java/org/apache/servicemix/camel/JbiInOutTest.java
    incubator/servicemix/trunk/deployables/serviceengines/servicemix-camel/src/test/java/org/apache/servicemix/camel/TestCamelRouter.java
      - copied, changed from r570705, incubator/servicemix/trunk/deployables/serviceengines/servicemix-camel/src/test/java/org/apache/servicemix/camel/SendFromCamelToJbiTest.java
    incubator/servicemix/trunk/deployables/serviceengines/servicemix-camel/src/test/resources/org/apache/servicemix/camel/su5-src/
    incubator/servicemix/trunk/deployables/serviceengines/servicemix-camel/src/test/resources/org/apache/servicemix/camel/su5-src/camel-context.xml
Removed:
    incubator/servicemix/trunk/deployables/serviceengines/servicemix-camel/src/main/java/org/apache/servicemix/camel/FromJbiProcessor.java
    incubator/servicemix/trunk/deployables/serviceengines/servicemix-camel/src/main/java/org/apache/servicemix/camel/MEPConstants.java
Modified:
    incubator/servicemix/trunk/deployables/serviceengines/servicemix-camel/pom.xml
    incubator/servicemix/trunk/deployables/serviceengines/servicemix-camel/src/main/java/org/apache/servicemix/camel/CamelJbiEndpoint.java
    incubator/servicemix/trunk/deployables/serviceengines/servicemix-camel/src/main/java/org/apache/servicemix/camel/JbiBinding.java
    incubator/servicemix/trunk/deployables/serviceengines/servicemix-camel/src/main/java/org/apache/servicemix/camel/JbiExchange.java
    incubator/servicemix/trunk/deployables/serviceengines/servicemix-camel/src/main/java/org/apache/servicemix/camel/JbiMessage.java
    incubator/servicemix/trunk/deployables/serviceengines/servicemix-camel/src/main/java/org/apache/servicemix/camel/ToJbiProcessor.java
    incubator/servicemix/trunk/deployables/serviceengines/servicemix-camel/src/test/java/org/apache/servicemix/camel/NonJbiCamelEndpointsIntegrationTest.java
    incubator/servicemix/trunk/deployables/serviceengines/servicemix-camel/src/test/java/org/apache/servicemix/camel/SendFromCamelToJbiAndBackToCamelTest.java

Modified: incubator/servicemix/trunk/deployables/serviceengines/servicemix-camel/pom.xml
URL: http://svn.apache.org/viewvc/incubator/servicemix/trunk/deployables/serviceengines/servicemix-camel/pom.xml?rev=572700&r1=572699&r2=572700&view=diff
==============================================================================
--- incubator/servicemix/trunk/deployables/serviceengines/servicemix-camel/pom.xml (original)
+++ incubator/servicemix/trunk/deployables/serviceengines/servicemix-camel/pom.xml Tue Sep
 4 07:57:46 2007
@@ -38,7 +38,7 @@
     <dependency>
       <groupId>org.apache.camel</groupId>
       <artifactId>camel-spring</artifactId>
-      <version>${camel-version}</version>
+      <version>1.1-SNAPSHOT</version>
       <exclusions>
 	    <exclusion>
 		  <groupId>org.springframework</groupId>

Modified: incubator/servicemix/trunk/deployables/serviceengines/servicemix-camel/src/main/java/org/apache/servicemix/camel/CamelJbiEndpoint.java
URL: http://svn.apache.org/viewvc/incubator/servicemix/trunk/deployables/serviceengines/servicemix-camel/src/main/java/org/apache/servicemix/camel/CamelJbiEndpoint.java?rev=572700&r1=572699&r2=572700&view=diff
==============================================================================
--- incubator/servicemix/trunk/deployables/serviceengines/servicemix-camel/src/main/java/org/apache/servicemix/camel/CamelJbiEndpoint.java
(original)
+++ incubator/servicemix/trunk/deployables/serviceengines/servicemix-camel/src/main/java/org/apache/servicemix/camel/CamelJbiEndpoint.java
Tue Sep  4 07:57:46 2007
@@ -51,8 +51,8 @@
         this.binding = binding;
     }
 
-    public CamelJbiEndpoint(ServiceUnit serviceUnit, Endpoint camelEndpoint, JbiBinding binding,
Processor camelProcesso) {
-        this(serviceUnit, SERVICE_NAME, camelEndpoint.getEndpointUri(), camelEndpoint, binding,
camelProcesso);
+    public CamelJbiEndpoint(ServiceUnit serviceUnit, Endpoint camelEndpoint, JbiBinding binding,
Processor camelProcessor) {
+        this(serviceUnit, SERVICE_NAME, camelEndpoint.getEndpointUri(), camelEndpoint, binding,
camelProcessor);
     }
 
     @Override
@@ -69,8 +69,7 @@
         if (LOG.isDebugEnabled()) {
             LOG.debug("Received exchange: " + exchange);
         }
-        /*
-         * ToDo
-         */
+        JbiExchange camelExchange = new JbiExchange(camelEndpoint.getContext(), binding,
exchange);
+        camelProcessor.process(camelExchange);
     }
 }

Modified: incubator/servicemix/trunk/deployables/serviceengines/servicemix-camel/src/main/java/org/apache/servicemix/camel/JbiBinding.java
URL: http://svn.apache.org/viewvc/incubator/servicemix/trunk/deployables/serviceengines/servicemix-camel/src/main/java/org/apache/servicemix/camel/JbiBinding.java?rev=572700&r1=572699&r2=572700&view=diff
==============================================================================
--- incubator/servicemix/trunk/deployables/serviceengines/servicemix-camel/src/main/java/org/apache/servicemix/camel/JbiBinding.java
(original)
+++ incubator/servicemix/trunk/deployables/serviceengines/servicemix-camel/src/main/java/org/apache/servicemix/camel/JbiBinding.java
Tue Sep  4 07:57:46 2007
@@ -21,6 +21,7 @@
 import java.net.URISyntaxException;
 import java.util.Map;
 import java.util.Set;
+
 import javax.jbi.messaging.MessageExchange;
 import javax.jbi.messaging.MessageExchangeFactory;
 import javax.jbi.messaging.MessagingException;
@@ -29,8 +30,8 @@
 import javax.xml.transform.stream.StreamSource;
 
 import org.apache.camel.Exchange;
+import org.apache.camel.ExchangePattern;
 import org.apache.camel.Message;
-import static org.apache.servicemix.camel.MEPConstants.*;
 
 /**
  * The binding of how Camel messages get mapped to JBI and back again
@@ -48,10 +49,17 @@
         return normalizedMessage.getContent();
     }
 
-    public MessageExchange makeJbiMessageExchange(Exchange camelExchange, MessageExchangeFactory
exchangeFactory)
+    public Source convertBodyToJbi(Object body) {
+        // TODO: conversion strategy?
+        return null;
+    }
+
+    public MessageExchange makeJbiMessageExchange(Exchange camelExchange,
+                                                  MessageExchangeFactory exchangeFactory,
+                                                  String defaultMep)
         throws MessagingException, URISyntaxException {
         
-        MessageExchange jbiExchange = createJbiMessageExchange(camelExchange, exchangeFactory);
+        MessageExchange jbiExchange = createJbiMessageExchange(camelExchange, exchangeFactory,
defaultMep);
         NormalizedMessage normalizedMessage = jbiExchange.getMessage("in");
         if (normalizedMessage == null) {
             normalizedMessage = jbiExchange.createMessage();
@@ -78,27 +86,34 @@
         this.messageExchangePattern = messageExchangePattern;
     }
 
-    protected MessageExchange createJbiMessageExchange(Exchange camelExchange, MessageExchangeFactory
exchangeFactory)
+    protected MessageExchange createJbiMessageExchange(Exchange camelExchange,
+                                                       MessageExchangeFactory exchangeFactory,
+                                                       String defaultMep)
         throws MessagingException, URISyntaxException {
 
-        String mep = camelExchange.getProperty(PROPERTY, String.class);
+        ExchangePattern mep = camelExchange.getPattern();
         if (mep == null) {
-            mep = getMessageExchangePattern();
+            mep = ExchangePattern.fromWsdlUri(defaultMep);
+        }
+        if (mep == null) {
+            mep = ExchangePattern.fromWsdlUri(getMessageExchangePattern());
         }
         MessageExchange answer = null;
         if (mep != null) {
-            if (IN_ONLY.equals(mep)) {
+            if (mep == ExchangePattern.InOnly) {
                 answer = exchangeFactory.createInOnlyExchange();
-            } else if (IN_OPTIONAL_OUT.equals(mep)) {
+            } else if (mep == ExchangePattern.InOptionalOut) {
                 answer = exchangeFactory.createInOptionalOutExchange();
-            } else if (IN_OUT.equals(mep)) {
+            } else if (mep == ExchangePattern.InOut) {
                 answer = exchangeFactory.createInOutExchange();
-            } else if (ROBUST_IN_ONLY.equals(mep)) {
+            } else if (mep == ExchangePattern.RobustInOnly) {
                 answer = exchangeFactory.createRobustInOnlyExchange();
             } else {
-                answer = exchangeFactory.createExchange(new URI(mep));
+                answer = exchangeFactory.createExchange(new URI(mep.toString()));
             }
         }
+        // TODO: this is not really usefull as the out will not be
+        // TODO: populated at that time
         if (answer == null) {
             // lets try choose the best MEP based on the camel message
             Message out = camelExchange.getOut(false);
@@ -126,4 +141,5 @@
             normalizedMessage.setProperty(entry.getKey(), entry.getValue());
         }
     }
+
 }

Modified: incubator/servicemix/trunk/deployables/serviceengines/servicemix-camel/src/main/java/org/apache/servicemix/camel/JbiExchange.java
URL: http://svn.apache.org/viewvc/incubator/servicemix/trunk/deployables/serviceengines/servicemix-camel/src/main/java/org/apache/servicemix/camel/JbiExchange.java?rev=572700&r1=572699&r2=572700&view=diff
==============================================================================
--- incubator/servicemix/trunk/deployables/serviceengines/servicemix-camel/src/main/java/org/apache/servicemix/camel/JbiExchange.java
(original)
+++ incubator/servicemix/trunk/deployables/serviceengines/servicemix-camel/src/main/java/org/apache/servicemix/camel/JbiExchange.java
Tue Sep  4 07:57:46 2007
@@ -20,6 +20,7 @@
 import javax.jbi.messaging.NormalizedMessage;
 
 import org.apache.camel.CamelContext;
+import org.apache.camel.ExchangePattern;
 import org.apache.camel.impl.DefaultExchange;
 
 /**
@@ -37,18 +38,23 @@
     public JbiExchange(CamelContext context, JbiBinding binding) {
         super(context);
         this.binding = binding;
+        populateProperties();
     }
 
+
+
     public JbiExchange(CamelContext context, JbiBinding binding, MessageExchange messageExchange)
{
         super(context);
         this.binding = binding;
         this.messageExchange = messageExchange;
 
+        setPattern(ExchangePattern.fromWsdlUri(messageExchange.getPattern().toString()));
         // TODO we could maybe use the typesafe APIs of different derived APIs
         // from JBI
         setIn(new JbiMessage(messageExchange.getMessage("in")));
         setOut(new JbiMessage(messageExchange.getMessage("out")));
         setFault(new JbiMessage(messageExchange.getMessage("fault")));
+        populateProperties();
     }
 
     @Override
@@ -71,6 +77,11 @@
         return (JbiMessage) super.getFault();
     }
 
+    @Override
+    public JbiMessage getFault(boolean lazyCreate) {
+        return (JbiMessage) super.getFault(lazyCreate);
+    }
+
     /**
      * @return the Camel <-> JBI binding
      */
@@ -130,4 +141,16 @@
     protected JbiMessage createOutMessage() {
         return new JbiMessage();
     }
+
+    @Override
+    protected JbiMessage createFaultMessage() {
+        return new JbiMessage();
+    }
+
+    private void populateProperties() {
+        if (messageExchange != null && messageExchange.getOperation() != null) {
+            setProperty("jbi.operation", messageExchange.getOperation().toString());
+        }
+    }
+
 }

Modified: incubator/servicemix/trunk/deployables/serviceengines/servicemix-camel/src/main/java/org/apache/servicemix/camel/JbiMessage.java
URL: http://svn.apache.org/viewvc/incubator/servicemix/trunk/deployables/serviceengines/servicemix-camel/src/main/java/org/apache/servicemix/camel/JbiMessage.java?rev=572700&r1=572699&r2=572700&view=diff
==============================================================================
--- incubator/servicemix/trunk/deployables/serviceengines/servicemix-camel/src/main/java/org/apache/servicemix/camel/JbiMessage.java
(original)
+++ incubator/servicemix/trunk/deployables/serviceengines/servicemix-camel/src/main/java/org/apache/servicemix/camel/JbiMessage.java
Tue Sep  4 07:57:46 2007
@@ -19,7 +19,9 @@
 import java.util.Iterator;
 import java.util.Map;
 
+import javax.jbi.messaging.MessagingException;
 import javax.jbi.messaging.NormalizedMessage;
+import javax.xml.transform.Source;
 
 import org.apache.camel.impl.DefaultMessage;
 
@@ -99,6 +101,20 @@
                 String name = iter.next().toString();
                 Object value = normalizedMessage.getProperty(name);
                 map.put(name, value);
+            }
+        }
+    }
+
+    @Override
+    public void setBody(Object body) {
+        if (normalizedMessage != null) {
+            if (!(body instanceof Source)) {
+                body = getExchange().getBinding().convertBodyToJbi(body);
+            }
+            try {
+                normalizedMessage.setContent((Source) body);
+            } catch (MessagingException e) {
+                throw new JbiException(e);
             }
         }
     }

Modified: incubator/servicemix/trunk/deployables/serviceengines/servicemix-camel/src/main/java/org/apache/servicemix/camel/ToJbiProcessor.java
URL: http://svn.apache.org/viewvc/incubator/servicemix/trunk/deployables/serviceengines/servicemix-camel/src/main/java/org/apache/servicemix/camel/ToJbiProcessor.java?rev=572700&r1=572699&r2=572700&view=diff
==============================================================================
--- incubator/servicemix/trunk/deployables/serviceengines/servicemix-camel/src/main/java/org/apache/servicemix/camel/ToJbiProcessor.java
(original)
+++ incubator/servicemix/trunk/deployables/serviceengines/servicemix-camel/src/main/java/org/apache/servicemix/camel/ToJbiProcessor.java
Tue Sep  4 07:57:46 2007
@@ -17,14 +17,18 @@
 package org.apache.servicemix.camel;
 
 import java.net.URISyntaxException;
+import java.util.Map;
+
 import javax.jbi.component.ComponentContext;
 import javax.jbi.messaging.DeliveryChannel;
+import javax.jbi.messaging.ExchangeStatus;
 import javax.jbi.messaging.MessageExchange;
 import javax.jbi.messaging.MessageExchangeFactory;
 import javax.jbi.messaging.MessagingException;
 
 import org.apache.camel.Exchange;
 import org.apache.camel.Processor;
+import org.apache.camel.util.URISupport;
 import org.apache.servicemix.jbi.resolver.URIResolver;
 
 /**
@@ -41,20 +45,48 @@
 
     private String destinationUri;
 
+    private String mep;
+
     public ToJbiProcessor(JbiBinding binding, ComponentContext componentContext, String destinationUri)
{
         this.binding = binding;
         this.componentContext = componentContext;
         this.destinationUri = destinationUri;
+        try {
+            int idx = destinationUri.indexOf('?');
+            if (idx > 0) {
+                Map params = URISupport.parseQuery(destinationUri.substring(idx + 1));
+                mep = (String) params.get("mep");
+                if (mep != null && !mep.startsWith("http://www.w3.org/ns/wsdl/"))
{
+                    mep = "http://www.w3.org/ns/wsdl/" + mep;
+                }
+                this.destinationUri = destinationUri.substring(0, idx);
+            }
+        } catch (URISyntaxException e) {
+            throw new JbiException(e);
+        }
     }
 
     public void process(Exchange exchange) {
         try {
             DeliveryChannel deliveryChannel = componentContext.getDeliveryChannel();
             MessageExchangeFactory exchangeFactory = deliveryChannel.createExchangeFactory();
-            MessageExchange messageExchange = binding.makeJbiMessageExchange(exchange, exchangeFactory);
+            MessageExchange messageExchange = binding.makeJbiMessageExchange(exchange, exchangeFactory,
mep);
 
             URIResolver.configureExchange(messageExchange, componentContext, destinationUri);
             deliveryChannel.sendSync(messageExchange);
+
+            if (messageExchange.getStatus() == ExchangeStatus.ERROR) {
+                exchange.setException(messageExchange.getError());
+            } else if (messageExchange.getStatus() == ExchangeStatus.ACTIVE) {
+                if (messageExchange.getFault() != null) {
+                    exchange.getFault().setBody(messageExchange.getFault().getContent());
+                } else {
+                    exchange.getOut().setBody(messageExchange.getMessage("out").getContent());
+                }
+                messageExchange.setStatus(ExchangeStatus.DONE);
+                deliveryChannel.send(messageExchange);
+            }
+
         } catch (MessagingException e) {
             throw new JbiException(e);
         } catch (URISyntaxException e) {

Added: incubator/servicemix/trunk/deployables/serviceengines/servicemix-camel/src/test/java/org/apache/servicemix/camel/JbiInOutTest.java
URL: http://svn.apache.org/viewvc/incubator/servicemix/trunk/deployables/serviceengines/servicemix-camel/src/test/java/org/apache/servicemix/camel/JbiInOutTest.java?rev=572700&view=auto
==============================================================================
--- incubator/servicemix/trunk/deployables/serviceengines/servicemix-camel/src/test/java/org/apache/servicemix/camel/JbiInOutTest.java
(added)
+++ incubator/servicemix/trunk/deployables/serviceengines/servicemix-camel/src/test/java/org/apache/servicemix/camel/JbiInOutTest.java
Tue Sep  4 07:57:46 2007
@@ -0,0 +1,53 @@
+/*
+ * 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.jbi.messaging.MessageExchange;
+import javax.jbi.servicedesc.ServiceEndpoint;
+import javax.xml.namespace.QName;
+
+import org.apache.servicemix.client.ServiceMixClient;
+import org.apache.servicemix.components.util.EchoComponent;
+
+/**
+ * @version $Revision: 1.1 $
+ */
+public class JbiInOutTest extends
+        NonJbiCamelEndpointsIntegrationTest {
+    /*
+     * @see TestCase#setUp()
+     */
+    @Override
+    protected void setUp() throws Exception {
+        suName = "su5";
+        super.setUp();
+
+        EchoComponent echo = new EchoComponent();
+        echo.setService(new QName("namespace", "echo"));
+        echo.setEndpoint("endpoint");
+        container.activateComponent(echo, "echo");
+    }
+
+    @Override
+    protected void configureExchange(ServiceMixClient client,
+            MessageExchange exchange) {
+        ServiceEndpoint endpoint = client.getContext().getEndpoint(
+                CamelJbiEndpoint.SERVICE_NAME, "cheese");
+        assertNotNull("Should have a Camel endpoint exposed in JBI!", endpoint);
+        exchange.setEndpoint(endpoint);
+    }
+}

Modified: incubator/servicemix/trunk/deployables/serviceengines/servicemix-camel/src/test/java/org/apache/servicemix/camel/NonJbiCamelEndpointsIntegrationTest.java
URL: http://svn.apache.org/viewvc/incubator/servicemix/trunk/deployables/serviceengines/servicemix-camel/src/test/java/org/apache/servicemix/camel/NonJbiCamelEndpointsIntegrationTest.java?rev=572700&r1=572699&r2=572700&view=diff
==============================================================================
--- incubator/servicemix/trunk/deployables/serviceengines/servicemix-camel/src/test/java/org/apache/servicemix/camel/NonJbiCamelEndpointsIntegrationTest.java
(original)
+++ incubator/servicemix/trunk/deployables/serviceengines/servicemix-camel/src/test/java/org/apache/servicemix/camel/NonJbiCamelEndpointsIntegrationTest.java
Tue Sep  4 07:57:46 2007
@@ -23,6 +23,7 @@
 import javax.jbi.messaging.InOut;
 import javax.jbi.messaging.MessageExchange;
 import javax.jbi.messaging.MessagingException;
+import javax.jbi.messaging.NormalizedMessage;
 import javax.jbi.servicedesc.ServiceEndpoint;
 
 import junit.framework.TestCase;
@@ -32,6 +33,7 @@
 import org.apache.servicemix.client.DefaultServiceMixClient;
 import org.apache.servicemix.client.ServiceMixClient;
 import org.apache.servicemix.jbi.container.JBIContainer;
+import org.apache.servicemix.jbi.jaxp.StringSource;
 
 /**
  * @version $Revision: 1.1 $
@@ -70,7 +72,12 @@
                 // Send message
                 MessageExchange exchange = createExchange(client);
                 configureExchange(client, exchange);
-                client.send(exchange);
+                populateExchange(exchange);
+                client.sendSync(exchange);
+                assertNotNull(exchange.getMessage("out"));
+                //assertNotNull(exchange.getMessage("out").getContent());
+                // TODO: check out
+                client.done(exchange);
 
                 // Stop and undeploy
                 component.getServiceUnitManager().stop(suName);
@@ -114,10 +121,8 @@
         LOG.info("Using temporary root directory ["
                 + tempRootDir.getAbsolutePath() + "]");
 
-        container.setRootDir(tempRootDir.getAbsolutePath());
-        container.setMonitorInstallationDirectory(false);
-        container.setUseMBeanServer(false);
-        container.setCreateMBeanServer(false);
+        container.setEmbedded(true);
+        container.setCreateJmxConnector(false);
         container.setFlowName("st");
         container.init();
         container.start();
@@ -146,6 +151,15 @@
                 CamelJbiEndpoint.SERVICE_NAME, "seda:a");
         assertNotNull("Should have a Camel endpoint exposed in JBI!", endpoint);
         exchange.setEndpoint(endpoint);
+    }
+
+    protected void populateExchange(MessageExchange exchange) throws Exception {
+        NormalizedMessage msg = exchange.getMessage("in");
+        if (msg == null) {
+            msg = exchange.createMessage();
+            exchange.setMessage(msg, "in");
+        }
+        msg.setContent(new StringSource("<hello>world</hello>"));
     }
 
     public static boolean deleteDir(File dir) {

Modified: incubator/servicemix/trunk/deployables/serviceengines/servicemix-camel/src/test/java/org/apache/servicemix/camel/SendFromCamelToJbiAndBackToCamelTest.java
URL: http://svn.apache.org/viewvc/incubator/servicemix/trunk/deployables/serviceengines/servicemix-camel/src/test/java/org/apache/servicemix/camel/SendFromCamelToJbiAndBackToCamelTest.java?rev=572700&r1=572699&r2=572700&view=diff
==============================================================================
--- incubator/servicemix/trunk/deployables/serviceengines/servicemix-camel/src/test/java/org/apache/servicemix/camel/SendFromCamelToJbiAndBackToCamelTest.java
(original)
+++ incubator/servicemix/trunk/deployables/serviceengines/servicemix-camel/src/test/java/org/apache/servicemix/camel/SendFromCamelToJbiAndBackToCamelTest.java
Tue Sep  4 07:57:46 2007
@@ -22,7 +22,6 @@
 
 import javax.xml.namespace.QName;
 
-import org.apache.camel.Exchange;
 import org.apache.camel.builder.RouteBuilder;
 import org.apache.camel.component.seda.SedaEndpoint;
 import org.apache.servicemix.jbi.container.ActivationSpec;
@@ -41,15 +40,15 @@
         SedaEndpoint receiverEndpoint = (SedaEndpoint) camelContext
                 .getEndpoint("seda:receiver");
 
-        BlockingQueue<Exchange> queue = receiverEndpoint.getQueue();
-        Exchange exchange = queue.poll(5, TimeUnit.SECONDS);
+        BlockingQueue<SedaEndpoint.Entry> queue = receiverEndpoint.getQueue();
+        SedaEndpoint.Entry entry = queue.poll(5, TimeUnit.SECONDS);
 
         assertNotNull(
                 "Camel Receiver queue should have received an exchange by now",
-                exchange);
+                entry);
 
-        log.debug("Receiver got exchange: " + exchange + " with body: "
-                + exchange.getIn().getBody());
+        log.debug("Receiver got exchange: " + entry.getExchange() + " with body: "
+                + entry.getExchange().getIn().getBody());
     }
 
     @Override

Copied: incubator/servicemix/trunk/deployables/serviceengines/servicemix-camel/src/test/java/org/apache/servicemix/camel/TestCamelRouter.java
(from r570705, incubator/servicemix/trunk/deployables/serviceengines/servicemix-camel/src/test/java/org/apache/servicemix/camel/SendFromCamelToJbiTest.java)
URL: http://svn.apache.org/viewvc/incubator/servicemix/trunk/deployables/serviceengines/servicemix-camel/src/test/java/org/apache/servicemix/camel/TestCamelRouter.java?p2=incubator/servicemix/trunk/deployables/serviceengines/servicemix-camel/src/test/java/org/apache/servicemix/camel/TestCamelRouter.java&p1=incubator/servicemix/trunk/deployables/serviceengines/servicemix-camel/src/test/java/org/apache/servicemix/camel/SendFromCamelToJbiTest.java&r1=570705&r2=572700&rev=572700&view=diff
==============================================================================
--- incubator/servicemix/trunk/deployables/serviceengines/servicemix-camel/src/test/java/org/apache/servicemix/camel/SendFromCamelToJbiTest.java
(original)
+++ incubator/servicemix/trunk/deployables/serviceengines/servicemix-camel/src/test/java/org/apache/servicemix/camel/TestCamelRouter.java
Tue Sep  4 07:57:46 2007
@@ -16,59 +16,74 @@
  */
 package org.apache.servicemix.camel;
 
-import java.util.List;
-
-import javax.jbi.messaging.NormalizedMessage;
-import javax.xml.namespace.QName;
-
+import org.apache.camel.ContextTestSupport;
+import org.apache.camel.Exchange;
+import org.apache.camel.Processor;
 import org.apache.camel.builder.RouteBuilder;
-import org.apache.servicemix.jbi.container.ActivationSpec;
-import org.apache.servicemix.tck.MessageList;
-import org.apache.servicemix.tck.ReceiverComponent;
+import org.apache.camel.component.mock.MockEndpoint;
 
 /**
  * @version $Revision: 563665 $
  */
-public class SendFromCamelToJbiTest extends JbiTestSupport {
-    private ReceiverComponent receiverComponent = new ReceiverComponent();
+public class TestCamelRouter extends ContextTestSupport {
+    private MockEndpoint a;
+    private MockEndpoint b;
+    private MockEndpoint c;
+
+    public void testWithOut() throws Exception {
+        a.whenExchangeReceived(1, new Processor() {
+			public void process(Exchange exchange) throws Exception {
+				exchange.getOut().setBody("out");
+			}
+        });
+        a.expectedMessageCount(1);
+        b.expectedMessageCount(1);
+        b.expectedBodiesReceived("out");
+        c.expectedMessageCount(0);
+        
+        template.sendBody("direct:start", "in");
+     
+        MockEndpoint.assertIsSatisfied(a, b, c);
+    }
 
-    public void testCamelInvokingJbi() throws Exception {
-        sendExchange("<foo bar='123'/>");
-        MessageList list = receiverComponent.getMessageList();
-
-        list.assertMessagesReceived(1);
-        List messages = list.getMessages();
-        NormalizedMessage message = (NormalizedMessage) messages.get(0);
-        assertNotNull("null message!", message);
-        log.info("Received: " + message);
+    public void testWithFault() throws Exception {
+        a.whenExchangeReceived(1, new Processor() {
+			public void process(Exchange exchange) throws Exception {
+				exchange.getFault().setBody("fault");
+			}
+        });
+        a.expectedMessageCount(1);
+        b.expectedMessageCount(0);
+        c.expectedMessageCount(1);
+        c.expectedBodiesReceived("fault");
+        
+        template.sendBody("direct:start", "in");
+     
+        //MockEndpoint.assertIsSatisfied(a, b, c);
+    }
 
-        assertEquals("cheese header", 123, message.getProperty("cheese"));
+    @Override
+    protected void setUp() throws Exception {
+        super.setUp();
+        a = resolveMandatoryEndpoint("mock:a", MockEndpoint.class);
+        b = resolveMandatoryEndpoint("mock:b", MockEndpoint.class);
+        c = resolveMandatoryEndpoint("mock:c", MockEndpoint.class);
     }
 
     @Override
-    protected RouteBuilder createRoutes() {
+    protected RouteBuilder createRouteBuilder() throws Exception {
         return new RouteBuilder() {
             @Override
             public void configure() {
-                // no routes required
+                from("direct:start")
+                        .to("mock:a")
+                        .choice()
+                            .when(faultBody().isNull())
+                                .to("mock:b")
+                            .otherwise()
+                                .to("mock:c");
             }
         };
     }
 
-    @Override
-    protected void appendJbiActivationSpecs(
-            List<ActivationSpec> activationSpecList) {
-        ActivationSpec activationSpec = new ActivationSpec();
-        activationSpec.setId("jbiReceiver");
-        activationSpec.setService(new QName("serviceNamespace", "serviceA"));
-        activationSpec.setEndpoint("endpointA");
-        activationSpec.setComponent(receiverComponent);
-
-        activationSpecList.add(activationSpec);
-    }
-
-    @Override
-    protected void tearDown() throws Exception {
-        camelContext.stop();
-    }
-}
+}
\ No newline at end of file

Added: incubator/servicemix/trunk/deployables/serviceengines/servicemix-camel/src/test/resources/org/apache/servicemix/camel/su5-src/camel-context.xml
URL: http://svn.apache.org/viewvc/incubator/servicemix/trunk/deployables/serviceengines/servicemix-camel/src/test/resources/org/apache/servicemix/camel/su5-src/camel-context.xml?rev=572700&view=auto
==============================================================================
--- incubator/servicemix/trunk/deployables/serviceengines/servicemix-camel/src/test/resources/org/apache/servicemix/camel/su5-src/camel-context.xml
(added)
+++ incubator/servicemix/trunk/deployables/serviceengines/servicemix-camel/src/test/resources/org/apache/servicemix/camel/su5-src/camel-context.xml
Tue Sep  4 07:57:46 2007
@@ -0,0 +1,39 @@
+<?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.
+
+-->
+<!-- START SNIPPET: camel -->
+<beans xmlns="http://www.springframework.org/schema/beans"
+       xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+       xsi:schemaLocation="
+       http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-2.0.xsd
+       http://activemq.apache.org/camel/schema/spring http://activemq.apache.org/camel/schema/spring/camel-spring.xsd
+    ">
+
+  <!--
+     from("seda:a").to("seda:b");
+  -->
+  <camelContext id="camel" xmlns="http://activemq.apache.org/camel/schema/spring">
+    <route>
+      <from uri="jbi:name:cheese"/>
+      <to uri="jbi:service:namespace:echo?mep=in-out"/>
+    </route>
+  </camelContext>
+
+</beans>
+<!-- END SNIPPET: camel -->



Mime
View raw message