• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Tim Cooke
  • paul wheaton
  • Jeanne Boyarsky
  • Ron McLeod
Sheriffs:
  • Paul Clapham
  • Liutauras Vilda
  • Devaka Cooray
Saloon Keepers:
  • Tim Holloway
  • Roland Mueller
Bartenders:

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

 
Ranch Hand
Posts: 763
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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,
 
Bartender
Posts: 1381
39
IBM DB2 Netbeans IDE Spring Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

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
Posts: 763
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
Bartender
Posts: 1381
39
IBM DB2 Netbeans IDE Spring Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

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
Posts: 763
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
Bartender
Posts: 1381
39
IBM DB2 Netbeans IDE Spring Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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 ?

 
Sheriff
Posts: 10445
227
IntelliJ IDE Ubuntu
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

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.
 
Jigar Naik
Ranch Hand
Posts: 763
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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 !!!
4.JPG
[Thumbnail for 4.JPG]
But i am not able to find the client jar as its just uri or something i am not able to understand
12.JPG
[Thumbnail for 12.JPG]
This is how i create project and there is a option of client jar
3.JPG
[Thumbnail for 3.JPG]
This is how i create project and there is a option of client jar
 
Claude Moore
Bartender
Posts: 1381
39
IBM DB2 Netbeans IDE Spring Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
Posts: 763
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
Bartender
Posts: 1381
39
IBM DB2 Netbeans IDE Spring Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
Posts: 763
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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...
1.JPG
[Thumbnail for 1.JPG]
EJB Deployed Successfully...
 
The human mind is a dangerous plaything. This tiny ad is pretty safe:
Smokeless wood heat with a rocket mass heater
https://woodheat.net
reply
    Bookmark Topic Watch Topic
  • New Topic