I am trying to call a service running on weblogic application server 8.1. I am using websphere 5.1 app server.
I am using the iiop protocol for the same.
My sample servlet code is..
========================================================
Hashtable ParamHash = new Hashtable();
String url = "iiop://hob3mla60402:7001";
ParamHash.put(InitialContext.INITIAL_CONTEXT_FACTORY, "com.ibm.websphere.naming.WsnInitialContextFactory");
ParamHash.put(InitialContext.PROVIDER_URL,url);
InitialContext ctx = new InitialContext(ParamHash);
TraderHome th = (TraderHome)
PortableRemoteObject.narrow(ctx.lookup("ejb20-statelessSession-TraderHome"),TraderHome.class);
=========================================================
I have written a servlet and deployed the same on the websphere application server and the code above is giving a call to the EJB service on the weblogic 8.1 server.
weblogic has some example EJB deployed..I am using the same.
I am getting the exception as folows.
java.lang.ClassCastException: Unable to load class: examples.ejb20.basic.statelessSession._TraderHome_Stub at com.ibm.rmi.javax.rmi.PortableRemoteObject.narrow(PortableRemoteObject.java:386) at javax.rmi.PortableRemoteObject.narrow(PortableRemoteObject.java:156) at HelloServlet.doGet(HelloServlet.java:40) at javax.servlet.http.HttpServlet.service(HttpServlet.java:740) at javax.servlet.http.HttpServlet.service(HttpServlet.java:853) at com.ibm.ws.webcontainer.servlet.StrictServletInstance.doService(StrictServletInstance.java:110) at com.ibm.ws.webcontainer.servlet.StrictLifecycleServlet._service(StrictLifecycleServlet.java:174) at com.ibm.ws.webcontainer.servlet.IdleServletState.service(StrictLifecycleServlet.java:313) at com.ibm.ws.webcontainer.servlet.StrictLifecycleServlet.service(StrictLifecycleServlet.java:116) at com.ibm.ws.webcontainer.servlet.ServletInstance.service(ServletInstance.java:283) at com.ibm.ws.webcontainer.servlet.ValidServletReferenceState.dispatch(ValidServletReferenceState.java:42) at com.ibm.ws.webcontainer.servlet.ServletInstanceReference.dispatch(ServletInstanceReference.java:40) at com.ibm.ws.webcontainer.webapp.WebAppRequestDispatcher.handleWebAppDispatch(WebAppRequestDispatcher.java:974) at com.ibm.ws.webcontainer.webapp.WebAppRequestDispatcher.dispatch(WebAppRequestDispatcher.java:555) at
Discussions
EJB programming & troubleshooting: Calling EJB running on weblogic 8.1 from websphere 5.1
-
Calling EJB running on weblogic 8.1 from websphere 5.1 (8 messages)
- Posted by: M T
- Posted on: July 13 2004 12:53 EDT
Threaded Messages (8)
- Use Weblogic. by Anil Kumar T on July 15 2004 07:01 EDT
- Sample code. by Anil Kumar T on July 15 2004 07:30 EDT
- Sample code. by M T on July 27 2004 16:51 EDT
-
Sample code. by M T on July 28 2004 11:54 EDT
- Sample code. by Amit Kulkarni on August 30 2004 09:06 EDT
-
Sample code. by M T on July 28 2004 11:54 EDT
- Sample code. by M T on July 27 2004 16:51 EDT
- Call the Weblogic RMI API from websphere application by Mohammad Intiyaz on February 16 2005 02:06 EST
- what about weblogic.jar by M T on February 25 2005 16:25 EST
- so what is the final solution by Raghu Subramaniam on July 05 2005 06:31 EDT
- what about weblogic.jar by M T on February 25 2005 16:25 EST
-
Use Weblogic.[ Go to top ]
- Posted by: Anil Kumar T
- Posted on: July 15 2004 07:01 EDT
- in response to M T
Hi, If I'm not wrong you are trying to call EJB which is runnin on weblogic from WebSphere. Your code looks like you are trying to call a EJB which is running on websphere. you need to lookup for WebLogic server EJB. Find out the Lookup procedure for weblogic version you are using and then try it.
thanks,
Anil. -
Sample code.[ Go to top ]
- Posted by: Anil Kumar T
- Posted on: July 15 2004 07:30 EDT
- in response to M T
Hi, below is the sample code if you dont get it. I think this is 8.1 version.
private SalesHome lookupSalesHome() throws NamingException {
String url = "t3://localhost:7001";
String user = "userid";
String password = "password";
Context ctx = null;
try {
// Get an InitialContext
Properties h = new Properties();
h.put(Context.INITIAL_CONTEXT_FACTORY, "weblogic.jndi.WLInitialContextFactory");
h.put(Context.PROVIDER_URL, url);
if (user != null) {
log ("user: " + user);
h.put(Context.SECURITY_PRINCIPAL, user);
if (password == null)
password = "";
h.put(Context.SECURITY_CREDENTIALS, password);
}
ctx = new InitialContext(h);
} catch (NamingException ne) {
log("We were unable to get a connection to the WebLogic server at "+url);
log("Please make sure that the server is running.");
throw ne;
}
try {
Object home = (SalesHome)ctx.lookup("SalesEJB.SalesHome");
return (SalesHome)PortableRemoteObject.narrow(home, SalesHome.class);
} catch (NamingException ne) {
log("The client was unable to lookup the EJBHome. Please make sure " +
"that you have deployed the ejb with the JNDI name " +
"SalesEJB.SalesHome on the WebLogic server at "+url);
throw ne;
}
} -
Sample code.[ Go to top ]
- Posted by: M T
- Posted on: July 27 2004 16:51 EDT
- in response to Anil Kumar T
I am trying to call the service running on Weblogic from Websphere.
My weblogic server is listening on 7001 port, If you look at the port in the URL it is 7001. I have to use the InitialContext factory as websphere's I can not use as weblogic's If I put the weblogic.jar in my classpath, the weblogic server does not start..!!
So I have to use the websphere's InitialContextFactory. Also I can not use t3 protocol as it is weblogic specific protocol...That is why I am using iiop as a base protocol..!! -
Sample code.[ Go to top ]
- Posted by: M T
- Posted on: July 28 2004 11:54 EDT
- in response to M T
I am trying to call the service running on Weblogic from Websphere.My weblogic server is listening on 7001 port, If you look at the port in the URL it is 7001. I have to use the InitialContext factory as websphere's I can not use as weblogic's If I put the weblogic.jar in my classpath, the websphere server does not start..!!So I have to use the websphere's InitialContextFactory. Also I can not use t3 protocol as it is weblogic specific protocol...That is why I am using iiop as a base protocol..!!
-
Sample code.[ Go to top ]
- Posted by: Amit Kulkarni
- Posted on: August 30 2004 21:06 EDT
- in response to M T
I think you have to specify the InitialContextFactory class of Weblogic.
With that class you can either use the URL as t3://xxxx or http://xxxx
For me both the lookups work but I need to have the weblogic class on the calling side. If websphere does not start with the entire weblogic.jar in its classpath, try starting it with the class weblogic.jndi.WLInitialContextFactory and the other required classes for this class in your classpath.
The J2EE contract here is only till the InitialContext and InitialContextFactory interfaces level. In order to use the JNDI service of a particular app server you need a corresponding ContextFactory class. -
Call the Weblogic RMI API from websphere application[ Go to top ]
- Posted by: Mohammad Intiyaz
- Posted on: February 16 2005 02:06 EST
- in response to M T
Hi,
I could able to invoke the session bean running in weblogic 7.0 from web sphere by following code.
*********************************
String url = "t3://localhost:7001";
String user = "XXX";
String password = "YYY";
Hashtable env = new Hashtable();
env.put(Context.INITIAL_CONTEXT_FACTORY, "weblogic.jndi.WLInitialContextFactory");
env.put(Context.PROVIDER_URL, url);
env.put(Context.SECURITY_PRINCIPAL, user);
env.put(Context.SECURITY_CREDENTIALS, password);
ctx = new InitialContext(env);
****************************************
how can we give Web sphere context and iiop protocal for achieving the same.
can you through some light on this
Thanks -
what about weblogic.jar[ Go to top ]
- Posted by: M T
- Posted on: February 25 2005 16:25 EST
- in response to Mohammad Intiyaz
do you have to include the weblogic.jar file somewhere on your websphere server location? -
so what is the final solution[ Go to top ]
- Posted by: Raghu Subramaniam
- Posted on: July 05 2005 06:31 EDT
- in response to M T
Hi,
We also tried using the iiop protocol to connect. We had a JSP in the Websphere and connected to a EJB in WebLogic using iiop. It worked from the JSP, but when we move the same code into EJB method of Websphere (that calls the EJB in WebLogic), it stops working.
We are getting the error:
javax.naming.CommunicationException: A communication failure occurred while attempting to obtain an initial context with the provider URL: "iiop://xxxxxxx:7001". 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.COMM_FAILURE: purge_calls:1218 reason=1 state=5 vmcid: IBM minor code: 306 completed: Maybe
Does it work if you call the WLS SB method from WAS SB method?
Regards
Raghu
The code is as follows:
try
{
String JNDI_NAME = "ejb20-statelessSession-TraderHome";
TraderHome home;
System.out.println("\n Start of JSP \n");
String url = "iiop://xxxxxxx:7001";
Properties env = new Properties();
env.put(
Context.INITIAL_CONTEXT_FACTORY,
"com.ibm.websphere.naming.WsnInitialContextFactory");
env.put(Context.PROVIDER_URL, url);
System.out.println("\n URL set = "+ url + " \n");
Context ctx = new InitialContext(env);
System.out.println("\n Created the context \n");
home = (TraderHome) ctx.lookup (JNDI_NAME);
System.out.println("\n JNDI_NAME set = "+ JNDI_NAME + " \n");
// create a Trader
System.out.println("Creating a trader");
Trader trader = home.create();
System.out.println("After Remote Create");
//(Trader) narrow(home.create(), Trader.class);
String [] stocks = {"BEAS", "MSFT", "AMZN", "HWP" };
// execute some buys
for (int i=0; i<stocks.length; i++) {
int shares = (i+1) * 100;
System.out.println("Buying "+shares+" shares of "+stocks[i]+".");
System.out.println("Using Remote Method");
trader.buy(stocks[i], shares);
}