Java 从远程客户端访问websphere jms队列

Java 从远程客户端访问websphere jms队列,java,jms,websphere,Java,Jms,Websphere,背景 我是php&前端web开发人员,使用Netbeans在Java中开发一个应用程序,从websphere(我想是V8.5)JMS队列中读取数据,然后向适当的脚本/服务器发出命令。这是我10年来第一次接触Java,请耐心听我说。我的初始测试应用程序在承载jms队列的服务器上运行良好,但在尝试从远程位置连接时(此时正好是windows,但最终将是linux),我遇到了一个又一个错误。我一直在努力克服我对Java缺乏经验、诊断jar问题以及从websphere和其他地方查找显然需要的jar的过程,

背景 我是php&前端web开发人员,使用Netbeans在Java中开发一个应用程序,从websphere(我想是V8.5)JMS队列中读取数据,然后向适当的脚本/服务器发出命令。这是我10年来第一次接触Java,请耐心听我说。我的初始测试应用程序在承载jms队列的服务器上运行良好,但在尝试从远程位置连接时(此时正好是windows,但最终将是linux),我遇到了一个又一个错误。我一直在努力克服我对Java缺乏经验、诊断jar问题以及从websphere和其他地方查找显然需要的jar的过程,但最终还是遇到了麻烦。我已经看到了很多答案,包括“您需要正确的jar文件”之类的语句,但没有说明您需要哪个文件或thisone.jar以及其中提到的所有jar。我不知道如何找出应该是什么罐子。我读过一些帖子,上面说这个过程应该只使用我的库中的一些jar。我完全被卡住了

错误 我没有幸通过的错误

 javax.naming.NamingException: Failed to initialize the ORB [Root
 exception is org.omg.CORBA.INITIALIZE: can't instantiate default ORB
 implementation com.ibm.CORBA.iiop.ORB
剩下的全部信息是这样的

javax.naming.NamingException: Failed to initialize the ORB [Root exception is
org.omg.CORBA.INITIALIZE: can't instantiate default ORB implementation 
com.ibm.CORBA.iiop.ORB  vmcid: 0x0  minor code: 0  completed: No]   
at com.ibm.ws.naming.util.Helpers.getOrb(Helpers.java:314)     
javax.naming.NamingException: Failed to initialize the ORB [Root exception is  org.omg.CORBA.INITIALIZE: can't instantiate default ORB implementation  
com.ibm.CORBA.iiop.ORB  vmcid: 0x0  minor code: 0  completed: No]   
at com.ibm.ws.naming.util.WsnInitCtxFactory.getInitialContextInternal(WsnInitCtxFactory.java:384)   
at com.ibm.ws.naming.util.WsnInitCtx.getContext(WsnInitCtx.java:113)    
at com.ibm.ws.naming.util.WsnInitCtx.getContextIfNull(WsnInitCtx.java:428)  
at com.ibm.ws.naming.util.WsnInitCtx.lookup(WsnInitCtx.java:144)    
at javax.naming.InitialContext.lookup(InitialContext.java:411)  
at jmstool2.JmsConn.CreateFactCon(JmsConn.java:101)     
at jmstool2.JmsConn.connect(JmsConn.java:56)    
at jmstool2.Jmstool2.main(Jmstool2.java:20) 
Caused by: org.omg.CORBA.INITIALIZE: can't instantiate default ORB implementation com.ibm.CORBA.iiop.ORB  vmcid: 0x0  minor code: 0  completed: No  
at org.omg.CORBA.ORB.create_impl(ORB.java:327)  
at org.omg.CORBA.ORB.init(ORB.java:367)     
at com.ibm.ws.orb.GlobalORBFactory.init(GlobalORBFactory.java:85)   
at com.ibm.ejs.oa.EJSORBImpl.initializeORB(EJSORBImpl.java:174)     
at com.ibm.ejs.oa.EJSClientORBImpl.<init>(EJSClientORBImpl.java:97)     
at com.ibm.ejs.oa.EJSClientORBImpl.<init>(EJSClientORBImpl.java:73)     
at com.ibm.ejs.oa.EJSORB.init(EJSORB.java:386)  
at com.ibm.ws.naming.util.Helpers.getOrb(Helpers.java:305)  ... 8 more 
Caused by: java.lang.NoSuchFieldError: UNKNOWN  
at com.ibm.rmi.util.RepositoryId.createHashString(RepositoryId.java:738)    
at com.ibm.rmi.util.RepositoryId.<clinit>(RepositoryId.java:254)    
at com.ibm.rmi.iiop.CDROutputStream.<clinit>(CDROutputStream.java:1107)     
at com.ibm.rmi.corba.ORB.<init>(ORB.java:281)   at com.ibm.rmi.iiop.ORB.<init>(ORB.java:187)    at com.ibm.CORBA.iiop.ORB.<init>(ORB.java:576)  
at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)    
at sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:57)     
at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:45)
at java.lang.reflect.Constructor.newInstance(Constructor.java:526)
at java.lang.Class.newInstance(Class.java:374)
at org.omg.CORBA.ORB.create_impl(ORB.java:325)  ... 15 more
我还读到需要以下罐子

