JMS-JNDI-QConnectionFactory lookup-WSAD 5.1

Discussions

General J2EE: JMS-JNDI-QConnectionFactory lookup-WSAD 5.1

  1. JMS-JNDI-QConnectionFactory lookup-WSAD 5.1 (4 messages)

    Hi

    I am trying to create a stand-alone client to Websphere MQ JMS using
    the following simple code:
       Hashtable h = new Hashtable();
       h.put(Context.INITIAL_CONTEXT_FACTORY,"com.ibm.websphere.naming.WsnInitialContextFactory");
       //h.put(Context.INITIAL_CONTEXT_FACTORY,"com.ibm.ejs.ns.jndi.CNInitialContextFactory");
       h.put(Context.PROVIDER_URL,"iiop://localhost:2809");
       Context context = new InitialContext(h);
       System.out.println("Initial Context obtained");
       Object o = context.lookup("jms/qcf");
       System.out.println("QueueConnectionFactory obtained as object");
       System.out.println(o.getClass().getName());
       System.out.println(o.toString());
       QueueConnectionFactory qcf =
    (QueueConnectionFactory)context.lookup("jms/qcf");

    and it fails while casting to QueueConnectionFactory (context is
    fine).
    java.lang.ClassCastException: javax.naming.Reference


    I include all the required JARS from base_v5/lib and
    base_v5/mqjms/java/lib and the implFactory.jar from
    wstools/eclipse/plugin folder and the java/javac from
    base_v5\java\bin.

    Any help would be much appreciated.

    Sincerely
    Rajneesh
  2. Hi Rajineesh,

    I used the following code to post a message to Websphere MQ.
    Chk whether it's useful.

    Rgds
    Srini - TCS


     public void writeMessageToMQ(Message message)
      {
    String s1="";
    try
    {
    s1 = ((TextMessage)message).getText();
    }
    catch (Exception e)
    { System.out.println("Error while converting in to String");
    e.printStackTrace();
            }
    Hashtable properties= new Hashtable();
    MQQueueManager qMgr;
    System.out.println(" getMQ property file");
    ResourceBundle mqResource = ResourceBundle.getBundle("MQResources");
    String hostname = mqResource.getString("hostname");
    String transportvalue = mqResource.getString("transport");
    String portvalue = mqResource.getString("port");
    String channelvalue = mqResource.getString("channel");
    String qmvalue = mqResource.getString("queuemanager");
    String qvalue = mqResource.getString("queue");
            properties.put("port", new Integer(Integer.parseInt(portvalue)));
            properties.put("hostname", hostname);
            properties.put("transport", transportvalue);

            if(channelvalue != null)
                properties.put("channel", channelvalue);
    MQEnvironment.hostname = hostname;
    MQEnvironment.channel = channelvalue;
    try {
    System.out.println("Posting in to MQ");
    qMgr = new MQQueueManager(qmvalue,properties);
    int openOptions = MQC.MQOO_INPUT_AS_Q_DEF | MQC.MQOO_OUTPUT ;
    MQQueue queue = qMgr.accessQueue(qvalue,openOptions);
    MQMessage inputMessage = new MQMessage();
    inputMessage.format=MQC.MQFMT_STRING;
    inputMessage.writeString(s1);
    MQPutMessageOptions pmo = new MQPutMessageOptions();
    queue.put(inputMessage,pmo);
    System.out.println("Posted in to MQ Queue");
            }
    catch(Exception e)
    { e.printStackTrace();
    System.out.println("Some problem in posting");
    }

    }
  3. Check references...[ Go to top ]

    Hello,

    ich you get an class-cast exception, check if
    your references can be resolved, the jndi
    has the nasty behaviour to return a reference object
    itself if it cannot be resolved.

    Stefan
  4. Check references...[ Go to top ]

    Hello,ich you get an class-cast exception, check ifyour references can be resolved, the jndihas the nasty behaviour to return a reference objectitself if it cannot be resolved.Stefan

    What do you mean exactly by "see if your references can be resolved"?
  5. You have to add ‘messagingClient.jar’ in your WSAD Run->RUN xxx->ClassPath. This should solve the issue. I got this error and I solved this. --------------------- jgeorge at itprototype dot com www.itprototype.com