【问题标题】:Error during EJB3 callEJB3 调用期间出错
【发布时间】:2016-10-19 07:22:20
【问题描述】:

我写了一个简单的 Ejb 程序,从

http://mrbool.com/how-to-use-enterprise-java-beans-3-x-based-application-with-websphere-8-5-application-server/28063

文件是

package ejb3.test;
import javax.ejb.Remote;
/**
 * TODO: Document me!
 *
 * @author aprashanth
 *
 */
@Remote 
public interface ITestEJBRemoteInterface { 
    public boolean checkNames(String fsName); 
   }

实现类:

package ejb3.test;

/**
 * TODO: Document me!
 *
 * @author aprashanth
 *
 */
import java.util.Arrays;
import java.util.List;

import javax.ejb.Stateless;
/** * Session Bean implementation class TestEJB */ 
@Stateless 
public class TestEJB implements ITestEJBRemoteInterface { 
    List<String> moListOfNames = Arrays.asList("Kevin","Jiten","Martina","Brian");

    /** * Default constructor. */ 
    public TestEJB() { } 
    /** * Find if the passed name is present in the default list of names * * 
     * 
     * @return */ 
        public boolean checkNames(String fsName) { 
            boolean lboolNamePresent = false; 
            if(fsName != null) 
            { 
                lboolNamePresent = moListOfNames.contains(fsName); 
             } 
            return lboolNamePresent; 
            } 
        }

Ejb-jar.xml:

<?xml version="1.0" encoding="UTF-8"?>
<ejb-jar xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://java.sun.com/xml/ns/javaee" xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/ejb-jar_3_1.xsd" version="3.1">
  <display-name>TestEJB3 </display-name>
  <ejb-client-jar>TestEJB3Client.jar</ejb-client-jar>
</ejb-jar>

在客户端:

我已经使用 IBM 的 createStub.bat 创建了存根,并且该 jar 是在客户端导入的。

package ejb31.test;

/**
 * TODO: Document me!
 *
 * @author aprashanth
 *
 */
import java.util.Properties;

import javax.naming.Context;
import javax.naming.InitialContext;
import javax.naming.NamingException;

import ejb3.test.ITestEJBRemoteInterface;

public class TestEJBClient { 
    /** * @param args */ 
    public static void main(String[] args) { 
        Properties props = new Properties(); 
        props.put(Context.INITIAL_CONTEXT_FACTORY, "com.ibm.websphere.naming.WsnInitialContextFactory");

        props.put(javax.naming.Context.PROVIDER_URL, "iiop://localhost:2809");

        ITestEJBRemoteInterface loEJB =null; 
        Object lobj; try { InitialContext ctx = new InitialContext(props); 
        lobj = ctx.lookup("checkName"); 
        if (lobj instanceof ITestEJBRemoteInterface) { 
            loEJB = (ITestEJBRemoteInterface) lobj; 
            } 
            String lsName = "Imran"; 
            System.out.println("Is "+ lsName + " present in the list:: "+loEJB.checkNames(lsName)); 
            System.out.println("EJB run successful"); 
            } catch (NamingException e) { 
                e.printStackTrace(); 
                } 
        } 
   }

我的项目结构和导入的库如下图:

在WAS端,设置步骤如下: 端口

安装步骤

最后是 JndI 配置。

当我运行客户端代码时,出现以下错误。

