Enterprise java bean is a technology to create deployable business components. These components implement business logic in the application layer of a distributed architecture. If a component can be available in an application server for any type of client then it is called a deployable component.
- JDK - This provides the core package
and compile for EJB files.
- Application server - This provides the runtime environment for EJB. It provides an EJB container and web container.
This can be WebLogic, WebSphere or JBoss.
Using Web logic
Domain creation in web logic
Domain - This is a name to refer to a folder of the file system. A domain
can be used to start the server. The server present in a domain can be used to
deploy web applications and EJB.
In web logic 7.0
Start-> program->web logic platform->configuration wizard->Choose WLS domain+
provide domain name.
->A single server->provide server name and port number (keep default)->provide
username + password->window service (no)-> start menus (yes)->create->End
configuration wizard->next->finish
Starting server in the domain
Start->program->web logic platform->user projects->domain name->start server
Finding the default page in a browser
Use http://localhost:7001 in any web browser after starting the server.
Context creation in WebLogic 7.0 for servlet and JSP
- Create the context folder inside the domain
folder with WEB-INF classes and web.xml in their predefined locations. Open
administration console in a web browser by using
http://localhost:7001/console
- Click on the web application node in the applet
window. Configure a new web application. Click on the select link available besides the context folder. Move available server to target server. Provide application name as the context name. Configure and deploy (wait for the status
to become true)
- To get the index of the context in the web
browser, click configuration tab->click file tab->Choose index
directory->apply.
- Restart the server and access the context.
In web logic 10
Domain creation
Start->program->Bea product->Tools->Configuration wizard->Create a new web logic
domain->next->next
Provide username + password ->next->next->next
Provide domain name and location (keep default)
Creation of context in web logic 10
- Access the administration console in the web browser by using
http://localhost:7001/console provide userid + password. Click on deployment
->Click on lock and edit->Click on install->Select the folder of the
context->Next->Next->Choose no –Finish
- Click on activate changes->Select the application->start->servicing all
request->yes
Architecture of EJB
Home Interface
This interface contains methods for creating instances of EJB. Whenever the
client application wants to communicate with EJB for the first time then it calls
create () method of the home interface. This interface may contain more than one
create() method. This interface can be created by inheriting javax.ejb.EJBHOME
interface.
Remote Interface
This interface contains methods to implements business logic. The client
application calls this method after getting a reference to a remote interface from
create() method of the home interface. This interface can be created by inheriting
javax.ejb.EJBOBJECT.
Bean Class
This class contains logic for the methods of present in-home and remote interfaces.
Whenever the clients call any method of home and remote interface, then the EJB the container calls the corresponding method available in bean
class. The bean class can be three types, they are below
This type of bean implements business logic in the application layer. This bean
can perform all types of operations or calculation required for an application.
This bean can contain the state of the user for a period or session. If the state
can be available for only one transaction then it is called a stateless session
bean. If the state can be available for more than one transaction then it is
called a state full session bean. A session bean can be created by inheriting
javax.ejb.SessionBean interface.
This bean can be created to implement persistence logic. Persistence logic means the creation and maintenance of data in Dbms. This bean can contain the state of the user
forever. If the persistence logic is being implemented by the bean class
explicitly then it is called as bean-managed persistency. If the persistence
logic gets implemented by the EJB container then it is called as container-managed persistency. An entity bean can be created by inheriting
javax.ejb.EntityBean interface.
This bean can be used to implements any type of logic or acceptance of a message
from a jms client. Whenever a Jms client sends a message to the MOM then this
bean receives the message to implements the required logic. This bean does not
need home and remote interface. This bean can be created by inheriting
javax.ejb.MessageDrivenBean.