camel-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From davscl...@apache.org
Subject [5/5] camel git commit: CAMEL-8489: camel-sjms - allow null body option.
Date Sun, 15 Mar 2015 09:51:13 GMT
CAMEL-8489: camel-sjms - allow null body option.


Project: http://git-wip-us.apache.org/repos/asf/camel/repo
Commit: http://git-wip-us.apache.org/repos/asf/camel/commit/78bcbf13
Tree: http://git-wip-us.apache.org/repos/asf/camel/tree/78bcbf13
Diff: http://git-wip-us.apache.org/repos/asf/camel/diff/78bcbf13

Branch: refs/heads/camel-2.15.x
Commit: 78bcbf135414c703d9c0fdb1b162888e85a00e4c
Parents: 5c286b3
Author: Claus Ibsen <davsclaus@apache.org>
Authored: Sun Mar 15 10:51:51 2015 +0100
Committer: Claus Ibsen <davsclaus@apache.org>
Committed: Sun Mar 15 10:52:19 2015 +0100

----------------------------------------------------------------------
 .../camel/component/sjms/SjmsEndpoint.java      | 10 +++
 .../component/sjms/jms/JmsMessageHelper.java    | 87 ++++++++++----------
 2 files changed, 55 insertions(+), 42 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/camel/blob/78bcbf13/components/camel-sjms/src/main/java/org/apache/camel/component/sjms/SjmsEndpoint.java
----------------------------------------------------------------------
diff --git a/components/camel-sjms/src/main/java/org/apache/camel/component/sjms/SjmsEndpoint.java
b/components/camel-sjms/src/main/java/org/apache/camel/component/sjms/SjmsEndpoint.java
index 5dbeb03..0ea668c 100644
--- a/components/camel-sjms/src/main/java/org/apache/camel/component/sjms/SjmsEndpoint.java
+++ b/components/camel-sjms/src/main/java/org/apache/camel/component/sjms/SjmsEndpoint.java
@@ -84,6 +84,8 @@ public class SjmsEndpoint extends DefaultEndpoint implements MultipleConsumersSu
     private boolean asyncStopListener;
     @UriParam(defaultValue = "true")
     private boolean prefillPool = true;
+    @UriParam(defaultValue = "true")
+    private boolean allowNullBody = true;
     @UriParam
     private TransactionCommitStrategy transactionCommitStrategy;
     @UriParam
@@ -504,4 +506,12 @@ public class SjmsEndpoint extends DefaultEndpoint implements MultipleConsumersSu
     public void setDestinationCreationStrategy(DestinationCreationStrategy destinationCreationStrategy)
{
         this.destinationCreationStrategy = destinationCreationStrategy;
     }
+
+    public boolean isAllowNullBody() {
+        return allowNullBody;
+    }
+
+    public void setAllowNullBody(boolean allowNullBody) {
+        this.allowNullBody = allowNullBody;
+    }
 }

http://git-wip-us.apache.org/repos/asf/camel/blob/78bcbf13/components/camel-sjms/src/main/java/org/apache/camel/component/sjms/jms/JmsMessageHelper.java
----------------------------------------------------------------------
diff --git a/components/camel-sjms/src/main/java/org/apache/camel/component/sjms/jms/JmsMessageHelper.java
b/components/camel-sjms/src/main/java/org/apache/camel/component/sjms/jms/JmsMessageHelper.java
index 062d143..81091d6 100644
--- a/components/camel-sjms/src/main/java/org/apache/camel/component/sjms/jms/JmsMessageHelper.java
+++ b/components/camel-sjms/src/main/java/org/apache/camel/component/sjms/jms/JmsMessageHelper.java
@@ -153,55 +153,58 @@ public final class JmsMessageHelper implements JmsConstants {
     }
 
     public static Message createMessage(Session session, Object payload, Map<String, Object>
messageHeaders, SjmsEndpoint endpoint) throws Exception {
-        return createMessage(session, payload, messageHeaders, endpoint.getJmsKeyFormatStrategy(),
endpoint.getCamelContext().getTypeConverter());
+        return createMessage(session, payload, messageHeaders, endpoint.isAllowNullBody(),
endpoint.getJmsKeyFormatStrategy(), endpoint.getCamelContext().getTypeConverter());
     }
 
