Home Java Javaee6 Building Enterprise Bean Perspective to Allow Access
Questions:Ask|Latest


 
 

Share on Google+Share on Google+

Building Enterprise Bean Perspective to Allow Access

Advertisement
In this tutorial you will learn how to create an enterprise bean that will be allowed to access locally or remotely.

Building Enterprise Bean Perspective to Allow Access

In this tutorial you will learn how to create an enterprise bean that will be allowed to access locally or remotely.

If the business interface of bean is not defined with @Local or @Remote then by default the business interface is a local interface.

Creating enterprise bean to permit local access

An enterprise bean that permits only for the local access can be created by one of the following (optional) way :

  • Make an enterprise bean implementation class without implement a business interface.
  • Use the @Local interface annotation to annotate the enterprise bean's business interface.
  • Define the interface by using the bean class with @Local and defining the interface name. for example :
    @Local(InterfaceName.class)
    public class BeanName implements InterfaceName { ... }

How to locally access an enterprise bean

To achieve the no-interface view for locally accessing of an enterprise bean which is disclosed as a local, use either the dependency injection or JNDI lookup.

  • Through Dependency Injection javax.ejb.EJB annotation and with defining the implementation class of enterprise bean is used to get the reference of the enterprise bean to the no-interface view. for example :
  • @EJB
    XYZBean xyzBean;
  • Through JNDI lookup, lookup method of javax.naming.InitialContext interface is used to get the reference of the enterprise bean to the no-interface view. for example :
  • XYZBean xyzBean= (XYZBean)
    InitialContext.lookup("java:module/XYZBean");

To achieve locally accessing of an enterprise bean which implements the local business interfaces, use either the dependency injection or JNDI lookup.

  • Through Dependency Injection javax.ejb.EJB annotation and with defining the local business interface name of enterprise bean is used to get the reference of the enterprise bean to the local business interface. for example
  • @EJB
    XYZ xyz;
  • Through JNDI lookup, lookup method of javax.naming.InitialContext interface is used to get the reference of the enterprise bean to the local business interface. for exmaple :
  • XYZLocal example = (XYZLocal)
    InitialContext.lookup("java:module/XYZLocal");

Creating enterprise bean to permit remote access

An enterprise bean that permits for the remote access can be created must either by :

  • Use the @Remote annotation with the enterprise bean's business interface. for example :
  • @Remote
    public interface InterfaceName { ... }
  • Use the @Remote with bean class, defining the business interface or interfaces.
  • @Remote(InterfaceName.class)
    public class BeanName implements InterfaceName { ... }

How to remotely access an enterprise bean

To achieve the accessing a client to an enterprise bean which implements the remote business interface, use either the dependency injection or JNDI lookup.

  • Through dependency injection javax.ejb.EJB annotation and defining the remote business interface name of enterprise bean is used to get the reference of an enterprise bean to the remote business interface. for example :
  • @EJB
    Example example;
  • Through JNDI lookup, lookup method of javax.naming.InitialContext interface is used to get the reference of the enterprise bean to a remote business interface.
  • ExampleRemote example = (ExampleRemote)
    InitialContext.lookup("java:global/myApp/ExampleRemote");
Advertisements

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

Ask Questions?    Discuss: Building Enterprise Bean Perspective to Allow Access  

Post your Comment


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