cancel
Showing results for 
Search instead for 
Did you mean: 

Calling session bean's business method through web dynpro component

Amey-Mogare
Contributor
0 Kudos

Hi All,

Can anybody tell me how to call a session bean's methods through a web dynpro WITHOUT java-model or web service model ??

I have following scenario:-

1. Stateless Session bean having two business methods

2. Web Dynpro component

3.Now i want to call business methods without using any model. I have got following piece of code but I dont know how to go about it.

4.Where do i have to set JNDI name for session bean? which interface will be looked for?

5. Do I have to declare public part for EJB DC? If yes, how?


//This is inside web dynpro component

InitialContext   context = new InitialContext(); 
o = context.lookup(JNDIName);
 
TestSessionbeanHome homeRef = (TestSessionbeanHome) PortableRemoteObject.narrow( o,                                                                                
TestSessionbeanHome.class);

TestSessionbean beanRef = homeRef.create();

<returnValue> = beanRef.<ejb method name>

Please help to get a step-by-step approach to this case.

Thanks and regards,

Amey Mogare

Accepted Solutions (0)

Answers (3)

Answers (3)

Amey-Mogare
Contributor
0 Kudos

Hi,

My issue got resolved by following procedure. I did local lookup.

1.In ejb-j2ee-engine.xml, put the JNDI name of Sessionbean

2. Add complete EJB DC to Used DCs of Web Dynpro DC with Build-time dependency

3. Add u201CActive DCs --> sap.com_SAP-JEE_1 --> ejb20u201D to Used DCs of Web Dynpro DC with Build-n-Deploy-n-Run time dependency

4. Add EJB DC project to Java Build Path of Web Dynpro DC

5. Add a Sharing Reference of J2EE Application DC to Web Dynpro DC

6. Sharing Reference String = <provider name> + <display name of J2EE Application as appearing in application.xml file replacing u2018/u2019 by u2018~u2019>

for ex: u2013 sap.com/reqpstapscreqpstapja_reqid

6. Add following Code into Web Dynpro Controller to lookup and access session bean

*Note: In the lookup string, append JNDI name of Sessionbean after u2018localejbs/u2019


InitialContext context;
SessionRequestIDLocalHome beanLocalHome;
SessionRequestIDLocal beanLocal;
String requestID = null;	
		
context = new InitialContext();

beanLocalHome = (SessionRequestIDLocalHome) context.lookup("localejbs/SessionRequestIDBean");
		
beanLocal = beanLocalHome.create();

requestID = beanLocal.<business method>;

Edited by: Amey Mogare on Dec 24, 2008 5:13 AM

siddharth_jain
Active Contributor
0 Kudos

Hi,

please make sure that you have declared Business methods in Corresponding local and remote interfaces of EJB class also.

Siddharth

Amey-Mogare
Contributor
0 Kudos

I just checked it. Those business methods are declared in respective interfaces too.

Thanks and regards,

Amey Mogare

Former Member
0 Kudos

Hi,

Is compiler able to resolve SessionRequestID class?

if not try to make sure that your dependencies are correct.

Regards

Ayyapparaj

Amey-Mogare
Contributor
0 Kudos

Yes,

Because see in above code, it is not giving any error on line


SessionRequestID beanRef = homeRef.create();

And also when I do control+space after typing 'SessionReq' it is showinh all interfaces.

I have already mentioned about the type of dependencies I'm using.

This is very strange !!!

Thanks and regards,

Amey Mogare

Former Member
0 Kudos

Hi Amey Mogare,

Do the DC Build. (Right click on Webdynpro DC -> Development Components -> build).

Regards,

VJR.

Amey-Mogare
Contributor
0 Kudos

Hi,

If I comment out the part that is using session bean's business method, DC is building fine.

And if I uncomment, then compiler is unabl eto resolve business method(s).

And i would like to mention that my EJB + J2EE App DC is building properly, but it havent yet deployed properly as I am waiting for data-source-alias name prefix to be configured by ERP team. So will this be a reason why Web Dynpro DC is not able to resolve business methods ??

Because Web Dynpro DC is able to resolved all interfaces of Session bean and entity bean. But when it comes to business method, its not able to resolve.

Any more ideas why it is not happening?

Pls help.

-


Now i went through some forum posts regarding this and found that we also need to add EJB DC to Java Build Path for WebDynproDC>Properties>Java Build Path.

I did this and now it is able to resolve business methods and DTOs as well. So to summarize I did following:-

1. Added EJB DC (complete DC) as a Used DC to Web Dynpro DC with Buid-n-Deploy-n-Run time dependency

2. Added Sharing reference of J2EE application DC to Web Dynpro DC -->Properties

This reference I constructed as follows:-

<vendorname>/<name of j2ee application as appearing under display name tag in application.xml (replacing '/' with '~')>

So my Sharing Reference becomes:- <vendorname>/reqpstapscreqpstapja_reqid

3. Added EJB DC to Java Build Path in Web Dynpro DC's properties

4. Then I added following piece of code to get object of SessionBean class


InitialContext context = new InitialContext();
Object o = context.lookup("java:comp/env/ejb/SessionRequestIDBean");
SessionRequestIDHome homeRef = (SessionRequestIDHome) PortableRemoteObject.narrow(o, SessionRequestIDHome.class);
SessionRequestID beanRef = homeRef.create();
beanRef.<business method>

But After doing this I am facing another problem :-

The build fails saying it is not able find the package for DTOs. But when I see the Component Controller's code it is not showing any red or yellow marks.

Can anybody pls help me out here?

Thanks and regards,

Amey Mogare

Former Member
0 Kudos

hi amey,

Please read the following thread

this is explained there clearly

Thanks and Regards

shanto aloor

Amey-Mogare
Contributor
0 Kudos

Hi,

That thread was really very helpful.

I have done following :-

1. Added EJB DC (complete DC) as a Used DC to Web Dynpro DC with Buid-time dependency

2. Added Sharing reference of J2EE application DC to Web Dynpro DC -->Properties

This reference I constructed as follows:-

<vendorname>/<name of j2ee application as appearing under display name tag in application.xml (replacing '/' with '~')>

So my Sharing Reference becomes:- <vendorname>/reqpstapscreqpstapja_reqid

3. Then I added following piece of code to get handle of SessionBean class


InitialContext context = new InitialContext();
Object o = context.lookup("java:comp/env/ejb/SessionRequestIDBean");
SessionRequestIDHome homeRef = (SessionRequestIDHome) PortableRemoteObject.narrow(o, SessionRequestIDHome.class);
SessionRequestID beanRef = homeRef.create();
beanRef.<business method>		

Now problem here is, when I do control + space after beanRef, I am not able to see my business methods.

Why is this happening??

Pls help.

Thanks and regards,

Amey Mogare