Results 1 to 2 of 2
  1. #1
    gberish is offline Member
    Join Date
    Sep 2009
    Posts
    2
    Rep Power
    0

    Default Glassfish InitialContext & ConnectionFactory lookup

    Hi .. I am shifting my JMS-using app from JBoss to Glassfish. So far defeat plagues my effort to instantiate an InitialContext and look up a ContextFactory.

    If a simple example exists for doing that with Glassfish, I can’t find it.

    If this is the wrong JavaForum category to post this, please suggest the correct one. This is my first try.

    To illustrate my problem, I created “MainTest” class (full code below) with a main() method to do that. My problem seems to be that I haven’t yet found the correct property parameters for the InitialContex constructor.

    If anyone can help perfect my attempt below, I think it will be a great help to those who follow.

    Anyway, here is what follows below:

    A. The output from MainTest’s main() method.
    [Black text is my code output. Red is from the System.err stream.]

    B. Complete MainTest class code.

    ?1: I can’t find a clear explanation of how to resolve the reference to “endpoints” below.

    ?2: Please see the underlined red text. I seems like it is telling me it is doing what I thought my properties already did????

    Thanks for any help.
    GLB
    --------------------------------
    A. MainTest OUTPUT
    java.naming.factory.initial=com.sun.appserv.naming .S1ASCtxFactory
    java.naming.factory.url.pkgs=com.sun.enterprise.na ming
    java.naming.provider.url=iiop://localhost:3700
    java.naming.factory.state=com.sun.corba.ee.impl.pr esentation.rmi.JNDIStateFactoryImpl
    Property key:value pairs successfully loaded.
    Attempting to instantiate InitialContext.
    Sep 4, 2009 9:22:27 AM com.sun.appserv.naming.RoundRobinPolicy setClusterInstanceInfo
    WARNING: NAM1005 : No Endpoints selected. Please specify using system property com.sun.appserv.iiop.endpoints.
    Sep 4, 2009 9:22:27 AM com.sun.appserv.naming.RoundRobinPolicy getEndpointForProviderURL
    WARNING: NAM1001: No Endpoints selected in com.sun.appserv.iiop.endpoints property.
    Using JNDI Provider URL iiop://localhost:3700 instead
    Sep 4, 2009 9:22:27 AM com.sun.appserv.naming.RoundRobinPolicy setClusterInstanceInfo
    INFO: endpoint.weight after checking isWeight = 10
    Sep 4, 2009 9:22:27 AM com.sun.appserv.naming.RoundRobinPolicy setClusterInstanceInfo
    INFO: sumOfAllWeights = 10

    InitialContext instatiated: InitialContext
    Attempting to lookup ConnectionFactory.
    Sep 4, 2009 9:22:27 AM com.sun.appserv.naming.S1ASCtxFactory getCorbalocURL
    INFO: list[i] ==> 127.0.0.1:3700
    Sep 4, 2009 9:22:27 AM com.sun.appserv.naming.S1ASCtxFactory getCorbalocURL
    INFO: corbaloc url ==> iiop:1.2@127.0.0.1:3700

    ERROR: NameNotFoundException
    null

    B. MainTest CLASS CODE
    Java Code:
    import javax.jms.ConnectionFactory;
    import javax.naming.Context;
    import javax.naming.InitialContext;
    import java.util.Properties;
    
    public class MainTest {
        
      static public void main (String[] args) {
        try {
          System.out.println("Attempting to instantiate InitialContext.");
          Context jndiContext = (Context) new InitialContext (prop);
          System.out.println("InitialContext instatiated: " + jndiContext.getClass().getSimpleName());
          System.out.println("Attempting to lookup ConnectionFactory.");
          ConnectionFactory factory = (ConnectionFactory) jndiContext.lookup("jms/connectionFactory");
          System.out.println("ConnectionFactory looked up: " + factory.getClass().getSimpleName());
        } catch (Exception e){
          System.out.println("ERROR: "  + e.getClass().getSimpleName() +
              "\n" + e.getMessage());
        }
      }
      
      // Define Property key:value pairs
      static private final Properties prop = new Properties ();
        static private final String [] keyValueArray = {
          "java.naming.factory.initial      com.sun.appserv.naming.S1ASCtxFactory"
         ,"java.naming.factory.url.pkgs     com.sun.enterprise.naming"
         ,"java.naming.provider.url     : iiop://localhost:3700"
         //Tried and failed
         //"iiop://localhost:3700"   
         //"iiop://localhost:4848"
         //"[http]  ://localhost:8080" I had to bracket http
         //"[http]  ://localhost:4848" because I can’t post “links” yet.
    
       ,"java.naming.factory.state    : com.sun.corba.ee.impl.presentation.rmi.JNDIStateFactoryImpl"
         // ,"org.omg.CORBA.ORBInitialHost   ????", Not sure if needed. Unsure of values
         // ,"org.omg.CORBA.ORBInitialPort   3700",  Not sure if needed.
         // ,"com.sun.appserv.iiop.endpoints ????"  Not sure if needed. Unsure of values
      };
      
      // Load Property key:value pairs
      static {
        for (int indx = 0; indx < keyValueArray.length; indx++) {
          String key  = keyValueArray[indx].substring(0, keyValueArray[indx].indexOf(' '));
          String value = keyValueArray[indx].substring(keyValueArray[indx].lastIndexOf(' ') + 1);
          System.out.println(key + "=" + value);
          prop.put(key, value);
        }
        System.out.println("Property key:value pairs successfully loaded.");
      }
    
    }

  2. #2
    gberish is offline Member
    Join Date
    Sep 2009
    Posts
    2
    Rep Power
    0

    Default

    Opps ... my definition of
    static private final String [] keyValueArray
    looks funny, because some pairs are seperated by spaces and some by ":".

    It doesn't matter (see output). However, for esthetics, it should look like:
    Java Code:
    static private final String [] keyValueArray = {
        "java.naming.factory.initial  : com.sun.appserv.naming.S1ASCtxFactory"
       ,"java.naming.factory.url.pkgs : com.sun.enterprise.naming"
       ,"java.naming.provider.url     : iiop://localhost:3700"
         //Tried and failed
         //"iiop://localhost:3700"   
         //"iiop://localhost:4848"
         //"[http]://localhost:8080"
         //"[http]://localhost:4848"
       ,"java.naming.factory.state    : com.sun.corba.ee.impl.presentation.rmi.JNDIStateFactoryImpl"
         // ,"org.omg.CORBA.ORBInitialHost   ????", Not sure if needed. Unsure of values
         // ,"org.omg.CORBA.ORBInitialPort   3700",  Not sure if needed.
         // ,"com.sun.appserv.iiop.endpoints ????"  Not sure if needed. Unsure of values
      };

Similar Threads

  1. About Application Server - Glassfish
    By sathishscjp in forum Advanced Java
    Replies: 1
    Last Post: 07-30-2009, 03:51 AM
  2. ping error in glassfish
    By tushar88 in forum Advanced Java
    Replies: 0
    Last Post: 03-09-2009, 03:17 PM
  3. What d u use, Apache Tomcat or GlassFish? Why
    By thom_ in forum New To Java
    Replies: 0
    Last Post: 03-05-2009, 11:14 PM
  4. Integrate JOSSO with Glassfish
    By Kavitha Kamath in forum New To Java
    Replies: 0
    Last Post: 11-12-2008, 09:59 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •