You are on page 1of 54

Developing & Deploying J2EE Application using

GWT Spring and Hibernate

Version 0.1

Date Author Comments Reviewed By


04/28/20 Alka/Sapna Initial document
11 preparation
04/28/20 Alka Updated the document
11 Sharma with Setting up the
environment and setting
up GWT module and
folder structure
04/28/20 Sapna Updated the document
11 with deploying the
application into web logic

1
Developing & Deploying J2EE Application using
GWT Spring and Hibernate

Table of Contents
.................................................................................................................................. 1
............................................................................................................................... 1
.................................................................................................................................. 1
.......................................................................................................................... 1
Table of Contents....................................................................................................... 2
Introduction................................................................................................................ 3
Setting up the environment........................................................................................3
GWT......................................................................................................................... 3
Spring 3.x................................................................................................................ 3
Hibernate 3.x........................................................................................................... 3
Eclipse Galileo 3.5 ..................................................................................................3
Application Server...................................................................................................4
Setting up GWT module and folder structure.............................................................4
Setting up the GWT.................................................................................................4
For integrated application (GWT + spring + Hibernate)..........................................8
Writing UI code, Service (RPC mechanism) and its implementation......................14
Business Logic involves integration of Hibernate with Spring...............................20
Deploying the .WAR file to the Web-logic.................................................................27
Create a User defined web-logic configuration......................................................27
Setting up the User-defined Admin Console and server as per the requirement...34
.............................................................................................................................. 36
Defining JNDI.........................................................................................................36
Setting the logging in web-logic (log 4j)................................................................48
Deploying the WAR file into the server..................................................................50

2
Developing & Deploying J2EE Application using
GWT Spring and Hibernate

Introduction
This document explains the procedure to develop and deploy a J2EE web
application which adheres to the AJAX (GWT), spring and Hibernate Framework.
Advantages of using GWT, spring and Hibernate Framework
 Eradicates performance issue
 Good UI presentation
 Code maintainability and less lines of codes to get functionality done.
 GUI and Server code can be written separately.
 MVC architecture.
 Efficient logging

Setting up the environment

GWT
• Link to download GWT plug-in for Eclipse Galileo 3.5
 GWT Plug-in - http://dl.google.com/eclipse/plugin/3.5
 Google Web Toolkit SDK 2.0.3
 Google App Engine Java SDK 1.4.2
• Link to download GWT – ext
 http://extjs.com/deploy/ext-2.0.2.zip
 http://code.google.com/webtoolkit/download.html (official site from
Google)
Spring 3.x
• Link to download Spring 3.x
 http://www.springsource.org/download
Hibernate 3.x
• Link to download Hibernate 3.x
 http://olex.openlogic.com/packages/hibernate
 http://www.hibernate.org/
Eclipse Galileo 3.5
• Link to download Eclipse Galileo 3.5

3
Developing & Deploying J2EE Application using
GWT Spring and Hibernate

Eclipse version - Galileo 3.5 (Eclipse Java EE IDE for Web


Developers)
 http://www.eclipse.org/downloads/
Application Server
• Weblogic 10.0

Setting up GWT module and folder structure

Setting up the GWT

After installing GWT plug-in one will have following icon in Eclipse

Click on highlighted icon .It opens web application set up wizard

4
Developing & Deploying J2EE Application using
GWT Spring and Hibernate

Enter project Name and package


For instance Project Name demopro and com.bt.demo
Folder structure created in eclipse workspace looks like

5
Developing & Deploying J2EE Application Contains
using
images, data, js
GWT Spring and Hibernate and GWT
module xml to
start application
locally.

Contains client
code such as
GUI Pojo class,
GUI constants
class, GUI
utility class

Contains
JUnit/test classes
for GWT service
and impl

Java
System
Library
(5 and
above)

Contains compiled classes


(src) and WEB-INF. Here
complied classes means
translation of GWT code
into lightweight Javascript.

