servicemix-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ge...@apache.org
Subject svn commit: r591300 - in /incubator/servicemix/trunk/deployables/serviceengines/servicemix-camel/src: main/java/org/apache/servicemix/camel/JbiBinding.java test/java/org/apache/servicemix/camel/JbiBindingTest.java
Date Fri, 02 Nov 2007 11:02:38 GMT
Author: gertv
Date: Fri Nov  2 04:02:35 2007
New Revision: 591300

URL: http://svn.apache.org/viewvc?rev=591300&view=rev
Log:
SM-1124: add warning when message content conversions fails + use Camel type converter for
String->Source

Added:
    incubator/servicemix/trunk/deployables/serviceengines/servicemix-camel/src/test/java/org/apache/servicemix/camel/JbiBindingTest.java
Modified:
    incubator/servicemix/trunk/deployables/serviceengines/servicemix-camel/src/main/java/org/apache/servicemix/camel/JbiBinding.java

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=591300&r1=591299&r2=591300&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
Fri Nov  2 04:02:35 2007
@@ -16,22 +16,23 @@
  */
 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;
 import javax.jbi.messaging.NormalizedMessage;
 import javax.xml.transform.Source;
-import javax.xml.transform.stream.StreamSource;
 
 import org.apache.camel.Exchange;
 import org.apache.camel.ExchangePattern;
 import org.apache.camel.Message;
 import org.apache.camel.util.ExchangeHelper;
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
 
 /**
  * The binding of how Camel messages get mapped to JBI and back again
@@ -39,6 +40,9 @@
  * @version $Revision: 563665 $
  */
 public class JbiBinding {
+
+    private static final Log LOG = LogFactory.getLog(JbiBinding.class);
+
     private String messageExchangePattern;
 
     /**
@@ -54,10 +58,9 @@
     }
 
     public MessageExchange makeJbiMessageExchange(Exchange camelExchange,
-                                                  MessageExchangeFactory exchangeFactory,
-                                                  String defaultMep)
+                                                  MessageExchangeFactory exchangeFactory,
String defaultMep)
         throws MessagingException, URISyntaxException {
-        
+
         MessageExchange jbiExchange = createJbiMessageExchange(camelExchange, exchangeFactory,
defaultMep);
         NormalizedMessage normalizedMessage = jbiExchange.getMessage("in");
         if (normalizedMessage == null) {
@@ -70,7 +73,7 @@
     }
 
     // Properties
-    //-------------------------------------------------------------------------
+    // -------------------------------------------------------------------------
 
     public String getMessageExchangePattern() {
         return messageExchangePattern;
@@ -78,7 +81,7 @@
 
     /**
      * Sets the message exchange pattern to use for communicating with JBI
-     *
+     * 
      * @param messageExchangePattern
      */
     public void setMessageExchangePattern(String messageExchangePattern) {
@@ -86,8 +89,7 @@
     }
 
     protected MessageExchange createJbiMessageExchange(Exchange camelExchange,
-                                                       MessageExchangeFactory exchangeFactory,
-                                                       String defaultMep)
+        MessageExchangeFactory exchangeFactory, String defaultMep) 
         throws MessagingException, URISyntaxException {
 
         ExchangePattern mep = camelExchange.getPattern();
@@ -127,14 +129,16 @@
 
     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()));
+        Source content = camelExchange.getIn().getBody(Source.class);
+        if (content == null && camelExchange.getIn().getBody() != null) {
+            LOG.warn("'in' message content of type " + camelExchange.getIn().getBody().getClass()
+                     + " could not be converted to Source and will be dropped");
         }
-        return camelExchange.getIn().getBody(Source.class);
+        return content;
     }
 
-    protected void addJbiHeaders(MessageExchange jbiExchange, NormalizedMessage normalizedMessage,
Exchange camelExchange) {
+    protected void addJbiHeaders(MessageExchange jbiExchange, NormalizedMessage normalizedMessage,
+                                 Exchange camelExchange) {
         Set<Map.Entry<String, Object>> entries = camelExchange.getIn().getHeaders().entrySet();
         for (Map.Entry<String, Object> entry : entries) {
             normalizedMessage.setProperty(entry.getKey(), entry.getValue());

Added: incubator/servicemix/trunk/deployables/serviceengines/servicemix-camel/src/test/java/org/apache/servicemix/camel/JbiBindingTest.java
URL: http://svn.apache.org/viewvc/incubator/servicemix/trunk/deployables/serviceengines/servicemix-camel/src/test/java/org/apache/servicemix/camel/JbiBindingTest.java?rev=591300&view=auto
==============================================================================
--- incubator/servicemix/trunk/deployables/serviceengines/servicemix-camel/src/test/java/org/apache/servicemix/camel/JbiBindingTest.java
(added)
+++ incubator/servicemix/trunk/deployables/serviceengines/servicemix-camel/src/test/java/org/apache/servicemix/camel/JbiBindingTest.java
Fri Nov  2 04:02:35 2007
@@ -0,0 +1,42 @@
+/*
+ * 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 junit.framework.TestCase;
+
+import org.apache.camel.CamelContext;
+import org.apache.camel.Exchange;
+import org.apache.camel.impl.DefaultCamelContext;
+import org.apache.camel.impl.DefaultExchange;
+
+public class JbiBindingTest extends TestCase {
+
+    private JbiBinding binding;
+    
+    @Override
+    protected void setUp() throws Exception {
+        binding = new JbiBinding();
+    }
+    
+    public void testGetJbiInContentForString() {
+        CamelContext context = new DefaultCamelContext();
+        Exchange exchange = new DefaultExchange(context);
+        exchange.getIn().setBody("<hello>world!</hello>");
+        assertNotNull(binding.getJbiInContent(exchange));
+    }
+
+}



Mime
View raw message