JSAS1480I: Security is not enabled because the ConfigURL property file is not set.
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 ejb31.test.TestEJBClient.main(TestEJBClient.java:27)
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:1276)
at com.ibm.CORBA.iiop.ClientDelegate.createRequest(ClientDelegate.java:1457)
at com.ibm.rmi.corba.ClientDelegate.createRequest(ClientDelegate.java:1164)
at com.ibm.CORBA.iiop.ClientDelegate.createRequest(ClientDelegate.java:1423)
at com.ibm.rmi.corba.ClientDelegate.request(ClientDelegate.java:1886)
at com.ibm.CORBA.iiop.ClientDelegate.request(ClientDelegate.java:1379)
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)
... 9 more
Caused by: java.net.ConnectException: connect: Address is invalid on local machine, or port is not valid on remote machine
at java.net.DualStackPlainSocketImpl.connect0(Native Method)
at java.net.DualStackPlainSocketImpl.socketConnect(DualStackPlainSocketImpl.java:83)
at java.net.AbstractPlainSocketImpl.doConnect(AbstractPlainSocketImpl.java:339)
at java.net.AbstractPlainSocketImpl.connectToAddress(AbstractPlainSocketImpl.java:200)
at java.net.AbstractPlainSocketImpl.connect(AbstractPlainSocketImpl.java:182)
at java.net.PlainSocketImpl.connect(PlainSocketImpl.java:172)
at java.net.SocksSocketImpl.connect(SocksSocketImpl.java:392)
at java.net.Socket.connect(Socket.java:579)
at com.ibm.ws.orbimpl.transport.WSTCPTransportConnection.createSocket(WSTCPTransportConnection.java:313)
at com.ibm.CORBA.transport.TransportConnectionBase.connect(TransportConnectionBase.java:357)
at com.ibm.ws.orbimpl.transport.WSTransport.getConnection(WSTransport.java:437)
at com.ibm.CORBA.transport.TransportBase.getConnection(TransportBase.java:187)
at com.ibm.rmi.iiop.TransportManager.get(TransportManager.java:97)
at com.ibm.rmi.iiop.GIOPImpl.getConnection(GIOPImpl.java:130)
at com.ibm.rmi.iiop.GIOPImpl.locate(GIOPImpl.java:219)
at com.ibm.rmi.corba.ClientDelegate.locate(ClientDelegate.java:1983)
at com.ibm.rmi.corba.ClientDelegate._createRequest(ClientDelegate.java:2008)
at com.ibm.rmi.corba.ClientDelegate.createRequest(ClientDelegate.java:1186)
at com.ibm.rmi.corba.ClientDelegate.createRequest(ClientDelegate.java:1272)
... 17 more

注意:端口和地址正确:

安全截图

更改入站配置时出现新错误

JSAS1480I: Security is not enabled because the ConfigURL property file is not set.
Exception in thread "P=818203:O=0:CT" java.lang.NullPointerException
at ejb31.test.TestEJBClient.main(TestEJBClient.java:32)

部署的war文件。

在客户端

war 文件里面的 server.jar 里面

【问题讨论】:

  • 您的服务器上是否开启了安全功能?添加全球安全页面的截图。
  • @XSurgent,我做了这些更改,现在我得到了一个不同的错误。我已经附在上面了。
  • @Gas 我已经粘贴了安全屏幕截图。
  • @Gas,未启用安全性...

标签: java deployment websphere ejb-3.0 websphere-8


【解决方案1】:

嗯,您必须在屏幕截图上看起来更好,因为很明显Enable Administrative Security 已检查

因此,您要么必须在 RMI/IIOP 入站传输配置中禁用 SSL,要么正确配置客户端以使用 SSL。

类似这样的:

<java_install_root>/bin/java  
-classpath com.ibm.ws.ejb.thinclient_8.5.0.jar:<list_of_your_application_jars_and_classes> 
-Djava.naming.provider.url=iiop://<your_application_server_machine_name> 
-Dcom.ibm.SSL.ConfigURL=file:///home/user1/ssl.client.props
-Dcom.ibm.CORBA.ConfigURL=file:///home/user1/sas.client.props
<fully_qualified_class_name_to_run>

详情请查看以下页面 - Running the IBM Thin Client for Enterprise JavaBeans (EJB)

更新

现在您的代码有问题。对于非托管客户端,您必须使用 PortableRemoteObject.narrow。 而不是:

   Object lobj; try { InitialContext ctx = new InitialContext(props); 
   lobj = ctx.lookup("checkName"); 
   if (lobj instanceof ITestEJBRemoteInterface) {   // <##### this is the problem
        loEJB = (ITestEJBRemoteInterface) lobj; 
   } 

使用:

lobj = initCtx.lookup(ejbJNDIName);
loEJB = (ITestEJBRemoteInterface)        javax.rmi.PortableRemoteObject.narrow(lobj , ITestEJBRemoteInterface.class);

详情见How to lookup the Remote Interface of an EJB 3 without using Dependency Injection

【讨论】:

  • 我已经按照您的建议进行了更改,但我仍然遇到同样的错误。还有哪些可能出错的可能性。
  • @user2900314,更新您的代码和错误,因为错误不能相同
  • 你是对的,不知道哪里出了问题。我重新部署了战争并重新启动了服务器,它现在工作正常。谢谢 非常感谢。 :)
猜你喜欢
  • 2014-09-25
  • 1970-01-01
  • 2012-10-28
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2021-08-26
  • 2011-07-18
相关资源
最近更新 更多