Connect to EMS JMS queue using Spring3 + JNDI

11,666

Solution 1

Got it - needed to wrap the connection factory in a UserCredentialsConnectionFactory:

<bean id="authenticationConnectionFactory"
    class="org.springframework.jms.connection.UserCredentialsConnectionFactoryAdapter">
    <property name="targetConnectionFactory" ref="jmsConnectionFactory" />
    <property name="username" value="yyyyy" />
    <property name="password" value="xxxx" />
</bean>

<bean id="jmsTemplate" class="org.springframework.jms.core.JmsTemplate">
    <property name="connectionFactory" ref="authenticationConnectionFactory" />
    <property name="destinationResolver" ref="jmsDestinationResolver" />
    <property name="defaultDestination" ref="destination" />

Solution 2

I had some similar problem , solution was to add (besides solution from this question)

<prop key="java.naming.security.principal">username</prop>
<prop key="java.naming.security.credentials">password</prop>

to jndiTemplate bean configuration

Solution 3

I don't have any experience with EMS, but user and password are typically set on the connection factory, so you'd want to configure that on the object being provided by JNDI.

Share:
11,666
ChrisM
Author by

ChrisM

Updated on June 26, 2022

Comments

  • ChrisM
    ChrisM almost 2 years

    I'm having some issues create a connection to (and reading from) a Tibco EMS JMS queue.

    <beans>
        <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://ems-dit-am-uat-1.app.xxx.net:30055</prop>
                </props>
            </property>
        </bean>
    
        <bean id="jmsConnectionFactory" class="org.springframework.jndi.JndiObjectFactoryBean">
            <property name="jndiTemplate" ref="jndiTemplate" /> <property name="jndiName"
            value="DRDRFIQueueConnectionFactory" /> </bean>
    
        <bean id="jmsDestinationResolver"
            class="org.springframework.jms.support.destination.JndiDestinationResolver">
            <property name="jndiTemplate" ref="jndiTemplate" />
            <property name="cache" value="true" />
        </bean>
    
        <bean id="destination" class="org.springframework.jndi.JndiObjectFactoryBean">
            <property name="jndiTemplate" ref="jndiTemplate" />
            <property name="jndiName" value="Q.NY.DERIV.DRD.RFI" />
        </bean>
    
        <bean id="jmsTemplate" class="org.springframework.jms.core.JmsTemplate">
            <property name="connectionFactory" ref="jmsConnectionFactory" />
            <property name="destinationResolver" ref="jmsDestinationResolver" />
            <property name="defaultDestination" ref="destination" />
        </bean>
    
    
        <bean id="jmsReceiver" class="com.csfb.fao.rds.rfi.application.DRDReceiverTst">
            <property name="jmsTemplate">
                <ref bean="jmsTemplate" />
            </property>
        </bean>
    
    </beans>
    

    The exception I'm getting is:

    javax.naming.AuthenticationException: Not permitted: invalid name or password [Root exception is javax.jms.JMSSecurityException: invalid name or password] at com.tibco.tibjms.naming.TibjmsContext.lookup(TibjmsContext.java:668) at com.tibco.tibjms.naming.TibjmsContext.lookup(TibjmsContext.java:489) at javax.naming.InitialContext.lookup(InitialContext.java:392) at org.springframework.jndi.JndiTemplate$1.doInContext(JndiTemplate.java:154) at org.springframework.jndi.JndiTemplate.execute(JndiTemplate.java:87) at org.springframework.jndi.JndiTemplate.lookup(JndiTemplate.java:152) at org.springframework.jndi.JndiTemplate.lookup(JndiTemplate.java:178) at org.springframework.jndi.JndiLocatorSupport.lookup(JndiLocatorSupport.java:95) at org.springframework.jndi.JndiObjectLocator.lookup(JndiObjectLocator.java:105) at org.springframework.jndi.JndiObjectFactoryBean.lookupWithFallback(JndiObjectFactoryBean.java:201) at org.springframework.jndi.JndiObjectFactoryBean.afterPropertiesSet(JndiObjectFactoryBean.java:187) at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.invokeInitMethods(AbstractAutowireCapableBeanFactory.java:1477) at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.initializeBean(AbstractAutowireCapableBeanFactory.java:1417) ... 12 more

    The only user/password I've been given is for the JMS queue itself - where do I set that?

    Thanks Chris

  • ChrisM
    ChrisM almost 13 years
    How do I set the user/pwd on a JndiObjectFactoryBean that returns the JMS Connection factory? I can't set it in the 'jmsConnectionFactory' bean above....
  • Ryan Stewart
    Ryan Stewart almost 13 years
    @Chris: You don't set it there. The JndiObjectFactoryBean only retrieves an object from the JNDI registry. The connection factory, being the thing responsible for creating connections, is where you have to set the credentials. You need to go wherever the connection factory is being configured in JNDI and fix it there.