How do I set Context.INITIAL_CONTEXT_FACTORY? NoInitialContextException?

I am new to JMS and Websphere Server and I am trying to access a JMS queue configured on WebSphere Application Server 8 from my Java code. I can't figure out exactly what value should be set for Context.INITIAL_CONTEXT_FACTORY. Should it be a fully qualified class name or something specific to the application server?

Hashtable environment = new Hashtable();
        environment.put(Context.INITIAL_CONTEXT_FACTORY, "com.ibm.websphere.naming.WsnInitialContextFactory");
        environment.put(Context.PROVIDER_URL, "iiop://localhost:9081");

      

When setting the value for Context.INITIAL_CONTEXT_FACTORY as fully qualified class name ie com.ms.test.Demo I get NoInitialContextException.

PFB code that I am using -

package com.jms.test;

import java.util.Hashtable;
import javax.jms.Queue;
import javax.naming.Context;
import javax.naming.InitialContext;
import javax.naming.NamingException;

public class Demo {
  public static void main(String[] args) throws NamingException {
        System.out.println("Start.....");
        Hashtable environment = new Hashtable();
        environment.put(Context.INITIAL_CONTEXT_FACTORY, "com.jms.test.Demo");
        environment.put(Context.PROVIDER_URL, "iiop://localhost:9081");
       //String pUrl = System.getProperty(Context.PROVIDER_URL);
        //System.out.println("*******"+pUrl+"********");
        InitialContext ctx = new InitialContext(environment);
        Queue queue = (Queue) ctx.lookup("jms/TestQ111200");
        System.out.println("*** Queue is *** "+queue.toString());
  }}

      

I created JMS config on Websphere Application Server following the steps given below: http://pic.dhe.ibm.com/infocenter/iisinfsv/v8r1/index.jsp?topic=/com.ibm.swg.im.iis .infoservdir.user.doc / topics / t_isd_user_setting_up_jms_in_was.html

+3


source to share


1 answer


When connecting to WebSphere, you always use the following and not your own class.

environment.put(Context.INITIAL_CONTEXT_FACTORY, "com.ibm.websphere.naming.WsnInitialContextFactory");

      

You must properly connect to WAS. For the second property, you need to provide a bootstrap port, not http. Usually 2809

, look for the following message in SystemOut.log

:



00000001 NameServerImp A   NMSV0018I: Name server available on bootstrap port 2809.

      

You will also need specific banks for your client to connect to WAS JMS. See Installing and Configuring Thin Client for JMS with WebSphere Application Server

+1


source







All Articles