Contains all
jars required
by application
Having GWT -ext in application
Make folder inside com.bt.demo public jsext
Copy highlighted folder and files form ext-2.0.2 inside ext folder.
In public folder, one can create img, data folder to have customized image
other than provided by GWT
Data folder is required to keep stubbed response xml received from server.

6
Developing & Deploying J2EE Application using
GWT Spring and Hibernate

Copy highlighted
folders and files to
public/js/ext
Note:-public, js, ext
folder need to be
created before
copying

7
Developing & Deploying J2EE Application using
GWT Spring and Hibernate

For integrated application (GWT + spring + Hibernate)

Hibernat
e
resource
s files

ApplicationContext.
xml contains
Hibernate
configuration for
local environment;
weblogic
environment and
Bean definition.
8
Developing & Deploying J2EE Application using
GWT Spring and Hibernate

9
Developing & Deploying J2EE Application using
GWT Spring and Hibernate

Can be set as
welcome page
and loading
message

WAR to
deploy

Build.xml to
build war for
deployment on
weblogic 10.0 10
Developing & Deploying J2EE Application using
GWT Spring and Hibernate

GWT Module xml


Developing GWT Module xml – start of Application

Give Application
main/entry point class
name (located in
client package)

Above xml, gets created using New Web Application Project


In this need to inherit module getting used in application like gwt-user.jar (available
in xml -default)

How to inherit GWTExt?


 gwtext.jar should be in classpath of project, expanding jar in eclipse.

11
Developing & Deploying J2EE Application using
GWT Spring and Hibernate

So in inherit
name would be
com.gwtext.G
wtExt

Therefore to inherit this module, need to write as

Developing welcome html page for application

BRASInterface.html BRASInterface.css

Above html and css, gets created using New Web Application Project
Modifications done by developer are:

Instead of below default code

12
Developing & Deploying J2EE Application using
GWT Spring and Hibernate

Can be replacing by loading message, loading image, title can be


customized according to app name

13
Developing & Deploying J2EE Application using
GWT Spring and Hibernate

Writing UI code, Service (RPC mechanism) and its


implementation
• Requirement:
 To fetch records from Oracle Database, pass the response to GUI,
read it and display on GUI.
• Technology used:
 GWT RPC mechanism
 Spring – application context, wiring and bean factory
 Hibernate – for table mapping and querying database

For GWT RPC service, serviceAysnc and serviceImpl are required.

 Naming convention
Service is GenerateBRASHistoryService so append Async to get
GenerateBRASHistoryServiceAsync and its implementation would be
GenerateBRASHistoryServiceImpl, append impl after service.

 Method convention
Need to write logic for fetching records from database for instance consider this
method:

Signature for above method in Service class

Signature for above method in ServiceAsync.class

 Why such naming convention?


Service class will have method to be implemented and specific return type, one
wants to return to GUI.
ServiceAsync class will always have return type void and have same signature, it
will add AsyncCallback
ServiceImpl class will implement above method and return type would be as
expected by Service class

14
Developing & Deploying J2EE Application using
GWT Spring and Hibernate

GenerateBRASHistoryService.java (located in shared. service package)

GenerateBRASHistoryServiceAsync.java (located in shared. service


package)

15
Developing & Deploying J2EE Application using
GWT Spring and Hibernate
GenerateBRASHistoryServiceImpl.java (located in server. service)

16
Developing & Deploying J2EE Application using
GWT Spring and Hibernate

How Service, ServiceAsync and ServiceImpl are tied together with web.xml
of application and Spring?
 Integration has been done by using spring4gwt-0.0.1 jar
 Servlet name as indicated in web.xml is mapped to services and html
is set as welcome file for app.

17
Developing & Deploying J2EE Application using
GWT Spring and Hibernate

And these URL pattern has mapped to Service class using Spring
annotation @RemoteServiceRelativePath as shown in below code

Flow control goes to ServiceImpl class using spring annotation @Service

