You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@servicemix.apache.org by js...@apache.org on 2007/08/17 12:09:50 UTC

svn commit: r566998 - in /incubator/servicemix/trunk/deployables/serviceengines/servicemix-camel/src/main/java/org/apache/servicemix/camel: CamelConstants.java JbiBinding.java ToJbiProcessor.java

Author: jstrachan
Date: Fri Aug 17 03:09:48 2007
New Revision: 566998

URL: http://svn.apache.org/viewvc?view=rev&rev=566998
Log:
added support for configurable message exchange patterns, on a component/endpoint or on a message Exchange so that came messages can be sent properly into JBI whether InOnly, InOut, InOptionalOut etc

Added:
    incubator/servicemix/trunk/deployables/serviceengines/servicemix-camel/src/main/java/org/apache/servicemix/camel/CamelConstants.java   (with props)
Modified:
    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/ToJbiProcessor.java

Added: incubator/servicemix/trunk/deployables/serviceengines/servicemix-camel/src/main/java/org/apache/servicemix/camel/CamelConstants.java
URL: http://svn.apache.org/viewvc/incubator/servicemix/trunk/deployables/serviceengines/servicemix-camel/src/main/java/org/apache/servicemix/camel/CamelConstants.java?view=auto&rev=566998
==============================================================================
--- incubator/servicemix/trunk/deployables/serviceengines/servicemix-camel/src/main/java/org/apache/servicemix/camel/CamelConstants.java (added)
+++ incubator/servicemix/trunk/deployables/serviceengines/servicemix-camel/src/main/java/org/apache/servicemix/camel/CamelConstants.java Fri Aug 17 03:09:48 2007
@@ -0,0 +1,43 @@
+/*
+ * 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;
+
+/**
+ * See the <a href="http://www.w3.org/TR/wsdl20-extensions/">WSDL 2.0 Extensions</a> for a description
+ * of message exchange patterns.
+ * 
+ * @version $Revision: 1.1 $
+ */
+public class CamelConstants {
+
+    // TODO we should probably move this to camel-core
+
+    public class Property {
+        public static final String MESSAGE_EXCHANGE_PATTERN = "org.apache.camel.MessageExchangePattern";
+    }
+
+    public class MessageExchangePattern {
+        public static final String IN_ONLY = "in-only";
+        public static final String ROBUST_IN_ONLY = "robust-in-only";
+        public static final String IN_OUT = "in-out";
+        public static final String IN_OPTIONAL_OUT = "in-optional-out";
+        public static final String OUT_ONLY = "out-only";
+        public static final String ROBUST_OUT_ONLY = "robust-out-only";
+        public static final String OUT_IN = "out-in";
+        public static final String OUT_OPTIONAL_IN = "out-optional_in";
+    }
+}

Propchange: incubator/servicemix/trunk/deployables/serviceengines/servicemix-camel/src/main/java/org/apache/servicemix/camel/CamelConstants.java
------------------------------------------------------------------------------
    svn:eol-style = native

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?view=diff&rev=566998&r1=566997&r2=566998
==============================================================================
--- 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 Fri Aug 17 03:09:48 2007
@@ -17,9 +17,10 @@
 package org.apache.servicemix.camel;
 
 import java.io.StringReader;
+import java.net.URI;
+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;
@@ -28,6 +29,9 @@
 import javax.xml.transform.stream.StreamSource;
 
 import org.apache.camel.Exchange;
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
+import static org.apache.servicemix.camel.CamelConstants.MessageExchangePattern.*;
 
 /**
  * The binding of how Camel messages get mapped to JBI and back again
@@ -35,6 +39,9 @@
  * @version $Revision: 563665 $
  */
 public class JbiBinding {
+    private static final transient Log LOG = LogFactory.getLog(JbiBinding.class);
+    private String messageExchangePattern = IN_ONLY;
+
     /**
      * Extracts the body from the given normalized message
      */
@@ -43,8 +50,8 @@
         return normalizedMessage.getContent();
     }
 
-    public MessageExchange makeJbiMessageExchange(Exchange camelExchange, MessageExchangeFactory exchangeFactory) 
-        throws MessagingException {
+    public MessageExchange makeJbiMessageExchange(Exchange camelExchange, MessageExchangeFactory exchangeFactory)
+        throws MessagingException, URISyntaxException {
         
         MessageExchange jbiExchange = createJbiMessageExchange(camelExchange, exchangeFactory);
         NormalizedMessage normalizedMessage = jbiExchange.getMessage("in");
@@ -57,10 +64,43 @@
         return jbiExchange;
     }
 
+    // Properties
+    //-------------------------------------------------------------------------
+
+    public String getMessageExchangePattern() {
+        return messageExchangePattern;
+    }
+
+    /**
+     * Sets the message exchange pattern to use for communicating with JBI
+     *
+     * @param messageExchangePattern
+     */
+    public void setMessageExchangePattern(String messageExchangePattern) {
+        this.messageExchangePattern = messageExchangePattern;
+    }
+
     protected MessageExchange createJbiMessageExchange(Exchange camelExchange, MessageExchangeFactory exchangeFactory)
-        throws MessagingException {
-        
-        // TODO we should deal with other forms of MEP
+        throws MessagingException, URISyntaxException {
+
+        String mep = camelExchange.getProperty(CamelConstants.Property.MESSAGE_EXCHANGE_PATTERN, String.class);
+        if (mep == null) {
+            mep = getMessageExchangePattern();
+        }
+        if (mep != null) {
+            if (IN_ONLY.equals(mep)) {
+                return exchangeFactory.createInOnlyExchange();
+            } else if (IN_OPTIONAL_OUT.equals(mep)) {
+                return exchangeFactory.createInOptionalOutExchange();
+            } else if (IN_OUT.equals(mep)) {
+                return exchangeFactory.createInOutExchange();
+            } else if (ROBUST_IN_ONLY.equals(mep)) {
+                return exchangeFactory.createRobustInOnlyExchange();
+            } else {
+                return exchangeFactory.createExchange(new URI(mep));
+            }
+        }
+        LOG.warn("No MessageExchangePattern specified so using InOnly");
         return exchangeFactory.createInOnlyExchange();
     }
 

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?view=diff&rev=566998&r1=566997&r2=566998
==============================================================================
--- 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 Fri Aug 17 03:09:48 2007
@@ -16,6 +16,7 @@
  */
 package org.apache.servicemix.camel;
 
+import java.net.URISyntaxException;
 import javax.jbi.component.ComponentContext;
 import javax.jbi.messaging.DeliveryChannel;
 import javax.jbi.messaging.MessageExchange;
@@ -55,6 +56,8 @@
             URIResolver.configureExchange(messageExchange, componentContext, destinationUri);
             deliveryChannel.sendSync(messageExchange);
         } catch (MessagingException e) {
+            throw new JbiException(e);
+        } catch (URISyntaxException e) {
             throw new JbiException(e);
         }
     }