Announcement Announcement Module
Collapse
No announcement yet.
javax.naming.NameNotFoundException problem Page Title Module
Move Remove Collapse
X
Conversation Detail Module
Collapse
  • Filter
  • Time
  • Show
Clear All
new posts

  • javax.naming.NameNotFoundException problem

    Hi,

    I am new to MQ and never worked with JNDI also.

    I am trying to run MQ example given in the ibm website at the URL:

    http://www-128.ibm.com/developerwork...ry/wa-spring4/

    Here is my code:

    Message Receiver Class:
    Code:
    import javax.jms.Message;
    import javax.jms.TextMessage;
    
    import org.springframework.jms.core.JmsTemplate;
    import org.springframework.jms.core.JmsTemplate102;
    
    public class JmsReceiver {
    
    	private JmsTemplate102 jmsTemplate102;
    	private JmsTemplate jmsTemplate;
    
    	public void setJmsTemplate102(JmsTemplate102 jmsTemplate102) {
    		this.jmsTemplate102 = jmsTemplate102;
    	}
    
    	public JmsTemplate102 getJmsTemplate102() {
    		return jmsTemplate102;
    	}
    
    	public void setJmsTemplate(JmsTemplate jmsTemplate) {
    		this.jmsTemplate = jmsTemplate;
    	}
    
    	public JmsTemplate getJmsTemplate() {
    		return jmsTemplate;
    	}
    	
        public void processMessage() {
        	
    //		Message msg = jmsTemplate102.receive("JMS_RequestResponseQueue");
    
        	Message msg = jmsTemplate.receive("RequestResponseQueue");
    		
    		try {
    			TextMessage textMessage = (TextMessage) msg;
    			if (msg != null) {
    				System.out.println(" Message Received -->"
    					+ textMessage.getText());
    			}
    		} catch (Exception e) {
    			e.printStackTrace();
    		}
    		
    	}
    	
    }

    Message Sender Class:
    Code:
    import javax.jms.JMSException;
    import javax.jms.Message;
    import javax.jms.Session;
    
    import org.springframework.jms.core.JmsTemplate;
    import org.springframework.jms.core.JmsTemplate102;
    import org.springframework.jms.core.MessageCreator;
    
    
    public class JmsSender {
    	
    	private JmsTemplate102 jmsTemplate102;
    	private JmsTemplate jmsTemplate;
    
    	public void setJmsTemplate102(JmsTemplate102 jmsTemplate102) {
    		this.jmsTemplate102 = jmsTemplate102;
    	}
    
    	public JmsTemplate102 getJmsTemplate102() {
    		return jmsTemplate102;
    	}
    
    	public void setJmsTemplate(JmsTemplate jmsTemplate) {
    		this.jmsTemplate = jmsTemplate;
    	}
    
    	public JmsTemplate getJmsTemplate() {
    		return jmsTemplate;
    	}
    
    //	public void sendMessage(){
    //		jmsTemplate102.send("JMS_RequestResponseQueue", new MessageCreator(){
    //	        public Message createMessage(Session session) 
    //	            throws JMSException {
    //		        	return session.createTextMessage("This is a sample message");
    //		        }
    //		});
    //	}
    	
    	public void sendMessage(String text){
    		final String textMessage = text.toString();
    		jmsTemplate.send("RequestResponseQueue", new MessageCreator(){
    	        public Message createMessage(Session session) 
    	            throws JMSException {
    		        	return session.createTextMessage(textMessage);
    		        }
    		});
    	}
    	
    }
    Test class:
    Code:
     
    import org.springframework.context.ApplicationContext;
    import org.springframework.context.support.ClassPathXmlApplicationContext;
    import com.myorg.ss.queues.mq.JmsSender;
    
    public class MDBTest {
    
    	public static void main(String args[]) {
            ApplicationContext context = new ClassPathXmlApplicationContext("classpath:shared-context.xml");
            JmsSender jmsSender = (JmsSender)context.getBean("jmsSender");
            System.out.println("JmsSender: " + jmsSender);
            jmsSender.sendMessage("Hello! Finally some thing happening here");        
    	}
    }
    shared-context.xml
    Code:
    <?xml version="1.0" encoding="UTF-8"?>
    <!DOCTYPE beans PUBLIC "-//SPRING//DTD BEAN//EN" 
    	"http://www.springframework.org/dtd/spring-beans.dtd">
    
    <beans>	
    	<!-- JNDI Template configuration for JNDI lookup -->	
    	<bean id="jndiTemplate" class="org.springframework.jndi.JndiTemplate">
    		<property name="environment">
    			<props>
    				<prop key="java.naming.factory.initial">com.sun.jndi.fscontext.RefFSContextFactory</prop>
    				<prop key="java.naming.provider.url">file:/C:/JNDI-Directory</prop>
    			</props>
    		</property>
    	</bean>
    	
    	<!-- JMS Connection Factory Configuration through JNDI -->
    	<bean id="internalJmsQueueConnectionFactory" 
    		class="org.springframework.jndi.JndiObjectFactoryBean">
    		<property name="jndiTemplate">
    			<ref bean="jndiTemplate"/>
    		</property>		
    		<property name="jndiName">
    			<value>MQ_JMS_MANAGER</value>
    		</property> 
    		<!-- 
    		<property name="jndiName">
    			<value>ZAC01</value>
    		</property> -->
    	</bean>
    
    	<!-- Spring JMS Queue Connection Factory -->
    	<bean id="jmsQueueConnectionFactory" 
    		class="org.springframework.jms.connection.SingleConnectionFactory">
    		<property name="targetConnectionFactory">
    			<ref bean="internalJmsQueueConnectionFactory"/>
    		</property>
    	    <property name="pubSubDomain">
                <value>false</value>
            </property>
    	</bean>
    	
    	<!-- JMS Destination Resolver -->
    	<bean id="jmsDestinationResolver" 
    		class="org.springframework.jms.support.destination.JndiDestinationResolver">
    		<property name="jndiTemplate">
    			<ref bean="jndiTemplate"/>
    		</property>
    		<property name="cache">
    			<value>true</value>
    		</property>
    	</bean>
    
    	<!-- JMS Queue Template configuration -->	
    	<bean id="jmsQueueTemplate"
    		class="org.springframework.jms.core.JmsTemplate">
    		<property name="connectionFactory">
    			<ref bean="jmsQueueConnectionFactory"/>
    		</property>
    		<property name="destinationResolver">
    			<ref bean="jmsDestinationResolver"/>
    		</property>
    		<!-- 
    		<property name="defaultDestinationName">
    			<value>RequestResponseQueue</value>
    		</property> 
    		-->
    		<property name="pubSubDomain">
    			<value>false</value>
    		</property>		
    		<property name="receiveTimeout">
    			<value>20000</value>
    		</property>
    	</bean>
    	
    	<!-- *************** Wiring JmsTemplate into SuperScripts Application *************** -->
    	<bean id="jmsSender" class="com.myorg.ss.queues.mq.JMSSender">
    		<property name="jmsTemplate">
    			<ref bean="jmsQueueTemplate"/>
    		</property>
    	</bean>
    
    	<bean id="jmsReceiver" class="com.myorg.ss.queues.mq.JMSReceiver">
    		<property name="jmsTemplate">
    			<ref bean="jmsQueueTemplate"/>
    		</property>
    	</bean>
    
    </beans>
    I am using RAD 7.0 and Websphere MQ 7.0 to run this program.

    When I ran the Test class I am getting following error:

    Code:
    Exception in thread "main" org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'internalJmsQueueConnectionFactory' defined in class path resource [shared-context.xml]: Invocation of init method failed; nested exception is javax.naming.NameNotFoundException: MQ_JMS_MANAGER
    	at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.initializeBean(AbstractAutowireCapableBeanFactory.java:1302)
    	at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:463)
    	at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory$1.run(AbstractAutowireCapableBeanFactory.java:404)
    	at java.security.AccessController.doPrivileged(Native Method)
    	at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:375)
    	at org.springframework.beans.factory.support.AbstractBeanFactory$1.getObject(AbstractBeanFactory.java:263)
    	at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:170)
    	at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:260)
    	at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:184)
    	at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:163)
    	at org.springframework.beans.factory.support.DefaultListableBeanFactory.preInstantiateSingletons(DefaultListableBeanFactory.java:424)
    	at org.springframework.context.support.AbstractApplicationContext.finishBeanFactoryInitialization(AbstractApplicationContext.java:729)
    	at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:381)
    	at org.springframework.context.support.ClassPathXmlApplicationContext.<init>(ClassPathXmlApplicationContext.java:139)
    	at org.springframework.context.support.ClassPathXmlApplicationContext.<init>(ClassPathXmlApplicationContext.java:83)
    	at com.myorg.ss.utils.MDBTest.main(MDBTest.java:17)
    Caused by: javax.naming.NameNotFoundException: MQ_JMS_MANAGER
    	at com.sun.jndi.fscontext.RefFSContext.getObjectFromBindings(RefFSContext.java:400)
    	at com.sun.jndi.fscontext.RefFSContext.lookupObject(RefFSContext.java:327)
    	at com.sun.jndi.fscontext.RefFSContext.lookup(RefFSContext.java:146)
    	at com.sun.jndi.fscontext.FSContext.lookup(FSContext.java:127)
    	at javax.naming.InitialContext.lookup(Unknown Source)
    	at org.springframework.jndi.JndiTemplate$1.doInContext(JndiTemplate.java:132)
    	at org.springframework.jndi.JndiTemplate.execute(JndiTemplate.java:88)
    	at org.springframework.jndi.JndiTemplate.lookup(JndiTemplate.java:130)
    	at org.springframework.jndi.JndiTemplate.lookup(JndiTemplate.java:155)
    	at org.springframework.jndi.JndiLocatorSupport.lookup(JndiLocatorSupport.java:93)
    	at org.springframework.jndi.JndiObjectLocator.lookup(JndiObjectLocator.java:105)
    	at org.springframework.jndi.JndiObjectFactoryBean.lookupWithFallback(JndiObjectFactoryBean.java:192)
    	at org.springframework.jndi.JndiObjectFactoryBean.afterPropertiesSet(JndiObjectFactoryBean.java:179)
    	at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.invokeInitMethods(AbstractAutowireCapableBeanFactory.java:1333)
    	at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.initializeBean(AbstractAutowireCapableBeanFactory.java:1299)
    I defined a JNDI-Directory.file in the C drive with the following code snippet:
    MQ_JMS_MANAGER=zAC01

    Please help me how can fix this and run this program?

    Any help is really appreciated. Thanks in advance.
    rsrch
    Last edited by rsrch; Jul 29th, 2008, 12:04 PM. Reason: Modifying some code

  • #2
    I followed the same article and was able to get it working.
    Have you followed the steps detailed in settingup the QueManager? Yhat section there is a part where you need to setup the jndi environment which is very important.

    Comment


    • #3
      Originally posted by vijaycr View Post
      I followed the same article and was able to get it working.
      Have you followed the steps detailed in settingup the QueManager? Yhat section there is a part where you need to setup the jndi environment which is very important.
      Hi Vijay,

      Can you please explain how you set up your JNDI environment?
      Can you please explain what I am supposed to do with JNDI environment?

      I am learning setting up JNDI. I know I didn't set up JNDI environment properly.

      Please respond ASAP.

      Thanks,
      rsrch

      Comment


      • #4
        Its already in the airticle. Check the section sub section Set up JMS and JNDI administration under the sectionQueue manager setup

        Comment


        • #5
          Originally posted by vijaycr View Post
          Its already in the airticle. Check the section sub section Set up JMS and JNDI administration under the sectionQueue manager setup
          Thanks Vijay. I didn't follow Queue Manager Setup part correctly. Now it's working. By the way are you from Andhra?

          Thanks,
          rsrch

          Comment

          Working...
          X