44
EJB (Enterprise JavaBeans ) development using Borland ® JBuilder ® X and BEA ® WebLogic ® 8.1 Jumpstart development, deployment, optimization, and debugging EJBs A Borland White Paper by Sudhansu Pati, senior systems engineer June 2004 1

Jumpstart development, deployment, optimization, and ... · Now you can see a runtime configuration called WebLogic Server in the Runtime Configurations window. 4. Click OK. See Figure

  • Upload
    others

  • View
    1

  • Download
    0

Embed Size (px)

Citation preview

Page 1: Jumpstart development, deployment, optimization, and ... · Now you can see a runtime configuration called WebLogic Server in the Runtime Configurations window. 4. Click OK. See Figure

EJB™ (Enterprise JavaBeans™)

development using Borland® JBuilder® X and BEA® WebLogic® 8.1

Jumpstart development, deployment,

optimization, and debugging EJBs

A Borland White Paper

by Sudhansu Pati, senior systems engineer

June 2004

1

Page 2: Jumpstart development, deployment, optimization, and ... · Now you can see a runtime configuration called WebLogic Server in the Runtime Configurations window. 4. Click OK. See Figure

EJB™ Development Using Borland® JBuilder® X and BEA Weblogic Server 8.1

Contents

Introduction .. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 4

Installation and configuration .. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 4

Working with session beans .. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 7

Create a project ..................................................................................................................... 7 Make WebLogic Server the target server.............................................................................. 7 Create an EJB module™ ........................................................................................................ 8 Visually create a session bean............................................................................................. 10 Deploy and run the session bean......................................................................................... 12

Create a runtime configuration....................................................................................................... 12 Make the project (Ctrl + F9)........................................................................................................... 13 Run WebLogic Server within JBuilder®......................................................................................... 13

Deploy the session bean...................................................................................................... 14 Test the session bean........................................................................................................... 16

Create a test client .......................................................................................................................... 16 Run the test client ........................................................................................................................... 17

Optimizing EJB applications™ ............................................................................................ 18 Optimizeit™ Code Coverage ......................................................................................................... 18 Optimizeit™ Profiler...................................................................................................................... 18 Optimizeit™ Thread Debugger ...................................................................................................... 19

Working with entity beans.. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 20

Setting up WebLogic for database configuration................................................................ 20 Create a project ................................................................................................................... 22 Create an entity bean........................................................................................................... 22 Launch DTO/Façade Wizard .............................................................................................. 24 Deploy and run the J2EE application.................................................................................. 27

Create an EAR module................................................................................................................... 27 Make the Project (Ctrl + F9) .......................................................................................................... 28

2

Page 3: Jumpstart development, deployment, optimization, and ... · Now you can see a runtime configuration called WebLogic Server in the Runtime Configurations window. 4. Click OK. See Figure

EJB™ Development Using Borland® JBuilder® X and BEA Weblogic Server 8.1

Start WebLogic Server ................................................................................................................... 28 Deploy WebLogicAppMod to WebLogic Server ........................................................................... 29

Test the entity bean ............................................................................................................. 29

Debugging an application in WebLogic .. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 31

Local debugging.................................................................................................................. 32 Remote debugging .............................................................................................................. 32

Set up and run remote WebLogic Server........................................................................................ 33 Create runtime configuration for remote debugging....................................................................... 34 Attach JBuilder to WebLogic Server remotely............................................................................... 35 Run the Struts client to debug the EJBs.......................................................................................... 36

Working with Message Driven Beans .. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 37

Create JMS Configurations in WebLogic ........................................................................... 38 Create a Connection Factory .......................................................................................................... 38 Create a JMS Store......................................................................................................................... 38 Create a JMS server........................................................................................................................ 38 Create a queue ................................................................................................................................ 39

Create a Message Driven Bean ........................................................................................... 39 Deploy and run the MDB.................................................................................................... 42 Test the MDB...................................................................................................................... 42

Feedback and suggestions .. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 44

3

Page 4: Jumpstart development, deployment, optimization, and ... · Now you can see a runtime configuration called WebLogic Server in the Runtime Configurations window. 4. Click OK. See Figure

EJB™ Development Using Borland® JBuilder® X and BEA Weblogic Server 8.1

Introduction

Borland® JBuilder X Enterprise is a comprehensive set of award-winning visual development

tools for creating enterprise-scale applications written entirely in the Java™ programming

language for the Java™ 2 platform.

The audiences for this paper are project managers, architects, and developers. To fully

understand the contents of this paper, the reader should have basic knowledge of Java and

Enterprise JavaBeans.™

This paper provides an overview of creating, testing, debugging, optimizing, and deploying

EJB using Borland JBuilder X Enterprise and BEA WebLogic Server 8.1. The step-by-step

instructions demonstrate how easily a new-to-J2EE developer can build enterprise

applications using JBuilder X.

It will take approximately 1-2 hours for a developer to complete the steps illustrated in this

paper to be familiar with JBuilder X as well as build basic enterprise applications. The paper

focuses on building simple end-to-end EJB applications to help give developers a jumpstart

with JBuilder X and WebLogic Server 8.1. Through more complex Java applications can be

developed using JBuilder, this paper avoids such complexity.

Installation and configuration

JBuilder X trial edition can be installed from the following link

http://www.borland.com/products/downloads/download_jbuilder.html

Also install the latest updates for JBuilder X from the above link.

WebLogic Server 8.1 can be installed from the following link

http://commerce.bea.com/showproduct.jsp?family=WLS&major=8.1&minor=2

4

Page 5: Jumpstart development, deployment, optimization, and ... · Now you can see a runtime configuration called WebLogic Server in the Runtime Configurations window. 4. Click OK. See Figure

