1
votes

when I run my application, I have an error about the JNDI connection. Precisely, the error happens on a lookup. Here's the code :

   public static final String PROPERTIES_FILE = "jms-server"; //$NON-NLS-1$

   private static Logger logger = Logger.getLogger(JmsMessageProducer.class);

   private static final ResourceBundle res = ResourceBundle.getBundle(PROPERTIES_FILE);

   private static final String JBOSS_JNDI_PROVIDER_URL = res.getString("JBOSS_JNDI_PROVIDER_URL");

   private static final String JBOSS_JNDI_INITIAL_CONTEXT_FACTORY = res
         .getString("JBOSS_JNDI_INITIAL_CONTEXT_FACTORY");

   private static final String JBOSS_JMS_CONNECTION_FACTORY = res
         .getString("JBOSS_JMS_CONNECTION_FACTORY");

   private static final String JNDI_INPUT_JMS_QUEUE = res.getString("JNDI_INPUT_JMS_QUEUE");


   /**
    * Send JMS Text Message
    * 
    * @param myString
    */
   @SuppressWarnings({"unchecked", "rawtypes"})
   public void sendJmsTextMessage(String myString) {

      Context jndiContext = null;
      ConnectionFactory connectionFactory = null;
      Connection connection = null;
      Session session = null;
      Queue queue = null;
      MessageProducer messageProducer = null;

      try {
         // [1] Create a JNDI API InitialContext object.
         Hashtable properties = new Hashtable(2);
         properties.put(Context.INITIAL_CONTEXT_FACTORY, JBOSS_JNDI_INITIAL_CONTEXT_FACTORY);
         properties.put(Context.PROVIDER_URL, JBOSS_JNDI_PROVIDER_URL);
         logger.debug("Create Jndi Context with :" + Context.INITIAL_CONTEXT_FACTORY + "="
               + JBOSS_JNDI_INITIAL_CONTEXT_FACTORY + " " + Context.PROVIDER_URL + "="
               + JBOSS_JNDI_PROVIDER_URL);
         jndiContext = new InitialContext(properties);

         // [2] Look up connection factory and queue.
         logger.debug("Create connexion factory :" + JBOSS_JMS_CONNECTION_FACTORY);
         connectionFactory = (ConnectionFactory) jndiContext.lookup(JBOSS_JMS_CONNECTION_FACTORY);
         logger.debug("Create queue :" + JNDI_INPUT_JMS_QUEUE);
         queue = (Queue) jndiContext.lookup(JNDI_INPUT_JMS_QUEUE);

So, he's looking in the jms-server.properties files :

JBOSS_JNDI_PROVIDER_URL = jnp://localhost:1199
JBOSS_JNDI_INITIAL_CONTEXT_FACTORY = org.jnp.interfaces.NamingContextFactory
JBOSS_JMS_CONNECTION_FACTORY = ConnectionFactory

JNDI_INPUT_JMS_QUEUE = queue/Incoming1JobsQueue

The entire error that I get is :

12:36:35,198 ERROR JmsMessageProducer:90 - Error in trying to send JMS Message javax.naming.NameNotFoundException: Incoming1JobsQueue not bound at org.jnp.server.NamingServer.getBinding(NamingServer.java:771) at org.jnp.server.NamingServer.getBinding(NamingServer.java:779) at org.jnp.server.NamingServer.getObject(NamingServer.java:785) at org.jnp.server.NamingServer.lookup(NamingServer.java:443) at org.jnp.server.NamingServer.lookup(NamingServer.java:399) at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) at >sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl. java:57) at >sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAcces sorImpl.java:43) at java.lang.reflect.Method.invoke(Method.java:606) at sun.rmi.server.UnicastServerRef.dispatch(UnicastServerRef.java:322) at sun.rmi.transport.Transport$2.run(Transport.java:202) at sun.rmi.transport.Transport$2.run(Transport.java:199) at java.security.AccessController.doPrivileged(Native Method) at sun.rmi.transport.Transport.serviceCall(Transport.java:198) at >sun.rmi.transport.tcp.TCPTransport.handleMessages(TCPTransport.java:5 67) at >sun.rmi.transport.tcp.TCPTransport$ConnectionHandler.run0(TCPTranspor t.java:828) at >sun.rmi.transport.tcp.TCPTransport$ConnectionHandler.access$400(TCPTr ansport.java:619) at >sun.rmi.transport.tcp.TCPTransport$ConnectionHandler$1.run(TCPTranspo rt.java:684) at >sun.rmi.transport.tcp.TCPTransport$ConnectionHandler$1.run(TCPTranspo rt.java:681) at java.security.AccessController.doPrivileged(Native Method) at >sun.rmi.transport.tcp.TCPTransport$ConnectionHandler.run(TCPTransport .java:681) at >java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor. java:1145) at >java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor .java:615) at java.lang.Thread.run(Thread.java:745) at >sun.rmi.transport.StreamRemoteCall.exceptionReceivedFromServer(Stream RemoteCall.java:275) at >sun.rmi.transport.StreamRemoteCall.executeCall(StreamRemoteCall.java: 252) at sun.rmi.server.UnicastRef.invoke(UnicastRef.java:161) at org.jnp.server.NamingServer_Stub.lookup(Unknown Source) at org.jnp.interfaces.NamingContext.lookup(NamingContext.java:728) at org.jnp.interfaces.NamingContext.lookup(NamingContext.java:688) at javax.naming.InitialContext.lookup(InitialContext.java:411) at >fr.inra.grignon.persyst.web.jms.JmsMessageProducer.sendJmsTextMessage (JmsMessageProducer.java:74) at >fr.inra.grignon.persyst.web.servlet.DoResultats.doPost(DoResultats.ja va:407) at javax.servlet.http.HttpServlet.service(HttpServlet.java:650) at javax.servlet.http.HttpServlet.service(HttpServlet.java:731) at >org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(Appl icationFilterChain.java:303) at >org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationF ilterChain.java:208) at >org.apache.tomcat.websocket.server.WsFilter.doFilter(WsFilter.java:52 ) at >org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(Appl icationFilterChain.java:241) at >org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationF ilterChain.java:208) at >org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperV alve.java:220) at >org.apache.catalina.core.StandardContextValve.invoke(StandardContextV alve.java:122) at org.apache.tomee.catalina.OpenEJBValve.invoke(OpenEJBValve.java:44) at >org.apache.catalina.authenticator.AuthenticatorBase.invoke(Authentica torBase.java:505) at >org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.j ava:170) at >org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.j ava:103) at >org.apache.catalina.valves.AccessLogValve.invoke(AccessLogValve.java: 957) at >org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineVal ve.java:116) at >org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.jav a:423) at >org.apache.coyote.http11.AbstractHttp11Processor.process(AbstractHttp 11Processor.java:1079) at >org.apache.coyote.AbstractProtocol$AbstractConnectionHandler.process( AbstractProtocol.java:620) at org.apache.tomcat.util.net.JIoEndpoint$SocketProcessor.run(JIoEndpoin t.java:316) at >java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor. java:1145) at >java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor .java:615) at >org.apache.tomcat.util.threads.TaskThread$WrappingRunnable.run(TaskTh read.java:61) at java.lang.Thread.run(Thread.java:745)

I'm using JBoss and Tomcat (both) for some reasons. And in the JBoss jmx console, I have : (I insert it as an image for the indentation)

enter image description here

I don't know where the problem comes from and why the connection is not bound. Thanks in advance for your help !

1

1 Answers

0
votes

if you're running in a JEE environment the container's going to expect a JNDI name, because you want the container to manage the resource not do it natively, so make a JMS resource for the queue you're interested in and then use the appropriately JNDI name to access it,