0 Replies Latest reply: Apr 23, 2012 6:47 AM by 932533 RSS

    jndi unknown source

    932533
      I am trying jms example but i have problen while in lookup ,i could not find the resource running in the sun app server.
      the below is the code


      import javax.jms.*;
      import javax.naming.*;
      import java.util.*;

      public class SimpleTopicPublisher {

      /**
      * Main method.
      *
      * @param args the topic used by the example and,
      * optionally, the number of messages to send
      */
      public static void main(String[] args) {
      String topicName = null;
      Context jndiContext = null;
      TopicConnectionFactory topicConnectionFactory = null;
      TopicConnection topicConnection = null;
      TopicSession topicSession = null;
      Topic topic = null;
      TopicPublisher topicPublisher = null;
      TextMessage message = null;
      final int NUM_MSGS;

      if ( (args.length < 1) || (args.length > 2) ) {
      System.out.println("Usage: java " +
      "SimpleTopicPublisher <topic-name> " +
      "[<number-of-messages>]");
      System.exit(1);
      }
      topicName = new String(args[0]);
      System.out.println("Topic name is " + topicName);
      if (args.length == 2){
      NUM_MSGS = (new Integer(args[1])).intValue();
      } else {
      NUM_MSGS = 1;
      }

      /*
      * Create a JNDI API InitialContext object if none exists
      * yet.
      */
      try {
                     // String url = "mq://INBANN0L3CT171.ap01.lucent.com:7676/";
      // Properties p = new Properties();
                //p.put(Context.INITIAL_CONTEXT_FACTORY,"com.sun.appserv.naming.S1ASCtxFactory");
      // p.put(Context.INITIAL_CONTEXT_FACTORY, "com.sun.enterprise.naming.SerialInitContextFactory");
      //p.put(Context.PROVIDER_URL, url);
      //ctx = new InitialContext(p);
      jndiContext = new InitialContext();
      } catch (NamingException e) {
      System.out.println("Could not create JNDI API " +
      "context: " + e.toString());
      e.printStackTrace();
      System.exit(1);
      }

      /*
      * Look up connection factory and topic. If either does
      * not exist, exit.
      */
      try {
                     
      topicConnectionFactory = (TopicConnectionFactory)
                     
      jndiContext.lookup("jms/myjms");
      topic = (Topic) jndiContext.lookup(topicName);
      } catch (NamingException e) {
      System.out.println("JNDI API lookup failed: " +
      e.toString());
      e.printStackTrace();
      System.exit(1);
      }

      /*
      * Create connection.
      * Create session from connection; false means session is
      * not transacted.
      * Create publisher and text message.
      * Send messages, varying text slightly.
      * Finally, close connection.
      */
      try {
      topicConnection =
      topicConnectionFactory.createTopicConnection();
      topicSession =
      topicConnection.createTopicSession(false,
      Session.AUTO_ACKNOWLEDGE);
      topicPublisher = topicSession.createPublisher(topic);
      message = topicSession.createTextMessage();
      for (int i = 0; i < NUM_MSGS; i++) {
      message.setText("This is message " + (i + 1));
      System.out.println("Publishing message: " +
      message.getText());
      topicPublisher.publish(message);
      }
      } catch (JMSException e) {
      System.out.println("Exception occurred: " +
      e.toString());
      } finally {
      if (topicConnection != null) {
      try {
      topicConnection.close();
      } catch (JMSException e) {}
      }
      }
      }
      }


      and below is the error while running


      D:\>java SimpleTopicPublisher mytopic 3
      Topic name is mytopic
      Apr 23, 2012 5:03:48 PM com.sun.enterprise.v3.server.CommonClassLoaderServiceIm
      l findDerbyClient
      INFO: Cannot find javadb client jar file, derby jdbc driver will not be availab
      e by default.
      JNDI API lookup failed: javax.naming.NamingException: Lookup failed for 'java:c
      mp/env/jms/myjms' in SerialContext[myEnv={java.naming.factory.initial=com.sun.e
      terprise.naming.impl.SerialInitContextFactory, java.naming.factory.url.pkgs=com
      sun.enterprise.naming, java.naming.factory.state=com.sun.corba.ee.impl.presenta
      ion.rmi.JNDIStateFactoryImpl} [Root exception is javax.naming.NamingException:
      nvocation exception: Got null ComponentInvocation ]
      javax.naming.NamingException: Lookup failed for 'java:comp/env/jms/myjms' in Se
      ialContext[myEnv={java.naming.factory.initial=com.sun.enterprise.naming.impl.Se
      ialInitContextFactory, java.naming.factory.url.pkgs=com.sun.enterprise.naming,
      ava.naming.factory.state=com.sun.corba.ee.impl.presentation.rmi.JNDIStateFactor
      Impl} [Root exception is javax.naming.NamingException: Invocation exception: Go
      null ComponentInvocation ]
      at com.sun.enterprise.naming.impl.SerialContext.lookup(SerialContext.ja
      a:518)
      at com.sun.enterprise.naming.impl.SerialContext.lookup(SerialContext.ja
      a:455)
      at javax.naming.InitialContext.lookup(Unknown Source)
      at SimpleTopicPublisher.main(SimpleTopicPublisher.java:112)
      Caused by: javax.naming.NamingException: Invocation exception: Got null Compone
      tInvocation
      at com.sun.enterprise.naming.impl.GlassfishNamingManagerImpl.getCompone
      tId(GlassfishNamingManagerImpl.java:873)
      at com.sun.enterprise.naming.impl.GlassfishNamingManagerImpl.lookup(Gla
      sfishNamingManagerImpl.java:742)
      at com.sun.enterprise.naming.impl.JavaURLContext.lookup(JavaURLContext.
      ava:169)
      at com.sun.enterprise.naming.impl.SerialContext.lookup(SerialContext.ja
      a:498)
      ... 3 more

      D:\>javac SimpleTopicPublisher.java

      D:\>java SimpleTopicPublisher mytopic 3
      Topic name is mytopic
      Apr 23, 2012 5:09:28 PM com.sun.enterprise.v3.server.CommonClassLoaderServiceIm
      l findDerbyClient
      INFO: Cannot find javadb client jar file, derby jdbc driver will not be availab
      e by default.
      java.lang.ClassCastException
      at com.sun.corba.ee.impl.javax.rmi.PortableRemoteObject.narrow(Portable
      emoteObject.java:262)
      at javax.rmi.PortableRemoteObject.narrow(Unknown Source)
      at com.sun.enterprise.naming.impl.SerialContext$ProviderCacheKey.getNam
      Service(SerialContext.java:1244)
      at com.sun.enterprise.naming.impl.SerialContext.getRemoteProvider(Seria
      Context.java:410)
      at com.sun.enterprise.naming.impl.SerialContext.getProvider(SerialConte
      t.java:346)
      at com.sun.enterprise.naming.impl.SerialContext.lookup(SerialContext.ja
      a:504)
      at com.sun.enterprise.naming.impl.SerialContext.lookup(SerialContext.ja
      a:455)
      at javax.naming.InitialContext.lookup(Unknown Source)
      at SimpleTopicPublisher.main(SimpleTopicPublisher.java:112)
      Caused by: java.lang.ClassCastException: Object is not of remote type com.sun.e
      terprise.naming.impl.SerialContextProvider
      at com.sun.corba.ee.impl.javax.rmi.PortableRemoteObject.narrow(Portable
      emoteObject.java:254)
      ... 8 more
      JNDI API lookup failed: javax.naming.NamingException: Lookup failed for 'jms/my
      ms' in SerialContext[myEnv={java.naming.factory.initial=com.sun.enterprise.nami
      g.impl.SerialInitContextFactory, java.naming.factory.url.pkgs=com.sun.enterpris
      .naming, java.naming.factory.state=com.sun.corba.ee.impl.presentation.rmi.JNDIS
      ateFactoryImpl} [Root exception is javax.naming.NamingException: Unable to acqu
      re SerialContextProvider for SerialContext[myEnv={java.naming.factory.initial=c
      m.sun.enterprise.naming.impl.SerialInitContextFactory, java.naming.factory.url.
      kgs=com.sun.enterprise.naming, java.naming.factory.state=com.sun.corba.ee.impl.
      resentation.rmi.JNDIStateFactoryImpl} [Root exception is java.lang.ClassCastExc
      ption]]
      javax.naming.NamingException: Lookup failed for 'jms/myjms' in SerialContext[my
      nv={java.naming.factory.initial=com.sun.enterprise.naming.impl.SerialInitContex
      Factory, java.naming.factory.url.pkgs=com.sun.enterprise.naming, java.naming.fa
      tory.state=com.sun.corba.ee.impl.presentation.rmi.JNDIStateFactoryImpl} [Root e
      ception is javax.naming.NamingException: Unable to acquire SerialContextProvide
      for SerialContext[myEnv={java.naming.factory.initial=com.sun.enterprise.naming
      impl.SerialInitContextFactory, java.naming.factory.url.pkgs=com.sun.enterprise.
      aming, java.naming.factory.state=com.sun.corba.ee.impl.presentation.rmi.JNDISta
      eFactoryImpl} [Root exception is java.lang.ClassCastException]]
      at com.sun.enterprise.naming.impl.SerialContext.lookup(SerialContext.ja
      a:518)
      at com.sun.enterprise.naming.impl.SerialContext.lookup(SerialContext.ja
      a:455)
      at javax.naming.InitialContext.lookup(Unknown Source)
      at SimpleTopicPublisher.main(SimpleTopicPublisher.java:112)
      Caused by: javax.naming.NamingException: Unable to acquire SerialContextProvide
      for SerialContext[myEnv={java.naming.factory.initial=com.sun.enterprise.naming
      impl.SerialInitContextFactory, java.naming.factory.url.pkgs=com.sun.enterprise.
      aming, java.naming.factory.state=com.sun.corba.ee.impl.presentation.rmi.JNDISta
      eFactoryImpl} [Root exception is java.lang.ClassCastException]
      at com.sun.enterprise.naming.impl.SerialContext.getProvider(SerialConte
      t.java:351)
      at com.sun.enterprise.naming.impl.SerialContext.lookup(SerialContext.ja
      a:504)
      ... 3 more
      Caused by: java.lang.ClassCastException
      at com.sun.corba.ee.impl.javax.rmi.PortableRemoteObject.narrow(Portable
      emoteObject.java:262)
      at javax.rmi.PortableRemoteObject.narrow(Unknown Source)
      at com.sun.enterprise.naming.impl.SerialContext$ProviderCacheKey.getNam
      Service(SerialContext.java:1244)
      at com.sun.enterprise.naming.impl.SerialContext.getRemoteProvider(Seria
      Context.java:410)
      at com.sun.enterprise.naming.impl.SerialContext.getProvider(SerialConte
      t.java:346)
      ... 4 more
      Caused by: java.lang.ClassCastException: Object is not of remote type com.sun.e
      terprise.naming.impl.SerialContextProvider
      at com.sun.corba.ee.impl.javax.rmi.PortableRemoteObject.narrow(Portable
      emoteObject.java:254)
      ... 8 more


      plese help me in resolving...