Home Java Javaee6 How to access Enterprise Beans

Related Tutorials


 
 

Share on Google+Share on Google+

How to access Enterprise Beans

Advertisement
In this tutorial you will learn that how to access Enterprise Beans (applicable only to session beans not to message-driven beans)

How to access Enterprise Beans

In this tutorial you will learn that how to access Enterprise Beans (applicable only to session beans not to message-driven beans)

Enterprise beans are accessed by the client in two ways either through a no-interface view or through a business interface.

  • No-interface view
  • In this view the enterprise bean implemented class discloses the public methods to clients. Using this view enterprise bean implemented class's or any super classes of the implementation class's public methods may be accessed by an enterprise bean.

  • Business interface
  • This interface is an interface of Java programming language which keeps the business methods of enterprise bean.

To use a session bean client will have to required either bean's business's interface methods or enterprise bean's public methods which has a no-interface view.

How to use Enterprise Beans in clients

To know before the use of Enterprise Beans in clients let us first know about the clients. The can be Local clients, Remote clients and Web Service clients. To identify these clients they have some characteristic.

Characteristics of Local clients :

  • They must run in the same application.
  • Clients can be a web component or other enterprise bean.
  • Enterprise bean position which will be used is not diaphanous to the local client.

Characteristics of Remote clients :

  • An enterprise bean which will access the client, called remote client if it run on an other machine or JVM however, running on different JVM is not necessary.
  • Clients can be a web component, an application client, or other enterprise bean.
  • Enterprise bean position which will be used is diaphanous to the remote client.
  • Remote clients which will use an enterprise bean that, enterprise bean will must have to implement the business interface.

Web Service clients :

Java EE application can be accessed by a web service client in two manner :

  • A web service made with JAX-WS can be used by the client.
  • By invoking stateless session bean's business methods.

Enterprise Beans are the server side component that encapsulates the logic of fulfillment of the purpose of an application. Instance of these Enterprise Beans in clients can be use/get by either the dependency injection or JNDI lookup.

Dependency Injection is a Java programming language annotations using which a instance of an Enterprise Bean can be get in a easy way. It is used when a client run inside the Java EE server-managed environment. Annotation that is used to support the dependency injection to the enterprise beans or the applications (JavaServer Faces web applications, Java EE application clients, JAX-RS web services, or other enterprise beans) which are runs within the Java EE server managed environment is javax.ejb.EJB.

JNDI, Java Naming and Directory Interface syntax is also used to get an instance of an Enterprise Bean. It is used when an application is running outside a Java EE server managed environment must required to perform an explicit lookup. To identify a Java EE components that will be explicitly lookup JNDI provides a global syntax.

Portable JNDI syntax :

There are three JNDI namespaces that are used for portable JNDI lookup :

java:global :- Used to find out the remote enterprise beans.

java:global[/application name]/module name/enterprise bean name[/interface name]

Here application and module names are the by default application and module names minus the file extension. Interface name is need only when more than one business interfaces are implemented by an enterprise bean, and the application names are need only when the application is packaged into an EAR (Enterprise Archieve ).

java:module :- use to find out the local enterprise beans inside the same module.

java:module/enterprise bean name/[interface name]

Here interface is need only when more than one business interfaces are implemented by an enterprise bean.

java:app :- used to find out the local enterprise beans which are packaged inside the same application.

java:app[/module name]/enterprise bean name[/interface name]

Here the module name is optional and the interface is need only when more than one business interfaces are implemented by an enterprise bean.

Allow a client for accessing

It is very important in any Java EE application that how to allow a client accessing by the enterprise bean i.e. remote, local or web service.

To allow for a remote or local accessing it is based on the following factors :

  1. Bean's coupling : It should be first identifiable that how the bean's are coupled i.e. Tight coupled or Loose coupled. Tightly coupled means that the beans which are contingent upon each other. Beans that are tightly coupled are beneficial for local accessing.
  2. Client's type : If application clients uses the enterprise bean then it should be permitted for remote accessing.
  3. Component distribution : In case of component distribution (components that can be distributed across various machine) enterprise bean should be permit to access remotely.
  4. Performance : Performance is a main factor for any application, it may depends upon the different operational environment. So you should not to worry about the performance, allow access according to their need.
Advertisements

If you enjoyed this post then why not add us on Google+? Add us to your Circles



Liked it!  Share this Tutorial


Follow us on Twitter, or add us on Facebook or Google Plus to keep you updated with the recent trends of Java and other open source platforms.

Posted on: December 20, 2011

Related Tutorials

Discuss: How to access Enterprise Beans  

Post your Comment


Your Name (*) :
Your Email :
Subject (*):
Your Comment (*):
  Reload Image
 
 
Comments:0
DMCA.com