sibc.jms.jar
sibc.jndi.jar
sibc.orb.jar
我已经找到了这些,并添加了它们,尽管我也读到,如果您拥有我已经拥有的瘦客户机,就不需要这些

我使用的是JDK1.7

context factory: com.ibm.websphere.naming.WsnInitialContextFactory 
Provider URL: corbaloc:iiop:192.168.254.202:2809
正在创建上下文。但我无法建立队列工厂连接。我可以创建一个ip地址的套接字,并使用快速测试应用程序进行post

代码 这是类文件和所有连接位。这是一项正在进行的完整工作

import java.util.Hashtable;
import javax.naming.*;  
import javax.jms.*;
import com.ibm.CORBA.*;
import com.ibm.ws.*; /* 
/**

 * Connection Factory Notes on IBM Websphere
 * 
 * jndi/INConnectionFactory
 * jndi/OUTConnectionFactory 
 * 
 * jndi/INQueue
 * jndi/OUTQueue
 * 
 * jndi/INActivation  
 * jndi/OUTActivation  
 * 
 * websphere server:  192.168.254.202
 * 
 * JMS queued port: 5558  unsecured (MQ)   and 5578 secure
 * JMS Security Port 5557
 * JMS Direct Port: 5559
 * SOAP: 9976
 * //other ports mentioned: 7276 (unsecured) and 7286 (secured)
 * NOTE:  A bootstrap address with no port specification defaults to port 2809
 */
public class JmsConn {
    /*int jmsQueuedPort   = 5558;
    int jmsSecrityPort  = 5557;
    int jmsDirectPort   = 5559;
    int soapPort        = 9976;*/
    int bootstrap       = 2809; //default port
    int bootstrap10     = 2810;
    int unSecPort       = 7276;
    String serverIP     = "192.168.254.202";    
    String scheme       = "corbaloc:iiop:"; //e.g. ws, ldap,iiop, corbaloc:iiop
    String contextFactory   = "com.ibm.websphere.naming.WsnInitialContextFactory";
    String queueInName      = "jndi/INQueue";
    String queueOutName     = "jndi/OUTQueue";
    String outFactory       = "jndi/OUTConnectionFactory";
    String inFactory        = "jndi/INConnectionFactory";
    InitialContext jndiContext;
    ConnectionFactory connectionFactory;
    Connection qConn;
    String providerUrl = scheme+serverIP+":"+bootstrap;
    Session qSession;
    Queue q;


    public void connect() {          
        this.CreateContext();
        this.CreateFactCon(this.outFactory);
        this.getQueue(this.queueOutName);

    }

    public void Lookup(String thingToLookup){
        try{
            System.out.println("Attempting to lookup "+thingToLookup);
        }catch(Exception ex){
            System.out.println("ERROR: Could not perform lookup of  " + thingToLookup +             
                System.lineSeparator() + ex.toString());
           // System.out.println("Lookup Result: " + this.jndiContext.lookup);
            System.exit(3);
        }

    }


