问题
I have written a simple Ejb program, by looking from
http://mrbool.com/how-to-use-enterprise-java-beans-3-x-based-application-with-websphere-8-5-application-server/28063
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
回答1:
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
来源:https://stackoverflow.com/questions/40124759/error-during-ejb3-call