连接Weblogic JMS队列失败

3

我正在尝试向运行在Weblogic上的JMS队列写入消息,但当我从Eclipse程序尝试连接时,我收到了一个java.rmi.ConnectIOException错误。

    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)

以下是我的客户端程序。
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);
 }
}

我从异常信息中看到上下文查找失败了,但我不知道原因是什么?

我从Oracle博客(https://blogs.oracle.com/soaproactive/entry/jms_step_2_using_the)中获取了代码。


你检查过URL了吗?为什么在main方法的try块中覆盖URL变量?将t3://localhost:7001传递给getInitialContext()。 - Manish Kothari
@ManishKothari 我使用了几个 URL,一些是 IP 地址,一些是 localhost,一些是 HTTP,但每次都遇到了相同的错误。7001 端口也是我访问 WebLogic 控制台的端口。我有点觉得这不能是我应该编写消息的端口。 - Geek
2个回答

2

我已经解决了这个问题。问题的原因是我添加了一些不必要的jar包到项目中。基本上,我将所有的Weblogic jar文件都添加到了我的项目中。后来我删除了所有的jar包,只留下了wlclient.jar和wljmsclient.jar。在阅读https://redstack.wordpress.com/2009/12/21/a-simple-jms-client-for-weblogic-11g/上的文章时,怀疑出现了jar包冲突。


1

您只需要在类路径中添加此 jar 文件:

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

这个回答是否解决了问题?如果没有,那么最好将其作为评论(您目前缺乏声望来发表评论)。 - Wai Ha Lee

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接