    public void CreateContext(){
        try{
            System.out.println("Attempting to create connection context");
            Hashtable env = new Hashtable(); // [jh] in theory this has been superceeded 
              // and should use HashMap
            env.put(Context.INITIAL_CONTEXT_FACTORY,this.contextFactory);
            System.out.println("context factory: "+this.contextFactory);
            System.out.println("Provider URL: "+this.providerUrl);
            env.put(Context.PROVIDER_URL, providerUrl); //+":"+this.jmsDirectPort
            try{
                this.jndiContext = new InitialContext(env);
                //this.jndiContext = new InitialContext();
            }catch(NamingException e){
                System.out.println("ERROR: Could not create JNDI context: " +  
                   System.lineSeparator() + e.toString());
                System.exit(1);
            }

            System.out.println("End of CreateContext.");  

        }catch(Exception exc){
            System.out.println("ERROR in CreateContext: "+exc.toString());
            System.exit(1);

        }
    }

    public void CreateFactCon(String factory){
        try{
            System.out.println("Attmepting to create factory lookup:");
            this.connectionFactory = (ConnectionFactory)this.jndiContext.lookup(factory);


        }catch(NamingException e){
            System.out.println("ERROR: Could not create factory connection:");
            e.printStackTrace(System.err);
            System.out.println(e.toString());
            System.exit(2);
        }
        System.out.println("Lookup successfull:");

        try{
            System.out.println("Attmepting to create connection:");
            this.qConn = this.connectionFactory.createConnection();
            this.qSession = qConn.createSession(false,Session.AUTO_ACKNOWLEDGE);
        }catch(Exception e){
            e.printStackTrace(System.err);
            System.out.println(e.toString());
            System.exit(4);
        }
        System.out.println("Connection successful.");



        System.out.println("End of CreateFactoryConnection.");            
    }


    public void getQueue(String queueName){
        try{
            this.q = (Queue)this.jndiContext.lookup(queueName);
        }catch(Exception e){
             System.out.println("ERROR: Could not get Queue:");
            e.printStackTrace(System.err);
            System.out.println(e.toString());
            System.exit(2);
        }
    }
    }
更新 将jar文件缩减到

com.ibm.ws.orb_8.5.0.jar com.ibm.ws.wjb.thingclient_8.5.0.jar com.ibm.ws.sib.client.thin.jms_8.5.0.jar

抛出以下错误

javax.naming.NamingException: Error getting WsnNameService properties [Root exception is org.omg.CORBA.TRANSIENT: initial and forwarded IOR inaccessible  vmcid: 0x4942f000  minor code: 3591  completed: No]
    at com.ibm.ws.naming.util.WsnInitCtxFactory.mergeWsnNSProperties(WsnInitCtxFactory.java:1552)
    at com.ibm.ws.naming.util.WsnInitCtxFactory.getRootContextFromServer(WsnInitCtxFactory.java:1042)
    at com.ibm.ws.naming.util.WsnInitCtxFactory.getRootJndiContext(WsnInitCtxFactory.java:962)
    at com.ibm.ws.naming.util.WsnInitCtxFactory.getInitialContextInternal(WsnInitCtxFactory.java:614)
    at com.ibm.ws.naming.util.WsnInitCtx.getContext(WsnInitCtx.java:128)
    at com.ibm.ws.naming.util.WsnInitCtx.getContextIfNull(WsnInitCtx.java:765)
    at com.ibm.ws.naming.util.WsnInitCtx.lookup(WsnInitCtx.java:164)
    at com.ibm.ws.naming.util.WsnInitCtx.lookup(WsnInitCtx.java:179)
    at javax.naming.InitialContext.lookup(InitialContext.java:411)
    at jmstool2.JmsConn.CreateFactCon(JmsConn.java:104)
    at jmstool2.JmsConn.connect(JmsConn.java:59)
    at jmstool2.Jmstool2.main(Jmstool2.java:20)
