cancel
Showing results for 
Search instead for 
Did you mean: 

SOS: ClassCastException While Accessing EJB RemoteHome Interface from a WD

Former Member
0 Kudos

Hello All,

I am trying to access some EJB functionality from Web Dynpro project using the Data Access Command Bean (DACB) pattern.

The project is the popular BonusCalculator example from SDN but i am now implementing it in a DC format.

My Steps:

1. Created a simple EJB DC with both entity and session beans.

2. Wrap the EJB DC created in 1 as an EAR DC to make it deployable.

3. Create a Java Project DC to function as the JavaBean / DACB with the aim of exposing some of the methods in the session beans of the EJB DC. (Public Parts were created to allow for references).

I accessed the EJB interface in the DACB this way:

Properties props = new Properties();

props.put(Context.PROVIDER_URL,"localhost:50004");

props.put(Context.INITIAL_CONTEXT_FACTORY, "com.sap.engine.services.jndi.InitialContextFactoryImpl");

ctx = new InitialContext(props);

Object homeobjref = ctx.lookup("obi.com/dcearbonuscalculation/BonusCalculatorBean");

BonusCalculatorHome home =(BonusCalculatorHome) PortableRemoteObject.narrow(homeobjref, BonusCalculatorHome.class);

BonusCalculator theCalculator = home.create();

4. Create a Web Dynpro Project and did a JavaBean model import on the Java Project (that is, DACB).

5. Add the EAR to the WD project through sharing reference, add the JavaBean/DACB to WD project through Public Part.

6. Create a library project to warehourse the ejb and DACB jars for onward reference by the WD project.

7. EJB jar contains the EJB DC client classes, the DACB jar conatins the client clasees

6. Did the neccesary mappings and bindings in the controllers.

Each time i deployed and run the WD Project, the ClassCastException is thrown indicating some problem with the remote home interface in the EJB.

I have tried all sorts of tricks and with plenty of googling without sucess.

Strangely enough, an entirely diffrent Java DC project i created was able to use the EJB DC from an EJB client point of view (via the same DACB) without any issues; i was indeed able to persist data in my database table but the WD DC project will always throws exception on line number that points to:

BonusCalculatorHome home =(BonusCalculatorHome) PortableRemoteObject.narrow(homeobjref, BonusCalculatorHome.class) in the JavaBean model project - DACB;

I am just stuck at this point; I have been on this issue for days.

My Platform is:

NetWeaver Developer Studio (Version: 7.0.09) Build id: 200608262203

Regards.

Bakau Onafuwa

Edited by: Bakau Onafuwa on Oct 5, 2010 2:41 PM

Edited by: Bakau Onafuwa on Oct 5, 2010 8:42 PM

Accepted Solutions (0)

Answers (1)

Answers (1)

Former Member
0 Kudos

i) Your step 2) created an ear file for your ejbs.

ii) You should created an libary sda for your Java classes that expose the ejb

iii) You should test your java classes work before trying to use them through WD (If I understand you correctly you have done that already.)

iv) You should share the ear file as a sharing reference in WD

v) You should share the library sda as a library reference

Why don't you just use the Model framework provided by WD?

Former Member
0 Kudos

Thanks IIan for your response.

As i have said earlier, i created and deployed the EAR for the EJBs successfully.

I had done the Sharing Refeence in the WD DC; and i believe it is working because when

i removed the reference and re-ran the WD DC project; it threw all kind of exceptions.I had to put the reference back for the WD Project to build.

Getting the Classes for the JavaBean DC project for the SDA was a bit of challenge (i just could not figure it out initially)

Here are my steps:

(1.) Create a Java DC project (already exist in this instance)

(2.) Create the appropriate class in a package.

(3.) From the Package Explorer window, right-click the Java DC Project and select Export from the sub-menu.

(4.) choose Jar file and select your project as the resource to export in the next screen.

(5.) Specify the destination folder with the name of the jar; I specified a folder on my desktop. Could this be a problem?

(6.) Checked all the check boxes except 'Overwrite the file without warning' checkbox.

(7.) Click Next, Next, and finish.

(8.) It comes with an error prompt that Jar creation failed. The errro message says something about the resources being out of sync.......

I dont know the implication of this.

Note: For a Non-Java DC project, this error does not come up at all. The Jar export is always successfull. But i need the component as a DC.

(9.) Click Cancel to exit.

Though the creation failed, the jar file will stil be created with the classes.

I repeated these steps to get the EJB classes in a jar.

I used the Deploy tool to create the library SDA from the two Jars (JavaBean and EJB) and deployed it to the server.

I then reference the lib SDA from my WD DC project.

Can you a explain to me a better/seamless approach to get my EJB and Java DC project classes?

I had tried to get the EJB jar from the deployed EAR in Visual Admin but that could not help me.

As i have said, the JAva client i created works perfectly well but the WD DC will not.

I just cant figure out what i have done wrong. Can explain further what you meant by 'Model framework provided by WD'?

Thanks for you time.

Bakau Onafuwa

Former Member
0 Kudos

Thanks IIan for your response.

As i have said earlier, i created and deployed the EAR for the EJBs successfully.

I had done the Sharing Refeence in the WD DC; and i believe it is working because when

i removed the reference and re-ran the WD DC project; it threw all kind of exceptions.I had to put the reference back for the WD Project to build.

Getting the Classes for the JavaBean DC project for the SDA was a bit of challenge (i just could not figure it out initially)

Here are my steps:

(1.) Create a Java DC project (already exist in this instance)

(2.) Create the appropriate class in a package.

