File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes EJB and other Java EE Technologies and the fly likes EJB 3.0, Application-client vs. Web-client 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 "EJB 3.0, Application-client vs. Web-client" Watch "EJB 3.0, Application-client vs. Web-client" New topic
Author

EJB 3.0, Application-client vs. Web-client

ing erl
Greenhorn

Joined: Jan 27, 2006
Posts: 15
Hello,

Writing a tiny EJB 3.0 example here;
the application has 1 session bean acting as a facade, 1 entity bean matching a table within my database.
Creating a Application-client (main-method ) with a jndi.properties file which has the following content

'java.naming.factory.initial=org.jnp.interfaces.NamingContextFactory
java.naming.factory.url.pkgs=org.jboss.naming rg.jnp.interfaces
java.naming.provider.url=localhost'



I am able to fetch my Session-bean, with the code down below, which implements an Interface which is annotated with @Remote.
this is the code:





The example is working, and I am able to fetch the content of my database-table.

Wanting to perform the same operations using an Web-client.
For that task I create anservlet and within the doPost-method I want to fetch the reference to my EmployeeBean.
Should I not let my bean implement a Interface that uses the @Local annoatation ? due to the fact that my bean and webclient-app is floating around within the same Application Server ?

If you wanted to explain the InitialContext to me, not just referring me to the API but rather to an article or a book! *S* , how would you explain that - am I getting trhough to the containers-environment here ?

I am running JBoss 4.2.1, running Eclipse Europe 3.3 ( if you have any further tip ... )

Best regards, i
Krithika Srinath
Ranch Hand

Joined: Apr 11, 2006
Posts: 52
Yes. You can have a @Local business interface for your session bean and access it from your servlet or any web component as long as it runs in the same JVM of your EJBs(both belongs to same application and packaged in singel ear).

PS: you cannot use the same business interface for both remote and local.
ing erl
Greenhorn

Joined: Jan 27, 2006
Posts: 15
Hello,

Thanks for your reply.

Looking at my datasource which is configured in mysql-ds.xml and persistence.xml, I am able to access the handle to my database through an injection instead of a JNDI lookup like this:


Can I not do the same thing regarding my Local interface, or is the correct and right way ( maby the only way ) to access it using a JNDI lookup ?

Any ideas on how I could explain Context / InitialContext in the best way ?

regards, i
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: EJB 3.0, Application-client vs. Web-client