EJB™ Development Using Borland® JBuilder® X and BEA Weblogic Server 8.1

This white paper uses C:\Borland\JavaStudio as the installation directory of JBuilder and

C:\ThirdParty\bea\weblogic81 as the installation directory for WebLogic Server 8.1.

To configure JBuilder X with WebLogic Server, follow the steps below.

1. Start JBuilder.

2. From the JBuilder main menubar, click Tools | Configure Servers.

3. Click the Enable Server checkbox.

4. Click the Home Directory ellipses and navigate to the WebLogic Server directory

(C:/ThirdParty/bea/weblogic81/server). The Main Class and VM Parameters fields in

the Configure Servers window are populated automatically. See Figure 1 for details.

Figure 1: Configure JBuilder X with WebLogic Server 8.1

5

Page 6: Jumpstart development, deployment, optimization, and ... · Now you can see a runtime configuration called WebLogic Server in the Runtime Configurations window. 4. Click OK. See Figure

EJB™ Development Using Borland® JBuilder® X and BEA Weblogic Server 8.1

5. Click the Custom tab from Configure Servers window.

6. Provide BEA home directory (C:\ThirdParty\bea). The JDK installation directory

is automatically populated.

7. Provide Domain directory (C:\ThirdParty\bea\user_projects\domains\mydomain). If

the domain “mydomain” doesn’t exist, then follow BEA documentation to create a

domain.

8. Provide Username and Password. They must be the same username and password

that you provided while creating the domain.

9. Provide Web browser path (C:\Program Files\Internet Explorer\IEXPLORE.EXE).

JBuilder adds an entry in the Tools menu to start the admin console, which requires a

browser. See Figure 2 for details.

Figure 2: Configure JBuilder X with WebLogic Server 8.1

6

Page 7: Jumpstart development, deployment, optimization, and ... · Now you can see a runtime configuration called WebLogic Server in the Runtime Configurations window. 4. Click OK. See Figure

EJB™ Development Using Borland® JBuilder® X and BEA Weblogic Server 8.1

Note: You may get an “Invalid JDK Installation directory” error when you click OK from the

Configure Servers window. That is because WebLogic may have shipped with a version of JDK

different from what is defined in JBuilder. Click the ellipses and choose the correctly installed JDK

(For example, we have chosen C:/ThirdParty/bea/jdk141_05). This configuration is a one-time

effort. From this point, the developers can use JBuilder X to build and manage enterprise

application for WebLogic without having to worry about configuration.

Working with session beans

For this exercise, let’s create a simple session bean using JBuilder wizards. We will deploy it

and run it in WebLogic Server, and then we’ll optimize it using JBuilder.

Create a project

1. From the JBuilder main menubar, click File | New Project.

2. In the Project Wizard, enter the Project Name as WebLogicSesProject and the

Directory Name as C:/Projects/weblogic81/WebLogicSesProject.

Make WebLogic Server the target server

1. From the JBuilder main menubar, click Project | Project Properties

2. From the Project properties window, click the Server node.

3. From the combo box, select WebLogic Platform Server 8.x.

4. Leave all other defaults, and click OK.

See Figure 3 for details.

7

Page 8: Jumpstart development, deployment, optimization, and ... · Now you can see a runtime configuration called WebLogic Server in the Runtime Configurations window. 4. Click OK. See Figure

EJB™ Development Using Borland® JBuilder® X and BEA Weblogic Server 8.1

Note: You can set WebLogic as the target application server in JBuilder Default Project Properties

so that the WebLogic application server is automatically selected for every project you create in

JBuilder. Click Project | Default Project Properties | select Server as WebLogic Platform Server

8.x to make WebLogic the default application server for JBuilder.

Figure 3: Selecting WebLogic Server 8.1 as the application server for the current project

Create an EJB™ module

From the JBuilder menubar, click File | New. In the Object Gallery, click EJB on the left tree

node. Click the EJB Designer icon on the right. Click OK. See Figure 4 for details.

8

Page 9: Jumpstart development, deployment, optimization, and ... · Now you can see a runtime configuration called WebLogic Server in the Runtime Configurations window. 4. Click OK. See Figure

EJB™ Development Using Borland® JBuilder® X and BEA Weblogic Server 8.1

Figure 4: Selecting the visual EJB Designer in JBuilder

1. In the EJB Designer Wizard, click New to create a new EJB Module.

2. In the EJB Module Wizard, Step 1 of 2, leave the defaults. Click Next.

3. In the EJB Module Wizard, Step 2 of 2, enter the module name as

WebLogicSesMod. Leave the other defaults.

4. Click Finish. See Figure 5 for details.

Figure 5: Using the EJB Module Wizard to create an EJB Module in JBuilder

9

Page 10: Jumpstart development, deployment, optimization, and ... · Now you can see a runtime configuration called WebLogic Server in the Runtime Configurations window. 4. Click OK. See Figure

EJB™ Development Using Borland® JBuilder® X and BEA Weblogic Server 8.1

5. Click OK from the EJB Designer Window.

Note: An EJB Module is merely a hosting environment for EJBs. Each EJB module produces an

EJB jar file. So if you like to keep different EJBs in different jar files, create one EJB Module for

each jar file.

Visually create a session bean

With JBuilder, EJBs can be created visually.

1. Double-click EJBModule WebLogicSesMod.

2. Right-click the editor pane.

3. Click Create EJB. Click Session Bean. See Figure 6 for details.

Figure 6: Visually creating a session bean in JBuilder

4. Enter the Bean name as WebLogicSes in the Session Bean Properties window, then

click anywhere in the designer to create the Session Bean.

1 0

