Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

added custom JMS connection factory for inbound ebms messages #38

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,6 @@
import javax.xml.soap.SOAPException;
import javax.xml.soap.SOAPMessage;

import org.apache.activemq.ActiveMQConnectionFactory;

public class MessageListenerJMSClient extends EbmsEventListener {

Expand All @@ -49,10 +48,7 @@ public class MessageListenerJMSClient extends EbmsEventListener {

@Override
public void init() {
connectionFactory = new ActiveMQConnectionFactory(getConnectionUrl());
((ActiveMQConnectionFactory)connectionFactory).setUserName(getUsername());
((ActiveMQConnectionFactory)connectionFactory).setPassword(getPassword());

connectionFactory = buildConnectionFactory();
}

@Override
Expand Down Expand Up @@ -169,6 +165,26 @@ public String getQueueName() {
return getParameters().getProperty("queueName");
}

protected ConnectionFactory buildConnectionFactory() {
try {
String connectionFactoryUrl = getConnectionUrl();
Class connectionFactoryClass = getConnectionFactoryClass();
ConnectionFactory cf = (ConnectionFactory)connectionFactoryClass.getConstructor(String.class).newInstance(new Object[]{connectionFactoryUrl});
return cf;
} catch (Exception e) {
e.printStackTrace();
return null;
}
}

protected Class getConnectionFactoryClass() throws ClassNotFoundException {
return Class.forName(getConnectionFactoryClassName());
}

protected String getConnectionFactoryClassName() {
return getParameters().getProperty("connectionFactory");
}

protected String getConnectionUrl() {
return getParameters().getProperty("connectionUrl");
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -59,8 +59,8 @@ public static void tearDownClass() throws Exception {
public void setUp() throws JMSException {

instance = spy(new MessageListenerJMSClient());


doReturn("org.apache.activemq.ActiveMQConnectionFactory").when(instance).getConnectionFactoryClassName();
doReturn("vm://mdh?broker.persistent=false").when(instance).getConnectionUrl();
doReturn("testQueue").when(instance).getQueueName();
doReturn(null).when(instance).getUsername();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@

import javax.jms.ConnectionFactory;

import org.apache.activemq.ActiveMQConnectionFactory;
import org.apache.camel.CamelContext;
import org.apache.camel.ConsumerTemplate;
import org.apache.camel.Exchange;
Expand Down Expand Up @@ -59,17 +58,25 @@ public ConsumerTemplate getConsumer() {
}

protected ConnectionFactory buildConnectionFactory() {
String connectionFactoryUrl = getConnectionFactoryUrl();
ActiveMQConnectionFactory cf = new ActiveMQConnectionFactory(connectionFactoryUrl);
cf.setUserName(getUsername());
cf.setPassword(getPassword());
return cf;
try {
String connectionFactoryUrl = getConnectionFactoryUrl();
Class connectionFactoryClass = getConnectionFactoryClass();
ConnectionFactory cf = (ConnectionFactory)connectionFactoryClass.getConstructor(String.class).newInstance(new Object[]{connectionFactoryUrl});
return cf;
} catch (Exception e) {
e.printStackTrace();
return null;
}
}


protected Class getConnectionFactoryClass() throws ClassNotFoundException {
return Class.forName(getParameters().getProperty("connectionFactory"));
}

protected String getConnectionFactoryUrl() {
return getParameters().getProperty("connectionFactoryUrl");
}

protected String getErrorUri() {
return getParameters().getProperty("errorUri",getId() + ":queue:DLQ");
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
<!-- connectionFactoryUrl is the ActiveMQ connection factory URL -->
<!-- example tcp://somehost:61616 -->
<!-- see http://activemq.apache.org/uri-protocols.html for more details -->
<parameter name="connectionFactory" value="${jentrata.activemq.connectionFactory:org.apache.activemq.ActiveMQConnectionFactory}" />
<parameter name="connectionFactoryUrl" value="${jentrata.activemq.connectionFactoryUrl:tcp://localhost:61616}" />
<parameter name="username" value="${jentrata.activemq.username:}" />
<parameter name="password" value="${jentrata.activemq.password:}" />
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,8 @@

<component id="jmsTest" name="test-jms">
<class>org.jentrata.spa.jms.module.JMSComponent</class>
<parameter name="connectionFactoryUrl" value="vm://localhost?broker.persistent=false" />
<parameter name="connectionFactoryUrl" value="vm://localhost?broker.persistent=false" />
<parameter name="connectionFactory" value="org.apache.activemq.ActiveMQConnectionFactory" />
</component>

</module>