Professional Documents
Culture Documents
Version 0.1
04/28/20 11
Sapna
Comments Initial document preparation Updated the document with Setting up the environment and setting up GWT module and folder structure Updated the document with deploying the application into web logic
Reviewed By
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
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
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/
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
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
Developing & Deploying J2EE Application Containsdata, js using images, and GWT GWT Spring and Hibernate
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 jsext 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.
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
Developing & Deploying J2EE Application using GWT Spring and Hibernate
ApplicationContext. xml contains Hibernate configuration for local environment; weblogic environment and Bean definition.
8
Developing & Deploying J2EE Application using GWT Spring and Hibernate
Developing & Deploying J2EE Application using GWT Spring and Hibernate
WAR to deploy
Developing & Deploying J2EE Application using GWT Spring and Hibernate
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
Therefore to inherit this module, need to write as Developing welcome html page for application
BRASInterface.htm l BRASInterface.css
Above html and css, gets created using 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
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
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 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
20
Developing & Deploying J2EE Application using GWT Spring and Hibernate
datasource bean is referenced in sessionFactory bean block and this sessionFactory gets called in serviceImpl class using Spring annotation @Autowired
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
23
Developing & Deploying J2EE Application using GWT Spring and Hibernate
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
Debugging by using log4j Keep Log4j.xml in source folder of project and have
26
Developing & Deploying J2EE Application using GWT Spring and Hibernate
27
Developing & Deploying J2EE Application using GWT Spring and Hibernate
28
Developing & Deploying J2EE Application using GWT Spring and Hibernate
29
Developing & Deploying J2EE Application using GWT Spring and Hibernate
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
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
38
Developing & Deploying J2EE Application using GWT Spring and Hibernate
Developing & Deploying J2EE Application using GWT Spring and Hibernate
Database Name Host Name Port Database user name Password
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
Developing & Deploying J2EE Application using GWT Spring and Hibernate
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, 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
follow
the
45
Developing & Deploying J2EE Application using GWT Spring and Hibernate
46
Developing & Deploying J2EE Application using GWT Spring and Hibernate
47
Developing & Deploying J2EE Application using GWT Spring and Hibernate
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
49
Developing & Deploying J2EE Application using GWT Spring and Hibernate
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
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.
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