Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Eclipse Projects » Remote Application Platform (RAP) » RAP/OSGi under WebSphere 8.5 to EJB(Talking to an EJB in WAS from a RAP/OSGi WAR (same WebSphere))
RAP/OSGi under WebSphere 8.5 to EJB [message #1272252] Mon, 17 March 2014 09:29 Go to next message
John Gymer is currently offline John Gymer
Messages: 187
Registered: November 2012
Location: UK
Senior Member
Struggling to get a RAP/OSGi application packaged in a WAR and deployed to IBM Websphere 8.5 to successfully call an EJB packaged into a separate EAR within the same WebSphere server. I'm using a single Windows 7 machine for all this, but don't think this is relevant.

The same configuration works ok in WebLogic and JBoss without any problems, and it appears that there is something different about the way WAS uses ClassLoaders.

Here's my code to call the EJB:

System.out.println("<<<<****EABEJB****>>>> EJB call...");

System.out.println("<<<<****EABEJB****>>>> Initialise the Contexts...");
Hashtable env = new Hashtable();
Context baseContext;
try {
	baseContext = new InitialContext();
} catch (NamingException e1) {
	System.out.println("<<<<****EABEJB****>>>> EABEJB failed - creating base context - " + e1);
	e1.printStackTrace();
	return;
}
Context localContext;
try {
	localContext = (Context)baseContext.lookup("java:comp/env");
} catch (NamingException e1) {
	System.out.println("<<<<****EABEJB****>>>> EABEJB failed - creating local context (use base context for local context) - " + e1);
	localContext = baseContext;
	e1.printStackTrace();
}
Context ejbContext;
try {
	ejbContext = (Context)localContext.lookup("ejb");
} catch (NamingException e1) {
	System.out.println("<<<<****EABEJB****>>>> EABEJB failed - creating ejb context (use local context for ejb context) - " + e1);
	ejbContext = localContext;
	e1.printStackTrace();
}

System.out.println("<<<<****EABEJB****>>>> Locate the SOM EJB...");
Object localObject = null;
try {
	localObject = ejbContext.lookup("SOM");
} catch (NamingException e1) {
	System.out.println("<<<<****EABEJB****>>>> EABEJB failed - lookup SOM in ejbContext (trying base Context next) - " + e1);
	e1.printStackTrace();
	try {
		localObject = baseContext.lookup("SOM");
	} catch (NamingException e) {
		System.out.println("<<<<****EABEJB****>>>> EABEJB failed - lookup SOM in baseContext - " + e1);
		e.printStackTrace();
		return;
	}
}

System.out.println("<<<<****EABEJB****>>>> Locate SOM's CALL method...");
Method localMethod;
Method[] arrayOfMethod = null;
Class<?>[] interfaces = localObject.getClass().getInterfaces();
String foundIName = null;
for (int i = 0; i < interfaces.length; i++) {
	String iName = interfaces[i].getName();
	if ((iName.endsWith("_Local")) || (iName.endsWith("_Remote"))) {
		arrayOfMethod = interfaces[i].getMethods();
		foundIName = interfaces[i].getName();
		System.out.println("<<<<****EABEJB****>>>> Found interface " + foundIName);
		break;
	}
}
if (arrayOfMethod == null)
{
	System.out.println("<<<<****EABEJB****>>>> Failed to locate an appropriate interface on " + localObject.getClass().getName());
	return;
}
String callMName = null;
for (int j = 0; j < arrayOfMethod.length; j++)
if (arrayOfMethod[j].getName().endsWith("call"))
{
	localMethod = arrayOfMethod[j];
	callMName = arrayOfMethod[j].getName();
	System.out.println("<<<<****EABEJB****>>>> Found call method " + callMName + " for " + localObject.getClass().getName() + " on interface " + foundIName);
	break;
}
if (callMName == null)
{
	System.out.println("<<<<****EABEJB****>>>> Failed to locate call method for " + localObject.getClass().getName() + " on interface " + foundIName);
	return;
}
System.out.println("<<<<****EABEJB****>>>> Happy so far!");
  
System.out.println("<<<<****EABEJB****>>>> Preparing Import Views...");
SomImport importView = new SomImport();
ImpInteger ins = new ImpInteger();
ins.setA(w_ia.ImportCalc85IntegerA);
ins.setB(w_ia.ImportCalc85IntegerB);
importView.setImpInteger(ins);

System.out.println("<<<<****EABEJB****>>>> Classloaders on each side...");
System.out.println("[[[****EABEJB****]]] Got the remote lookup object OK (localObject): " + localObject.getClass().getName() + " object: " + localObject);
System.out.println("[[[****EABEJB****]]] localObject's classloader: " + localObject.getClass().getClassLoader());
System.out.println("[[[****EABEJB****]]] server's classloader: " + SOM_Remote.class.getClassLoader());
System.out.println("[[[****EABEJB****]]] localObject's super: " + localObject.getClass().getSuperclass());
System.out.println("[[[****EABEJB****]]] server's super: " + SOM_Remote.class.getSuperclass());

System.out.println("<<<<****EABEJB****>>>> Cast SOM_Remote...");
SOM_Remote server = (SOM_Remote)localObject;

System.out.println("<<<<****EABEJB****>>>> Call SOM EJB...");
SomExport exportView;
try {
	exportView = server.Somcall(importView);
} catch (Exception e) {
	System.out.println("<<<<****EABEJB****>>>> Failed to call SOM EJB Server - " + e);
	e.printStackTrace();
	return;
}

//retrieve exportView data
System.out.println("<<<<****EABEJB****>>>> EJB SOM returned a result of: " + exportView.getExpResult());

w_oa.ExportCalc85ResultInt = exportView.getExpResult().getInt();
System.out.println("<<<<****EABEJB****>>>> All fabulous!");

It doesn't matter too much what this does, and in fact the EJB (called "SOM") is a simple addition calculator with 2 numeric inputs and 1 numeric result, so very simple.

Under WAS, I get a Class Cast Exception on the line, toward the end:

SOM_Remote server = (SOM_Remote)localObject;


Here is the debug output:
...
[17/03/14 10:29:25:292 GMT] 0000027b SystemOut     O <<<<****EABEJB****>>>> Locate SOM's CALL method...
[17/03/14 10:29:25:292 GMT] 0000027b SystemOut     O <<<<****EABEJB****>>>> Found interface calc.SOM_Remote
[17/03/14 10:29:25:292 GMT] 0000027b SystemOut     O <<<<****EABEJB****>>>> Found call method Somcall for calc._SOM_Remote_Stub on interface calc.SOM_Remote
[17/03/14 10:29:25:292 GMT] 0000027b SystemOut     O <<<<****EABEJB****>>>> Happy so far!
[17/03/14 10:29:25:292 GMT] 0000027b SystemOut     O <<<<****EABEJB****>>>> Preparing Import Views...
[17/03/14 10:29:25:293 GMT] 0000027b SystemOut     O <<<<****EABEJB****>>>> Classloaders on each side...
[17/03/14 10:29:25:294 GMT] 0000027b SystemOut     O [[[****EABEJB****]]] Got the remote lookup object OK (localObject): calc._SOM_Remote_Stub object:
 IOR:00bdbdbd00000025524d493a63616c632e534f4d5f52656d6f74653a30303030303030303030303
03030303000bdbdbd000000010000000000000104000102bd000000096a6d6764656c6c3700bd238c000
0007c4a4d4249000000124773e3aa37643062633737336533616166633334000000240000005849454a5
002004410e7a7077365727665723103454a420000003eadac00020001000000000f00000063616c632e5
34f4d5f52656d6f7465acac00020001111600000043414c43454a4223534f4d454a422e6a617223534f4
d00000007000000010000001400bdbdbd0501000100000000000101000000000049424d0a0000000800b
d00011626000100000026000000020002bdbd49424d04000000050005020102bdbdbd0000001f0000000
400bd0003000000200000000400bd0001000000250000000400bd0003
[17/03/14 10:29:25:294 GMT] 0000027b SystemOut     O [[[****EABEJB****]]] localObject's classloader: 
com.ibm.ws.classloader.CompoundClassLoader@699bb9e6[app:CALCEJB]
Local ClassPath: C:\JVM\WebSphere\WSAppSvr85\profiles\AppSrv01\installedApps\jmgdell7Node01Cell\CALCEJB.ear\SOMEJB.jar;
C:\JVM\WebSphere\WSAppSvr85\profiles\AppSrv01\installedApps\jmgdell7Node01Cell\CALCEJB.ear;
C:\JVM\WebSphere\WSAppSvr85\profiles\AppSrv01\installedApps\jmgdell7Node01Cell;
C:\JVM\WebSphere\WSAppSvr85\profiles\AppSrv01\installedApps\jmgdell7Node01Cell\CALCEJB.ear\genrt.85.jar
   Parent: com.ibm.ws.classloader.ProtectionClassLoader@b0563276
   Delegation Mode: PARENT_FIRST
[17/03/14 10:29:25:294 GMT] 0000027b SystemOut     O [[[****EABEJB****]]] server's classloader: org.eclipse.osgi.internal.baseadaptor.DefaultClassLoader@b831d9c[uk.co.iet.rapide.appsvr:1.0.0(id=3)]
[17/03/14 10:29:25:294 GMT] 0000027b SystemOut     O [[[****EABEJB****]]] localObject's super: class javax.rmi.CORBA.Stub
[17/03/14 10:29:25:294 GMT] 0000027b SystemOut     O [[[****EABEJB****]]] server's super: null
[17/03/14 10:29:25:294 GMT] 0000027b SystemOut     O <<<<****EABEJB****>>>> Cast SOM_Remote...


...the pertinent exception returned as:

[17/03/14 12:18:50:233 GMT] 0000007b SystemErr     R   Caused by: java.lang.ClassCastException: calc._SOM_Remote_Stub incompatible with calc.SOM_Remote


As you can see, it finds the EJB "SOM" no problems, but for some odd reason the ClassLoader being used on the client side is the EJB's ClassLoader (CALCEJB).

If I code my EJB call into a standard EAR/WAR (not using RAP/OSGi), then it resolves correctly using the client's ClassLoader... like this:

...
[17/03/14 10:42:46:343 GMT] 00000072 SystemOut     O <<<<****EABEJB****>>>> Locate SOM's CALL method...
[17/03/14 10:42:46:343 GMT] 00000072 SystemOut     O <<<<****EABEJB****>>>> Found interface calc.SOM_Remote
[17/03/14 10:42:46:343 GMT] 00000072 SystemOut     O <<<<****EABEJB****>>>> Found call method Somcall for calc._SOM_Remote_Stub on interface calc.SOM_Remote
[17/03/14 10:42:46:343 GMT] 00000072 SystemOut     O <<<<****EABEJB****>>>> Happy so far!
[17/03/14 10:42:46:344 GMT] 00000072 SystemOut     O <<<<****EABEJB****>>>> Preparing Import Views...
[17/03/14 10:42:46:348 GMT] 00000072 SystemOut     O <<<<****EABEJB****>>>> Classloaders on each side...
[17/03/14 10:42:46:349 GMT] 00000072 SystemOut     O [[[****EABEJB****]]] Got the remote lookup object OK (localObject): calc._SOM_Remote_Stub object:
IOR:00bdbdbd00000025524d493a63616c632e534f4d5f52656d6f74653a303030303030303030303030
3030303000bdbdbd000000010000000000000104000102bd000000096a6d6764656c6c3700bd238c0000
007c4a4d4249000000124773e3aa37643062633737336533616166633334000000240000005849454a50
02004410e7a7077365727665723103454a420000003eadac00020001000000000f00000063616c632e53
4f4d5f52656d6f7465acac00020001111600000043414c43454a4223534f4d454a422e6a617223534f4d
00000007000000010000001400bdbdbd0501000100000000000101000000000049424d0a0000000800bd
00011626000100000026000000020002bdbd49424d04000000050005020102bdbdbd0000001f00000004
00bd0003000000200000000400bd0001000000250000000400bd0003
[17/03/14 10:42:46:349 GMT] 00000072 SystemOut     O [[[****EABEJB****]]] localObject's classloader: 
com.ibm.ws.classloader.CompoundClassLoader@a98662b1[war:CALCWVWS/calcwvws.war]
   Local ClassPath: C:\JVM\WebSphere\WSAppSvr85\profiles\AppSrv01\installedApps\jmgdell7Node01Cell\CALCWVWS.ear\calcwvws.war\WEB-INF\lib\CCALC85.jar;C:\JVM\WebSphere\WSAppSvr85\profiles\AppSrv01\installedApps\jmgdell7Node01Cell\CALCWVWS.ear\calcwvws.war\WEB-INF\lib\EAB.jar;
C:\JVM\WebSphere\WSAppSvr85\profiles\AppSrv01\installedApps\jmgdell7Node01Cell\CALCWVWS.ear\calcwvws.war\WEB-INF\lib\json.jar;
C:\JVM\WebSphere\WSAppSvr85\profiles\AppSrv01\installedApps\jmgdell7Node01Cell\CALCWVWS.ear\calcwvws.war\WEB-INF\lib\SOM_dpy.jar;
C:\JVM\WebSphere\WSAppSvr85\profiles\AppSrv01\installedApps\jmgdell7Node01Cell\CALCWVWS.ear\calcwvws.war\WEB-INF\lib\webview85.jar;
C:\JVM\WebSphere\WSAppSvr85\profiles\AppSrv01\installedApps\jmgdell7Node01Cell\CALCWVWS.ear\calcwvws.war;
C:\JVM\WebSphere\WSAppSvr85\profiles\AppSrv01\temp\wscache\CALCWVWS\calcwvws.war\com.ca.gen.webview.soap.requests.RequestHandler
   Parent: com.ibm.ws.classloader.CompoundClassLoader@1872e2c5[app:CALCWVWS]
   Delegation Mode: PARENT_FIRST
[17/03/14 10:42:46:349 GMT] 00000072 SystemOut     O [[[****EABEJB****]]] server's classloader: 
com.ibm.ws.classloader.CompoundClassLoader@a98662b1[war:CALCWVWS/calcwvws.war]
   
Local ClassPath: C:\JVM\WebSphere\WSAppSvr85\profiles\AppSrv01\installedApps\jmgdell7Node01Cell\CALCWVWS.ear\calcwvws.war\WEB-INF\lib\CCALC85.jar;C:\JVM\WebSphere\WSAppSvr85\profiles\AppSrv01\installedApps\jmgdell7Node01Cell\CALCWVWS.ear\calcwvws.war\WEB-INF\lib\EAB.jar;C:\JVM\WebSphere\WSAppSvr85\profiles\AppSrv01\installedApps\jmgdell7Node01Cell\CALCWVWS.ear\calcwvws.war\WEB-INF\lib\json.jar;C:\JVM\WebSphere\WSAppSvr85\profiles\AppSrv01\installedApps\jmgdell7Node01Cell\CALCWVWS.ear\calcwvws.war\WEB-INF\lib\SOM_dpy.jar;C:\JVM\WebSphere\WSAppSvr85\profiles\AppSrv01\installedApps\jmgdell7Node01Cell\CALCWVWS.ear\calcwvws.war\WEB-INF\lib\webview85.jar;C:\JVM\WebSphere\WSAppSvr85\profiles\AppSrv01\installedApps\jmgdell7Node01Cell\CALCWVWS.ear\calcwvws.war;
C:\JVM\WebSphere\WSAppSvr85\profiles\AppSrv01\temp\wscache\CALCWVWS\calcwvws.war\com.ca.gen.webview.soap.requests.RequestHandler
   Parent: com.ibm.ws.classloader.CompoundClassLoader@1872e2c5[app:CALCWVWS]
   Delegation Mode: PARENT_FIRST
[17/03/14 10:42:46:350 GMT] 00000072 SystemOut     O [[[****EABEJB****]]] localObject's super: class javax.rmi.CORBA.Stub
[17/03/14 10:42:46:350 GMT] 00000072 SystemOut     O [[[****EABEJB****]]] server's super: null
[17/03/14 10:42:46:350 GMT] 00000072 SystemOut     O <<<<****EABEJB****>>>> Cast SOM_Remote...
[17/03/14 10:42:46:350 GMT] 00000072 SystemOut     O <<<<****EABEJB****>>>> Call SOM EJB...
[17/03/14 10:42:47:132 GMT] 00000072 SystemOut     O <<<<****EABEJB****>>>> EJB SOM returned a result of: Int = "3"
[17/03/14 10:42:47:132 GMT] 00000072 SystemOut     O <<<<****EABEJB****>>>> All fabulous!


You can see that this time it used the client ClassLoader (CALCWVWS/calcwvws.war) and the Cast worked fine.

Back to the RAP/OSGi WAR... I have specified this for my launch.ini:

osgi.parentClassloader=app
osgi.contextClassLoaderParent=ccl


..."ccl" appears to be required, or it doesn't make it very far through the JNDI lookup at all. I'm don't understand these properties for OSGi properly though, so this may be inappopriate.

In the client WAR I have my EJB interface defined as:

import javax.ejb.Remote;

@Remote public interface SOM_Remote 
{
  public SomExport Somcall(SomImport in)
  	throws Exception
  ;
}


I have NOT included any of the WebSphere EJB or ORB jars as these are all available in WebSphere anyway... these are being resolved ok, so I don't believe there is anything missing - it is a ClassLoader issue.

Another option I have tried is to change WAS to have a Classloader policy of "Single" instead of "Multiple", in an effort to force the EJB and client WAR to use the same ClassLoader, but to no avail.

I'm sure my config is close to working, but I am just missing something about the ClassLoader/ClassPath and how this works under OSGi/RAP within WebSphere. Every other combination of OSGi (standalone), WebLogic, JBoss, and also a non-RAP/OSGi Client in WebSphere work just fine, as expected, but WebSphere appears different.

Any help and suggestions would be appreciated! If I've ommitted some other useful information then let me know - I've provided quite a lot already, but didn't want to overload with irrelevant info!

Thanks, John


---
Just because you can doesn't mean you should
Re: RAP/OSGi under WebSphere 8.5 to EJB [message #1273153 is a reply to message #1272252] Wed, 19 March 2014 12:03 Go to previous messageGo to next message
Roland Welker is currently offline Roland Welker
Messages: 10
Registered: October 2013
Junior Member
Sounds very familiar with the problems I had on WASCE (I know not the same code base). Try to use a remote initial context, that worked fine for me.
Re: RAP/OSGi under WebSphere 8.5 to EJB [message #1274398 is a reply to message #1273153] Fri, 21 March 2014 08:18 Go to previous messageGo to next message
John Gymer is currently offline John Gymer
Messages: 187
Registered: November 2012
Location: UK
Senior Member
Thanks Roland. I'm not sure how to do that, but will research a bit... any detailed info would be appreciated!


---
Just because you can doesn't mean you should
Re: RAP/OSGi under WebSphere 8.5 to EJB [message #1277779 is a reply to message #1274398] Wed, 26 March 2014 09:05 Go to previous messageGo to next message
Roland Welker is currently offline Roland Welker
Messages: 10
Registered: October 2013
Junior Member
Hi John,

Sorry for the delay. In WASCE you do it this way:

prop.put(Context.INITIAL_CONTEXT_FACTORY,"org.apache.openejb.client.RemoteInitialContextFactory");
prop.put("java.naming.provider.url", "ejbd://localhost:4201");
					
prop.setProperty(Context.SECURITY_PRINCIPAL, "system");
prop.setProperty(Context.SECURITY_CREDENTIALS, "manager");
					prop.setProperty("openejb.authentication.realmName", "geronimo-admin"); 
InitialContext ServerConnection = new InitialContext(prop);


So, you will find the relevant WAS Remote Initial Context Factory. the second option is to give it relevant network details (you probably can ommit that).

And last 3 options is security on the Initial Context.

I hope this is of any use.

Roland
Re: RAP/OSGi under WebSphere 8.5 to EJB [message #1281754 is a reply to message #1277779] Tue, 01 April 2014 05:56 Go to previous message
John Gymer is currently offline John Gymer
Messages: 187
Registered: November 2012
Location: UK
Senior Member
FYI, I've resolved my WebSphere/RAP issues by removing OSGi from, the picture and going for RWT stand-alone. Took a lot of fiddling to figure out what JARs to put at which level, but mostly everything sits simply in the WAR in WEB-INF/lib. Accessing Resources were also an issue - any file that I needed access to had to be placed in the src folder of my application jar, and anything accessed as an RWT Resource had to go within an appropriate JAR at the WAR's WEB-LIB/lib level.
Hopefully that's useful info for others in the future.


---
Just because you can doesn't mean you should
Previous Topic:Chrome and RAP 2.1
Next Topic:How to configure Apache as Reverse Proxy for RAP Application
Goto Forum:
  


Current Time: Fri Aug 22 07:51:44 EDT 2014

Powered by FUDForum. Page generated in 0.02549 seconds