Announcement Announcement Module
Collapse
No announcement yet.
ClientId = null in JndiTemplate using tibco Page Title Module
Move Remove Collapse
X
Conversation Detail Module
Collapse
  • Filter
  • Time
  • Show
Clear All
new posts

  • ClientId = null in JndiTemplate using tibco

    I am attempting to use jmsTemplate to consume messages off of a topic. The JMS server is tibco (JMS version 1.1). This server requires a authentication. When I run my sample program I get a "org.springframework.jms.JmsSecurityException: Not permitted;". Judging from the log entry below it appears that my credentials are not being passed "ClientId=null". I am missing something on the setup?


    Output from spring log

    Code:
    Aug 31 2009 11:38:35.571 AM INFO  org.springframework.jms.connection.CachingConnectionFactory : Established shared JMS Connection: TopicConnection[ClientId=null Connected=tcp://myservername:7222, URL=tcp://myservername:7222]
    topic-context.xml

    Code:
    <!-- lookup the connection info -->
    <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://myservername:7222</prop> 
              <prop key="java.naming.security.principal">username</prop> 
              <prop key="java.naming.security.credentials">password</prop>
           </props> 
        </property> 
     </bean> 
      
    <bean id="jndiTopicConnectionFactory" class="org.springframework.jndi.JndiObjectFactoryBean"> 
        <property name="jndiTemplate" ref="jndiTemplate"/> 
        <property name="jndiName" value="TopicConnectionFactory"/> 
    </bean> 
    
    <bean id="topicConnectionFactory" class="org.springframework.jms.connection.CachingConnectionFactory"> 
       <property name="targetConnectionFactory" ref="jndiTopicConnectionFactory"/> 
       <property name="sessionCacheSize" value="1"/> 
    </bean>        
    
    <bean id="destinationResolver"  class="org.springframework.jms.support.destination.JndiDestinationResolver"> 
       <property name="jndiTemplate" ref="jndiTemplate"/> 
       <property name="cache" value="true"/> 
       <property name="fallbackToDynamicDestination" value="false"/> 
    </bean> 
    
    <bean id="jmsTemplate" class="org.springframework.jms.core.JmsTemplate"> 
       <property name="connectionFactory" ref="topicConnectionFactory"/> 
       <property name="destinationResolver" ref="destinationResolver"/> 
       <property name="defaultDestinationName" value="Updates_Topic"/> 
       <property name="receiveTimeout" value="30000"/> 
       <property name="pubSubDomain" value="true"/> 
    </bean>


    Code:
    public class SimpleJMSReceiver {
    
       public static void main(String[] args) {
         try {
            ApplicationContext ctx =  new FileSystemXmlApplicationContext("topic-context.xml");
           
           JmsTemplate jmsTemplate = (JmsTemplate)ctx.getBean("jmsTemplate");
           Message msg = jmsTemplate.receive();
           
           if (msg instanceof TextMessage) {
              System.out.println(((TextMessage)msg).getText());
           } else {
              throw new IllegalStateException("Message type not supported");
           }
         } catch (Exception ex) {
             ex.printStackTrace();
         }
       }
    }

  • #2
    I found out how to set the clientId but am still getting the security exception.


    Code:
    <bean id="topicConnectionFactory" class="org.springframework.jms.connection.CachingConnectionFactory"> 
       <property name="targetConnectionFactory" ref="jndiTopicConnectionFactory"/> 
       <property name="sessionCacheSize" value="1"/> 
       <property name="clientId" value="username" />
    </bean>

    Comment


    • #3
      This is how we have ours setup and it works fine:

      Code:
      <bean id="tibcoJndiTemplate" 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">${tibco.naming.provider.url}</prop>
              <prop key="java.naming.security.principal">admin</prop>
            </props>
          </property>
        </bean>

      Comment


      • #4
        It turns out my security exception is related to not passing userid/password when creating the topic connection. If I create a connection using the code below it works. How can I do the equivalent in spring?

        Code:
        ...
        Context ctx = new InitialContext(env);
        TopicConnectionFactory qFactory = (TopicConnectionFactory)
          ctx.lookup("TopicConnectionFactory");
        
        // this works
        tConnect = qFactory.createTopicConnection("user","password");
        
        // this causes exception
        //tConnect = qFactory.createTopicConnection();
        ...

        Comment


        • #5
          I got it working by wrapping the connection factory with UserCredentialsConnectionFactoryAdapter.

          Comment


          • #6
            This is my complete Tibco JMS configuration for spring, however we are using Atomikos so keep that in mind..

            Code:
            <bean id="queueConnectionFactoryBean" class="org.springframework.jms.connection.SingleConnectionFactory" destroy-method="destroy">
                  <constructor-arg>
                    <bean class="com.atomikos.jms.QueueConnectionFactoryBean" init-method="init">
                      <property name="xaQueueConnectionFactory" ref="queueConnectionFactoryXa"/>
                    </bean>
                  </constructor-arg>
                  <property name="reconnectOnException"  value="true"></property>
              </bean>
              
              <bean id="queueConnectionFactoryXa"
                    class="com.tibco.tibjms.TibjmsXAQueueConnectionFactory">
                    <property name="serverUrl">
                        <value>${tibco.naming.provider.url}</value>
                    </property>
              </bean>
            
              <bean id="tibcoDestinationResolver" class="org.springframework.jms.support.destination.JndiDestinationResolver">
                <property name="jndiTemplate"><ref local="tibcoJndiTemplate" /></property>
              </bean>
              
              
              <bean id="tibcoJndiTemplate" 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">${tibco.naming.provider.url}</prop>
                    <prop key="java.naming.security.principal">admin</prop>
                  </props>
                </property>
              </bean>
              
              <bean id="jmsTemplateXa" class="org.springframework.jms.core.JmsTemplate">
                <property name="connectionFactory"><ref local="queueConnectionFactoryBean" /></property>
                <property name="destinationResolver"><ref local="tibcoDestinationResolver" /></property>
                <property name="receiveTimeout" value="-1"/>
                <!-- Atomikos needs this to be set to work correctly -->
                <property name="sessionTransacted" value="true"/>
              </bean>
              
              <bean id="messageSenderHelper" class="com.qualcomm.qdc.common.spring.jms.TibcoMessageSenderHelperImpl">
                  <property name="jmsTemplate" ref="jmsTemplateXa"/>
              </bean>

            Comment

            Working...
            X