Page 11: Jumpstart development, deployment, optimization, and ... · Now you can see a runtime configuration called WebLogic Server in the Runtime Configurations window. 4. Click OK. See Figure

EJB™ Development Using Borland® JBuilder® X and BEA Weblogic Server 8.1

Note: The previous step automatically creates three EJB files (WebLogicSesBean.java,

WebLogicSes.java, and WebLogicSesHome.java). You can see these files in the JBuilder project

tree.

5. To add a method in the session bean, right-click WebLogicSes.

6. Click Add.

7. Click Method. See Figure 7 for details.

Figure 7: Visually creating a business method in session bean in JBuilder

8. Enter the method name as getMessage(), return type as String and interfaces as

remote.

9. Right-click the EJB WebLogicSes and click View Bean Source. This opens the

WebLogicSesBean.java file in the JBuilder editor pane.

Change the method getMessage() as follows.

public String getMessage() { return "Hello There!! I am WebLogic Session Bean"; }

1 1

Page 12: Jumpstart development, deployment, optimization, and ... · Now you can see a runtime configuration called WebLogic Server in the Runtime Configurations window. 4. Click OK. See Figure

EJB™ Development Using Borland® JBuilder® X and BEA Weblogic Server 8.1

Deploy and run the session bean

Create a runtime configuration JBuilder allows users to create runtime configurations for running different applications

within JBuilder.

Note: A Runtime Configuration is a configuration to run applications in JBuilder. Runtime

configuration is essential when your project has multiple files or applications that can be run, and

you want to run a specific application.

1. From the JBuilder main menubar, click Run | Configurations. The Project

Properties window appears with the Run tab selected. Click New to create a new

runtime configuration.

2. In the Runtime Configuration Properties window, enter the following values.

Name: WebLogic Server [Users can enter any name here]

Build target: <None>

Type: Server

1 2

Page 13: Jumpstart development, deployment, optimization, and ... · Now you can see a runtime configuration called WebLogic Server in the Runtime Configurations window. 4. Click OK. See Figure

EJB™ Development Using Borland® JBuilder® X and BEA Weblogic Server 8.1

.

Figure 8: Runtime configuration to run WebLogic Server within JBuilder

3. Click OK. Now you can see a runtime configuration called WebLogic Server in the

Runtime Configurations window.

4. Click OK. See Figure 8 for details.

Make the project (Ctrl + F9).

Note: With the make operation, JBuilder creates WebLogic specific deployment descriptors

(weblogic.xml). Also JBuilder packages the EJB files and Deployment Descriptors and creates a jar

file named WebLogicSesMod.jar

Run WebLogic Server within JBuilder Click on the Run Project icon from the JBuilder toolbar. This makes WebLogic run within

the JBuilder message pane. See Figure 9 for details.

1 3

Page 14: Jumpstart development, deployment, optimization, and ... · Now you can see a runtime configuration called WebLogic Server in the Runtime Configurations window. 4. Click OK. See Figure

EJB™ Development Using Borland® JBuilder® X and BEA Weblogic Server 8.1

Figure 9: WebLogic Server running within JBuilder

Deploy the session bean

JBuilder provides menu options to deploy enterprise applications to WebLogic Server.

JBuilder supports hot-deployment of J2EE applications to WebLogic Server.

1. From the JBuilder Project pane, right-click WebLogicSesMod

2. Click Deploy Options for “WebLogicSesMod.jar” | Deploy. See Figure 10 for

details.

1 4

Page 15: Jumpstart development, deployment, optimization, and ... · Now you can see a runtime configuration called WebLogic Server in the Runtime Configurations window. 4. Click OK. See Figure

EJB™ Development Using Borland® JBuilder® X and BEA Weblogic Server 8.1

Figure 10: Deploying EJB Module to WebLogic within JBuilder

JBuilder starts another tab in the message window showing the deployment status. See Figure

11 for details.

Figure 11: JBuilder showing the deployment status in message pane

1 5

Page 16: Jumpstart development, deployment, optimization, and ... · Now you can see a runtime configuration called WebLogic Server in the Runtime Configurations window. 4. Click OK. See Figure

EJB™ Development Using Borland® JBuilder® X and BEA Weblogic Server 8.1

Test the session bean

This exercise explains how to test the session bean using a Java client. JBuilder provides a

wizard to create a test client to test the EJBs.

Create a test client 1. From the JBuilder menubar, click File | New

2. Click the EJB node from the Object Gallery.

3. Click the Test Client icon.

4. Click OK. See Figure 12.

Figure 12: Creating a test client to test a session bean using the JBuilder Wizard

5. In the EJB Test Client Wizard–Step 1 of 3, leave the default selection and click

Next.

6. In the EJB Test Client Wizard–Step 2 of 3, leave the default selection and click

Next.

7. In the EJB Test Client Wizard–Step 3 of 3, leave the default selection and click

Finish.

1 6

Page 17: Jumpstart development, deployment, optimization, and ... · Now you can see a runtime configuration called WebLogic Server in the Runtime Configurations window. 4. Click OK. See Figure

EJB™ Development Using Borland® JBuilder® X and BEA Weblogic Server 8.1

Change the main() method of WebLogicSesTestClient1.java as follows:

public static void main(String[] args) { WebLogicSesTestClient1 client = new WebLogicSesTestClient1(); try { client.create(); client.getMessage(); } catch (Exception ex) { } }

Run the test client To run the test client, right-click WebLogicSesTestClient1.java from JBuilder project pane,

click Run using WebLogicSesTestClient1.

The test client runs within JBuilder by creating another tab in the message pane. You can see

the successful execution of the test client from the last line Message From the Test Client

“Hello There!! I am WebLogic Session Bean”.

