You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@camel.apache.org by Anurag Telang <an...@gmail.com> on 2018/06/01 07:43:42 UTC

Problem with JndiObjectFactoryBean in connection with UserCredentialsConnectionFactoryAdapter while connecting to TIBCO EMS

Hi,

I have TIBCO EMS running in local. I am able to push messages into it and
pull messages from it using following Camel Spring code.

<!----------applicationContext-camel-SpringTibcoQueue.xml ------------>
<bean id="jndiTemplate" class="org.springframework.jndi.JndiTemplate">
<property name="environment">
<props>
<prop
key="java.naming.factory.initial">com.tibco.tibjms.naming.TibjmsInitialContextFactory</prop>
<prop key="java.naming.provider.url">tcp://localhost:7222</prop>
<prop key="java.naming.security.principal"></prop>
<prop key="java.naming.security.credentials"></prop>
</props>
</property>
</bean>
<bean id="jndiFactoryBean"
class="org.springframework.jndi.JndiObjectFactoryBean">
<property name="jndiName" value="QueueConnectionFactory"/>
<property name="jndiTemplate" ref="jndiTemplate"/>
</bean>
<bean id="proxyConnectionFactory"
class="org.springframework.jms.connection.UserCredentialsConnectionFactoryAdapter">
<property name="targetConnectionFactory" ref="jndiFactoryBean"/>
<property name="username" value=""/>
<property name="password" value=""/>
</bean>
<bean id="jndiDestinationResolver"
class="org.springframework.jms.support.destination.JndiDestinationResolver">
<property name="jndiTemplate" ref="jndiTemplate"/>
</bean>
<bean id="jmsConfiguration"
class="org.apache.camel.component.jms.JmsConfiguration">
<property name="connectionFactory" ref="proxyConnectionFactory"/>
<property name="destinationResolver" ref="jndiDestinationResolver"/>
</bean>
<bean id="JmsTibco" class="org.apache.camel.component.jms.JmsComponent">
<property name="configuration" ref="jmsConfiguration" />
</bean>
<camelContext xmlns="http://camel.apache.org/schema/spring">
<route>
<from uri="file:C:/inputFolder?noop=true" />
<to uri="JmsTibco:queue:sampleQueue" />
</route>
</camelContext>

And the following Java code:

public static void main(String[] args) {

AbstractApplicationContext ctx = null;

try {
ctx = new
ClassPathXmlApplicationContext("applicationContext-camel-SpringTibcoQueue.xml");
ctx.start();
Thread.sleep(10000);
ctx.stop();
} catch (Exception e) {
e.printStackTrace();
}
}

*But I am not able to achieve it through non-spring xml (Java
implementation) of it. I have converted the above Camel Spring xml into the
below mentioned java code.*

*My below code is not working. It fails with the error*
"java.lang.ClassCastException:
org.springframework.jndi.JndiObjectFactoryBean cannot be cast to
javax.jms.ConnectionFactory"

public static void main(String[] args) {
SimpleRouteBuilderJavaTibcoQueue routeBuilder = new
SimpleRouteBuilderJavaTibcoQueue();
CamelContext ctx = new DefaultCamelContext();
JndiTemplate jndiTemplate = new JndiTemplate();
Properties environment = new Properties();//jndiTemplate.getEnvironment();
environment.setProperty("java.naming.factory.initial",
"com.tibco.tibjms.naming.TibjmsInitialContextFactory");
environment.setProperty("java.naming.provider.url", "tcp://localhost:7222");
environment.setProperty("java.naming.security.principal", "");
environment.setProperty("java.naming.security.credentials", "");
jndiTemplate.setEnvironment(environment);
JndiObjectFactoryBean jndiFactoryBean = new JndiObjectFactoryBean();
jndiFactoryBean.setJndiName("QueueConnectionFactory");
jndiFactoryBean.setJndiTemplate(jndiTemplate);
UserCredentialsConnectionFactoryAdapter proxyConnectionFactory = new
UserCredentialsConnectionFactoryAdapter();
proxyConnectionFactory.setTargetConnectionFactory((ConnectionFactory)jndiFactoryBean);
JndiDestinationResolver jndiDestinationResolver = new
JndiDestinationResolver();
jndiDestinationResolver.setJndiTemplate(jndiTemplate);
JmsConfiguration jmsConfiguration = new JmsConfiguration();
jmsConfiguration.setConnectionFactory(proxyConnectionFactory);
jmsConfiguration.setDestinationResolver(jndiDestinationResolver);
JmsComponent jmsTibco = new JmsComponent();
jmsTibco.setConfiguration(jmsConfiguration);
try {
ctx.addComponent("jmsTibco", jmsTibco);
ctx.addRoutes(routeBuilder);
ctx.start();
Thread.sleep(10000);
ctx.stop();
} catch (Exception e) {
e.printStackTrace();
}
}

And code for SimpleRouteBuilderJavaTibcoQueue is as follows.

public class SimpleRouteBuilderJavaTibcoQueue extends RouteBuilder{
@Override
public void configure() throws Exception {

from("file:C:/inputFolder?noop=true").to("jmsTibco:queue:sampleQueue");
}
}

Need your help in connecting to connect through Java code to TIBCO EMS.
I hope my this email is readable.

Thanks,
Anurag