-    private static Message createMessage(Session session, Object payload, Map<String,
Object> messageHeaders, KeyFormatStrategy keyFormatStrategy, TypeConverter typeConverter)
throws Exception {
+    private static Message createMessage(Session session, Object payload, Map<String,
Object> messageHeaders, boolean allowNullBody,
+                                         KeyFormatStrategy keyFormatStrategy, TypeConverter
typeConverter) throws Exception {
         Message answer = null;
         JmsMessageType messageType = JmsMessageHelper.discoverMessageTypeFromPayload(payload);
-        try {
 
-            switch (messageType) {
-            case Bytes:
-                BytesMessage bytesMessage = session.createBytesMessage();
-                byte[] bytesToWrite = typeConverter.convertTo(byte[].class, payload);
-                bytesMessage.writeBytes(bytesToWrite);
-                answer = bytesMessage;
-                break;
-            case Map:
-                MapMessage mapMessage = session.createMapMessage();
-                Map objMap = (Map) payload;
-                for (final Map.Entry entry : (Set<Map.Entry>)objMap.entrySet()) {
-                    mapMessage.setObject(entry.getKey().toString(), entry.getValue());
-                }
-                answer = mapMessage;
-                break;
-            case Object:
-                ObjectMessage objectMessage = session.createObjectMessage();
-                objectMessage.setObject((Serializable) payload);
-                answer = objectMessage;
-                break;
-            case Text:
-                TextMessage textMessage = session.createTextMessage();
-                String convertedText = typeConverter.convertTo(String.class, payload);
-                textMessage.setText(convertedText);
-                answer = textMessage;
-                break;
-            case Stream:
-                StreamMessage streamMessage = session.createStreamMessage();
-                Collection collection = (Collection)payload;
-                for (final Object obj : collection) {
-                    streamMessage.writeObject(obj);
-                }
-                answer = streamMessage;
-                break;
-            default:
-                break;
+        switch (messageType) {
+        case Bytes:
+            BytesMessage bytesMessage = session.createBytesMessage();
+            byte[] bytesToWrite = typeConverter.convertTo(byte[].class, payload);
+            bytesMessage.writeBytes(bytesToWrite);
+            answer = bytesMessage;
+            break;
+        case Map:
+            MapMessage mapMessage = session.createMapMessage();
+            Map objMap = (Map) payload;
+            for (final Map.Entry entry : (Set<Map.Entry>)objMap.entrySet()) {
+                mapMessage.setObject(entry.getKey().toString(), entry.getValue());
             }
-        } catch (Exception e) {
-            LOGGER.error("Error creating a message of type: {}", messageType, e);
-            throw e;
+            answer = mapMessage;
+            break;
+        case Object:
+            ObjectMessage objectMessage = session.createObjectMessage();
+            objectMessage.setObject((Serializable) payload);
+            answer = objectMessage;
+            break;
+        case Text:
+            TextMessage textMessage = session.createTextMessage();
+            String convertedText = typeConverter.convertTo(String.class, payload);
+            textMessage.setText(convertedText);
+            answer = textMessage;
+            break;
+        case Stream:
+            StreamMessage streamMessage = session.createStreamMessage();
+            Collection collection = (Collection)payload;
+            for (final Object obj : collection) {
+                streamMessage.writeObject(obj);
+            }
+            answer = streamMessage;
+            break;
+        case Message:
+            if (allowNullBody && payload == null) {
+                answer = session.createMessage();
+            } else {
+                throw new JMSException("Null body is not allowed");
+            }
+        default:
+            break;
         }
+
         if (messageHeaders != null && !messageHeaders.isEmpty()) {
             answer = JmsMessageHelper.setJmsMessageHeaders(answer, messageHeaders, keyFormatStrategy);
         }


Mime
View raw message