cancel
Showing results for 
Search instead for 
Did you mean: 

java bean model using ejb

Former Member
0 Kudos

hi all,

I a working on a sample webdynpro application where am using javabean model which access a bussiness method from ejb containing business logic..Now my problem is that bussiness method of ejb is not geting called..My java bean code is as follows:

public class sampleejbbean {
int num1,num2,res;
SampleejbLocal local = null;
SampleejbLocalHome home = null;
public sampleejbbean() throws CreateException
{
try
{
InitialContext ctx = new InitialContext();
home = (SampleejbLocalHome)ctx.lookup("samplesession");
local = home.create();
}
catch(Exception e)
{
e.printStackTrace();
}
}
public void execute()
{	
	try
{
this.res = local.method1(num1,num2);	
System.out.print("result");
System.out.println(res);
}
catch(Exception ex)
{
ex.printStackTrace();
return;
}

Here method1 is my ejb bussiness method..am able to see output display but when i enter inputs am not getting any output..and when we try to excute it a java application it is showing an exception at initial context.

javax.naming.NoInitialContextException: Need to specify class name in environment or system property, or as an applet parameter, or in an application resource file:  java.naming.factory.initial
	at javax.naming.spi.NamingManager.getInitialContext(NamingManager.java:640)
	at javax.naming.InitialContext.getDefaultInitCtx(InitialContext.java:243)
	at javax.naming.InitialContext.getURLOrDefaultInitCtx(InitialContext.java:280)
	at javax.naming.InitialContext.lookup(InitialContext.java:347)
	at com.samplejava.sampleejbbean.<init>(sampleejbbean.java:30)
	at com.samplejava.sampleejbbean.main(sampleejbbean.java:98)

Can anyone give me an idea about this.

Thanks in advance,

Anusha

Edited by: anusha sabbineni on Sep 1, 2008 10:02 AM

Accepted Solutions (0)

Answers (3)

Answers (3)

Former Member
0 Kudos
Former Member
0 Kudos

Hi Anusha,

InitialContext ctx = new InitialContext();

Replace above line with the following Code:

Properties p = new Properties();

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

p.put(Context.PROVIDER_URL, "Server IPAddress:Portnumber");

p.put(Context.SECURITY_PRINCIPAL, "username");

p.put(Context.SECURITY_CREDENTIALS, "password");

InitialContext ctx = new InitialContext(p );

//Server IP Address -- give u r server ip address

//Portnumber -- like 50004

//username, password means server user name and server password

and also replace this line:

home = (SampleejbLocalHome)ctx.lookup("samplesession");

as : home = (SampleejbHome)ctx.lookup("samplesession");

and also replace the below two lines :

SampleejbLocal local = null;

SampleejbLocalHome home = null;

with the following Code:

Sampleejb local = null;

SampleejbHome home = null;

becoz remote objects need to be take.

With Regards,

Roop Kumar

Edited by: Roop kumar Annavarapu on Sep 1, 2008 3:49 PM

Former Member
0 Kudos

Hi Anusha Sabbineni,

Add " ejb20.jar " file to Project reference of that Particular Project.

Right click on the Project & Select Properties. In that Properties window select " Java Build Path " on Left side & Select " Libraries " Tab on Top & Click on " Add External JARs " Button and select " ejb20.jar " and Click " Ok " Button on Lower side.

I hope it will solve your Problem.

If You have any more doubts feel free to ask.

With Regards,

Roop Kumar.

Edited by: Roop kumar Annavarapu on Sep 1, 2008 2:41 PM

Former Member
0 Kudos

hi,

Thanks for your reply. I already added that jar file.But am unable to get the output.Can you provide some other solution

regards,

Anusha

Former Member
0 Kudos

Hi Anusha,

1.) Which Version of ejb your are using ? Means ejb 3.0 ?

Please give reply to the above Question for Clear Understanding the Scenario ..

With Regards,

RooP KumaR.

Edited by: Roop kumar Annavarapu on Sep 1, 2008 3:40 PM