You are on page 1of 30

Introduction Ito Weblogic 10.

3
Oracle BEA Weblogic 10.3:
Oracle BEA Weblogic platform is a unified, simplified, and extensible platform
for building, extending, integrating, deploying, and managing applications. Weblogic
platform includes a rich development and deployment framework for integrating
valuable resources and tools into your environment: third-party application
packages, custom applications, messaging systems, web services, trading partners,
and more.

Download link:
Link to download - Oracle Workshop for WebLogic 10.3 - Package Installer:
http://www.oracle.com/technology/software/products/ias/bea_main.html

Installation:
While installing WebLogic 10.3 package, include workshop for weblogic along
with weblogic server.
Workshop for weblogic is a set of plug-ins to the Eclipse IDE platform that
allows you to quickly and easily create enterprise applications (SOA, J2EE) for
deployment on a wide variety of servers, including WebLogic Server, Tomcat, JBoss,
and others.
For installation, please refer the below link,
http://edocs.bea.com/wls/docs103/getstart/overview.html

TCS Confidential

Steps to configure a weblogic server:


Right click on new > server in the server configuration area in IDE.

Click on the link click here to launch configuration wizard to create a new domain
to create new domain

TCS Confidential

TCS Confidential

TCS Confidential

TCS Confidential

TCS Confidential

TCS Confidential

Click on create to create the domain.

What is a Domain and why we are creating Domain in weblogic server?


TCS Confidential

Domain is logical grouping of resources and services and consists


of Administration Server, Managed Server and cluster. There can only be one
administration Server in domain and zero to N Managed Server.

A domain is the basic administration unit for WebLogic Server instances. A


domain consists of one or more WebLogic Server instances (and their associated
resources) that you manage with a single Administration Server. You can define
multiple domains based on different system administrators' responsibilities,
application boundaries, or geographical locations of servers. Conversely, you can use
a single domain to centralize all WebLogic Server administration activities.
Each domain's configuration is stored in a separate configuration file called
config.xml, which is stored on the Administration Server along with other files such
as logs and security files. When you use the Administration Server to perform a
configuration task, the changes you make apply only to the domain managed by that
Administration Server. To manage another domain, use the Administration Server for
that domain. For this reason, the servers instances, applications, and resources in
one domain should be treated as being independent of servers, applications, and
resources in a different domain.You cannot perform configuration or deployment
tasks in multiple domains at the same time.

Types of servers:

TCS Confidential

Administration Server - A domain always includes one WebLogic Server instance that
is configured as an Administration Server. The Administration Server provides a
central point from which to manage the domain, and it provides access to WebLogic
Server administration tools.
Managed Servers - All other WebLogic Server instances in a domain are called
Managed Servers.Managed Servers host the application components and resources,
which are also deployed and managed as part of the domain.
Clusters - A domain may also include WebLogic Server clusters, which are groups of
WebLogic
Server instances that work together to provide scalability and high availability for
applications. Clusters can improve performance and provide failover should a server
instance becomes unavailable.

Steps involved in deploying a J2EE application:


The purpose of this document is to explain the deployment of a J2EE
application in Weblogic server 10.3. In our sample application user will submit a
request at front end and the required information is fetched from DB and displayed in
a report format.

J2EE project has been created by selecting Enter Application project in other
category in Eclipse IDE.

TCS Confidential

TCS Confidential

Enter the project name and select appropriate target runtime and configuration.

Select the version of ear

TCS Confidential

Select J2EE modules to be added as part of the ear.

TCS Confidential

Click Finish button to create a J2EE application.

Our sample J2EE application includes a web module and EJB module.

TCS Confidential

The structure of J2EE application will be as below:

TCS Confidential

Basically web module will have the source files required by the presentation layer
and EJB module will have different types of ejbs(session bean, entity bean and
message driven bean). EJBs will have the business logic of an enterprise application.
To deploy our application we need an application server. For our feasibility study we
are going to user weblogic server 10.3 version.
In our sample application user will submit a request in JSP and request is delegated
to a stateless session bean through httpservlet.
From EJB, SQL server db table is queried and required information is fetched from
DB and the result is forwarded to the JSP.
JSP will display the information in a report format.

EJB Module Creation and Deployment:

TCS Confidential

An EJB module is used to assemble one or more enterprise beans into a single
deployable unit. An EJB module is stored in a standard Java archive (JAR) file.
An EJB module contains the following:

One or more deployable enterprise beans.


A deployment descriptor, stored in an Extensible Markup Language (XML) file.
This file declares the contents of the module, defines the structure and
external dependencies of the beans in the module, and describes how the
beans are to be used at run time.

We can deploy an EJB module as a stand alone application, or combine it with other
EJB modules or with Web modules to create a J2EE application. An EJB module is
installed and run in an enterprise bean container.

Create an EJB in weblogic workshop IDE as below:

Since we are using weblogic workshop IDE for our application development, EJB gen
support which is an EJB2.0 code generator can be used for creating and deploying
EJBs.

TCS Confidential

Select the package and enter the ejb name as filename.

TCS Confidential

Clcik Finish button.

Employee is created as below:

TCS Confidential

Once EmployeeBean is created our ejb-jar.xml will look like as below:<ejb-jar


xmlns="http://java.sun.com/xml/ns/j2ee"

TCS Confidential

xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://java.sun.com/xml/ns/j2ee
http://java.sun.com/xml/ns/j2ee/ejb-jar_2_1.xsd"
version="2.1">
<enterprise-beans>
<session>
<ejb-name>EmployeeBean</ejb-name>
<home>com.Employee.EmployeeBeanRemoteHome</home>
<remote>com.Employee.EmployeeBeanRemote</remote>
<ejb-class>com.Employee.EmployeeBean</ejb-class>
<session-type>Stateless</session-type>
<transaction-type>Container</transaction-type>
</session>
</enterprise-beans>
</ejb-jar>

Weblogic-ejb-jar.xml will look like as below:<? xml version="1.0" encoding="UTF-8"?>


<!-** This file was automatically generated by
** EJBGen WebLogic Server 10.3 SP0 Fri Jul 25 16:30:05 EDT 2008 1137967
-->
<weblogic-ejb-jar
xmlns="http://www.bea.com/ns/weblogic/90"
xmlns:j2ee="http://java.sun.com/xml/ns/j2ee"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://www.bea.com/ns/weblogic/90
http://www.bea.com/ns/weblogic/90/weblogic-ejb-jar.xsd">
<weblogic-enterprise-bean>
<ejb-name>EmployeeBean</ejb-name>
<stateless-session-descriptor>
</stateless-session-descriptor>
<jndi-name>ejb.EmployeeBeanRemoteHome</jndi-name>
</weblogic-enterprise-bean>
</weblogic-ejb-jar>

Note:

Ejb-jar.xml will have all the deployment information for all the beans in the
ejb-jar file.

TCS Confidential

weblogic-ejb-jar.xml deployment descriptor file describes the elements that


are unique to WebLogic Server

Add business methods in ejb by using proper annotations provided by weblogic


EJBGEN support.

We will first create the source files required for the webmodule as below:Create a new JSP in webmodule as below.

TCS Confidential

Enter name of the JSP file and click finish button.

TCS Confidential

TCS Confidential

Create a new servlet in webmodule as below:-

TCS Confidential

Enter the package and name of the servlet

TCS Confidential

Click next button and specify Initialization parameters if any and check the URL
mappings for the servlet which will be reflected in web.xml.
NOTE:
The web.xml file provides configuration and deployment information for the Web
components that comprise a Web application. Examples of Web components are
servlet parameters, servlet and JavaServer Pages (JSP) definitions, and Uniform
Resource Locators (URL) mappings.

URL mapping for Employee servlet has been added in web.xml as below:-

TCS Confidential

<servlet>
<description></description>
<display-name>EmployeeServlet</display-name>
<servlet-name>EmployeeServlet</servlet-name>
<servlet-class>com.Employee.EmployeeServlet</servlet-class>
</servlet>
<servlet-mapping>
<servlet-name>EmployeeServlet</servlet-name>
<url-pattern>/EmployeeServlet</url-pattern>
</servlet-mapping>

Invoking EJB from servlet


By using component naming environment business method of an EJB is invoked from
webmodule. This can be achieved by creating an EJB reference in web module as
below:<ejb-ref>
<ejb-ref-name>ejb/EmployeeBeanRemote</ejb-ref-name>
<ejb-ref-type>Session</ejb-ref-type>
<home>com.employee.EmployeeBeanRemoteHome</home>
<remote>com.employee.EmployeeBeanRemote</remote>
<ejb-link>EmployeeBean</ejb-link>
</ejb-ref>

The following code fragment will get the home interface of the EJB which is used as
the handle to invoke the business method.
EmployeeBeanRemoteHome homeObj =
(EmployeeBeanRemoteHome)PortableRemoteObject.narrow(obj,
EmployeeBeanRemoteHome.class);
myComponentInterface = homeObj.create();
myComponentInterface.getFieldNames(bucketname);

TCS Confidential

Invoking the iBATIS-related methods from ejb module:


In the ejb module, create a Hashmap object, set the bucketName value and
call the getObjects() with that HashMap object as below
HashMap<String,Object> attrs = new HashMap<String,Object>();
attrs.put("bucketName", bucketName);
FieldInformationSource src = new FieldInformationSource();
FieldInformationVO[] fieldInformationVO =
FieldInformationVO[])src.getObjects(attrs);
The query to the database was made using iBATIS framework and the code
related to iBATIS was put in a db.jar
db.jar:
db.jar includes the following source files
1.
2.
3.
4.
5.

FieldInformationSource.java
FieldInformationVO.java
Util.java
FieldFormat-sqlmap.xml
SqlMapConfig.xml

FieldInformationSource class has getObjects() method, which decides what query to


execute like below,
list = sqlMapClient.queryForList("fetchFieldInformationVO", props);
FieldInformationVO class has getter and setter methods for all the fileds in a table.
Util class has getSqlMapClient() method that returns the SqlMapClient object which
the query methods like queryForList, insert, update, delete are called.
FieldFormat-sqlmap.xml has the list of queries relating to a table
SqlMapConfig has the configuration details about the database like driver, URL,
username, password and the list of sqlmap files used.
Jars referenced:
1. ibatis-2.3.4.726.jar
2. mysql-connector-java-3.1.7.jar

TCS Confidential

The collection object is returned to the servlet which inturn set the values in
the request attribute and forward the request attribute to JSP as below:Servlet Code
request.setAttribute("fieldNames", list);
request.getRequestDispatcher("welcome.jsf").forward(request,
response);
JSP Code
Request.getAttribute("fieldNames")

The values are displayed in a report format in JSP.

TCS Confidential