我写了一个简单的Ejb程序,从
开始文件是
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内部
答案 0 :(得分: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