JMS-JNDI-QConnectionFactory lookup-WSAD 5.1


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

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


    I am trying to create a stand-alone client to Websphere MQ JMS using
    the following simple code:
       Hashtable h = new Hashtable();
       Context context = new InitialContext(h);
       System.out.println("Initial Context obtained");
       Object o = context.lookup("jms/qcf");
       System.out.println("QueueConnectionFactory obtained as object");
       QueueConnectionFactory qcf =

    and it fails while casting to QueueConnectionFactory (context is
    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

    Any help would be much appreciated.

  2. Hi Rajineesh,

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

    Srini - TCS

     public void writeMessageToMQ(Message message)
    String s1="";
    s1 = ((TextMessage)message).getText();
    catch (Exception e)
    { System.out.println("Error while converting in to String");
    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; = 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();
    MQPutMessageOptions pmo = new MQPutMessageOptions();
    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 ]


    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.

  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