At first I want to tell that similar type of questions has been asked here but still I can't find the solution of my problem.
I have a EJB Project (name = HelloWorldEJBProject). There I have created a stateless remote EJB (name = HelloWorldEJB). I have also created an remote interface there (name= HelloWorldEJBInterfaceRemote). After that I am creating a jar & an ear of the project after compiling everything using ant. Then I deployed the EAR in the WebSphere Application Server 6.1.
Next I have also created a stand alone java project (name = HelloWorldClient), put the jar of the HelloWorldEJBProject to this project build path. Now while I am doing the look up I am getting errors.
HelloWorldEJB.java:
package com.staples.ejb;
import com.staples.ejb.interfaces.HelloWorldEJBInterfaceRemote;
import javax.ejb.Stateless;
@Stateless
public class HelloWorldEJB implements HelloWorldEJBInterfaceRemote {
public HelloWorldEJB() {
}
public String helloWorld() {
return "Hello World";
}
}
Client.java (Inside HelloWorldClient project):
package com.staples.client.processor;
import com.staples.client.util.ApplicationUtil;
import com.staples.ejb.interfaces.HelloWorldEJBInterfaceRemote;
public class Client {
static private HelloWorldEJBInterfaceRemote helloInterface = ApplicationUtil.getHelloEJBHandle();
public static void main(String[] args) {
System.out.println(helloInterface.helloWorld());
}
}
ApplicationUtil.java (Inside HelloWorldClient project):
import java.util.Hashtable;
import javax.naming.Context;
import javax.naming.InitialContext;
import javax.naming.NamingException;
import javax.rmi.PortableRemoteObject;
import com.staples.ejb.interfaces.HelloWorldEJBInterfaceRemote;
public class ApplicationUtil {
public static Object getContext(){
Object obj = null;
Context context;
try {
Hashtable env = new Hashtable();
env.put(Context.INITIAL_CONTEXT_FACTORY,"com.ibm.websphere.naming.WsnInitialContextFactory");
//Also tried the following
//env.put(Context.PROVIDER_URL,"iiop://localhost:2809");
env.put(Context.PROVIDER_URL,"corbaloc:iiop:localhost:2809");
Context ctx = new InitialContext(env);
obj = ctx.lookup("ejb/HelloEAR/http://ift.tt/1GyhATM" + HelloWorldEJBInterfaceRemote.class.getName());
} catch (NamingException e) {
e.printStackTrace();
}
return obj;
}
public static HelloWorldEJBInterfaceRemote getHelloEJBHandle()
{
Object obj = getContext();
HelloWorldEJBInterfaceRemote helloInterface = (HelloWorldEJBInterfaceRemote) PortableRemoteObject.narrow(obj, HelloWorldEJBInterfaceRemote.class);
return helloInterface;
}
Error:
Jun 10, 2015 6:25:55 PM com.ibm.ws.naming.util.WsnInitCtxFactory
WARNING: jndiUnavailCommErr
javax.naming.ServiceUnavailableException: A communication failure occurred while attempting to obtain an initial context with the provider URL: "corbaloc:iiop:localhost:2809". Make sure that any bootstrap address information in the URL is correct and that the target name server is running. A bootstrap address with no port specification defaults to port 2809. Possible causes other than an incorrect bootstrap address or unavailable name server include the network environment and workstation network configuration. [Root exception is org.omg.CORBA.TRANSIENT: java.net.ConnectException: Connection refused: connect:host=vdipn5243.staplesams.com,port=2809 vmcid: IBM minor code: E02 completed: No]
at com.ibm.ws.naming.util.WsnInitCtxFactory.mapInitialReferenceFailure(WsnInitCtxFactory.java:2226)
at com.ibm.ws.naming.util.WsnInitCtxFactory.mergeWsnNSProperties(WsnInitCtxFactory.java:1386)
at com.ibm.ws.naming.util.WsnInitCtxFactory.getRootContextFromServer(WsnInitCtxFactory.java:924)
at com.ibm.ws.naming.util.WsnInitCtxFactory.getRootJndiContext(WsnInitCtxFactory.java:848)
at com.ibm.ws.naming.util.WsnInitCtxFactory.getInitialContextInternal(WsnInitCtxFactory.java:533)
at com.ibm.ws.naming.util.WsnInitCtx.getContext(WsnInitCtx.java:117)
at com.ibm.ws.naming.util.WsnInitCtx.getContextIfNull(WsnInitCtx.java:712)
at com.ibm.ws.naming.util.WsnInitCtx.lookup(WsnInitCtx.java:171)
at javax.naming.InitialContext.lookup(InitialContext.java:363)
at com.staples.client.util.ApplicationUtil.getContext(ApplicationUtil.java:27)
at com.staples.client.util.ApplicationUtil.getHelloEJBHandle(ApplicationUtil.java:38)
at com.staples.client.processor.Client.<clinit>(Client.java:8)
at java.lang.J9VMInternals.initializeImpl(Native Method)
at java.lang.J9VMInternals.initialize(J9VMInternals.java:196)
Caused by: org.omg.CORBA.TRANSIENT: java.net.ConnectException: Connection refused: connect:host=vdipn5243.staplesams.com,port=2809 vmcid: IBM minor code: E02 completed: No
at com.ibm.CORBA.transport.TransportConnectionBase.connect(TransportConnectionBase.java:425)
at com.ibm.ws.orbimpl.transport.WSTransport.getConnection(WSTransport.java:429)
at com.ibm.CORBA.transport.TransportBase.getConnection(TransportBase.java:187)
at com.ibm.rmi.iiop.TransportManager.get(TransportManager.java:93)
at com.ibm.rmi.iiop.GIOPImpl.getConnection(GIOPImpl.java:129)
at com.ibm.rmi.iiop.GIOPImpl.locate(GIOPImpl.java:205)
at com.ibm.rmi.corba.Corbaloc.locateUsingINS(Corbaloc.java:307)
at com.ibm.rmi.corba.Corbaloc.resolve(Corbaloc.java:378)
at com.ibm.rmi.corba.ORB.objectURLToObject(ORB.java:3770)
at com.ibm.CORBA.iiop.ORB.objectURLToObject(ORB.java:3256)
at com.ibm.rmi.corba.ORB.string_to_object(ORB.java:3667)
at com.ibm.ws.naming.util.WsnInitCtxFactory.stringToObject(WsnInitCtxFactory.java:1511)
at com.ibm.ws.naming.util.WsnInitCtxFactory.mergeWsnNSProperties(WsnInitCtxFactory.java:1362)
... 12 more
Caused by: java.net.ConnectException: Connection refused: connect
at java.net.PlainSocketImpl.socketConnect(Native Method)
at java.net.PlainSocketImpl.doConnect(PlainSocketImpl.java:391)
at java.net.PlainSocketImpl.connectToAddress(PlainSocketImpl.java:252)
at java.net.PlainSocketImpl.connect(PlainSocketImpl.java:239)
at java.net.SocksSocketImpl.connect(SocksSocketImpl.java:389)
at java.net.Socket.connect(Socket.java:551)
at java.net.Socket.connect(Socket.java:501)
at java.net.Socket.<init>(Socket.java:409)
at java.net.Socket.<init>(Socket.java:223)
at com.ibm.ws.orbimpl.transport.WSTCPTransportConnection.createSocket(WSTCPTransportConnection.java:270)
at com.ibm.CORBA.transport.TransportConnectionBase.connect(TransportConnectionBase.java:354)
... 24 more
Exception in thread "P=953453:O=0:CT" java.lang.NullPointerException
at com.staples.client.processor.Client.main(Client.java:13)
I am not sure also what to write as a argument of context.lookup(). I am pretty new in EJB. Can anybody help me please? Thanks in advance.
Aucun commentaire:
Enregistrer un commentaire