Академический Документы
Профессиональный Документы
Культура Документы
Download NetBeans
IDE
Java Developer
Resources
Visit java.sun.com
for everything you
need to know about
the Java technology.
Java Developer
Tools
Java Standard
Edition
Java Enterprise
Edition
For enterprise,
server-side Java
applications.
Java Training
Java Support
Becoming an Sun
Developer
Network (SDN)
member makes
you part of a
vibrant worldwide
community of
developers, and
gives you access
to cool stuff and
exclusive offers.
APIs
Java Card
Java EE
Java ME
Java SE
Solaris
Sun Studio Compilers &
Tools
Web Services
See All »
Java Card
Java EE
Java ME
Java SE
Solaris
Sun Studio Compilers &
Tools
Web Services
See All »
Downloads
Early Access
Java EE
Java ME
Java SE
Java Studio Creator
Java Studio Enterprise
NetBeans
Solaris
Sun Studio Compilers &
Tools
See All »
Early Access
Java EE
Java ME
Java SE
Java Studio Creator
Java Studio Enterprise
NetBeans
Solaris
Sun Studio Compilers &
Tools
See All »
Technologies
Java EE
Java ME
Java SE
Mobility
Solaris
See All »
Java EE
Java ME
Java SE
Mobility
Solaris
See All »
Products
Support
Big Admin
Developer Services
Forums
See All »
Big Admin
Developer Services
Forums
See All »
Training
Certification
Developer Training
See All »
Certification
Developer Training
See All »
Sun.com
About Sun
Downloads
Products
Services & Solutions
Support
Training
See All »
About Sun
Downloads
Products
Services & Solutions
Support
Training
See All »
Learning Resources
GlassFish is the first Java EE 5 based application server with many ease of development features including Annotations, EJB 3.0, JPA, JAX-WS,
etc. GlassFish V2 adds enterprise level clustering to enable scalability and high availability. It also has ease of management capabilities and other
useful features for your production environment. In this lab, participants will learn, build, and run the Java EE 5 technologies using glassfish-
samples project. In the second half of the lab, we will guide participants to set up a cluster and deploy the examples to demonstrate high
availability.
GlassFish is the name for the open source development project for building a Java EE 5 application server. It is based on the source code for Sun
Java System Application Server PE 9 donated by Sun Microsystems and TopLink persistence code donated by Oracle.
The aim of the hands-on-lab is to get familiar with Java EE 5 technology features and recently introduced enterprise clustering feature through
open community Application Server, GlassFish V2.
Copyright
Copyright 2007 Sun Microsystems, Inc. All rights reserved. Sun, Sun Microsystems, the Sun logo, Solaris, Java, the Java Coffee
Cup logo, JavaOne, the JavaOne logo, and all Solaris-based and Java-based marks and logos are trademarks or registered
trademarks of Sun Microsystems, Inc. in the United States and other countries.
Prerequisites
This hands-on lab assumes you have some basic knowledge or programming experience on the following technologies.
System requirement
Supported OS: Windows 2000/ XP, Solaris 9/10, Linux, MacOS X(Darwin)
Memory requirement: 512M minimum, 1024M recommended
Disk space requirement: 300M bytes
Loadbalancer plugin is not tested for support on Windows XP; on Win platform - Windows 2000 AS, and Windows server 2003 are the tested /
supported ones
On JavaOne Lab machines, most of these softwares are installed and configured in the PATH already. But for your laptop or own system, please
download and install the following set of software. If you have any questions on installation, please feel free to send questions to the email alias
mentioned below.
Notes to JavaOne 2007 attendees using lab machines provided (This does not apply to those who use their own machines)
The lab machines are running Java Desktop System over Solaris 10
In order to open a terminal window in Java Desktop System, right click any point in the background of the desktop, and select Open
Terminal in the pop-up menu.
The following source code editors are provided on the lab machines
vi (type vi in a terminal window)
emacs (type emacs in a terminal window)
jedit (type jedit in a terminal window)
NetBeans (either click NetBeans icon or type netbeans in a terminal window)
Lab exercises
Exercise 0: Install and configure the lab environment
Exercise 1:Java EE 5 features using glassfish-samples
Exercise 2:Demonstrate the scalability and availability using clustering
Resources
Where to send questions or feedbacks on this lab and public discussion forums
You can send technical questions via email to the authors of this Hands-on lab (and experts on the subject) or you can post the questions to
the web. Please post questions that are relevant only to this hands-on lab.
handson lab06-glassfishV2@yahoogroups.com (via email)
http://groups.yahoo.com/group/handsonlab06-glassfishV2 /
You can also send your questions to the public GlassFish forums - this forum can be used to ask any GlassFish V2 related questions.
GlassFish forum in java.net
Exercise 0: Install and Configure Lab Environment
For JavaOne 2007 attendees using the lab machines provided, the steps in Exercise 0 are done for you as part of the login process. So
please proceed to Exercise 1.
Make sure the installation has set %JAVA_HOME% (Windows) or $JAVA_HOME (Solaris/Linux) environment variable to the installation
directory of Java SE 1.5.0_11
On Windows:Type "echo %JAVA_HOME%" in a command window to make sure the value is set properly.
On Solaris/Linux: "echo $JAVA_HOME" in a terminal window to make sure the value is set properly.
Verify the installation of GlassFish V2 application server
On Windows
cd %JAVAEE_HOME%\bin
asadmin version --verbose
On Solaris/Linux
cd ${JAVAEE_HOME}/bin
./asadmin version --verbose
Make sure that NetBeans IDE 5.5.1 is installed by verifying
On Windows: Start > All Programs > NetBeans 5.5.1 > NetBeans IDE or NetBeans IDE 5.5.1 desktop icon
On Solaris/Linux: <NETBEANS551_HOME>/bin/netbeans
Verify that Java EE 5 samples are installed by checking for the existence of
On Windows: %JAVAEE_HOME%\samples\javaee5
On Solaris/Linux: ${JAVAEE_HOME}/samples/javaee5
Verify the installation of SJS Webserver 6.1 and LB plugin
cd %sjsws6.1% (Windows) or $sjsws6.1 (Solaris/Linux)
cd https-<hostname>/bin
start
logs/errors will show output something similar to below:
Introduction:
Demonstrate the Java EE 5 technology features such as Web Services, JPA, EJB 3.0, Annotations, and Security using open source glassfish-
samples project. The sample applications can be built and run either using command line ant or NetBeans IDE. The samples are NetBeans
ready and participants will learn how to use the samples from NetBeans and be able to update and deploy the sample applications seamlessly to
the Application Server.
Because of time constraint, we will attempt to demo just 2 features of Java EE 5, which are Web Services and JPA using command line ant and
NetBeans IDE respectively. The downloaded glassfish-samples project contains samples for other areas as well including EJB 3.0, Annotations,
Security and JAXB. Students are expected to practise these samples on their own after the following exercises.
The goal of this exercise is to let you experience the features of Java EE 5 by building and running the Java EE 5 technology samples
using command line ant scripts and NetBeans IDE. In this exercise, you will learn the following:
Build and Run a simple web services sample hello-jaxws using ant
Build and Run a simple web based persistence sample web-jpa-war using NetBeans IDE
Ask the students to experiment with other samples related to EJB Annotations, Persistence, Web Services, Security, and EJB Interceptor
Steps to follow:
1. Update build.properties
2. Start the application server and default database
3. Build and Run a simple web services sample hello-jaxws using ant
4. Start NetBeans IDE
5. Configure application server for the NetBeans IDE
6. Build and Run a simple web based persistence sample web-jpa-war using NetBeans IDE
Step 1: Update build.properties
Update samples/bp-project/build.properties corresponding to your installation of GlassFish application server. This is needed to build and run the
samples using command line based ant, if one plans to use only NetBeans IDE then this is not required.
cd ${JAVAEE_HOME}/samples/bp-project
Edit build.properties using your favorite text editor, most of the properties are already set to default values.
...
# File that contains the password for the App-Server admin account.
# Edit this property to point to a file that
# contains the admin password for your app-server.
# The file should contain the password in the following line:
#
# AS_ADMIN_PASSWORD=adminadmin
#
# Notice that the password is adminadmin since this is
# the default password used by the glassfish app-server installation.
# For your purpose, use the password that you chose while installing
# the SDK
javaee.server.passwordfile=${JAVAEE_HOME}/samples/bp-project/passwordfile
...
build.properties
Make sure the passwordfile is created and contains the proper password.
cd ${JAVAEE_HOME}/bin
asadmin start-database
Start the default application server.
asadmin start-domain
Step 3: Build and Run a simple web services sample hello-jaxws using ant
New and updated web services (JAX-WS 2.0 and JAXB 2.0) in GlassFish simplifies SOA implementation. With JAX-WS 2.0 the code
developers need to write can be significantly reduced and Web services performance increased by up to 5 times.
Study the Web Services sample for instructions on building and running by referring to the sample documentation, which is also accessible from
samples/javaee5/webservices/hello-jaxws/docs/index.html.
cd ${JAVAEE_HOME}/samples/javaee5/webservices/hello-jaxws
ant all
The ant target all executes the individual targets compile-deploy-service, get-artifacts, compile-client, and run-client. To experiment, these
targets can be run separately.
Step 4: Start NetBeans IDE
Since NetBeans IDE uses its internal configuration for application server and database, let us stop the previously started application server and
database.
cd ${JAVAEE_HOME}/bin
asadmin stop-database
asadmin stop-domain
On Windows: Start > All Programs > NetBeans 5.5.1 > NetBeans IDE or click NetBeans IDE 5.5.1 desktop icon
Solaris/Linux: <NETBEANS551_HOME>/bin/netbeans
Step 5: Configure default web browser
Select Tools, Options which will pop up Options windowOn Options window, select General, WebBrowser and select appropriate Web
Browser
tools_options_browser
Select Runtime tab, expand Servers node, right-click Servers and select Add Server ...
Choose Server
Choose the install location of application server
click on Browse... and select the application server installation directory which is same as JAVAEE_HOME
notice that the Domain field is populated automatically
click on Next>
Provide values for admin login and password, the default values are admin and adminadmin respectively.
Click on Finish which completes the configuration for application server.
Now start the application server by selecting the Sun Java System Application Server under Servers node, right-click Sun Java System
Application Server, and click on Start. This will start the application server and the default database.
Step 7: Build and Run a simple web based persistence sample web-jpa-war using NetBeans IDE
New Java Persistence API makes object-relational mapping cleaner and easier. Java annotations can now be used to specify the mapping of Java
business objects to a relational database. The persistence implementation in the application server supports both the generation of database
schemas from Java objects and the mapping of existing database schemas to Java objects. In addition to using persistence inside the EJB
container, one can use the Persistence API directly with Java SE. This allows maximum flexibility in the application persistence needs, with a
common solution for both client and server environments.
Study the sample for instructions on building and running by referring to the sample documentation, which is also accessible from
samples/javaee5/enterprise/web-jpa-war/docs/index.html.
Select File, OpenProject and select <JAVAEE_HOME>/samples/javaee5/enterprise/web-jpa-war as the project and click on Open
Project Folder button.
When you expand the web-jpa-war node under projects, you'll see the following info.
Right click on web-jpa-war and select Run Project which will build, deploy and run the project.
The NetBeans IDE will open a separate output window for the project and logs the messages similar to the one shown below.
The IDE will open the browser as configured in build.properties with appropriate url of the deployed application.
Once you are done with the sample, you may want to stop the application server, by right clicking on Sun Java System Application
Server and selecting stop.
Summary:
In this exercise, you learned the features of Java EE 5 using Java EE 5 technology samples thru command line ant scripts and NetBeans IDE.
Exercise 2: Demonstrate the scalability and availability using clustering (30 minutes)
Glassfish V2 has new features such as Clustering, In-memory replication, so the goal of this exercise is to get students familiarize these concepts
and test these features with GlassFish V2.
User can create clusters of application server instances which can help distribute server instances from remote machines, and serve more
users by using Load balancing like Sun Webserver with Software Load Balancer plugin to avoid single-point of failure.
Other great feature of V2 is providing high availability using In-Memory replication to serve Http requests. High availability can be
enabled for both webcontainer (http requests) and ejb container (sfsb) in GlassFish V2 but this excercise will be based on http
loadbalancing / highavailability.
In these exercise students will learn how to setup clusters, use load balancer to distribute the http requests, and simulate the fail over of the
requests to healthy server instance if one of the instance is not available.
Steps to follow:
Configure the GlassFish application server and setup the Clustering, Load balancing and Availability features.
If you haven't verified the GlassFish V2 and SJS Webserver installation and configuration, please verify it as Exercise 0, as the next steps
assumes you have installed GlassFish V2 and SJS Webserver 6.1 and LB plugin.
Now to create the cluster, we need to first configure and start GlassFish V2 domain (which is in cluster mode), run following commands:
% cd $JAVAEE_HOME
This step is optional if you already have completed Exercise 1. But if you want to clean up previous
GlassFish Installation, and start everything from fresh, do
% ant -f setup-cluster.xml clean-runtime
% ant -f setup-cluster.xml
% cd ${JAVAEE_HOME}/bin
% asadmin start-domain domain1
To create a cluster on the machine running the above Domain Administartion Server (DAS), follow these steps:
You can do the above steps using Adminstration GUI by accessing http://<glassfish-host-name>:<admin-port>
After installing the Load Balancer Plugin, configure the <websrvr_instance_dir>/config/loadbalancer.xml file as follows:
<!DOCTYPE loadbalancer PUBLIC "-//Sun Microsystems Inc.//DTD Sun One Application Server 8.1//EN"
"sun-loadbalancer_1_2.dtd">
<loadbalancer>
<cluster name="cluster1" policy="round-robin">
<instance name="instance1" enabled="true" disable-timeout-in-minutes="60"
listeners="http://instance-one-host:instance-one-port" weight="100"/>
<instance name="instance2" enabled="true" disable-timeout-in-minutes="60"
listeners="http://instance-two-host:instance-two-port weight="100"/>
<web-module context-root="clusterjsp" enabled="true" disable-timeout-in-minutes="60"
error-url="sun-http-lberror.html" />
<health-checker url="/" interval-in-seconds="10" timeout-in-seconds="30" />
</cluster>
To turn on load balancer plug-in monitor messages, set the require-monitor-data property value to true. The load balancer plug-in logs record
the following information:
Restart the Web Server after configuring the LB plugin from loadbalancer.xml file.
Step 3: Deploying and Running the clusterjsp Sample Application, and testing clustering/load balancing.
To test cluster1 of two GlassFish V2 Server instances, use the "clusterjsp" application located in
${JAVAEE_HOME} /samples/quickstart/clusterjsp directory as clusterjsp.ear
To deploy the clusterjsp application on "cluster1" of two instances, run following command
cd ${JAVAEE_HOME}/samples/quickstart/clusterjsp
% ${JAVAEE_HOME}/bin/asant deploy
Now all the clustering, load balancing configurations and application deployment is done.
You can access the clusterjsp application using http://hostname:web-server-port/clusterjsp (webserver port) and add
sessions to the application.
Clusterjsp http response will show which GlassFish Server instance (instance-ONE or instance-TWO) serving the request of the client. To
simulate application server clustering along with load-balancing, follow steps below
1. You will need to use two Firefox browsers or at least two seperate sessions of the browsers, and clear cache/cookies from the
browser before every new request (this is needed to simulate unique clients) to access a deployed clusterjsp sample application.
2. You access the clusterjsp application through webserver http://web-server-host:web-server-port/clusterjsp
and see the request is served by first instance that is running (instance-ONE in our case) in the http response you get in browser.
Healthy and the Unhealthy instance is been detected by webserver load-balancer plugin.
3. Open another Firefox browser, clear cache/cookies from the browser (Do it couple of times to really clear cache/cookies) and
access clusterjsp application again through webserver http://web-server-host:web-server-port/clusterjsp This time, you
can see the request is served by second instance that is running (instance-TWO in this case) in the http response you get in browser.
This ensures that requests are served by instances in the order set in the loadbalancer.xml file in Round-Robin fashion.
Screenshots below.
instance-ONE instance-TWO
This demonstrates the cluster of two instances instance-ONE, and instance-TWO which are managed by the Node-agents and Domain
Admininstration Server of GlassFish V2 and load balanced through Load Balancer plugin installed on SJS Webserver 6.1.
To verify GlassFish server High-Availability or failover while accessing a deployed clusterjsp sample application, follow the steps below:
1. You can make a particular instance serve a request by restarting the web server that has the load balancer plugin installed before deploying
an application. This ensures that requests are served by instances in the order set in the loadbalancer.xml file. From the above
loadbalancer.xml instance-ONE will serve the first request.
2. We have already deployed a sample application that stores session data, e.g. clusterjsp web application as above. With this we should be
able to see that successive requests from same client are served by the same instance that the served first request and the session data is
maintained across the requests.
3. Send few requests and note down the instance that served those requests and shutdown that particular instance. Use this command to stop
the instance:
asadmin stop-instance --user adminuser --password adminpassword instance-name
4. Now send in the next request and verify that the new data is stored properly and that the previously added data is still there in the session.
Session Data
This demonstrate the same shopping-cart scenario to avoid single-point of failure. If one of the server serving requests and adding items in
shopping cart initially crashed, or not available anymore, then another server in the same cluster will take-over the request with all earlier session
data (added items of shopping cart) and complete the request. Here the session data is stored in Memory, so this demonstrates the in-memory
replication feature to get GlassFish server Highly Available.
1. To stop the cluster1 Cluster of two instances and cluster1-nodeagent nodeagent, run following command
cd ${JAVAEE_HOME}/samples/quickstart/clusterjsp
% ${JAVAEE_HOME}/bin/asant stop_cluster
% ${JAVAEE_HOME}/bin/asant stop_nodeagent
% $sjsws6.1/stop
Summary:
This verifies the load balancing of GlassFish V2 with the SJS Webserver Load Balancer Plugin. The exercise above also verifies the in-memory
replication feature to get GlassFish server Highly Available
Congratulations! You have successfully completed the "LAB-3315: Java EE 5 Hands-on and Clustering using Open Source GlassFish Application Server " Hands -on lab.
Congratulations! You have successfully completed the "LAB-3315: Java EE 5 Hands-on and Clustering using Open Source GlassFish Application Server " Hands -on lab.
Please send your feedback to https://hands-on-labs.dev.java.net/servlets/ForumMessageList?forumID=2562
Content Feeds