EJB3调用期间发生错误 [英] Error during EJB3 call
问题描述
我已经写了一个简单的Ejb程序,从
安装步骤
最后JndI配置。
当我运行客户端代码时,我得到以下错误。
JSAS1480I:安装没有启用,因为ConfigURL属性文件未设置。
javax.naming.NamingException:获取WsnNameService属性时出错[根异常是org.omg.CORBA.TRANSIENT:初始和转发IOR不可访问vmcid:0x4942f000次要代码:3591已完成:否]
在com.ibm .ws.naming.util.WsnInitCtxFactory.mergeWsnNSProperties(WsnInitCtxFactory.java:1552)
在com.ibm.ws.naming.util.WsnInitCtxFactory.getRootContextFromServer(WsnInitCtxFactory.java:1042)
在com.ibm .ws.naming.util.WsnInitCtxFactory.getRootJndiContext(WsnInitCtxFactory.java:962)
在com.ibm.ws.naming.util.WsnInitCtxFactory.getInitialContextInternal(WsnInitCtxFactory.java:614)
在com.ibm .ws.naming.util.WsnInitCtx.getContext(WsnInitCtx.java:128)
在com.ibm.ws.naming.util.WsnInitCtx.getContextIfNull(WsnInitCtx.java:765)
在com.ibm .ws.naming.util.WsnInitCtx.lookup(WsnInitCtx.java:164)
在com.ibm.ws.naming.util.WsnInitCtx.lookup(WsnInitCtx.java:179)
在javax.naming .InitialContext.lookup(InitialContext.java:411)
at ejb31.test.TestEJB Client.main(TestEJBClient.java:27)
导致:org.omg.CORBA.TRANSIENT:初始和转发IOR无法访问vmcid:0x4942f000次要代码:3591已完成:否
在com.ibm.rmi .corba.ClientDelegate.createRequest(ClientDelegate.java:1276)
在com.ibm.CORBA.iiop.ClientDelegate.createRequest(ClientDelegate.java:1457)
在com.ibm.rmi.corba.ClientDelegate .createRequest(ClientDelegate.java:1164)
在com.ibm.CORBA.iiop.ClientDelegate.createRequest(ClientDelegate.java:1423)
在com.ibm.rmi.corba.ClientDelegate.request(ClientDelegate .java:1886)
at com.ibm.CORBA.iiop.ClientDelegate.request(ClientDelegate.java:1379)
在org.omg.CORBA.portable.ObjectImpl._request(ObjectImpl.java:449 )
在com.ibm.WsnBootstrap._WsnNameServiceStub.getProperties(_WsnNameServiceStub.java:38)
在com.ibm.ws.naming.util.WsnInitCtxFactory.mergeWsnNSProperties(WsnInitCtxFactory.java:1549)
... 9更多
引起的:java.net.ConnectException:connect:地址对loc无效机器或端口在远程机器上无效
在java.net.DualStackPlainSocketImpl.connect0(本机方法)
在java.net.DualStackPlainSocketImpl.socketConnect(DualStackPlainSocketImpl.java:83)
在java.net.AbstractPlainSocketImpl.doConnect(AbstractPlainSocketImpl.java:339)
在java.net.AbstractPlainSocketImpl.connectToAddress(AbstractPlainSocketImpl.java:200)
在java.net.AbstractPlainSocketImpl.connect(AbstractPlainSocketImpl.java :182)
在java.net.PlainSocketImpl.connect(PlainSocketImpl.java:172)
在java.net.SocksSocketImpl.connect(SocksSocketImpl.java:392)
在java.net。 Socket.connect(Socket.java:579)
在com.ibm.ws.orbimpl.transport.WSTCPTransportConnection.createSocket(WSTCPTransportConnection.java:313)
在com.ibm.CORBA.transport.TransportConnectionBase。 connect(TransportConnectionBase.java:357)
在com.ibm.ws.orbimpl.transport.WSTransport.getConnection(WSTransport.java:437)
在com.ibm.CORBA.transport.TransportBase.getConnecti on(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)
在com.ibm.rmi.corba.ClientDelegate._createRequest(ClientDelegate.java:2008)
在com.ibm.rmi.corba.ClientDelegate.createRequest(ClientDelegate.java:1186)
在com.ibm.rmi.corba.ClientDelegate.createRequest(ClientDelegate.java:1272)
... 17更多
注意:端口和地址是正确的:
安全屏幕截图
内部客户端
在war文件内的server.jar内
嗯,你必须看起来更好的屏幕截图,因为它是清晰可见启用管理安全性
是CHECKED 。
所以您必须在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>
有关详细信息,请查看以下页面 - 运行IBM Thin Client for Enterprise JavaBeans(EJB)
更新
现在您在代码中有问题。您必须对非托管客户端使用 PortableRemoteObject.narrow
。
而不是:
对象lobj;尝试{InitialContext ctx = new InitialContext(props);
lobj = ctx.lookup(checkName);
if(lobj instanceof ITestEJBRemoteInterface){//< #####这是问题
loEJB =(ITestEJBRemoteInterface)lobj;
}
使用:
lobj = initCtx.lookup(ejbJNDIName);
loEJB =(ITestEJBRemoteInterface)javax.rmi.PortableRemoteObject.narrow(lobj,ITestEJBRemoteInterface.class);
有关详细信息,请参阅如何查找EJB 3的远程接口而不使用依赖注入
I have written a simple Ejb program, by looking from
The files are
package ejb3.test;
import javax.ejb.Remote;
/**
* TODO: Document me!
*
* @author aprashanth
*
*/
@Remote
public interface ITestEJBRemoteInterface {
public boolean checkNames(String fsName);
}
Implementation Class:
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>
At the client side:
I have created the stub using createStub.bat of IBM.and that jar is imported at the client side.
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();
}
}
}
My project structure and the imported libraries as in the below figure:
At the WAS side, setup steps are as below: Port
Installation Steps
Lastly JndI Configuration.
When I run the client code, I get the following error.
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
Note: Port and address is correct:
Screen Shot of Security
New error on changing the inbound Configuration
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)
The war file which is deployed.
inside Client
Inside server.jar inside war file
Hmm, you have to look better on your screenshot, as it is clearly visible that Enable Administrative Security
is CHECKED.
So you either have to disable SSL in the RMI/IIOP inbound transport configuration, or properly configure your client to use SSL.
Something like this:
<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>
For details check the following page - Running the IBM Thin Client for Enterprise JavaBeans (EJB)
UPDATE
Now you have issue in the code. You have to use PortableRemoteObject.narrow
for unmanaged clients.
Instead of:
Object lobj; try { InitialContext ctx = new InitialContext(props);
lobj = ctx.lookup("checkName");
if (lobj instanceof ITestEJBRemoteInterface) { // <##### this is the problem
loEJB = (ITestEJBRemoteInterface) lobj;
}
use:
lobj = initCtx.lookup(ejbJNDIName);
loEJB = (ITestEJBRemoteInterface) javax.rmi.PortableRemoteObject.narrow(lobj , ITestEJBRemoteInterface.class);
For details see How to lookup the Remote Interface of an EJB 3 without using Dependency Injection
这篇关于EJB3调用期间发生错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!