Note: This message comes from the WebLogicSes EJB. The test client

WebLogicSesTestClient1.java has a wrapper method called getMessage(), which is responsible for

displaying the output of getMessage() business method of WebLogicSes into system output

console.

1 7

Page 18: Jumpstart development, deployment, optimization, and ... · Now you can see a runtime configuration called WebLogic Server in the Runtime Configurations window. 4. Click OK. See Figure

EJB™ Development Using Borland® JBuilder® X and BEA Weblogic Server 8.1

Figure 13 shows the test client running within JBuilder.

Figure 13: Test client running within JBuilder and showing outputs from the EJB method

getMessage()

Optimizing EJB™ applications

JBuilder X has the capabilities to optimize Java application. There are three optimization

capabilities as described below.

Optimizeit™ Code Coverage Optimizeit Code Coverage enables developers to view the execution frequency of each class,

method, and line of code and it helps to reduce application footprint by removing dead code.

Optimizeit™ Profiler Optimizeit Profiler enables developers to maximize application speed and reliability and to

quickly isolate critical code that requires performance improvements.

1 8

Page 19: Jumpstart development, deployment, optimization, and ... · Now you can see a runtime configuration called WebLogic Server in the Runtime Configurations window. 4. Click OK. See Figure

EJB™ Development Using Borland® JBuilder® X and BEA Weblogic Server 8.1

Optimizeit™ Thread Debugger Optimizeit Thread Debugger helps developers solve mysterious thread issues easily, get the

status of all threads and monitors in real time, avoid thread starvation and contentions that

lead to crashes, and predict deadlocks before they occur.

For this case, let’s attach Optimizeit memory Profiler with WebLogic Server 8.1. Click the

Optimize Project icon from the JBuilder toolbar and click WebLogic Server, as shown in

Figure 14.

Figure 14: Starting WebLogic Server in Optimizeit mode within JBuilder

The Edit Runtime Configuration window pops up and allows users to select one of the three

tools (Profiler, Thread Debugger, and Code Coverage). Select Profiler from Type combo

box. See Figure 15 for details.

Figure 15: The runtime configuration window allows you to choose an Optimizeit tool

1 9

Page 20: Jumpstart development, deployment, optimization, and ... · Now you can see a runtime configuration called WebLogic Server in the Runtime Configurations window. 4. Click OK. See Figure

EJB™ Development Using Borland® JBuilder® X and BEA Weblogic Server 8.1

Click OK. Optimizeit starts within the JBuilder message pane. JBuilder has started WebLogic

Server and automatically attached Optimizeit with WebLogic Server. Now the Optimizeit

view in the message pane demonstrates the memory profiling information of WebLogic. See

Figure 16 for details.

Figure 16: Optimizeit Profiler attached to WebLogic Server within JBuilder

Optimizeit Suite has many features available to help detect critical memory leaks,

performance issues, deadlocks, etc. This paper just explained a snapshot of some of the

features. Read the Optimizeit Suite product documentation for more information about other

features of Optimizeit Suite.

Working with entity beans

Setting up WebLogic for database configuration

Entity beans require a persistent store such as a database. For our testing, we will use the

Borland® JDataStore™ database as the persistent store. JDataStore installs with the default

installation of JBuilder X and is licensed for development purpose only.

2 0

Page 21: Jumpstart development, deployment, optimization, and ... · Now you can see a runtime configuration called WebLogic Server in the Runtime Configurations window. 4. Click OK. See Figure

EJB™ Development Using Borland® JBuilder® X and BEA Weblogic Server 8.1

From the JBuilder toolbar, click Tools | Configure Servers. The Configure Servers window

opens.

From Configure Servers window, click WebLogic Platform 8.x | click the Required

Libraries tab | click ADD | from the Select One or more Libraries window, select

JDataStore | click OK.

You should see a JDataStore entry under the Required Libraries tab of Configure Servers

window. Click OK. See Figure 17 for details.

Note: The above exercise was necessary to add JDataStore libraries (JAR files) to the WebLogic

classpath, so that when WebLogic starts, it can find the JDataStore drivers.

Figure 17: Adding the JDataStore library to the WebLogic configuration

2 1

Page 22: Jumpstart development, deployment, optimization, and ... · Now you can see a runtime configuration called WebLogic Server in the Runtime Configurations window. 4. Click OK. See Figure

EJB™ Development Using Borland® JBuilder® X and BEA Weblogic Server 8.1

Create a project

Create a project and assign WebLogic Platform Server 8.x as the target application server for

the project. Create an EJB module. To get help on how to perform the above operations, see

to the previous section in this paper, “Working with session beans.”

For this exercise, enter the name of the project as WebLogicEntProject in the directory

C:\Projects\WebLogic81\WebLogicEntProject. Enter the EJB module name as

WebLogicEntMod.

Create an entity bean

An entity bean represents the state of real-time data from the database table(s). With JBuilder,

users can create entity beans in following ways:

• First create entity beans and then generate a database from the entity beans. • Generate entity beans from an existing database.

For this exercise, let’s focus on generating entity beans from an existing database.

Right-click on the editor pane. Click Import Schema from Database. See Figure 18

Figure 18: Importing schema from a database using the JBuilder visual EJB Designer

That brings up the Database Schema Provider window. Click the Choose Existing

Connection button. Select the following database URL.

jdbc:borland:dslocal:C:\Borland\JavaStudio\samples\JDataStore\datasto

res\employee.jds

2 2

Page 23: Jumpstart development, deployment, optimization, and ... · Now you can see a runtime configuration called WebLogic Server in the Runtime Configurations window. 4. Click OK. See Figure

