mirror of https://github.com/apache/activemq.git
AMQ-4325: Fixed ActiveMQ Camel component to support username/password being configured when using ActiveMQ factory method. Also fixes the factory method would eager create plain connection factory, instead of using createConnectionFactory method as otherwise, which is optimized for AMQ.
This commit is contained in:
parent
1ad6bd59ee
commit
48d615d311
|
@ -138,6 +138,12 @@
|
||||||
<optional>true</optional>
|
<optional>true</optional>
|
||||||
<scope>test</scope>
|
<scope>test</scope>
|
||||||
</dependency>
|
</dependency>
|
||||||
|
<dependency>
|
||||||
|
<groupId>${project.groupId}</groupId>
|
||||||
|
<artifactId>activemq-jaas</artifactId>
|
||||||
|
<optional>true</optional>
|
||||||
|
<scope>test</scope>
|
||||||
|
</dependency>
|
||||||
<dependency>
|
<dependency>
|
||||||
<groupId>${project.groupId}</groupId>
|
<groupId>${project.groupId}</groupId>
|
||||||
<artifactId>activemq-ra</artifactId>
|
<artifactId>activemq-ra</artifactId>
|
||||||
|
|
|
@ -80,8 +80,6 @@ public class ActiveMQComponent extends JmsComponent implements EndpointCompleter
|
||||||
.setBrokerURL(brokerURL);
|
.setBrokerURL(brokerURL);
|
||||||
}
|
}
|
||||||
|
|
||||||
// set the connection factory with the provided broker url
|
|
||||||
answer.setConnectionFactory(new ActiveMQConnectionFactory(brokerURL));
|
|
||||||
return answer;
|
return answer;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -54,7 +54,9 @@ public class AMQ2240Test {
|
||||||
"jms.maxXXXXReconnectAttempts=1&jms.timeout=3000";
|
"jms.maxXXXXReconnectAttempts=1&jms.timeout=3000";
|
||||||
|
|
||||||
LOG.info("creating context with bad URI: " + vmUri);
|
LOG.info("creating context with bad URI: " + vmUri);
|
||||||
ActiveMQComponent.activeMQComponent(vmUri);
|
ActiveMQComponent amq = ActiveMQComponent.activeMQComponent(vmUri);
|
||||||
|
|
||||||
|
amq.getConfiguration().getConnectionFactory();
|
||||||
|
|
||||||
fail("Should have received an exception from the bad URI.");
|
fail("Should have received an exception from the bad URI.");
|
||||||
} catch(Exception e) {
|
} catch(Exception e) {
|
||||||
|
|
|
@ -0,0 +1,49 @@
|
||||||
|
/**
|
||||||
|
* 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.activemq.camel;
|
||||||
|
|
||||||
|
import org.apache.activemq.camel.component.ActiveMQComponent;
|
||||||
|
import org.apache.activemq.camel.component.ActiveMQConfiguration;
|
||||||
|
import org.apache.camel.test.spring.CamelSpringTestSupport;
|
||||||
|
import org.junit.Test;
|
||||||
|
import org.springframework.context.support.AbstractApplicationContext;
|
||||||
|
import org.springframework.context.support.ClassPathXmlApplicationContext;
|
||||||
|
|
||||||
|
public class ActiveMQComponentFactoryUserNamePasswordTest extends CamelSpringTestSupport {
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected AbstractApplicationContext createApplicationContext() {
|
||||||
|
return new ClassPathXmlApplicationContext("org/apache/activemq/camel/ActiveMQComponentFactoryUserNamePassword.xml");
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void testActiveMQ() throws Exception {
|
||||||
|
ActiveMQComponent comp = context.getComponent("activemq", ActiveMQComponent.class);
|
||||||
|
assertNotNull(comp);
|
||||||
|
|
||||||
|
ActiveMQConfiguration config = (ActiveMQConfiguration) comp.getConfiguration();
|
||||||
|
assertNotNull(config);
|
||||||
|
assertEquals("admin2", config.getUserName());
|
||||||
|
assertEquals("secret2", config.getPassword());
|
||||||
|
|
||||||
|
getMockEndpoint("mock:result").expectedBodiesReceived("Hello World");
|
||||||
|
|
||||||
|
template.sendBody("activemq:queue:bar", "Hello World");
|
||||||
|
|
||||||
|
assertMockEndpointsSatisfied();
|
||||||
|
}
|
||||||
|
}
|
|
@ -0,0 +1,49 @@
|
||||||
|
/**
|
||||||
|
* 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.activemq.camel;
|
||||||
|
|
||||||
|
import org.apache.activemq.camel.component.ActiveMQComponent;
|
||||||
|
import org.apache.activemq.camel.component.ActiveMQConfiguration;
|
||||||
|
import org.apache.camel.test.spring.CamelSpringTestSupport;
|
||||||
|
import org.junit.Test;
|
||||||
|
import org.springframework.context.support.AbstractApplicationContext;
|
||||||
|
import org.springframework.context.support.ClassPathXmlApplicationContext;
|
||||||
|
|
||||||
|
public class ActiveMQComponentUserNamePasswordTest extends CamelSpringTestSupport {
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected AbstractApplicationContext createApplicationContext() {
|
||||||
|
return new ClassPathXmlApplicationContext("org/apache/activemq/camel/ActiveMQComponentUserNamePassword.xml");
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void testActiveMQ() throws Exception {
|
||||||
|
ActiveMQComponent comp = context.getComponent("activemq", ActiveMQComponent.class);
|
||||||
|
assertNotNull(comp);
|
||||||
|
|
||||||
|
ActiveMQConfiguration config = (ActiveMQConfiguration) comp.getConfiguration();
|
||||||
|
assertNotNull(config);
|
||||||
|
assertEquals("admin", config.getUserName());
|
||||||
|
assertEquals("secret", config.getPassword());
|
||||||
|
|
||||||
|
getMockEndpoint("mock:result").expectedBodiesReceived("Hello World");
|
||||||
|
|
||||||
|
template.sendBody("activemq:queue:foo", "Hello World");
|
||||||
|
|
||||||
|
assertMockEndpointsSatisfied();
|
||||||
|
}
|
||||||
|
}
|
|
@ -0,0 +1,58 @@
|
||||||
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
|
<!--
|
||||||
|
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.
|
||||||
|
-->
|
||||||
|
<beans xmlns="http://www.springframework.org/schema/beans"
|
||||||
|
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||||
|
xmlns:amq="http://activemq.apache.org/schema/core"
|
||||||
|
xsi:schemaLocation="
|
||||||
|
http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd
|
||||||
|
http://camel.apache.org/schema/spring http://camel.apache.org/schema/spring/camel-spring.xsd
|
||||||
|
http://activemq.apache.org/schema/core http://activemq.apache.org/schema/core/activemq-core.xsd">
|
||||||
|
|
||||||
|
<camelContext xmlns="http://camel.apache.org/schema/spring">
|
||||||
|
<route>
|
||||||
|
<from uri="activemq:queue:bar"/>
|
||||||
|
<to uri="mock:result"/>
|
||||||
|
</route>
|
||||||
|
</camelContext>
|
||||||
|
|
||||||
|
<bean id="activemq" class="org.apache.activemq.camel.component.ActiveMQComponent" factory-method="activeMQComponent">
|
||||||
|
<constructor-arg index="0" value="vm://testBroker2"/>
|
||||||
|
<property name="userName" value="admin2"/>
|
||||||
|
<property name="password" value="secret2"/>
|
||||||
|
</bean>
|
||||||
|
|
||||||
|
<broker brokerName="testBroker2" persistent="false" useShutdownHook="false" deleteAllMessagesOnStartup="true"
|
||||||
|
xmlns="http://activemq.apache.org/schema/core">
|
||||||
|
|
||||||
|
<transportConnectors>
|
||||||
|
<transportConnector uri="vm://testBroker2"/>
|
||||||
|
</transportConnectors>
|
||||||
|
|
||||||
|
<plugins>
|
||||||
|
|
||||||
|
<simpleAuthenticationPlugin>
|
||||||
|
<users>
|
||||||
|
<authenticationUser username="admin2" password="secret2" groups="users,admins"/>
|
||||||
|
</users>
|
||||||
|
</simpleAuthenticationPlugin>
|
||||||
|
|
||||||
|
</plugins>
|
||||||
|
</broker>
|
||||||
|
|
||||||
|
|
||||||
|
</beans>
|
|
@ -0,0 +1,58 @@
|
||||||
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
|
<!--
|
||||||
|
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.
|
||||||
|
-->
|
||||||
|
<beans xmlns="http://www.springframework.org/schema/beans"
|
||||||
|
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||||
|
xmlns:amq="http://activemq.apache.org/schema/core"
|
||||||
|
xsi:schemaLocation="
|
||||||
|
http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd
|
||||||
|
http://camel.apache.org/schema/spring http://camel.apache.org/schema/spring/camel-spring.xsd
|
||||||
|
http://activemq.apache.org/schema/core http://activemq.apache.org/schema/core/activemq-core.xsd">
|
||||||
|
|
||||||
|
<camelContext xmlns="http://camel.apache.org/schema/spring">
|
||||||
|
<route>
|
||||||
|
<from uri="activemq:queue:foo"/>
|
||||||
|
<to uri="mock:result"/>
|
||||||
|
</route>
|
||||||
|
</camelContext>
|
||||||
|
|
||||||
|
<bean id="activemq" class="org.apache.activemq.camel.component.ActiveMQComponent">
|
||||||
|
<property name="brokerURL" value="vm://testBroker"/>
|
||||||
|
<property name="userName" value="admin"/>
|
||||||
|
<property name="password" value="secret"/>
|
||||||
|
</bean>
|
||||||
|
|
||||||
|
<broker brokerName="testBroker" persistent="false" useShutdownHook="false" deleteAllMessagesOnStartup="true"
|
||||||
|
xmlns="http://activemq.apache.org/schema/core">
|
||||||
|
|
||||||
|
<transportConnectors>
|
||||||
|
<transportConnector uri="vm://testBroker"/>
|
||||||
|
</transportConnectors>
|
||||||
|
|
||||||
|
<plugins>
|
||||||
|
|
||||||
|
<simpleAuthenticationPlugin>
|
||||||
|
<users>
|
||||||
|
<authenticationUser username="admin" password="secret" groups="users,admins"/>
|
||||||
|
</users>
|
||||||
|
</simpleAuthenticationPlugin>
|
||||||
|
|
||||||
|
</plugins>
|
||||||
|
</broker>
|
||||||
|
|
||||||
|
|
||||||
|
</beans>
|
Loading…
Reference in New Issue