Hi,
I recently encountered a bug with the handling of usernames and passwords in
JMS configuration. The bug is that the connection username was being set as
the password on a JMS endpoint. The details of the problem I was encountering
are here:
http://cxf.547215.n5.nabble.com/JMS-Username-Password-issue-td4384709.html
I have taken the liberty of patching the bug, the patch file is attached. I
tried to follow the submission instructions and create a JIRA item, but
unfortunately I don't seem to have authority to create a JIRA item as an
anonymous user. You will also notice that I have done some very mild
refactoring to make the code a bit more testable and avoid sending messages and
relying on the timing of sleep statements for the test to pass.
Regards,
Chris Pike
This email and any attachments may contain information which is confidential
and/or privileged. The information is intended exclusively for the addressee
and the views expressed may not be official policy, but the personal views of
the originator. If you are not the intended recipient, be aware that any
disclosure, copying, distribution or use of the contents is prohibited. If you
have received this email and any file transmitted with it in error, please
notify the sender by telephone or return email immediately and delete the
material from your computer. Internet communications are not secure and Lab49
is not responsible for their abuse by third parties, nor for any alteration or
corruption in transmission, nor for any damage or loss caused by any virus or
other defect. Lab49 accepts no liability or responsibility arising out of or in
any way connected to this email.
Index:
rt/transports/jms/src/test/java/org/apache/cxf/transport/jms/OldConfigTest.java
===================================================================
---
rt/transports/jms/src/test/java/org/apache/cxf/transport/jms/OldConfigTest.java
(revision 0)
+++
rt/transports/jms/src/test/java/org/apache/cxf/transport/jms/OldConfigTest.java
(revision 0)
@@ -0,0 +1,45 @@
+/**
+ * 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 junit.framework.Assert;
+import org.apache.cxf.transport.jms.uri.JMSEndpoint;
+import org.junit.BeforeClass;
+import org.junit.Test;
+
+
+public class OldConfigTest extends AbstractJMSTester {
+
+ @BeforeClass
+ public static void createAndStartBroker() throws Exception {
+ startBroker(new JMSBrokerSetup("tcp://localhost:61500"));
+ }
+
+ @Test
+ public void testUsernameAndPassword() throws Exception {
+ setupServiceInfo("http://cxf.apache.org/hello_world_jms",
"/wsdl/jms_test.wsdl",
+ "HelloWorldService", "HelloWorldPort");
+ JMSOldConfigHolder holder = new JMSOldConfigHolder();
+ JMSEndpoint endpoint = holder.getExtensorsAndConfig(bus, endpointInfo,
target, false);
+ holder.configureEndpoint(false, endpoint);
+ Assert.assertEquals("User name does not match." , "testUser",
endpoint.getUsername());
+ Assert.assertEquals("Password does not match." , "testPassword",
endpoint.getPassword());
+ }
+}
Index:
rt/transports/jms/src/main/java/org/apache/cxf/transport/jms/JMSOldConfigHolder.java
===================================================================
---
rt/transports/jms/src/main/java/org/apache/cxf/transport/jms/JMSOldConfigHolder.java
(revision 1101995)
+++
rt/transports/jms/src/main/java/org/apache/cxf/transport/jms/JMSOldConfigHolder.java
(working copy)
@@ -124,7 +124,7 @@
* then be used to configure the JMSConfiguration object
* @param target
*/
- private JMSEndpoint getExtensorsAndConfig(Bus bus,
+ protected JMSEndpoint getExtensorsAndConfig(Bus bus,
EndpointInfo endpointInfo,
EndpointReferenceType target,
boolean isConduit) throws IOException {
@@ -184,6 +184,10 @@
throws IOException {
JMSEndpoint endpoint = getExtensorsAndConfig(bus, endpointInfo,
target, isConduit);
+ return configureEndpoint(isConduit, endpoint);
+ }
+
+ protected JMSConfiguration configureEndpoint(boolean isConduit,
JMSEndpoint endpoint) {
if (address != null) {
mapAddressToEndpoint(address, endpoint);
}
@@ -197,7 +201,7 @@
? DeliveryMode.PERSISTENT : DeliveryMode.NON_PERSISTENT;
jmsConfig.setDeliveryMode(deliveryMode);
}
-
+
if (endpoint.isSetPriority()) {
int priority = endpoint.getPriority();
jmsConfig.setPriority(priority);
@@ -210,10 +214,10 @@
JNDIConfiguration jndiConfig = new JNDIConfiguration();
jndiConfig.setJndiConnectionFactoryName(endpoint.getJndiConnectionFactoryName());
jmsConfig.setJndiTemplate(jt);
-
+
jndiConfig.setConnectionUserName(endpoint.getUsername());
jndiConfig.setConnectionPassword(endpoint.getPassword());
-
+
jmsConfig.setJndiConfig(jndiConfig);
if (endpoint.isSetReconnectOnException()) {
jmsConfig.setReconnectOnException(endpoint.isReconnectOnException());
@@ -281,7 +285,7 @@
}
}
}
-
+
String requestURI = endpoint.getRequestURI();
jmsConfig.setRequestURI(requestURI);
@@ -289,7 +293,7 @@
jmsConfig.setTargetService(targetService);
return jmsConfig;
}
-
+
private static void setReplyDestination(JMSConfiguration jmsConfig,
JMSEndpoint endpoint) {
if (endpoint.getReplyToName() != null) {
jmsConfig.setReplyDestination(endpoint.getReplyToName());
@@ -314,7 +318,7 @@
endpoint.setUsername(address.getConnectionUserName());
}
if (address.isSetConnectionPassword()) {
- endpoint.setPassword(address.getConnectionUserName());
+ endpoint.setPassword(address.getConnectionPassword());
}
if (address.isSetReconnectOnException()) {
endpoint.setReconnectOnException(address.isReconnectOnException());