EJB™ Development Using Borland® JBuilder® X and BEA Weblogic Server 8.1

Change the value of JNDI name to JDataStoreDS. Now you should have the following

values in the Database Schema provider window.

Driver: com.borland.datastore.jdbc.DataStoreDriver

URL:

jdbc:borland:dslocal:C:\Borland\JavaStudio\samples\JDataStore\datasto

res\employee.jds

Username: Sample

Password: <leave this empty>

Database name:

borland:dslocal:C:\Borland\JavaStudio\samples\JDataStore\datastores\employee.jds

JNDI name: JDSDataStoreDS

See Figure 19 for details.

Figure 19: JBuilder Database Schema Provider—to create entity beans from database

schema

2 3

Page 24: Jumpstart development, deployment, optimization, and ... · Now you can see a runtime configuration called WebLogic Server in the Runtime Configurations window. 4. Click OK. See Figure

EJB™ Development Using Borland® JBuilder® X and BEA Weblogic Server 8.1

Note: JBuilder imports all the tables from the specified database into the Structure pane. Now

developers can see the existing tables and create entity beans visually from the tables they need.

Expand JDataStoreDS from the JBuilder structure pane to see the list of tables available in

the database. You can create entity beans visually just by right-clicking a table name and

clicking Create CMP 2.0 Entity Bean or Create BMP Entity Bean.

For this exercise, let’s create a CMP 2.0 Entity Bean for the EMPLOYEE Table. Right-click

EMPLOYEE from the structure pane. Click Create CMP 2.0 Entity Bean. This creates a

Visual Employee Entity Bean in the editor pane. See Figure 20.

Figure 20: Visually creating a CMP 2.0 Entity bean from a database table.

Note: JBuilder creates the EJB files Employee.java, EmployeeBean.java, and EmployeeHome.java.

To check the source code, right-click the entity bean Employee, and click View Bean Source.

Launch the DTO/Façade Wizard

JBuilder provides wizards to create Session Façade and Struts client from entity beans. This

wizard creates state-of-the-art J2EE and Struts patterns to access the entity bean from outside.

2 4

Page 25: Jumpstart development, deployment, optimization, and ... · Now you can see a runtime configuration called WebLogic Server in the Runtime Configurations window. 4. Click OK. See Figure

EJB™ Development Using Borland® JBuilder® X and BEA Weblogic Server 8.1

This saves significant time for developers who otherwise would have to write lot of code

manually and need quite a bit of domain expertise in the J2EE and design aspects.

To launch the DTO/Façade Wizard, right-click the Employee entity bean from the JBuilder

editor pane. Click Launch DTO/Façade Wizard. See Figure 21 for details.

Figure 21: Launching DTO/Session Façade Wizard for an employee entity bean

In DTO and Session Façade Wizard – Step 1 of 8, check the checkbox against Generate

Struts Client. See Figure 22.

Figure 22: Creating advanced patterns (including Struts) from an entity bean

Keep clicking Next in all windows until you reach DTO and Session Façade Wizard – Step

8 of 8.

2 5

Page 26: Jumpstart development, deployment, optimization, and ... · Now you can see a runtime configuration called WebLogic Server in the Runtime Configurations window. 4. Click OK. See Figure

EJB™ Development Using Borland® JBuilder® X and BEA Weblogic Server 8.1

Click New against Web Module and follow the Web Module Wizard to create a new web

module named WebLogicWebMod. See Figure 23.

Figure 23: Providing a Web module for hosting Struts environment in WebLogic

Click Finish.

Note that with this Wizard, JBuilder creates a Session Façade, Business Delegate, Service

Locator, DTO, DTO Assembler, and Struts framework from the entity bean. All technical

artifacts and configurations for the above patterns and files are created automatically,

allowing the developer to focus on the business implementation instead of spending time in

the complex technical details of the EJBs, Struts, and patterns.

Figure 24 shows the JBuilder screen shot after the Wizard was run.

2 6

Page 27: Jumpstart development, deployment, optimization, and ... · Now you can see a runtime configuration called WebLogic Server in the Runtime Configurations window. 4. Click OK. See Figure

EJB™ Development Using Borland® JBuilder® X and BEA Weblogic Server 8.1

Figure 24: JBuilder has created the advanced patterns for the entity bean

Deploy and run the J2EE application

Create an EAR module JBuilder provides wizards to create an EAR Module. An EAR module is very helpful,

because it is a single file containing all Web modules and EJB modules. To create an EAR

module, click File | New | select Enterprise from the left-side tree | click Application

Module. See Figure 25 for details.

Figure 25: Creating an EAR module using the JBuilder wizard

2 7

Page 28: Jumpstart development, deployment, optimization, and ... · Now you can see a runtime configuration called WebLogic Server in the Runtime Configurations window. 4. Click OK. See Figure

EJB™ Development Using Borland® JBuilder® X and BEA Weblogic Server 8.1

Click OK. Click Next.

In the Application Module Wizard – Step 2 of 7, enter the Name as WebLogicAppMod.

In the Application Module Wizard – Step 3 of 7, check the checkbox under the “include”

column to include WebLogicEntMod.

In the Application Module Wizard – Step 4 of 7, check the checkbox under the “include”

column to include WebLogicWebMod.

Click Finish.

Make the Project (Ctrl + F9)

Start WebLogic Server Create a runtime configuration named WebLogic Server (Click Run | Configurations | New

from Runtime Configurations window | select Run Type as Server in new Runtime

Configuration window).

Click Run Project icon to Start WebLogic Server. See Figure 26.

Figure 26: WebLogic Server has started within JBuilder Message Pane

2 8

