3

I am trying to write a message to a JMS Queue running on Weblogic but I get a java.rmi.ConnectIOException when trying to connect from a Eclipse program.

    javax.naming.CommunicationException [Root exception is java.rmi.ConnectIOException: error during JRMP connection establishment; nested exception is: 
    java.io.EOFException]
    at weblogic.jrmp.Context.lookup(Context.java:189)
    at weblogic.jrmp.Context.lookup(Context.java:195)
    at javax.naming.InitialContext.lookup(Unknown Source)
    at example.jms.queue.JMSSender.sendMessage(JMSSender.java:42)
    at example.jms.queue.JMSSender.main(JMSSender.java:130)
Caused by: java.rmi.ConnectIOException: error during JRMP connection establishment; nested exception is: 
    java.io.EOFException
    at sun.rmi.transport.tcp.TCPChannel.createConnection(Unknown Source)
    at sun.rmi.transport.tcp.TCPChannel.newConnection(Unknown Source)
    at sun.rmi.server.UnicastRef.newCall(Unknown Source)
    at weblogic.jrmp.BaseRemoteRef.invoke(BaseRemoteRef.java:221)
    at weblogic.jrmp.RegistryImpl_Stub.lookup(Unknown Source)
    at weblogic.jrmp.Context.lookup(Context.java:185)
    ... 4 more
Caused by: java.io.EOFException
    at java.io.DataInputStream.readByte(Unknown Source)
    ... 10 more
Exception in thread "main" java.lang.NullPointerException
    at example.jms.queue.JMSSender.sendMessage(JMSSender.java:47)
    at example.jms.queue.JMSSender.main(JMSSender.java:130)

Below is my client program

package example.jms.queue;

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.Hashtable;
import javax.jms.*;
import javax.naming.Context;
import javax.naming.InitialContext;
import javax.naming.NamingException;

/** This example shows how to establish a connection
* and send messages to the JMS queue. The classes in this
* package operate on the same JMS queue. Run the classes together to
* witness messages being sent and received, and to browse the queue
* for messages. The class is used to send messages to the queue.
*
* @author Copyright (c) 1999-2005 by BEA Systems, Inc. All Rights Reserved.
*/
public class QueueSend
{
 // Defines the JNDI context factory.
 public final static String JNDI_FACTORY="weblogic.jndi.WLInitialContextFactory";

 // Defines the JMS context factory.
 public final static String JMS_FACTORY="jms/TestConnectionFactory";

 // Defines the queue.
 public final static String QUEUE="jms/TestJMSQueue";

 private QueueConnectionFactory qconFactory;
 private QueueConnection qcon;
 private QueueSession qsession;
 private QueueSender qsender;
 private Queue queue;
 private TextMessage msg;

 /**
  * Creates all the necessary objects for sending
  * messages to a JMS queue.
  *
  * @param ctx JNDI initial context
  * @param queueName name of queue
  * @exception NamingException if operation cannot be performed
  * @exception JMSException if JMS fails to initialize due to internal error
  */
 public void init(Context ctx, String queueName)
    throws NamingException, JMSException
 {
     System.out.println("1");
    qconFactory = (QueueConnectionFactory) ctx.lookup(JMS_FACTORY);
    System.out.println("1");
    qcon = qconFactory.createQueueConnection();
    System.out.println("1");
    qsession = qcon.createQueueSession(false, Session.AUTO_ACKNOWLEDGE);
    System.out.println("1");
    queue = (Queue) ctx.lookup(queueName);
    qsender = qsession.createSender(queue);
    msg = qsession.createTextMessage();
    qcon.start();
 }

 /**
  * Sends a message to a JMS queue.
  *
  * @param message  message to be sent
  * @exception JMSException if JMS fails to send message due to internal error
  */
 public void send(String message) throws JMSException {
    msg.setText(message);
    qsender.send(msg);
 }

 /**
  * Closes JMS objects.
  * @exception JMSException if JMS fails to close objects due to internal error
  */
 public void close() throws JMSException {
    qsender.close();
    qsession.close();
    qcon.close();
 }
/** main() method.
 *
 * @param args WebLogic Server URL
 * @exception Exception if operation fails
 */
 public static void main(String[] args) throws Exception {

     try{
         String url = "t3://localhost:7001";
            url = "http://127.0.0.1:7001/TestConnectionFactory/TestJMSQueue";
            //t://localhost:7001/ConnFact/QueueName
            InitialContext ic = getInitialContext(url);
            System.out.println("Hello");
            //System.out.println("cONTEXT----" + ic.lookup(url));
            QueueSend qs = new QueueSend();
            System.out.println("Initializing");
            qs.init(ic, QUEUE);
            System.out.println("Sending");
            readAndSend(qs);
            System.out.println("Sent");
            qs.close();
     }catch(Exception ex){
         ex.printStackTrace();
     }

 }

 private static void readAndSend(QueueSend qs)
    throws IOException, JMSException
 {

    String line="Test string 123";

    // line = msgStream.readLine();

       qs.send(line);


 }

 private static InitialContext getInitialContext(String url)
    throws NamingException
 {
    Hashtable env = new Hashtable();
    env.put(Context.INITIAL_CONTEXT_FACTORY, JNDI_FACTORY);
    env.put(Context.PROVIDER_URL, url);
    return new InitialContext(env);
 }
}

I have taken the code from a Oracle blog (https://blogs.oracle.com/soaproactive/entry/jms_step_2_using_the)

I see from the exception that the context lookup is failing, I cant suspect why ?

2
  • Have you checked the URL? why are you overwriting the URL variable in the try block in main method? pass the t3://localhost:7001 to getInitialContext() Commented Aug 3, 2015 at 8:47
  • @ManishKothari I tried with several URL's some with IP, some with localhost , some with HTTP but I get the same error all the time. 7001 is also the port on which I access the weblogic console. I somehow feel that it cannot be the port on which I should be writing the message. Commented Aug 3, 2015 at 8:56

2 Answers 2

2

I fixed this. The problem was because of some unwanted jars that I had added to the Project. Basically I had added all the Weblogic jars to my project. Later I removed all the Jars and just left wlclient.jar, wljmsclient.jar. I suspected Jar conflict while reading the article on https://redstack.wordpress.com/2009/12/21/a-simple-jms-client-for-weblogic-11g/.

Sign up to request clarification or add additional context in comments.

Comments

1

You only need this jar in classpath:

\wlserver_10.3\server\lib\wlclient.jar

1 Comment

Does this answer the question? If not, it may be better suited as a comment (which you currently lack the reputation to make).

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.