Flow goes to business logic implementation and completing processing it


returns to ServiceSync class which gets called in GUI as below:

where AsyncCallback is anonymous class which would handle failure and


success of incoming request

18
Developing & Deploying J2EE Application using
GWT Spring and Hibernate

19
Developing & Deploying J2EE Application using
GWT Spring and Hibernate

Business Logic involves integration of Hibernate with


Spring
In applicationContext database and hibernate config as follows(local
environment)

Datasource and
Hibernate configuration
for local settings

Give location
of Hibernate
resources

In applicationContext database and hibernate cofig as follows (weblogic


environment)

20
Developing & Deploying J2EE Application using
GWT Spring and Hibernate

Datasource and Hibernate


configuration for weblogic
settings

Give location
of Hibernate
resources

At weblogic 10.0 JNDI created

datasource bean is referenced in sessionFactory bean block and this sessionFactory


gets called in serviceImpl class using Spring annotation @Autowired

And applicationContext gets called from web.xml

21
Developing & Deploying J2EE Application using
GWT Spring and Hibernate

DAO provides sessionFactory to serviceImpl class using Spring annotation


@Repositry, @Autowired

Now remaining with fetching of records using Hibernate mapping and DTO.
DTO is pojo class and mapping file does ORM – Object Relation Mapping with
pojo class and tables in Oracle Database.DTO gets used in serviceImpl class to write
query as Java object.

22
Developing & Deploying J2EE Application using
GWT Spring and Hibernate

One of Hibernate mapping xml located resources/Hibernate source folder

23
Developing & Deploying J2EE Application using
GWT Spring and Hibernate

 Response at GUI looks like

24
Developing & Deploying J2EE Application using
GWT Spring and Hibernate

Paging in
GWT
Obtaining application context in code (feature of Spring) (feature)
Using ApplicationContextProvider Class and bean definition in applicationContext

25
Developing & Deploying J2EE Application using
GWT Spring and Hibernate
And in code get the appContext using
ApplicationContextProvider.getApplicationContext();

 Injecting HttpServletRequest in ServiceImpl class using Spring


(feature of Spring )
For this web.xml contains

and serviceImpl class one can have request using @autowired

 Debugging by using log4j


Keep Log4j.xml in source folder of project and have

26
Developing & Deploying J2EE Application using
GWT Spring and Hibernate

Deploying the .WAR file to the Web-logic

Create a User defined web-logic configuration


We create a user defined web-logic configuration, so that we could have our
requirement specific configurations.

 Go to Start -> All Programs -> BEA -> Tools -> Configuration Wizard

27
Developing & Deploying J2EE Application using
GWT Spring and Hibernate

 Click on Configuration Wizard

28
Developing & Deploying J2EE Application using
GWT Spring and Hibernate

 Click on Next and then select “Generate a domain …”

29
Developing & Deploying J2EE Application using
GWT Spring and Hibernate

 Enter the user-defined username/password

30
Developing & Deploying J2EE Application using
GWT Spring and Hibernate

 Select the option “Sun SDK 1.5.0_11…”

Note: We could also use any version of JDK.

31
Developing & Deploying J2EE Application using
GWT Spring and Hibernate

 Select “NO”

32
Developing & Deploying J2EE Application using
GWT Spring and Hibernate

 Enter the name and location for the domain and then click on “Create”

33
Developing & Deploying J2EE Application using
GWT Spring and Hibernate

Setting up the User-defined Admin Console and server as


per the requirement

 Start the Admin Server

34
Developing & Deploying J2EE Application using
GWT Spring and Hibernate

 Once the server is in RUNNING MODE, open the Admin server Console and
enter your credentials

35
Developing & Deploying J2EE Application using
GWT Spring and Hibernate

Defining JNDI
 Click on Services -> JDBC -> Data Sources
 Click on Lock & Edit button on upper left hand corner ( to enable the
button)

 Click on New Button