Page 29: Jumpstart development, deployment, optimization, and ... · Now you can see a runtime configuration called WebLogic Server in the Runtime Configurations window. 4. Click OK. See Figure

EJB™ Development Using Borland® JBuilder® X and BEA Weblogic Server 8.1

Note: If WebLogic Server is already running within JBuilder, you don’t have to stop it and start it

again. If it’s already running, you can skip the “Start WebLogic Server” section.

Deploy WebLogicAppMod to WebLogic Server

Right-click WebLogicAppMod | Deploy Options for “WebLogicAppMod.ear” | Deploy

Figure 27: Deploying an EAR module to WebLogic Server

Test the entity bean

Note that JBuilder has already created a Struts client to test the entity bean Employee.

From the JBuilder project pane, expand WebLogicWebMod | expand Module Directory |

expand employeeDelegateClient, right-click index.jsp, and click Web Run using WebLogic

Server.

Now the JSP (struts client) runs within JBuilder editor pane as shown in figure 28.

2 9

Page 30: Jumpstart development, deployment, optimization, and ... · Now you can see a runtime configuration called WebLogic Server in the Runtime Configurations window. 4. Click OK. See Figure

EJB™ Development Using Borland® JBuilder® X and BEA Weblogic Server 8.1

Figure 28: A Struts application running within JBuilder

Click employeeFinderIndex URL from the editor pane and then click

employeeFindByPrimaryKey URL from the next screen. You should see a screen as shown

in Figure 29.

Figure 29: A JBuilder Struts application requesting that a value be entered to look for an

employee

3 0

Page 31: Jumpstart development, deployment, optimization, and ... · Now you can see a runtime configuration called WebLogic Server in the Runtime Configurations window. 4. Click OK. See Figure

EJB™ Development Using Borland® JBuilder® X and BEA Weblogic Server 8.1

Type 2 under the EmpNo. Click Submit. JBuilder should navigate to a screen with the

employee information with EmpNo 2. See Figure 30.

Note: This information is from the JDataStore database through a Struts and EJB layer interface.

EmployeeSessionFacade retrieves the employee information from the Employee entity bean. The

Struts interface connects to the Session Facade and displays the employee information. This is a

typical technical implementation of J2EE application using Struts.

Figure 30: JBuilder returns the employee information

Debugging an application in WebLogic

At any point, developers can start WebLogic Server in debug mode within JBuilder. This is

called local debugging. Developers also can connect JBuilder to a remote WebLogic Server

to debug Java applications.

3 1

Page 32: Jumpstart development, deployment, optimization, and ... · Now you can see a runtime configuration called WebLogic Server in the Runtime Configurations window. 4. Click OK. See Figure

EJB™ Development Using Borland® JBuilder® X and BEA Weblogic Server 8.1

Local debugging

Stop WebLogic Server in JBuilder by clicking the square red icon at the bottom left corner of

the JBuilder message pane.

Click the Debug Project icon from the JBuilder toolbar. WebLogic Server now starts in

debug mode within the JBuilder message pane. See Figure 31 for details.

Figure 31: WebLogic has started in debug mode within JBuilder

After WebLogic has started in debug mode, developers can assign break points to the source

code and use the debugging capabilities of JBuilder to debug the application.

Remote debugging

JBuilder can remotely debug an already running application in a remote server – in this case

WebLogic Server. To remotely debug an application, WebLogic Server must be started in

debug mode.

3 2

Page 33: Jumpstart development, deployment, optimization, and ... · Now you can see a runtime configuration called WebLogic Server in the Runtime Configurations window. 4. Click OK. See Figure

EJB™ Development Using Borland® JBuilder® X and BEA Weblogic Server 8.1

Set up and run remote WebLogic Server WebLogic Server has to be started in debug mode for remote debugging. For your testing, you

can start myserver in debug mode as follows:

1. Open startWebLogic.cmd from

C:\ThirdParty\bea\user_projects\domains\mydomain

2. Add the following lines before SET JAVA_HOME line

set JAVA_OPTIONS=-Xdebug -Xnoagent -

Xrunjdwp:transport=dt_socket,server=y,address=5555,suspend=n

set JDATASTORE_CLASSPATH=C:\Borland\JavaStudio\lib\jds.jar;

C:\Borland\JavaStudio\lib\jdsserver.jar

3. Change the WebLogic CLASSPATH to include JDataStore as follows.

set

CLASSPATH=%WEBLOGIC_CLASSPATH%;%JDATASTORE_CLASSPATH%;%POINTBASE_C

LASSPATH%;%JAVA_HOME%\jre\lib\rt.jar;%WL_HOME%\server\lib\webservi

ces.jar;%CLASSPATH%

4. Run startWebLogic.cmd. See Figure 32 for details.

3 3

Page 34: Jumpstart development, deployment, optimization, and ... · Now you can see a runtime configuration called WebLogic Server in the Runtime Configurations window. 4. Click OK. See Figure

EJB™ Development Using Borland® JBuilder® X and BEA Weblogic Server 8.1

Figure 32: Running WebLogic externally in a remote server

Create runtime configuration for remote debugging From the JBuilder menubar, click Run | Configurations.

In the Runtime Configurations window, click New.

Enter the following configuration values in the Runtime Configuration Properties window.

Name: RemoteDebug

Build target: <None>

Type: Server

Expand Debug | Remote from Runtime Configuration window.

Check the Enable Remote Debugging checkbox, click Attach and enter the Address as

5555.

Note: The address specified here must be the same as the port number specified in the WebLogic

Server as debug options. JBuilder opens a socket connection to the WebLogic Server and attaches

to WebLogic using that port number.

See Figure 33.

3 4

Page 35: Jumpstart development, deployment, optimization, and ... · Now you can see a runtime configuration called WebLogic Server in the Runtime Configurations window. 4. Click OK. See Figure

