cxf-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From cschnei...@apache.org
Subject [1/2] cxf git commit: [CXF-7344] Fix for jms rest problem. Convert dots to underscores
Date Thu, 27 Apr 2017 15:14:16 GMT
Repository: cxf
Updated Branches:
  refs/heads/master 6070ddeef -> 7fab62456


[CXF-7344] Fix for jms rest problem. Convert dots to underscores


Project: http://git-wip-us.apache.org/repos/asf/cxf/repo
Commit: http://git-wip-us.apache.org/repos/asf/cxf/commit/7fab6245
Tree: http://git-wip-us.apache.org/repos/asf/cxf/tree/7fab6245
Diff: http://git-wip-us.apache.org/repos/asf/cxf/diff/7fab6245

Branch: refs/heads/master
Commit: 7fab6245608119634271e580166120b9c55dce48
Parents: 0a4d267
Author: Christian Schneider <chris@die-schneider.net>
Authored: Thu Apr 27 17:14:01 2017 +0200
Committer: Christian Schneider <chris@die-schneider.net>
Committed: Thu Apr 27 17:14:12 2017 +0200

----------------------------------------------------------------------
 .../transport/jms/JMSMessageHeadersType.java    |  7 +-
 .../cxf/transport/jms/JMSHeaderTypeTest.java    | 73 ++++++++++++++++++++
 2 files changed, 79 insertions(+), 1 deletion(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/cxf/blob/7fab6245/rt/transports/jms/src/main/java/org/apache/cxf/transport/jms/JMSMessageHeadersType.java
----------------------------------------------------------------------
diff --git a/rt/transports/jms/src/main/java/org/apache/cxf/transport/jms/JMSMessageHeadersType.java
b/rt/transports/jms/src/main/java/org/apache/cxf/transport/jms/JMSMessageHeadersType.java
index 9fcafba..1325112 100644
--- a/rt/transports/jms/src/main/java/org/apache/cxf/transport/jms/JMSMessageHeadersType.java
+++ b/rt/transports/jms/src/main/java/org/apache/cxf/transport/jms/JMSMessageHeadersType.java
@@ -72,10 +72,15 @@ public class JMSMessageHeadersType {
     }
     
     public void putProperty(String key, Object value) {
-        properties.put(key, value);
+        String escapedKey = key.replace(".", "_");
+        properties.put(escapedKey, value);
     }
     
     public Object getProperty(String key) {
+        String escapedKey = key.replace(".", "_");
+        if (properties.containsKey(escapedKey)) {
+            return properties.get(escapedKey);
+        }
         return properties.get(key);
     }
     

http://git-wip-us.apache.org/repos/asf/cxf/blob/7fab6245/rt/transports/jms/src/test/java/org/apache/cxf/transport/jms/JMSHeaderTypeTest.java
----------------------------------------------------------------------
diff --git a/rt/transports/jms/src/test/java/org/apache/cxf/transport/jms/JMSHeaderTypeTest.java
b/rt/transports/jms/src/test/java/org/apache/cxf/transport/jms/JMSHeaderTypeTest.java
new file mode 100644
index 0000000..2e66b28
--- /dev/null
+++ b/rt/transports/jms/src/test/java/org/apache/cxf/transport/jms/JMSHeaderTypeTest.java
@@ -0,0 +1,73 @@
+/**
+ * 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.cxf.transport.jms;
+
+import java.util.Set;
+
+import javax.jms.Connection;
+import javax.jms.JMSException;
+import javax.jms.Message;
+import javax.jms.Session;
+
+import org.apache.activemq.ActiveMQConnectionFactory;
+import org.junit.Assert;
+import org.junit.Test;
+
+import static org.junit.Assert.assertEquals;
+
+public class JMSHeaderTypeTest {
+
+    private static final String TEST_VALUE = "test";
+    private static final String CONVERTED_RESPONSE_KEY = "org_apache_cxf_message_Message_RESPONSE_CODE";
+    
+    @Test
+    public void testConversionIn() throws JMSException {
+        Message message = createMessage();
+        message.setStringProperty(org.apache.cxf.message.Message.RESPONSE_CODE, TEST_VALUE);
+        JMSMessageHeadersType messageHeaders = JMSMessageHeadersType.from(message);
+        Set<String> keys = messageHeaders.getPropertyKeys();
+        Assert.assertEquals(1, keys.size());
+        assertEquals(CONVERTED_RESPONSE_KEY, keys.iterator().next());
+        assertEquals(TEST_VALUE, (String)messageHeaders.getProperty(org.apache.cxf.message.Message.RESPONSE_CODE));
+        assertEquals(TEST_VALUE, (String)messageHeaders.getProperty(CONVERTED_RESPONSE_KEY));
+    }
+    
+    @Test
+    public void testConversionOut() throws JMSException {
+        Message message = createMessage();
+        
+        message.setStringProperty(org.apache.cxf.message.Message.RESPONSE_CODE, TEST_VALUE);
+        JMSMessageHeadersType messageHeaders = new JMSMessageHeadersType();
+        messageHeaders.putProperty(org.apache.cxf.message.Message.RESPONSE_CODE, TEST_VALUE);
+        messageHeaders.writeTo(message);
+        
+        Assert.assertEquals(CONVERTED_RESPONSE_KEY, message.getPropertyNames().nextElement());
+        
+    }
+
+    private Message createMessage() throws JMSException {
+        ActiveMQConnectionFactory cf = new ActiveMQConnectionFactory("vm://test?broker.persistent=false");
+        Connection connection = cf.createConnection();
+        connection.start();
+        Session session = connection.createSession(false, Session.AUTO_ACKNOWLEDGE);
+        Message message = session.createMessage();
+        connection.stop();
+        return message;
+    }
+}


Mime
View raw message