You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@camel.apache.org by da...@apache.org on 2009/03/27 08:30:52 UTC

svn commit: r759042 - /camel/trunk/components/camel-jms/src/main/java/org/apache/camel/component/jms/JmsBinding.java

Author: davsclaus
Date: Fri Mar 27 07:30:51 2009
New Revision: 759042

URL: http://svn.apache.org/viewvc?rev=759042&view=rev
Log:
CAMEL-1492: Fixed NPE when endpoint not pprovided in JmsBinding.

Modified:
    camel/trunk/components/camel-jms/src/main/java/org/apache/camel/component/jms/JmsBinding.java

Modified: camel/trunk/components/camel-jms/src/main/java/org/apache/camel/component/jms/JmsBinding.java
URL: http://svn.apache.org/viewvc/camel/trunk/components/camel-jms/src/main/java/org/apache/camel/component/jms/JmsBinding.java?rev=759042&r1=759041&r2=759042&view=diff
==============================================================================
--- camel/trunk/components/camel-jms/src/main/java/org/apache/camel/component/jms/JmsBinding.java (original)
+++ camel/trunk/components/camel-jms/src/main/java/org/apache/camel/component/jms/JmsBinding.java Fri Mar 27 07:30:51 2009
@@ -64,19 +64,28 @@
  */
 public class JmsBinding {
     private static final transient Log LOG = LogFactory.getLog(JmsBinding.class);
-    private JmsEndpoint endpoint;
-    private HeaderFilterStrategy headerFilterStrategy;
+    private final JmsEndpoint endpoint;
+    private final HeaderFilterStrategy headerFilterStrategy;
+    private final JmsKeyFormatStrategy jmsKeyFormatStrategy;
 
     public JmsBinding() {
+        this.endpoint = null;
         headerFilterStrategy = new JmsHeaderFilterStrategy();
+        jmsKeyFormatStrategy = new DefaultJmsKeyFormatStrategy();
     }
 
     public JmsBinding(JmsEndpoint endpoint) {
         this.endpoint = endpoint;
-        headerFilterStrategy = endpoint.getHeaderFilterStrategy();
-        if (headerFilterStrategy == null) {
+        if (endpoint.getHeaderFilterStrategy() != null) {
+            headerFilterStrategy = endpoint.getHeaderFilterStrategy();
+        } else {
             headerFilterStrategy = new JmsHeaderFilterStrategy();
         }
+        if (endpoint.getJmsKeyFormatStrategy() != null) {
+            jmsKeyFormatStrategy = endpoint.getJmsKeyFormatStrategy();
+        } else {
+            jmsKeyFormatStrategy = new DefaultJmsKeyFormatStrategy();
+        }
     }
 
     /**
@@ -154,7 +163,7 @@
 
                     // must decode back from safe JMS header name to original header name
                     // when storing on this Camel JmsMessage object.
-                    String key = endpoint.getJmsKeyFormatStrategy().decodeKey(name);
+                    String key = jmsKeyFormatStrategy.decodeKey(name);
                     map.put(key, value);
                 } catch (JMSException e) {
                     throw new RuntimeCamelException(name, e);
@@ -200,7 +209,7 @@
     public Message makeJmsMessage(Exchange exchange, org.apache.camel.Message camelMessage, Session session, Exception cause) throws JMSException {
         Message answer = null;
 
-        boolean alwaysCopy = (endpoint != null) && endpoint.getConfiguration().isAlwaysCopyMessage();
+        boolean alwaysCopy = endpoint != null && endpoint.getConfiguration().isAlwaysCopyMessage();
         if (!alwaysCopy && camelMessage instanceof JmsMessage) {
             JmsMessage jmsMessage = (JmsMessage)camelMessage;
             if (!jmsMessage.shouldCreateNewMessage()) {
@@ -432,7 +441,6 @@
      */
     protected boolean shouldOutputHeader(org.apache.camel.Message camelMessage, String headerName,
                                          Object headerValue, Exchange exchange) {
-
         return headerFilterStrategy == null
             || !headerFilterStrategy.applyFilterToCamelHeaders(headerName, headerValue, exchange);
     }