EJB™ Development Using Borland® JBuilder® X and BEA Weblogic Server 8.1

Figure 33: Setting the parameters to remotely debug WebLogic applications

Attach JBuilder to WebLogic Server remotely To attach JBuilder to WebLogic Server remotely, click the Debug Project icon |

RemoteDebug from JBuilder toolbar. Now a tab with name localhost:5555 opens in the

JBuilder message pane. See Figure 34.

Figure 34: JBuilder opens a connection to remote WebLogic Server

3 5

Page 36: Jumpstart development, deployment, optimization, and ... · Now you can see a runtime configuration called WebLogic Server in the Runtime Configurations window. 4. Click OK. See Figure

EJB™ Development Using Borland® JBuilder® X and BEA Weblogic Server 8.1

Now you can assign breakpoints to the Java files within JBuilder. A breakpoint can be

assigned just by clicking at the beginning of a source code line in JBuilder editor pane.

Note: JBuilder puts a green checkmark next to all valid breakpoints and a red crossmark next to all

nonvalid breakpoints.

Run the Struts client to debug the EJBs From the JBuilder project pane, right-click index.jsp | click Web Run | click Use

RemoteDebug. Follow the same testing steps as stated in the section “Test the entity bean” in

the “Working with entity beans” section in this white paper.

If you have a breakpoint set in any of the EJB files and the breakpoint has reached by the

struts client, you will see JBuilder debugger stopping execution at the breakpoint.

For testing, assign a breakpoint at line 115 of the File EmployeeSesssionFacadeBean.java. A

breakpoint can be assigned just by clicking at the beginning of a line and is represented by a

red dot.

When the execution reaches at the breakpoint (in our case by the Struts client), the JBuilder

debugger puts a blue arrow mark on top of the breakpoint indicating that the execution has

stopped at that line. See Figure 34.

3 6

Page 37: Jumpstart development, deployment, optimization, and ... · Now you can see a runtime configuration called WebLogic Server in the Runtime Configurations window. 4. Click OK. See Figure

EJB™ Development Using Borland® JBuilder® X and BEA Weblogic Server 8.1

Figure 35: The JBuilder remote debugger has stopped at the breakpoint

Now you can follow debugging techniques such as step over, step into, step out, etc.

Working with Message Driven Beans

JBuilder provides easy-to-use wizards to create Message Driven Beans (MDB) applications.

To work with MDB, the JMS configurations need to be created in WebLogic Server.

The required configurations:

• Create a connection factory • Create a JMS store • Create a JMS server • Create a destination (queue, topic)

To learn more about creating JMS application using WebLogic Server, visit the link http://e-

docs.bea.com/wls/docs70/jms/implement.html.

3 7

Page 38: Jumpstart development, deployment, optimization, and ... · Now you can see a runtime configuration called WebLogic Server in the Runtime Configurations window. 4. Click OK. See Figure

EJB™ Development Using Borland® JBuilder® X and BEA Weblogic Server 8.1

Create JMS Configurations in WebLogic

Create a Connection Factory Start WebLogic Server and open WebLogic Server Console. Expand mydomain | Services

| JMS | click Connection Factories. From the right-side pane, click Configure a new JMS

Connection Factory.

Enter the following values in the right-side window:

Name: DemoJMSConnectionFactory JNDIName: DemoJMSConnectionFactory

Leave other default values and click Create. Click the Target and Deploy tab. Check the

checkbox for myserver (or whatever server name you are using). Click Apply.

Create a JMS Store Two types of JMS configurations can be created in WebLogic: JMSJDBC Store and

JMSFile Store. For this exercise, let’s create a JMSFileStore.

From the WebLogic Server Console, expand JMS under Services and click Stores. Click

Configure a new JMSFile Store.

Enter the following values in the right-side window:

Name DemoJMSFileStore Directory C:\ThirdParty\bea\DEMOJMSFileStore

Click Create.

Make sure that you create the specified directory,

i.e. C:\ThirdParty\bea\DEMOJMSFileStore, before entering here.

Create a JMS server From the WebLogic Server Console, expand JMS under Services and click Servers. Click

Configure a new JMSServer.

3 8

Page 39: Jumpstart development, deployment, optimization, and ... · Now you can see a runtime configuration called WebLogic Server in the Runtime Configurations window. 4. Click OK. See Figure

EJB™ Development Using Borland® JBuilder® X and BEA Weblogic Server 8.1

Enter the following values in the right-side window:

Name: DemoJMSServer Store: DemoJMSFileStore

Click Create. Leave other defaults. Click Targets and Deploy tab and select myserver as the

Target.

Create a queue From the WebLogic Server Console, expand JMS under Services. Expand Servers >

DemoJMSserver | Destinations | Click Configure a new JMSQueue.

Enter the following values in the right-side window:

Name: DemoJMSQueue

JNDIName: DemoJMSQueue

Leave other defaults. Click Create.

Create a Message Driven Bean

Create a project, assign WebLogic Platform Server 8.x as the target application server for the

project, and create an EJB module. For help with how to perform the above operations, see

the previous section, “Working with session bean.”

For this exercise, enter the name of the project as WebLogicJMSProject in the directory

C:\Projects\WebLogic81\WebLogicJMSProject and enter the EJB module name as

WebLogicJMSMod.

To create an MDB, double-click EJBModule WebLogicJMSMod, right-click on the editor

pane, and click Create EJB | Message-Driven Bean.

Enter the following values in the Bean Properties window:

3 9

Page 40: Jumpstart development, deployment, optimization, and ... · Now you can see a runtime configuration called WebLogic Server in the Runtime Configurations window. 4. Click OK. See Figure