(3.) From the Package Explorer window, right-click the Java DC Project and select Export from the sub-menu.

(4.) choose Jar file and select your project as the resource to export in the next screen.

(5.) Specify the destination folder with the name of the jar; I specified a folder on my desktop. Could this be a problem?

(6.) Checked all the check boxes except 'Overwrite the file without warning' checkbox.

(7.) Click Next, Next, and finish.

(8.) It comes with an error prompt that Jar creation failed. The errro message says something about the resources being out of sync.......

I dont know the implication of this.

Note: For a Non-Java DC project, this error does not come up at all. The Jar export is always successfull. But i need the component as a DC.

(9.) Click Cancel to exit.

Though the creation failed, the jar file will stil be created with the classes.

I repeated these steps to get the EJB classes in a jar.

I used the Deploy tool to create the library SDA from the two Jars (JavaBean and EJB) and deployed it to the server.

I then reference the lib SDA from my WD DC project.

Can you a explain to me a better/seamless approach to get my EJB and Java DC project classes?

I had tried to get the EJB jar from the deployed EAR in Visual Admin but that could not help me.

As i have said, the JAva client i created works perfectly well but the WD DC will not.

I just cant figure out what i have done wrong. Can explain further what you meant by 'Model framework provided by WD'?

Thanks for you time.

Bakau Onafuwa

Former Member
0 Kudos

The SDA library just needs to include the sda public part as a used DC, you don't need to export anything.

You right click you packages in the Java DC and add them to two types of Public Parts. A Public part for builds (api) and public part for deploys (sda).

You then deploy the sda file (in the library file) and reference it in the sharing library reference in web dynpro and in the api in the used DC's as a build dependency.

Also you do not add the EJBs to the sda file; they are in their own ear file. If you put them into two deployables and reference both you will get Class Cast Exceptions; as the web dynpro deployable won't know which of the two to use.

Former Member
0 Kudos

Hi IIan.

I have tried this approach before but with myriad of issues, especially the not too pleasant 'NoClassFoundException' on the home interface.

I will still try it the way you have suggested and revert.

Apologies for the double posting.

Thanks once again.

Bakau Onafuwa

Former Member
0 Kudos

If you are finding it too complicated then just put your java classes in the same EJB DC as your ejb; and then add all of them to both the client and ejbjar public parts.

Then just add the client public part as a (build time dependency) used DC in the Web Dynpro DC; and then add the ear file as a sharing reference. You probably should also add the ear file as a (deploy and run time dependency) used DC in the Web Dynpro DC.

Edited by: Ilan Pillemer on Oct 6, 2010 10:09 PM

Former Member
0 Kudos

Hi IIan,

I am back again.

I have tried your suggestions and i did not hit any success point.

I created the Public Part of type assembly in the JavaBean DC and included it as a Used DC in a library project.

Then i did a library reference on the library project from my WD DC.

It built without any problem but threw a NoClassFoundException on a customised exception class i created in my EJB DC when i ran the WD DC project; I manage to resolve this.

Thereafter, the WD DC project complained of CreateException; i had to make the library DC project reference ejb20 library with the help of Deploy tool before the CreateException message could clear in the WD DC Project.

Now i am hitting the NoClassDefinitionException on the EJB Classes; it just seems to me that Sharing reference on the EAR DC project from the WD DC project is of no use; the WD project is not seen the classes of the EJB.

I am lost right now. It is really very frustrating that their are no definitve steps or procedure to get one of the simplest things done in NWDS 7.0

Are / Is there any other way to make my WD Project see the EJB classes so that i make progress?

Thanks for you time.

Bakau Onafuwa

Former Member
0 Kudos

Maybe you have a spelling mistake for the EJB ear reference in the sharing reference?

Check with the Classloader Viewer in VA that the ear is actually being referenced.

Former Member
0 Kudos

I dont think so.

This is what i put under my sharing reference:

obi.com/dcearbonuscalculation where 'obi.com' is my provider and dcearbonuscalculation is the application name.

Is it compulsory that the providers name is 'sap.com' ?

In my VA, the EAR name - 'obi.com/dcearbonuscalculation' is available under the EJB Container and the Deploy services. I can see my EJB jar under my EAR service in the EJB Container service and i have my two Bean Classses under the ejb jar. The bean classes are (1.) Session Bean Class: BonusCalculatorBean (2) Entity Bean Class: BonusBean. The home and remote interfaces are now where to be found.

Is it by default that EJB 2.* classes be available when the wrapping EAR is shared by WD project?

I have checked the Class Loader View! The WD is actually referecing the EAR with a red arrow to the EAR name. When i double click the EAR, it shows a linkage from the WD project with lemon green colored arrow.

rgds,

Bakau

Former Member
0 Kudos

How did you add your EJB to the ear file? Did you right click the DC and click "add to EAR"?

It sounds like your relevant classes are not in the ear. So you probably did not add your EJB to the ear file correctly.

Former Member
0 Kudos

Hopefullly you just need to now go to the package view of the EJB DC, find the package the Bean (and its interfaces are in) right click it and add it to both the ejbjar and client public parts as a tree.

Former Member
0 Kudos

Hello Illan,

Thanks for the suggestion,i will try it and revert.

Bakau Onafuwa

Former Member
0 Kudos

Hello IIan,

Finally, i have managed to clear the exceptions and everything is working perfectly well now.

For me, the sharing reference to the EAR DC from the WD DC project was problem; I had to remove the it before my project could work properly. Very very strange indeed!!! What a relief?

Thumbs up for you IIan; i found your suggestions (most especially the last one) very helpful.

Bakau Onafuwa