Doew anyone know th Initial Context properties for JMS?

Discussion in 'Java' started by Ken Baltrinic, Sep 23, 2004.

  1. I am trying to get the following code to work from a session bean running on
    AppServer8. When I call new InitialContext(), the context I get pack has no
    properties. This leads me to suspect that i need a jndi.properties file
    with the correct settings. I suspect the settings I need are
    java.naming.factory.initial and java.naming.provider.url but I don't know
    what to set them to. I am also not sure exactly where to put the properties
    file or how to tell the AppServer where to find it. Can anyone help?

    Thanks in Advance,
    Ken
    Ken Baltrinic, Sep 23, 2004
    #1
    1. Advertising

  2. Forgot to include the code:

    This is what I cant get to work:

    Context ctx = new InitialContext(prop);

    //THe above line runs but contains an empty context.
    //consequently the following fails.

    TopicConnectionFactory topicConnectionFactory;
    topicConnectionFactory = (TopicConnectionFactory) ctx.lookup(
    "jms/log4jConnectionFactory");
    Ken Baltrinic, Sep 23, 2004
    #2
    1. Advertising

  3. Ken Baltrinic

    Sudsy Guest

    Ken Baltrinic wrote:
    > I am trying to get the following code to work from a session bean running on
    > AppServer8. When I call new InitialContext(), the context I get pack has no
    > properties. This leads me to suspect that i need a jndi.properties file
    > with the correct settings. I suspect the settings I need are
    > java.naming.factory.initial and java.naming.provider.url but I don't know
    > what to set them to. I am also not sure exactly where to put the properties
    > file or how to tell the AppServer where to find it. Can anyone help?


    It's specific to the app server; you'll have to dig into the
    documentation to locate the definitive specification. I've
    used code like this in the past:

    Context context = null;
    Properties props = new Properties();

    try {
    // for BEA WebLogic
    props.put( Context.PROVIDER_URL,
    "t3://hostname:7001" );
    props.put( Context.INITIAL_CONTEXT_FACTORY,
    "weblogic.jndi.WLInitialContextFactory" );
    // for IBM WebSphere
    props.put( Context.PROVIDER_URL,
    "iiop://hostname" );
    props.put( Context.INITIAL_CONTEXT_FACTORY,
    "com.ibm.websphere.naming.WsnInitialContextFactory" );
    // for both
    context = new InitialContext( props );
    }
    catch( NamingException e ) {
    ...
    }

    I don't run AppServer8 so I don't know that this is going to be of
    any use whatsoever... :-(
    Sudsy, Sep 23, 2004
    #3
  4. Ken Baltrinic

    Oscar kind Guest

    Ken Baltrinic <> wrote:
    > I am trying to get the following code to work from a session bean running on
    > AppServer8. When I call new InitialContext(), the context I get pack has no
    > properties. This leads me to suspect that i need a jndi.properties file
    > with the correct settings. I suspect the settings I need are
    > java.naming.factory.initial and java.naming.provider.url but I don't know
    > what to set them to. I am also not sure exactly where to put the properties
    > file or how to tell the AppServer where to find it. Can anyone help?


    As Sudsy already pointed out, this depends on the application server
    you're using. For Resin and Tomcat for example, no properties are needed.

    Some examples:

    Resin:
    Context context = new InitialContext();
    // Option 1
    DataSource dataSource1 = (DataSource)context.lookup("jdbc/datasource");
    // Option 2
    DataSource dataSource2 = (DataSource)context.lookup("java:comp/env/jdbc/datasource");

    Tomcat:
    Context initialContext = new InitialContext();
    // Option 1
    Context context = (Context)initialContext.lookup("java:comp/env");
    DataSource dataSource = (DataSource)context.lookup("jdbc/datasource");
    // Option 2
    DataSource dataSource2 = (DataSource)initialContext.lookup("java:comp/env/jdbc/datasource");


    --
    Oscar Kind http://home.hccnet.nl/okind/
    Software Developer for contact information, see website

    PGP Key fingerprint: 91F3 6C72 F465 5E98 C246 61D9 2C32 8E24 097B B4E2
    Oscar kind, Sep 26, 2004
    #4
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Thomas Stein
    Replies:
    0
    Views:
    751
    Thomas Stein
    Oct 18, 2004
  2. Replies:
    0
    Views:
    415
  3. Jason Keats
    Replies:
    1
    Views:
    626
    Jason Keats
    Jan 9, 2010
  4. Simon Egginton

    LOOK! i just want to know does anyone know...

    Simon Egginton, Jul 26, 2004, in forum: Javascript
    Replies:
    3
    Views:
    169
    Dr John Stockton
    Jul 26, 2004
  5. Andries

    I know, I know, I don't know

    Andries, Apr 23, 2004, in forum: Perl Misc
    Replies:
    3
    Views:
    222
    Gregory Toomey
    Apr 23, 2004
Loading...

Share This Page