36
Developing & Deploying J2EE Application using
GWT Spring and Hibernate

 Enter the details like


 Name ( JDBC DataSource Name)
 JNDI Name ( this name would be referred in ApplicationContext.xml)
 Database Type
 Database driver

& click on Next

37
Developing & Deploying J2EE Application using
GWT Spring and Hibernate

 Choose the transactional options & click on Next

38
Developing & Deploying J2EE Application using
GWT Spring and Hibernate

 Enter the following details:

39
Developing & Deploying J2EE Application using
GWT Spring and Hibernate

 Database Name
 Host Name
 Port
 Database user name
 Password

 Check the details enter and click on Test Configuration button

40
Developing & Deploying J2EE Application using
GWT Spring and Hibernate

 Note: In the Test Table Name column, enter a valid SQL


statement prefixed with “SQL”

On success

 Choose the target server and click on Finish

41
Developing & Deploying J2EE Application using
GWT Spring and Hibernate

 On receiving the confirmation message, click on “Activate Changes”


button.

42
Developing & Deploying J2EE Application using
GWT Spring and Hibernate

 The changes would be activated and specified if restart of the server is


required or not.

43
Developing & Deploying J2EE Application using
GWT Spring and Hibernate

 To monitor, if the Data source is working, click on Data Source Name


and select the Monitoring tab

44
Developing & Deploying J2EE Application using
GWT Spring and Hibernate

 Click on the Monitoring tab and then select the Testing sub-tab. Select
the Admin server and then click on Test Data Source button

We get the above mentioned error. To avoid the above error, follow the
below steps
 Click on Lock and Edit
 Select the Configuration tab.
 Click on the Advanced icon
 Check the “Test Connections on Reserve”
 Click on Save button
 Activate the changes

45
Developing & Deploying J2EE Application using
GWT Spring and Hibernate

46
Developing & Deploying J2EE Application using
GWT Spring and Hibernate

 Again do the steps involved in “ix”, we get the confirmation message

47
Developing & Deploying J2EE Application using
GWT Spring and Hibernate

Setting the logging in web-logic (log 4j)


 In the left-hand corner, up –> click on the View changes and restart
hyperlink
 Select the Restart Checklist tab
 Click on the Server name
 In the Configuration tab, select the Server start sub-tab

In Class-path column – add the entries of jars


 antlr-2.7.6.jar;
 D:\bea\user_projects\BRASInterface_domain\BRASInterface\lib\lo
g4j-1.2.15.jar;
 D:\bea\user_projects\BRASInterface_domain\BRASInterface\lib\wl
log4j.jar;

Note: These jars should placed in the user defined project lib directory

In the Arguments section, add the below entry


 -Dweblogic.log.Log4jLoggingEnabled=true

 Click on Save button. (This action will require a restart of server)

48
Developing & Deploying J2EE Application using
GWT Spring and Hibernate

 In the main tab of Server, select the logging tab


 Click on the Advanced icon
 Select the logging implementation as Log4j

Click on Save button. (This action will require a restart of server)

49
Developing & Deploying J2EE Application using
GWT Spring and Hibernate

Deploying the WAR file into the server

 Click on the Deployments link with in the Domain Structure

50
Developing & Deploying J2EE Application using
GWT Spring and Hibernate

 On Click of the Install button in the screen, select the location of the WAR file
& click on Next

 Choose targeting style ( since we are deploying a web-application, we choose


the first option) & click on Next

51
Developing & Deploying J2EE Application using
GWT Spring and Hibernate

 Click on Finish

 Click on Activate changes.

52
Developing & Deploying J2EE Application using
GWT Spring and Hibernate

 Now, the application is in “Prepared” state


 Select the Application, and click on the Start drop-down, there select the
“Servicing all requests” option.

 The application is now in Active state and able to access

53
Developing & Deploying J2EE Application using
GWT Spring and Hibernate

 To test the application


 Select the application
 Click on Testing tab
 Click on the URL available – The application would open up in a
browser.

54