gpt4 book ai didi

java - 与 Weblogic JMS 队列的连接失败

转载 作者:行者123 更新时间:2023-11-30 08:48:41 37 4
gpt4 key购买 nike

我正在尝试将消息写入 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 ) 中获取了代码

我从异常中看到上下文查找失败,我不能怀疑为什么?

最佳答案

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

关于java - 与 Weblogic JMS 队列的连接失败,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31782138/

37 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com