我正在尝试向在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)
中获取了代码我从异常中看到上下文查找失败了,我不敢怀疑为什么?
答案 0 :(得分:1)
我修好了。问题是由于我添加到项目中的一些不需要的罐子。基本上我已将所有Weblogic jar添加到我的项目中。后来我删除了所有的Jars,然后离开了wlclient.jar,wljmsclient.jar。我在阅读https://redstack.wordpress.com/2009/12/21/a-simple-jms-client-for-weblogic-11g/上的文章时怀疑是Jar冲突。
答案 1 :(得分:1)
你只需要在classpath中使用这个jar:
\wlserver_10.3\server\lib\wlclient.jar