mdb项目已创建和部署,但无法从独立程序进行查找

时间:2017-08-19 06:50:33

标签: ejb jms message-driven-bean glassfish-4.1

我已经创建了一个MDB bean并在glassfish 4中部署并且应用程序已成功部署,但我正在尝试使用独立客户端将消息放入队列中。我收到了这个错误。

**显示java.lang.NullPointerException     at com.sun.enterprise.naming.impl.SerialContext.getORB(SerialContext.java:347) javax.naming.NamingException:查找失败的' jms / myQueue'在SerialContext中[myEnv = {java.naming.provider.url = iiop:// localhost:3700,java.naming.factory .initial = com.sun.enterprise.naming.SerialInitContextFactory,java.naming.factory.state = com。 sun.corba.ee.impl.presentation.rmi.JNDIStateFactoryImpl,java.naming.factory.url.pkgs = com.sun.enterprise.naming} [root异常是javax.naming.NamingException:无法获取SerialContext的SerialContextProvider [myEnv] = {java.naming.provider.url = iiop:// localhost:3700,java.naming.factory .initial = com.sun.enterprise.naming.SerialInitContextFactory,java.naming.factory.state = com.sun.corba。 ee.impl.presentation.rmi.JNDIStateFactoryImpl,java.naming.factory.url.pkgs = com.sun.enterprise.naming} [根异常是java.lang.NullPointerException]]

引起:javax.naming.NamingException:无法为SerialContext获取SerialContextProvider [myEnv = {java.naming.provider.url = iiop:// localhost:3700,java.naming.factory.initial = com.sun。 enterprise.naming.SerialInitContextFactory,java.naming.factory.state = com.sun.corba.ee.impl.presentation.rmi.JNDIStateFactoryImpl,java.naming.factory.url.pkgs = com.sun.enterprise.naming} [Root异常是java.lang.NullPointerException] **

MDB类代码是::

    package test;

import java.util.logging.Level;
import java.util.logging.Logger;
import javax.ejb.ActivationConfigProperty;
import javax.ejb.MessageDriven;
import javax.jms.JMSException;
import javax.jms.Message;
import javax.jms.MessageListener;
import javax.jms.TextMessage;

@MessageDriven(activationConfig = {
    @ActivationConfigProperty(propertyName = "destinationLookup", propertyValue = "jms/myQueue")
    ,
        @ActivationConfigProperty(propertyName = "destinationType", propertyValue = "javax.jms.Queue")
    ,
        @ActivationConfigProperty(propertyName = "connectionFactoryLookup", propertyValue = "jms/myConnectionFactory")
})
public class testMDB1 implements MessageListener {

    public testMDB1() {
    }

    @Override
    public void onMessage(Message message) {
        if (message instanceof TextMessage) {
            TextMessage t = (TextMessage) message;
            try {
                System.out.println("ye le " + t.getText());
            } catch (JMSException ex) {
                Logger.getLogger(TestMDB.class.getName()).log(Level.SEVERE, null, ex);
            }
        }
    }

}

,客户端文件是

package test;
import java.util.Properties;
import javax.jms.ConnectionFactory;
import javax.jms.JMSContext;
import javax.jms.JMSProducer;
import javax.jms.Queue;
import javax.naming.Context;
import javax.naming.InitialContext;
import javax.naming.NamingException;

public class TestClient {

    public static void main(String[] args) {

        try {

            final Properties env = new Properties();
            env.put(Context.INITIAL_CONTEXT_FACTORY, "com.sun.enterprise.naming.SerialInitContextFactory");
            env.put(Context.URL_PKG_PREFIXES, "com.sun.enterprise.naming");
            env.put(Context.PROVIDER_URL, "iiop://localhost:3700");
            Context remoteContext = new InitialContext(env);
            System.out.println("remote context" + remoteContext.getEnvironment());
            Queue queue = (Queue) remoteContext.lookup("jms/myQueue");
            JMSContext jmsContext = ((ConnectionFactory) remoteContext.lookup("jms/myConnectionFactory")).createContext();
            JMSProducer producer = jmsContext.createProducer();
            producer.send(queue, "hello ");
            System.out.println("1. Sent TextMessage to the Queue");

        } catch (NamingException e) {
            e.printStackTrace();
        }
    }
}

我添加了gf-client.jar,orb-iiop.jar和appserv-rt.jar,但没有解决我的问题。

1 个答案:

答案 0 :(得分:1)

我开始知道glassfish 4.1有这个错误,本地客户端无法连接到MDB。我尝试了两个ejb项目,它运行得很好。