wood burning stoves 2.0*
The moose likes EJB and other Java EE Technologies and the fly likes Query about EJB + Why i am able to access the bean directly ? Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » EJB and other Java EE Technologies
Bookmark "Query about EJB + Why i am able to access the bean directly ?" Watch "Query about EJB + Why i am able to access the bean directly ?" New topic
Author

Query about EJB + Why i am able to access the bean directly ?

Jigar Naik
Ranch Hand

Joined: Dec 12, 2006
Posts: 759
Hi,

Environment : WebLogic Server 10.3, EJB 2.1

I have created one Stateless session bean using EJB 2.1.

And i should be able to access the bean using below JNDI lookup.



but when i tried to access the bean directly using below code, i am able to access the method.




I guess i am doing something wrong.
Why is it so ? Where is the security ? I should not be able to access the business method directly right ???

I am able to access the bean directly because i have AdviceBean.jar(Bean) file in my client classpath. and if i do not include the jar file in class path of client AdviceHomeLocal & AdviceLocal won't get resolved.

below is the content of my ejb-jar.xml



Thanks & Regards,


Jigar Naik


Claude Moore
Ranch Hand

Joined: Jun 24, 2005
Posts: 493
    
    1

Jigar Naik wrote: but when i tried to access the bean directly using below code, i am able to access the method.




I guess i am doing something wrong.
Why is it so ? Where is the security ? I should not be able to access the business method directly right ???

I am able to access the bean directly because i have AdviceBean.jar(Bean) file in my client classpath. and if i do not include the jar file in class path of client AdviceHomeLocal & AdviceLocal won't get resolved.


Hi Jigar,

what do you mean with "client" ? Is it a Java swing client? Does the class which references and use you bean implementation (AdviceBean) work ?
I never tried this before, anyway I suppose that, for a Java client (i.e, in a Java SE enviroment) the EJB implementation is just a simple class, like all the others.
You should be able to istantiate it via new operator, something like
and methods of AdviceBean may run without problems, at least they use some J2EE service which requires to be run in a J2EE appserver.
And, of course, you're not accessing the bean on the remote server.. you're executing something locally ,
where you should have only remote interfaces of your ejbs packed in the "classical" EJBClient.jar file, not EJB implementation.

So, I don't think that security is really violated...

Regards !

Jigar Naik
Ranch Hand

Joined: Dec 12, 2006
Posts: 759
By client i meant simple java class containing main method.

Currently i have bean implementation in my client application's class path so that my client application can resolve AdviceHomeLocal & AdviceLocal

But if i remove the bean implementation from client application's class path AdviceHomeLocal and AdviceLocal won't get resolved.

There must be a way to generate client stubs which implements the component interface and the implementation has the same method method as bean class but different implementation who knows how to communicate with remote method, kind of handling RMI stuffs.

If i am able to access the business method directly as below. There is no point in writing EJB.

AdviceBean myBean = new AdviceBean();
Claude Moore
Ranch Hand

Joined: Jun 24, 2005
Posts: 493
    
    1

Jigar Naik wrote:
There must be a way to generate client stubs which implements the component interface and the implementation has the same method method as bean class but different implementation who knows how to communicate with remote method, kind of handling RMI stuffs.


Which IDE are you using ? It should provide a method to build up a jar containing interfaces, stubs and skeletons...
Jigar Naik
Ranch Hand

Joined: Dec 12, 2006
Posts: 759
Oh is it !!!

i am using Oracle BEA Workshop for WebLogic 10.3, I have also specified element in ejb-jar.xml but i am not able to find any jar files. where does it create jar file ? It's not even showing any error.

Thanks !!
Claude Moore
Ranch Hand

Joined: Jun 24, 2005
Posts: 493
    
    1

I usually use Eclipse, in which I can explicitly export EJB client jar, and I never used Oracle Bea WorkShop.. I just suppose that
with a full rebuild you should find somewhere your jar, or that it would be some "export" option... how do you export / prepare
EAR or WAR files ?

Jaikiran Pai
Marshal

Joined: Jul 20, 2005
Posts: 10266
    
168

Jigar Naik wrote:
If i am able to access the business method directly as below. There is no point in writing EJB.

AdviceBean myBean = new AdviceBean();


Remember that, even though you might be able to instantiate and call the methods on that instance, it no longer is an Enterprise Java Bean. i.e. you'll no longer see the EJB semantics (like transactions, security) on that call.

[My Blog] [JavaRanch Journal]
Jigar Naik
Ranch Hand

Joined: Dec 12, 2006
Posts: 759
Please find the attached images. this is how i created project and while creating project there is an option to specify the client jar URI. URI !!!



[Thumbnail for 4.JPG]


[Thumbnail for 12.JPG]


[Thumbnail for 3.JPG]

Claude Moore
Ranch Hand

Joined: Jun 24, 2005
Posts: 493
    
    1

Ok, in your projects' list, you have a AccessBeanLocalClient which is a Java Project itself (while others should be "Web Project", "EJB Projects", Enterprise Projects).
Try to right click AccessBeanLocalClient and select Export Jar. You should be able to specify a path to store your jar in.
Jigar Naik
Ranch Hand

Joined: Dec 12, 2006
Posts: 759
Hi Claude,

As you can see in the last image, The AdviceBeanLocalClient(Java Project) is created by IDE only but it does not contain any classes or java files. its just blank project created for end user to test the bean. the code which is there in the image is written by me which contain the JNDI lookup and call the business method.

you can download the last image and see the bigger image so that you can see the code. there is no stubs
Claude Moore
Ranch Hand

Joined: Jun 24, 2005
Posts: 493
    
    1

Sorry, I made a mistake... I thought that you assigned AccessLocal etc etc to the client module

The really strange thing is that when you state to create a EJB module client, the IDE should create a project in which you should find all artifacts: in your case, project's name should be
"TestBeanClient"... but you'd find it in your Project Workspace....

A question: did you exposed (in Eclipse jargon, the verb is "promote") any method to interfaces ? Did you invoke a "Prepare for deploy" action on your EAR ?
Jigar Naik
Ranch Hand

Joined: Dec 12, 2006
Posts: 759
Yes i also had the same impression the artifacts should be in the client project but it's not there.

Well, don't have much idea about "prepare for deploy" but i have deployed the EJB as you can see in the screenshot.

Anyways, i will dig into it more... will post my findings...



[Thumbnail for 1.JPG]

 
It is sorta covered in the JavaRanch Style Guide.
 
subject: Query about EJB + Why i am able to access the bean directly ?