EJB™ Development Using Borland® JBuilder® X and BEA Weblogic Server 8.1

Bean Name: WebLogicJMS

Transaction Type: Bean

Acknowledge Mode: Auto-acknowledge

Destination Type: javax.jms.Queue

Destination Name: DemoJMSQueue

Connection Factory Name: DemoJMSConnectionFactory

JMS polling interval: 5

Initial Context Factory: WebLogic.jndi.WLInitialContextFactory

Provider URL: t3://localhost:7001

Initial Pool size: 1

Maximum pool size: 10

See Figure 36.

4 0

Page 41: Jumpstart development, deployment, optimization, and ... · Now you can see a runtime configuration called WebLogic Server in the Runtime Configurations window. 4. Click OK. See Figure

EJB™ Development Using Borland® JBuilder® X and BEA Weblogic Server 8.1

Figure 36: JBuilder created a MDB visually and provided a GUI to configure the MDB

Right-click the MDB WebLogicJMS and click View Bean Source.

Change the onMessage() method of WebLogicJMSBean.java as follows:

public void onMessage(Message msg) {

try {

TextMessage txtMessage = (TextMessage) msg;

System.out.println("Message from WebLogicJMS = " + txtMessage.getText());

}

catch (JMSException ex) {

}

}

Note: The on Message () method gets executed when the MDB receives a message. In this case,

the on Message () method will print the received message.

4 1

Page 42: Jumpstart development, deployment, optimization, and ... · Now you can see a runtime configuration called WebLogic Server in the Runtime Configurations window. 4. Click OK. See Figure

EJB™ Development Using Borland® JBuilder® X and BEA Weblogic Server 8.1

You also must use the following import statements:

import javax.jms.TextMessage; import javax.jms.JMSException;

Make the project and make sure that there are no build errors.

Deploy and run the MDB

Create a runtime configuration to start WebLogic Server within JBuilder. From the main

JBuilder menubar, click Run |Configurations | click New from the Runtime Configurations

window.

Enter Name as WebLogic Server, Type as Server, and Build Target as Make.

Start WebLogic Server within JBuilder by clicking Run Project icon from JBuilder toolbar.

Test the MDB

To test the MDB, create a test client.

Click File| New Class | Enter Class name as JMSClient | Click OK.

4 2

Page 43: Jumpstart development, deployment, optimization, and ... · Now you can see a runtime configuration called WebLogic Server in the Runtime Configurations window. 4. Click OK. See Figure

EJB™ Development Using Borland® JBuilder® X and BEA Weblogic Server 8.1

Change the contents of JMSClient.java in JBuilder editor pane as follows:

JMSClient.java package weblogicjmsproject; import javax.naming.Context; import javax.naming.InitialContext; import javax.jms.Queue; import javax.jms.QueueConnection; import javax.jms.QueueConnectionFactory; import javax.jms.QueueSender; import javax.jms.QueueSession; import javax.jms.Session; import java.util.Hashtable; import javax.jms.Message; public class JMSClient { public static void main(String[] args) throws Exception { Hashtable env = new Hashtable(); env.put(Context.INITIAL_CONTEXT_FACTORY, "weblogic.jndi.WLInitialContextFactory"); env.put(Context.PROVIDER_URL," t3://localhost:7001"); Context jndiContext = new InitialContext(env); QueueConnectionFactory queueConnectionFactory = (QueueConnectionFactory) jndiContext.lookup("DemoJMSConnectionFactory"); Queue queue = (Queue) jndiContext.lookup("DemoJMSQueue"); QueueConnection queueConnection = queueConnectionFactory.createQueueConnection(); QueueSession queueSession = queueConnection.createQueueSession(false, Session.AUTO_ACKNOWLEDGE); QueueSender queueSender = queueSession.createSender(queue); Message message = queueSession.createTextMessage("Hello Message Bean"); queueSender.send(message); queueConnection.close(); System.exit(0); } }

Make the JMSClient.java file. Check for compilation errors. Run JMSClient.java by right-

clicking JMSClient.java | Run using defaults. After a successful execution, the following

message appears on the WebLogic Server:8080 tab: Message from WebLogicJMS = Hello

Message Bean. See Figure 37.

4 3

Page 44: Jumpstart development, deployment, optimization, and ... · Now you can see a runtime configuration called WebLogic Server in the Runtime Configurations window. 4. Click OK. See Figure

EJB™ Development Using Borland® JBuilder® X and BEA Weblogic Server 8.1

Figure 37: JBuilder showing successful execution of MDB in WebLogic running within

JBuilder

Feedback and suggestions

Please send your feedback and suggestions to:

Sudhansu Pati, senior systems engineer

[email protected]

100 Enterprise Way, Scotts Valley, CA 95066-3249

www.borland.com | 831-431-1000 | Fax: 831-431-4142

Made in Borland® Copyright © 2004 Borland Software Corporation. All rights reserved. All Borland brand and product names are trademarks or registered trademarks of Borland Software Corporation in the United States and other countries. Microsoft, Windows, and other Microsoft product names are trademarks or registered trademarks of Microsoft Corporation in the U.S. and other countries. All other marks are the property of their respective owners. Corporate Headquarters: 100 Enterprise Way, Scotts Valley, CA 95066-3249 • 831-431-1000 • www.borland.com • Offices in: Australia, Brazil, Canada, China, Czech Republic, Finland, France, Germany, Hong Kong, Hungary, India, Ireland, Italy, Japan, Korea, Mexico, the Netherlands, New Zealand, Russia, Singapore, Spain, Sweden, Taiwan, the United Kingdom, and the United States. • 22123

4 4