Caused by: org.omg.CORBA.TRANSIENT: initial and forwarded IOR inaccessible  vmcid: 0x4942f000  minor code: 3591  completed: No
    at com.ibm.rmi.corba.ClientDelegate.createRequest(ClientDelegate.java:1250)
    at com.ibm.CORBA.iiop.ClientDelegate.createRequest(ClientDelegate.java:1321)
    at com.ibm.rmi.corba.ClientDelegate.createRequest(ClientDelegate.java:1146)
    at com.ibm.CORBA.iiop.ClientDelegate.createRequest(ClientDelegate.java:1287)
    at com.ibm.rmi.corba.ClientDelegate.request(ClientDelegate.java:1853)
    at com.ibm.CORBA.iiop.ClientDelegate.request(ClientDelegate.java:1243)
    at org.omg.CORBA.portable.ObjectImpl._request(ObjectImpl.java:449)
    at com.ibm.WsnBootstrap._WsnNameServiceStub.getProperties(_WsnNameServiceStub.java:38)
    at com.ibm.ws.naming.util.WsnInitCtxFactory.mergeWsnNSProperties(WsnInitCtxFactory.java:1549)
    ... 11 more
Java Result: 2
检查这个-

您现在需要的唯一罐子是:

com.ibm.ws.orb_8.5.0.jar 
com.ibm.was.sib.client.thin.jms_8.5.0.jar 
com.ibm.ws.ejb.thinclient_8.5.0.jar 
因此,请从类路径中删除所有其他。 并确保这些JAR也在您的运行类路径中,而不仅仅是在构建期间

对于初始上下文,请尝试以下操作:

Hastable env = new Hastable();
env.put(Context.PROVIDER_URL,"iiop://localhost:2809");  // if using default ports
env.put(Context.INITIAL_CONTEXT_FACTORY, "com.ibm.websphere.naming.WsnInitialContextFactory");
InitialContext ctx = new InitialContext(env);

我发现了这一点,这实际上是一个非常接近的匹配项,但我不确定这与Netbeans SRC:Find On Page:org.omg.CORBA.INITIALIZE:cannot实例化默认ORB实现com.ibm.CORBA.iiop.orbigas有何关系,因为你昨天回答了我的帖子,似乎你就是这个主题的答案。我已经从我的库列表中删除了其他库,并尝试了更改,尽管localhost不是JMS队列所在的位置(代码中的IP地址是它所在的服务器),所以我将其保留在中,只是设置为使用iiop,而不是corbaloc:iiop。返回的错误是:javax.naming.NamingException:获取WsnNameService属性时出错[根异常是org.omg.CORBA.TRANSIENT:初始和转发IOR不可访问vmcid:0x4942f000次要代码:3591这种与系统相关的东西很烦人,因为它花费了所有的时间,而不是实际的“编程位”我通常可以计算出来,除了2809之外,它还使用其他端口,这就是为什么我要问防火墙的问题。你需要打开以下内容(给出默认值):ORB_LISTENER_ADDRESS=9100,SIB_ENDPOINT_ADDRESS=7276,SIB_ENDPOINT_SECURE_ADDRESS=7286。不,如果您是通过ip访问,您就可以了。您远程使用的是在本地工作的同一个Java版本吗?我慢慢没有主意了。您可以尝试-将此添加到您的客户端调用
-trace=ORBRas=all=enabled-tracefile=filename-Dcom.ibm.CORBA.Debug=true-Dcom.ibm.CORBA.CommTrace=true
。也许我们会在跟踪中找到一些有意义的东西。是的,它已经打开了。我想我已经对它进行了排序。查看返回的orbtraces,我得到了一个未知的后异常-websphere在远程机器所连接的传输连接中返回了它自己的本地服务器名uld在DNS中不匹配。我已将查找添加到远程主机文件中,并且答对了!
Hastable env = new Hastable();
env.put(Context.PROVIDER_URL,"iiop://localhost:2809");  // if using default ports
env.put(Context.INITIAL_CONTEXT_FACTORY, "com.ibm.websphere.naming.WsnInitialContextFactory");
InitialContext ctx = new InitialContext(env);