Arun Gupta's Blog
Arun Gupta is a GlassFish Evangelist focusing on Web Tier at Sun. He was the spec lead for APIs in the Java platform, committer in multiple Open Source projects, participated in standard bodies and contributed to Java EE and SE releases.
GlassFish setup for 120 programmers in University of Copenhagen
Posted by arungupta on February 25, 2009 at 09:57 AM | Permalink
| Comments (0)
Sidsel Jensen is a Sun
Campus Ambassador at University
of Copenhagen , Denmark. She configured GlassFish in her
department to be used by 120 freshman programmers. Starting with a
standard HP DL360 G5 rack server, installing Gentoo Linux, NetBeans for
deployment of web apps to a remote GlassFish, creating multiple domains
and even performance tuning the Application Server.
Read all the details in Gone
Fishing for GlassFish .
Thank you Sidsel for using GlassFish and sharing the steps with rest of
the community!
If you are interested in learning/talking about GlassFish at your
university, spotlight.dev.java.net/start
provides a comprehensive set of slides (with speaker notes), demos,
screencasts, training materials and other resources to get you started!
Technorati: glassfish
students
campusambassador
denmark
copenhagen
spotlight
Sun Tech Days Hyderabad 2009
Posted by arungupta on February 19, 2009 at 03:39 AM | Permalink
| Comments (1)
India has always had the largest number of attendees of all the Tech
Days, and this time is certainly no exception. 10,000+ attendees, the
passion for technology, the eagerness to share their work, and
everything else makes it certainly one of the most exciting venues for
Tech Days.
The Hyderabad
International Airport is certainly very impressive - big,
clean, and very 21st centurisque with a 8-lane freeway connecting to
the main city.
See a short video as the attendees were allowed to enter the Hyderabad International
Convention Center (the venue for Tech Days):
I got a chance to talk to the General Manager of the convention center
and very happy to
know that similar convention centers are planned for Pune (1/2 the size
of existing one), Mumbai (4x), and
Bangalore (2x) in the near future.
As part of the opening, there was an excellent performance by an
11-year old percussionist, enjoy the video here:
Absolutely stunning performance!
It was funny, I was standing right
next to the boy's parents while recording the video. Apparently the boy
was allotted 10 minutes and the parents were trying their best to
distract the boy right at the beginning of 11th minute :)
I presented on:
WSIT: Security, Reliability, Transactional, and
.NET-interoperable Web services (slides ).
The screencast
#ws7 is the demo shown during the talk.
GlassFish & Future of Java EE (slides )
There were 1000+ attendees in both the sessions and had some very
interactive discussions post session. It was a great opportunity to
meet lots of local Campus
Ambassadors , students using GlassFish for their projects,
engineers using GlassFish for their development/deployment, Sun
colleagues and lots of other folks!
Here are some of the pictures:
And finally the evolving album:
Technorati: conf
suntechdays
glassfish
metro wsit hyderabad
TOTD #69: GlassFish High Availability/Clustering using Sun Web Server + Load Balancer Plugin on Windows Vista
Posted by arungupta on February 12, 2009 at 12:16 AM | Permalink
| Comments (0)
TOTD
#67 shows how to configure GlassFish High Availability using
Apache httpd + mod_jk on Mac OS X. Even though that's a standard and
supported configuration, there are several
advantages for replacing
Apache httpd with Sun Web Server and mod_jk with Load Balancer plugin
that comes with GlassFish.
This T ip O f T he D ay (TOTD) shows how
to configure Clustering and Load Balancing using GlassFish
v2.1 , Sun
Web Server , Load
Balancer plugin on Windows Vista. This blog is using JDK 6 U7,
GlassFish v2.1 (cluster profile), Sun Web
Server 7 U4, and Load Balancer plug-in with Sun
GlassFish Enterprise
Server 2.1 Enterprise Profile (with HADB link).
Lets get started!
Install the required software
Download JDK (if not already installed).
Download and Install GlassFish v2.1.
Make sure to configure using "ant -f setup-cluster.xml". This will
ensure
that the created domain is capable of creating clusters and can perform
in-memory session replication for applications deployed on the cluster.
Download and Install Sun Web Server. The
process is very simple by unzipping the downloaded bundle, clicking on
"setup.exe" and taking all the defaults.
Download GlassFish Enterprise Profile for Load Balancer
plugin bits. Start the install by clicking on the
downloaded file and select the options as shown below:
Copy the following "loadbalancer.xml" in
"https-<host>" (replace <host> with the
host name of your machine) directory of Sun Web Server installation
directory:
<?xml version="1.0"
encoding="UTF-8"?>
<!DOCTYPE loadbalancer PUBLIC "-//Sun Microsystems Inc.//DTD Sun
Java
System Application Server 9.1//EN"
"file:///C:/Sun/WebServer7/https-LH-KRKZDW6CJE1V /config/sun-loadbalancer_1_2.dtd
">
<loadbalancer>
<cluster name="cluster1" policy="round-robin"
policy-module="">
<instance name="instance1" enabled="true"
disable-timeout-in-minutes="60" listeners="https://localhost:38080 "
weight="100"/>
<instance name="instance2" enabled="true"
disable-timeout-in-minutes="60" listeners="https://localhost:38081 "
weight="100"/>
<web-module context-root="/clusterjsp "
disable-timeout-in-minutes="30" enabled="true" error-url=""/>
<health-checker interval-in-seconds="7"
timeout-in-seconds="5" url="/"/>
</cluster>
<property name="response-timeout-in-seconds"
value="120"/>
<property name="reload-poll-interval-in-seconds"
value="7"/>
<property name="https-routing" value="false"/>
<property name="require-monitor-data"
value="false"/>
<property name="active-healthcheck-enabled"
value="false"/>
<property name="number-healthcheck-retries"
value="3"/>
<property name="rewrite-location" value="true"/>
</loadbalancer>
The parameters to be changed are highlighted in bold and explained
below:
Sun Web Server installation directory
HTTP port of instances created in the cluster. The
ports specified
are the default ones and can be found by clicking on the instance as
shown below:
Context root of the application that will be deployed
in the cluster. The Domain Administration Server (DAS) can be
configured to populate this file whenever any application is deployed
to the cluster.
Create the cluster as explained in TOTD
#67 . The admin console shows the following
screenshot after the cluster is
created and all instances are created/started:
and the following for 2 instances:
Deploy "clusterjsp" as explained in TOTD
#67 . The admin console shows the following screenshot after
"clusterjsp" is deployed:
Start Sun Web Server using "startserv.bat" in
"https-<host>" directory.
This concludes the installation and configuration steps, now show
time!
Accessing "https://localhost/clusterjsp" shows:
The Sun Web Server is running on port 80 and uses
"loadbalancer.xml" to serve the request from the configured instances
in <loadbalancer> fragment. This particular page is
served by
"instance1" as indicated in the image.
Lets add session data with property name "aaa" and value "111". The
value is shown as:
The instance serving the data, "instance1" in this case, and the
session data are highlighted.
Now lets stop "instance1" using the admin console and it looks like:
Click on "RELOAD PAGE" and it looks like:
Exactly same session data is served, this time by "instance2".
The sequence above proves that the session data created by the user is
preserved even if the instance serving the data goes down.
This is possible because of GlassFish High Availability. The
session
data is served by the "replica partner" where its already
copied using in-memory session replication.
The following articles are also useful:
Please leave suggestions on other TOTD (Tip Of The Day) that
you'd like to see.
A complete archive of all tips is available here .
Technorati: totd
glassfish
highavailability
clustering
loadbalancing
lbplugin
sunwebserver
windows
vista
TOTD #68: Installing Zones in Open Solaris 2008/11 on Virtual Box
Posted by arungupta on February 10, 2009 at 05:53 AM | Permalink
| Comments (0)
The TOTD
#64 describes how to install Open Solaris 2008/11
using Virtual Box .
This T ip O f T he D ay (TOTD) is going
to explain how to install non-global zones
(aka Solaris Containers) on this Open Solaris image. Containers provide
an operating-system level virtualization technology.
Thanks for the
extensive discussion at zones-discuss
forums , Bill
Walker for lots of off-line support, and last but not the
least Marcelo
Arbore 's nice blog showing how to install GlassFish
in an Open Solaris zone .
This blog is going to focus on installing couple of non-global
containers/zones in the Virtual Box image with all gory details. A
later blog will show how to leverage these zones to demonstrate GlassFish
High Availability .
Lets get started!
To begin with, there is one global zone always installed as shown below
(user
inputs highligted in bold):
arun@opensolaris:~# zoneadm
list -vi
ID
NAME
STATUS
PATH
BRAND IP
0
global
running
/
native shared
Lets install the zone. The IP address is specified in 192.168.0.XXX
range ...
arun@opensolaris:~# zonecfg
-z zone1
zone1: No such zone configured
Use 'create' to begin configuring a new zone.
zonecfg:zone1> create
zonecfg:zone1> set
zonepath=/export/home/zone1
zonecfg:zone1> set
autoboot=true
zonecfg:zone1> add
net
zonecfg:zone1:net> set
address=192.168.0.99/24
zonecfg:zone1:net> set
physical=e1000g0
zonecfg:zone1:net> end
zonecfg:zone1> commit
zonecfg:zone1> exit
arun@opensolaris:~# zoneadm
-z zone1 install
A ZFS file system has been created for this zone.
Authority: Using https://pkg.opensolaris.org/release/.
Image: Preparing at
/export/home/zone1/root ... done.
Cache: Using
/var/pkg/download.
Installing: (output follows)
DOWNLOAD
PKGS
FILES XFER (MB)
Completed
52/52 7862/7862 72.41/72.41
PHASE
ACTIONS
Install
Phase
12939/12939
PHASE
ITEMS
Reading Existing
Index
9/9
Indexing
Packages
52/52
Note: Man
pages can be obtained by installing SUNWman
Postinstall: Copying SMF seed repository ... done.
Postinstall: Working around
https://defect.opensolaris.org/bz/show_bug.cgi?id=741
Done:
Installation completed in 165.652 seconds.
Next Steps: Boot the zone, then log into the zone console
(zlogin -C) to complete the configuration process
arun@opensolaris:~# zoneadm
-z zone1 boot
arun@opensolaris:~# zlogin
-C zone1
[Connected to zone 'zone1' console]
68/68
Reading ZFS config: done.
Mounting ZFS filesystems: (6/6)
Specify the type of terminal ...
What type of terminal are you using?
1) ANSI Standard CRT
2) DEC VT100
3) PC Console
4) Sun Command Tool
5) Sun Workstation
6) X Terminal Emulator (xterms)
7) Other
Type the number of your choice and press Return: 1
Creating new rsa public/private host key pair
Creating new dsa public/private host key pair
Configuring network interface addresses: e1000g0.
Configure NIC ...
- Host Name for e1000g0:1
------------------------------------------------------
Enter the host name which identifies this system on the
network. The name
must be unique within your domain; creating a duplicate host
name will cause
problems on the network after you install Solaris.
A host name must have at least one character; it can contain
letters,
digits, and minus signs (-).
Host name for e1000g0:1 zone1
- Confirm Information for e1000g0:1
--------------------------------------------
> Confirm the following information. If it
is correct, press F2;
to change any information, press F4.
Host name: zone1
No Kerberos ...
- Configure Security Policy:
---------------------------------------------------
Specify Yes if the system will use the Kerberos security
mechanism.
Specify No if this system will use standard UNIX security.
Configure Kerberos
Security
---------------------------
[ ] Yes
[X] No
- Confirm Information
----------------------------------------------------------
> Confirm the following information. If it
is correct, press F2;
to change any information, press F4.
Configure Kerberos Security: No
Specify the name service, domain, and domain resolver ...
- Name Service
-----------------------------------------------------------------
On this screen you must provide name service
information. Select the name
service that will be used by this system, or None if your
system will either
not use a name service at all, or if it will use a name
service not listed
here.
> To make a selection, use the arrow keys to
highlight the option
and press Return to mark it [X].
Name service
------------
[ ] NIS+
[ ] NIS
[X ] DNS
[ ] LDAP
[ ] None
- Domain Name
------------------------------------------------------------------
On this screen you must specify the domain where this system
resides. Make
sure you enter the name correctly including capitalization
and punctuation.
Domain name: sfbay.sun.com
- DNS Server Addresses
---------------------------------------------------------
On this screen you must enter the IP address of your DNS
server(s). You
must enter at least one address. IP addresses must
contain four sets of
numbers separated by periods (for example 129.200.9.1).
Server's IP address: 10.0.2.3
Server's IP address:
Server's IP address:
The value of IP address for your DNS server is copied from
"/etc/resolv.conf" in the global zone. Specify DNS search list and
confirm the information ...
- DNS Search List
--------------------------------------------------------------
On this screen you can enter a list of domains that will be
searched when a
DNS query is made. If you do not enter any
domains, DNS will only search
the DNS domain chosen for this system. The domains
entered, when
concatenated, may not be longer than 250 characters.
Search domain:
Search domain:
Search domain:
Search domain:
Search domain:
Search domain:
- Confirm Information
----------------------------------------------------------
> Confirm the following information. If it
is correct, press F2;
to change any information, press F4.
Name service: DNS
Domain name: sfbay.sun.com
Server address(es): 10.0.2.3
No need to create an address entry for the zone ...
- Name Service Error
-----------------------------------------------------------
Unable to find an address entry for zone1 with the specified
DNS
configuration.
Enter new name
service information?
-----------------------------------
[ ] Yes
[X ] No
Specify and confirm NFSv4 domain name ...
- NFSv4 Domain Name
------------------------------------------------------------
NFS version 4 uses a domain name that is automatically
derived from the
system's naming services. The derived domain name is
sufficient for most
configurations. In a few cases, mounts that cross domain
boundaries might
cause files to appear to be owned by "nobody" due to the
lack of a common
domain name.
The current NFSv4 default domain is: "sfbay.sun.com"
NFSv4 Domain
Configuration
----------------------------------------------
[X] Use the NFSv4
domain derived by the system
[ ] Specify a
different NFSv4 domain
- Confirm Information for NFSv4 Domain
-----------------------------------------
> Confirm the following information. If it
is correct, press F2;
to change any information, press F4.
NFSv4 Domain Name:
<< Value to be derived dynamically >>
Timezone ...
- Confirm Information
----------------------------------------------------------
> Confirm the following information. If it
is correct, press F2;
to change any information, press F4.
Time zone: Pacific Time
(US/Pacific)
Specify the root password and then see the comment as:
System identification is completed.
This comment indicates successful creation of the zone.
Login to "zone1" as:
zone1 console login: root
Password:
Feb 8 16:12:10 zone1 login: ROOT LOGIN /dev/console
Sun Microsystems Inc. SunOS
5.11
snv_101b
November 2008
Check the network configuration ...
root@zone1:~# ifconfig
-a
lo0:1:
flags=2001000849<UP,LOOPBACK,RUNNING,MULTICAST,IPv4,VIRTUAL>
mtu 8232 index 1
inet 127.0.0.1 netmask ff000000
e1000g0:1:
flags=201000843<UP,BROADCAST,RUNNING,MULTICAST,IPv4,CoS>
mtu 1500 index 2
inet 192.168.0.99 netmask ffffff00 broadcast 192.168.0.255
root@zone1:~#
After "zone1" is completely installed, then it can be viewed as:
arun@opensolaris:~$ zoneadm list -vi
ID
NAME
STATUS
PATH
BRAND IP
0
global
running
/
native shared
1
zone1
running
/export/home/zone1
ipkg shared
And then install "zone2" using the steps described above and check it's
network configuration as:
root@zone2:~# ifconfig -a
lo0:2:
flags=2001000849<UP,LOOPBACK,RUNNING,MULTICAST,IPv4,VIRTUAL>
mtu 8232 index 1
inet 127.0.0.1 netmask ff000000
e1000g0:2:
flags=201000843<UP,BROADCAST,RUNNING,MULTICAST,IPv4,CoS>
mtu 1500 index 2
inet 192.168.0.98 netmask ffffff00 broadcast 192.168.0.255
root@zone2:~#
And it's shown in the list of zones as:
arun@opensolaris:~# zoneadm list -vi
ID
NAME
STATUS
PATH
BRAND IP
0
global
running
/
native shared
1
zone1
running
/export/home/zone1
ipkg shared
2
zone2
running
/export/home/zone2
ipkg shared
OK, so we installed 2 non-global zones in an Open Solaris image running
as guest in Virtual Box.
Typing "~." takes you back to the global zone.
Please leave suggestions on other TOTD (Tip Of The Day) that
you'd like to see.
A complete archive of all tips is available here .
Technorati: totd
opensolaris
zones containers
solaris
virtualbox
glassfish
GlassFish swimming to Singapore, Delhi, Bangalore, and Hyderabad - Feb 2009
Posted by arungupta on February 06, 2009 at 05:36 AM | Permalink
| Comments (0)
I'll be traveling (again )
and this time to Singapore, Delhi, Bangalore, and Hyderabad over
the next couple of weeks. A few meetings are already planned
but there is buffer for squeezing any last-minute JUG visits, Rails
Meetup or meeting Campus
Ambassadors .
Here is my schedule:
Singapore:
Feb
12 & 13
Delhi:
Feb
14, 20, & 21
Bangalore:
Feb
15, 16, & 17
Hyderabad:
Feb
18 & 19
One of the good things about traveling internationally is an
opportunity to taste the local cuisines. Here are a few local
delicacies that I don't intend to miss:
Any particular recommendations for restaurants or delicacies that are
missing ?
Anybody intersted in meeting or running together ?
You can always follow along at twitter.com/arungupta .
LOTD #16: Hotspot Flags, JRuby Version String, and JRuby/MRI Benchmark
Posted by arungupta on February 04, 2009 at 07:08 AM | Permalink
| Comments (0)
This post shares 3 links that were recently published.
The first one is about the Favorite
Hotspot JVM Flags by Charlie .
See how you can use them for tweaking performance or investigating
runtime metrics.
The second one is about using JRuby
Version String . It explains the detailed meaning of the
version string printed by "jruby --version". If you read it carefully
then you know the date, hardware, platform, SVN revision and even state
of Charlie's local git-svn clone.
The third and the last one is about benchmark results between MRI and
JRuby with the following summary:
From my tests it appears
that MRI is faster in single threaded mode, but JRuby makes up for the
loss big time in the multi-threaded tests. It's also interesting to see
that the multi-threaded mode gives MRI(green threads) a performance
boost, but it's nowhere close to the boost that JRuby(native threads)
can squeeze out from using multiple threads.
Read Igor's
report for more results.
And while you are reading this entry, did you know that GlassFish
Gem 0.9.2 was recently
released ? Use it for running your Rails applications
seamlessly :)
All previous entries in this series are archived at LOTD .
Technorati: lotd
glassfish
v3 gem jruby ruby hotspot vm
Rails/Merb and GlassFish at Super Happy Dev House 30
Posted by arungupta on February 03, 2009 at 05:39 AM | Permalink
| Comments (0)
Supper
Happy Dev
House is "a premier
monthly hackathon event that combines serious and
not-so-serious productivity
with a fun and exciting party
atmosphere ."
The 30th
monthly event was hosted at Sun Microsystem's Executive
Briefing Center (aka EBC) in Menlo Park. During my short stay at Dev
House, all the key characteristics of "productivity" and "party
atmosphere" were indeed evident. This was the biggest Dev House in it's
history. My previous visits to EBC have been for formal customer
presentations. And the Dev House gathering turned the EBC into a very
lively environment :)
I gave a lightning
talk (for 5 minutes) on Rails/Merb powered by GlassFish /NetBeans . The key
messages were:
JRuby - "It's just Ruby!" with passing over 55,000
compliance tests and continuous performance improvements.
NetBeans - light-weight and intuitive IDE for Rails
development/deployment
GlassFish - robust deployment environment for Rails/Merb
applications
The demo showed in the talk is available as screencast
#26 and TOTD
#53 . Sharat posted a recording of my talk and is included
below:
Read the latest on GlassFish/JRuby/Rails/Merb on the GlassFish
wiki .
Did you know Project Kenai
is a massive Rails application deployed on GlassFish
? Host your project on kenai.com
and get integrated support for Forums, Wikis, multiple source code
reposisotry (including Subversion, Mercurial, and Git), bug tracking
(including Bugzilla and JIRA) and much more. Empower your project on kenai.com - a complete
Rails application running on GlassFish.
Here are some pictures:
And the complete album at:
Technorati: conf
shdh shdh30 superhappydevhouse
rubyonrails
merb glassfish
netbeans
sun
TOTD #67: How to front-end a GlassFish Cluster with Apache + mod_jk on Mac OSX Leopard ?
Posted by arungupta on January 30, 2009 at 06:35 AM | Permalink
| Comments (0)
GlassFish
provides support for High Availability by creating a cluster of server
instances and session state replication. This enhances the
scalability and availability of your application and is a critical
piece of decision making critieria when selecting an Application
Server. Clustering
in GlassFish Version 2 provides comprehensive introduction to
clustering, high availability and load balancing in GlassFish.
GlassFish provides out-of-the-box support for load-balancing HTTP(S) ,
JMS ,
and RMI/IIOP
traffic and front-ended by Sun Java System Web Server, Apache Web
Server, and Microsoft IIS (more
details here ) using the Load
Balancer plug-in . This plug-in however is not available for
Mac OS X and a popular technique used on that platform for front-ending
is to use Apache httpd
+ mod_jk .
This is exactly what this TOTD (T ip
O f T he D ay) is going to
describe.
This TOTD is going to explain how to front-end a 3-instance GlassFish
cluster with Apache httpd and mod_jk on Mac OS X.
This blog is using information from the following blogs:
And thanks to Vivek
and Shreedhar
for helping me understand the guts of GlassFish High Availability.
Without further ado, lets get started. The steps are slightly involving
so strap your seatbelts!
First, lets create a 3-instance cluster following the
screencast at GlassFish
Clustering in under 10 minutes . Use the cluster name as
"cluster1" and instance names as "instance1", "instance2", "instance3".
The admin console will look like:
Deploy "clusterjsp" and make sure it works using port hopping as
explained in the screencast. Click on each instance to identify their
associated HTTP port.
Define "jvmRoute" and "enableJK" properties on the newly
created cluster as:
~/samples/v2/clustering/glassfish/bin
>./asadmin
create-jvm-options --target cluster1
"-DjvmRoute=\${AJP_INSTANCE_NAME}"
Command create-jvm-options executed successfully.
~/samples/v2/clustering/glassfish/bin >./asadmin
create-jvm-options --target cluster1
"-Dcom.sun.enterprise.web.connector.enableJK=\${AJP_PORT}"
Command create-jvm-options executed successfully.
These properties are required to enable "stickiness" for "mod_jk". More
details about how these properties are used internally is explained
here .
Configure the above system properties for each instance in
the cluster as shown:
~/samples/v2/clustering/glassfish/bin
>./asadmin
create-system-properties --target instance1
AJP_INSTANCE_NAME=instance1
Command create-system-properties executed successfully.
~/samples/v2/clustering/glassfish/bin >./asadmin
create-system-properties --target instance1 AJP_PORT=9090
Command create-system-properties executed successfully.
~/samples/v2/clustering/glassfish/bin >./asadmin
create-system-properties --target instance2 AJP_INSTANCE_NAME=instance2
Command create-system-properties executed successfully.
~/samples/v2/clustering/glassfish/bin >./asadmin
create-system-properties --target instance2 AJP_PORT=9091
Command create-system-properties executed successfully.
~/samples/v2/clustering/glassfish/bin >./asadmin
create-system-properties --target instance3 AJP_INSTANCE_NAME=instance3
Command create-system-properties executed successfully.
~/samples/v2/clustering/glassfish/bin >./asadmin
create-system-properties --target instance3 AJP_PORT=9092
Command create-system-properties executed successfully.
Note the value of "AJP_PORT" property for each instance, this will be
used for configuring "mod_jk" later. You may have to restart the
cluster in order for these properties to be synchronized for each
instance. This can be easily done using the admin console as explained
in the screencast above.
Install httpd: Mac OS X Leopard 10.5.6 comes bundled with
Apache httpd
2.2, so that's cool! Otherwise it can be downloaded from httpd.apache.org .
However in the pre-installed version there are some intricacies with
directory
names
that are explained below.
Lets install and configure "mod_jk" in "httpd".
The mod_jk binaries for Mac OSX are supposedly available
at www.apache.org/dist/tomcat/tomcat-connectors/jk/binaries/macosx/ .
But installing the available module in httpd gives the following error:
httpd: Syntax error on line 116 of
/private/etc/apache2/httpd.conf: Cannot load
/usr/libexec/apache2/mod_jk-1.2.25-httpd-2.2.4.so into server:
dlopen(/usr/libexec/apache2/mod_jk-1.2.25-httpd-2.2.4.so, 10): no
suitable image found. Did
find:\n\t/usr/libexec/apache2/mod_jk-1.2.25-httpd-2.2.4.so: mach-o, but
wrong architecture
The alternative is to build "mod_jk". Fortunately it
turned out to be a straight forward process because of this
blog .
Download latest
Connectors source code (version
1.2.27 ). The file "BUILD.txt" (included in the source bundle)
provide
clear instructions to build and described below as well.
Configure the build environment as shown:
~/workspaces/tomcat-connectors-1.2.27-src/native
>./configure
--with-apxs=/usr/sbin/apxs
It shows the output as:
.
. .
checking for target platform... unix
no apache given
no netscape given
configure: creating ./config.status
config.status: creating Makefile
config.status: creating apache-1.3/Makefile
config.status: creating apache-1.3/Makefile.apxs
config.status: creating apache-2.0/Makefile
config.status: creating apache-2.0/Makefile.apxs
config.status: creating common/Makefile
config.status: creating common/list.mk
config.status: creating common/jk_types.h
config.status: creating jni/Makefile
config.status: creating common/portable.h
config.status: executing depfiles commands
Edit Edit "native/apache-2.0/Makefile.apxs" and add
"-arch x86_64" as described here .
Please note that this string needs to be specified twice.
Invoke "make" and "mod_jk.so" is generated in
"native/apache-2.0" directory.
Copy the generated "mod_jk.so" as:
~/workspaces/tomcat-connectors-1.2.27-src/native/apache-2.0
>sudo cp mod_jk.so
/usr/libexec/apache2/
Load the "mod_jk" module in httpd by editing
"/etc/apache2/httpd.conf". Please note another similar file exists in
"/etc/httpd/httpd.conf" but ignore that one. Add the following as the
last "LoadModule" line:
LoadModule jk_module
libexec/apache2/mod_jk-1.2.25-httpd-2.2.4.so
Configure "mod_jk" by adding the following lines
immediately below the previously "LoadModule" line:
JkWorkersFile
/etc/apache2/worker.properties
# Where to put jk logs
JkLogFile /var/log/httpd/mod_jk.log
# Set the jk log level [debug/error/info]
JkLogLevel debug
# Select the log format
JkLogStampFormat "[%a %b %d %H:%M:%S %Y] "
# JkRequestLogFormat set the request format
JkRequestLogFormat "%w %V %T"
# Send all jsp requests to GlassFish
JkMount /*.jsp loadbalancer
The key lines in this configuration are the first and the last one.
The first line informs "mod_jk" about the location of
"worker.properties"
file (explained later). The last line instructs to redirect only JSP
requests. This will allow the static content such as images,
text files, and media to be served from
"httpd" itself.
Also create the log directory specified in the configuration as:
sudo mkdir /var/log/httpd
Create a new file "/etc/apache2/worker.properties".
Again, this is not in "/etc/httpd" directory. Use the following
contents:
#
Define 1 real worker using ajp13
worker.list=loadbalancer
# Set properties for instance1
worker.instance1.type=ajp13
worker.instance1.host=localhost
worker.instance1.port=9090
worker.instance1.lbfactor=50
worker.instance1.cachesize=10
worker.instance1.cache_timeout=600
worker.instance1.socket_keepalive=1
worker.instance1.socket_timeout=300
# Set properties for instance2
worker.instance2.type=ajp13
worker.instance2.host=localhost
worker.instance2.port=9091
worker.instance2.lbfactor=50
worker.instance2.cachesize=10
worker.instance2.cache_timeout=600
worker.instance2.socket_keepalive=1
worker.instance2.socket_timeout=300
# Set properties for instance3
worker.instance3.type=ajp13
worker.instance3.host=localhost
worker.instance3.port=9092
worker.instance3.lbfactor=50
worker.instance3.cachesize=10
worker.instance3.cache_timeout=600
worker.instance3.socket_keepalive=1
worker.instance3.socket_timeout=300
worker.loadbalancer.type=lb
worker.loadbalancer.balance_workers=instance1,instance2,instance3
Read more about worker.properties
format . Essentially this file is used to load-balance a
3-instance cluster and
specify configuration values for each instance. Note that the value of
"worker.instanceX.port" for instance X is exactly same as specified
during instance configuration earlier.
Copy "tomcat-ajp.jar" from the "lib" directory of the
latest Tomcat
5.5.x , commons-logging.jar
(version
1.1.1 ), and commons-modeler.jar
(version
2.0.1 ) to GLASSFISH_HOME/lib. This is done as:
~/samples/v2/clustering/glassfish/lib
>cp
~/tools/apache-tomcat-5.5.27/server/lib/tomcat-ajp.jar .
~/samples/v2/clustering/glassfish/lib >cp
~/Downloads/commons-logging-1.1.1/commons-logging-1.1.1.jar .
~/samples/v2/clustering/glassfish/lib >cp
~/tools/commons-modeler-2.0.1/commons-modeler-2.0.1.jar .
You may have to restart cluster in order for these JARs to be loaded by
each instance.
An "httpd" instance is already running on port# 80 in my
particular
instance of Mac OS X. Instead of mangling with that, I decided to
change the listening port for the new instance that will be spawn for
out front-end. This can be easily done by editing
"/etc/apache2/httpd.conf" and looking for lines similar to:
#Listen 12.34.56.78:80
Listen 80
And change "Listen 80" to "Listen 81".
That completes the configuration, phew!
Lets start "httpd" as:
The "httpd" logs are available in "/private/var/log/apache2". The
following message indicates a successful start of the web server:
. . .
[Thu
Jan 29 11:14:16 2009] [warn] Init: Session Cache is not configured
[hint: SSLSessionCache]
[Thu Jan 29 11:14:16 2009] [warn] No JkShmFile defined in httpd.conf.
Using default /usr/logs/jk-run
time-status
[Thu Jan 29 11:14:16 2009] [warn] No JkShmFile defined in httpd.conf.
Using default /usr/logs/jk-run
time-status
[Thu Jan 29 11:14:16 2009] [notice] Digest: generating secret for
digest authentication ...
[Thu Jan 29 11:14:16 2009] [notice] Digest: done
[Thu Jan 29 11:14:16 2009] [warn] pid file /private/var/run/httpd.pid
overwritten -- Unclean shutdow
n of previous Apache run?
[Thu Jan 29 11:14:16 2009] [notice] Apache/2.2.9 (Unix) mod_ssl/2.2.9
OpenSSL/0.9.7l DAV/2 mod_jk/1.
2.27 configured -- resuming normal operations
OK, now show time!
If everything has been configured properly as described above then
"https://localhost:81/clusterjsp/HaJsp.jsp" looks like:
Enter session attribute as "aaa" and value of the attribute as "111".
After you click on "ADD SESSION DATA" button, the updated page looks
like:
The highlighted part shows that the request is served from "instance1"
and recently added session data. Lets stop "instance1" and see if the
promise of high availability is fulfilled :)
Click on "Instances" tab, select "instance1" and click "Stop". The
admin console looks like:
Notice "instance1" is shown as stopped. Clicking on "Reload Page" on
"https://localhost:81/clusterjsp/HaJsp.jsp"
shows:
Aha!
Even though "instance1" is not runing the session data is still
available. And that is possible because of the seamless session
failover from primary ("instance1") to the replica partner
("instance2"). The highlighted part indicates that the request is now
indeed served by "instance2".
Here are some other useful links to consider:
Please leave suggestions on other TOTD (Tip Of The Day) that
you'd like to see.
A complete archive of all tips is available here .
Technorati: totd
glassfish
highavailability
clustering
loadbalancer
mod_jk
apache
httpd mac leopard
"Sparks of passion" in the "world of Open Source" - Archana N contributes to GlassFish Documentation
Posted by arungupta on January 30, 2009 at 06:33 AM | Permalink
| Comments (0)
Interested in contributing to open source ? Archana N has a
recommendation for you:
Flame the sparks of
passion in you,
Experience the world of
Open Source anew.
Discover your potentials
as they unfold,
Venture to contribute in
the technologies untold.
Archana N is an ex-Sun
Campus Ambassador from Amrita Vishwa
Vidyapeetham , India. Recently she contributed on how to
secure the
existing EJB converter example from the Java EE tutorial
using mutual authentication. She continue to work on developing RESTful
web services using Project
Jersey as her next contribution for GlassFish
documentation .
The GlassFish
Documentation team published her interview to recognize the
efforts, read it here .
Thank you Archana for your contribution to GlassFish , keep the
passion
alive!
If you are interested in learning/talking about GlassFish at your
university, spotlight.dev.java.net/start
provides a comprehensive set of slides (with speaker notes), demos,
screencasts, training materials and other resources to get you started!
Technorati: glassfish
students
campusambassador
spotlight
Free GlassFish Webinar for Students at OSUM
Posted by arungupta on January 29, 2009 at 06:19 AM | Permalink
| Comments (0)
Are you a student and would like to learn why GlassFish is meant for
you ?
Create/join a student community at osum.sun.com
and attend the GlassFish
Webinar . This webinar will introduce GlassFish application
server, show multiple demos that can be used to impress your
colleagues/professors, and answer your questions around GlassFish.
The coordinates are:
Feb 3, 2009, 8:30am PT
Webinar
Invite
This webinar will be conducted using Elluminate Live! You will be able
to listen to live audio via your computer speakers or ear phones and be
able to ask questions using chat/text.
Learn more about OSUM (pronounced "awesome") here .
Create your OSUM today
and join over 900 student clubs from over 80 countries!
If you are interested in talking about GlassFish, spotlight.dev.java.net/start
provides a comprehensive set of slides (with speaker notes), demos,
screencasts, training materials and other resources to get you started!
Technorati: glassfish
webinar
osum students
spotlight
GlassFish in CEUI and Campus Party
Posted by arungupta on January 28, 2009 at 08:47 AM | Permalink
| Comments (0)
As reported earlier ,
Alan Vargas ,
the Sun
Campus Ambassador at CEUI
(Centro Universitario de Ixltahuaca) presented on GlassFish. The
message of "GlassFish v2 - Fast, Easy, and Reliable" and "GlassFish v3
- Modular, Embeddable, and Extensible" was clearly delivered in the
talk .
Alan has published several useful blogs on GlassFish
(in Spanish and English) recently:
The slides from his talk are available here .
Here are some pictures from the talk:
The complete album is available here .
Thanks to Alan Vargas for delivering a GlassFish talk!
Ronaldo Prass talked about GlassFish at the recently concluded Campus Party Brazil
2009 . This is claimed to be biggest party of the Internet
world in Brazil :) An attendance of over 6655, sort of, vouch for that!
More details on Campus Party in the wikipedia
entry .
There is a Campus Party community at OSUM ,
join here .
Enjoy the images posted by the community on Flickr
and videos @
YouTube .
Thanks to Ronaldo Pass for spreading the GlassFish wealth!
Please drop a comment on this blog if you have talked about GlassFish
in your school/university/training. If you'd like to talk about it then
spotlight.dev.java.net/start
provides a comprehensive list of material (slides, demos, etc.) to get
you started!
Technorati: glassfish
students
spotlight
brazil
mexico
Singapore Tech Days 2009 - Wrapup
Posted by arungupta on January 28, 2009 at 08:47 AM | Permalink
| Comments (0)
A picture is worth thousand words! Now that Picasa 3.0 is available
on
Mac , here is a collage of pictures from the recently
concluded Sun Tech
Days in Singapore .
The complete photo album is available at:
And if you are interested in knowing all the action, read
here !
Technorati: conf
suntechdays
singapore
Singapore Tech Days 2009 - Talent Show, Cloud Camp, GlassFish Demo
Posted by arungupta on January 28, 2009 at 08:46 AM | Permalink
| Comments (0)
Follow up from Day
1 .
Matt Thompson talked about cloud computing. Even though the term "cloud
computing" is becoming more prominent now, it very well echoes Sun's 25
years old mantra - "The Network is the Computer". Even though there are
some prominent players but the field is very much emerging. Matt
touched upon different interpretations of a cloud - Platform,
Infrastructure or Software as a Service (PaaS, Iaas, SaaS). A set of
developer tools that allows you to manage your cloud is equally
important for it to be successful. He then gave a preview of some of
the open source developer tools (Kenai
and Zembly )
available from Sun Microsystems to assist in that direction.
After the keynote, some participants showed their "strange and unusual"
talent to add a bit of levity to the otherwise intense
technical conference. Even though there were 6 participants but it was
less "strange and unusal" than the previous ones I've attended (Sao
Paolo 2008 , Hyderabad
2008 , Beijing
2007 ). Here is a video of the show and judget it yourself:
A video of the GlassFish demo shown during Day
1 is now available:
The cloud
camp in the evening had approx 50 attendees with an
interesting discussion around the definition of cloud, security
concerns, portability of applications across clouds, major players in
the game, and much more. Free pizza and beer is always a good way to
keep audience engaged until late in the night ;-) Sign
up for a cloud camp near your city!
Here are some pictures from Day 2:
University
Day today!
And finally the complete photo album in Singapore so far:
Follow the latest updates on twitter.com/arungupta .
Technorati: conf
suntechdays
singapore
glassfish
cloudcamp
Sun Tech Days 2009, Singapore - Welcome Reception
Posted by arungupta on January 20, 2009 at 02:46 PM | Permalink
| Comments (0)
Follow up from Part
1 .
Attended "What Developers should care about MySQL ?" by Colin and
"Groovy and Grails" by Chuk-munn
Lee .
I enjoyed both the talks for different reasons. Colin's talk explained
the pluggable
storage engine architecture that is unique to MySQL
(pronounced my-ess-kew-ell ,
not my-sequel ).
It was interesting to know that the different storage engines can be
picked a la carte
based upon the requirements. The performance comparison for INSERTs was
5x between MyISAM, InnoDB and Archive storage engines. But then InnoDB
provide transactions and other goodies. Multiple performance tuning
tips such as using negative unsigned int instead of BIGINT and
partitioning databases if the number of records grow more than 1 billion were good! Keep an eye
on his blog
for slides.
Chuk's talk introduced Groovy, Grails,
showed several samples of NetBeans
and Grails
integration. A Grails application can be deployed as a WAR file on
GlassFish. Alternatively you can download the Grails module from GlassFish v3 Update
Center and use the standard "run-app" command to run your
Grails application using the embedded GlassFish v3 instead of Jetty.
This
is explained nicely in the screencast below:
Here are couple of pictures from rest of the day:
The welcome reception gave a good chance to engage with the audience.
There was a community-driven musical performance and I made a video
recording of the event. But because of the slow Internet connection,
it's taking forever to load this particular video (may be it's Picasa 3 on Mac
;-)
If you have not signed up for Cloud
Camp event
happening in Singapore at 6pm today, register here !
Here is the complete photo album so far:
Follow the latest updates on twitter.com/arungupta .
Technorati: conf
suntechdays
singapore
glassfish
mysql netbeans
Sun Tech Days 2009, Singapore - Day 1
Posted by arungupta on January 20, 2009 at 12:28 AM | Permalink
| Comments (2)
The Sun Tech Days
Singapore started earlier this morning - over 1100
developers, an outstanding audience!!!
The kick off had a good local flare when the Gods of
Longevity, Fortune, and Prosperity (Fu Lu Shou) showed up to
start the event ;-) The build up to their appearance was really
exciting as evident from
the video below:
This particular event will also be recorded in Singapore
Book of Records for the largest numbers of Sun developers
playing
a rattle together :) Here are some pictures from the event:
A Toshiba laptop and an iPod was raffled to the audience and the lucky
winners are:
And found another loyal reader of my blog :
Gosh, he even took my autograph ;-)
The steps to reproduce the different GlassFish demos shown during the
key note
are explained below.
GlassFish v3 OSGi-compliance and quick startup time
Download GlassFish v3 Prelude from here ,
unzip, and start the server as
glassfish/bin/asadmin start-domain --verbose
to see a message something like:
INFO: GlassFish v3 Prelude startup time :
Felix(1732ms) startup services(1091ms) total(2823ms)
The
GlassFish v3 container starts up fairly quickly, 2.8 secs in this case,
without starting any application-specific container. The container is
using OSGi R4 APIs and Apache Felix
as the runtime.
This allows any standard OSGi bundle to be easily deployed in GlassFish
v3. The underlying OSGi runtime can be easily replaced with Knopflerfish
or Equinox
because standard R4 APIs
are used. As you notice, Felix start up time is explicitly shown in the
startup message.
The quick start up is possible because
containers, such as Web container that serves web applications, is
started only when the first Web application is deployed. No web
application, no web container - simple! The same is true as other types
of applications are deployed, for example a Rails application. The
containers are started and stopped on demand giving a higher
utilization of resources.
Auto-deploy of Servlets and preserving servlet session
state across multiple re-deploys using NetBeans
and Eclipse .
This feature is really useful as it tremendously reduces your
development time. Focus on what you are good at i.e. adding business
logic and let NetBeans and GlassFish together take care of your
deployment worries. And why should you loose your session state just
because the application is re-deployed!
Modularity
and Extensibility of GlassFish v3 by running/debugging a Rails
application. GlassFish certainly supports traditional Java EE
applications. But starting with GlassFish v3 the newer Web frameworks
like Rails can also be deployed natively. The screencast
#26
shows how to develop, run and debug a Rails application natively
deployed on GlassFish. And this capability of deploying a Rails
application is added as an OSGi module and also demonstrates the
extensibility of GlassFish.
It provides future protection as well because any other Web framework
can be easily deployed as a standard OSGi module.
Extensibility
of GlassFish v3 by dropping a JAR in the "/modules" directory. The
admin console is a one-stop interface for the administration of your
GlassFish instance such as deploying WAR/EAR, creating JDBC/JMS
resource, and creating clusters. Starting with GlassFish v3, even the
admin console is extensible. There are clearly defined extension points
that allows you to write a "admin console module" and extend the
capability of your admin console. The demo showed dropping a JAR in the
standard "modules" directory and admin cosole recognizing the module. A
sample project that shows all the integration points to GlassFish v3
Admin Console is available here .
Other demos showcased JavaFX ,
Open Solaris
and jMaki Webtop
technology.
I particularly enjoyed the JavaFX demo by our "resident mad scientist"
- Simon Ritter
:) It was an interesting use of
technology to create something fun. Enjoy the demo below:
Also met Colin
Charles , Community Relations Manager for MySQL at Sun
Microsystems. It was certainly great to know that similar thought
process is applied for promoting both GlassFish and MySQL - state the
facts, offer an alternative, and let the customers decide. Both MySQL and GlassFish are open
source offerings with complete enterprise
support
available from Sun Microsystems. And together with OpenSolaris , NetBeans and many other
open source offerings
they make a killer platform for developing/deploying any kind of web
applications.
And if you have not signed up for Cloud Camp event
happening in Singapore tomorrow at 6pm, register here !
Here is the complete photo album so far:
Follow the latest updates on twitter.com/arungupta .
Technorati: conf
suntechdays
singapore
glassfish
mysql
javafx
netbeans
EJBs in a WAR - Simplified packaging defined by EJB 3.1, Available in GlassFish v3
Posted by arungupta on January 19, 2009 at 04:15 PM | Permalink
| Comments (2)
The EJB 3.1
specification says:
An enterprise bean class
with a component-defining annotation defines an enterprise bean
component when packaged within the WEB-INF/classes directory or in a
.jar file within WEB-INF/lib.
In simple English it means, an EJB can be a POJO annotated with EJB
annotations (such as @javax.ejb.Stateless) and bundled within
WEB-INF/classes inside a WAR.
This feature is available in GlassFish v3 for some
time now .
Imagine the ramifications, you now have Container Managed Persistence,
Transacations, Security, and all other standard benefits of EJB - only
this time in a WAR file.
The default configuration of GlassFish v3 Prelude does not include an
EJB container. Lets first install it!
The EJB container in GlassFish v3 Prelude can be installed in couple of
ways:
Using Update Center as described here .
Or using the "pkg" command which is described below
The "pkg" command shipped with GlassFish is platform-independent and
runs on all the supported platforms. You can use the standard "pkg-get"
command with OpenSolaris but that requires more options to be
specified. For simplicity, we'll use the "pkg" command bundled with
GlassFish as shown below:
arun@opensolaris:~/glassfishv3-prelude/bin$ ./pkg
The software needed for this command (pkg) is not installed.
When this tool interacts with package repositories, some system
information
such as your system's IP address and operating system type and version
is sent to the repository server. For more information please see:
https://wiki.updatecenter.java.net/Wiki.jsp?page=UsageMetricsUC2
Once installation is complete you may re-run this command.
Would you like to install this software now (y/n): y
Install image: /export/home/arun/glassfishv3-prelude/bin/..
Installing pkg packages.
Installing: [pkg:/pkg@1.0.7,0-15.1269:20081008T211255Z,
pkg:/python2.4-minimal@2.4.4.0,0-15.1269:20081008T211307Z]
Initialization complete.
Software successfully installed. You may now re-run this command (pkg).
Install the EJB container as:
arun@opensolaris:~/glassfishv3-prelude/bin$ ./pkg install glassfish-ejb
DOWNLOAD PKGS FILES XFER (MB) Completed 1/1 11/11 0.45/0.45
PHASE ACTIONS Install Phase 24/24
And verify as ...
arun@opensolaris:~/glassfishv3-prelude/bin$ ./pkg list
NAME (AUTHORITY) VERSION STATE UFIX felix 1.2.2-0 installed ---- glassfish-amx 3.0-28.3 installed ---- glassfish-api 3.0-28.3 installed ---- glassfish-common 3.0-28.3 installed ---- glassfish-ejb 3.0-28.3 installed ---- glassfish-grizzly 1.8.6.2-0 installed ---- glassfish-gui 3.0-28.3 installed ---- glassfish-hk2 3.0-28.3 installed ---- glassfish-jca 3.0-28.3 installed ---- glassfish-jdbc 3.0-28.3 installed ---- glassfish-jdbc-gui 3.0-28.3 installed ---- glassfish-jdbc-management 3.0-28.3 installed ---- glassfish-jpa 3.0-28.3 installed ---- glassfish-jsf 1.2.10-1 installed u--- glassfish-jta 3.0-28.3 installed ---- glassfish-management 3.0-28.3 installed ---- glassfish-nucleus 3.0-28.3 installed ---- glassfish-registration 3.0-28.3 installed ---- glassfish-scripting 3.0-28.3 installed ---- glassfish-web 3.0-28.3 installed ---- glassfish-web-gui 3.0-28.3 installed ---- glassfish-web-management 3.0-28.3 installed ---- javadb 10.2.2.1-0 installed ---- pkg 1.0.7-15.1269 installed ---- pkg-java 1.0.7-15.1269 installed ---- python2.4-minimal 2.4.4.0-15.1269 installed ----
As shown above, "glassfish-ejb" module with version "3.0.28.3" is now
installed.
Now your GlassFish v3 Prelude is ready to serve EJBs!
Next, lets create a simple web application and package EJB there. Using
the NetBeans IDE, create a template Web application. Lets say the
project is named "ReallySimpleEJB".
Create a POJO, choose the class name as "HelloEJB" and
package as "server" as shown
Declare a public method "sayHello" and add
@javax.ejb.Stateless annotation to mark it a stateless EJB as shown
Create a new Servlet by selecting the option as shown
and specify the name as "EJBClient" in "client" package
and click on "Finish".
In the generated Servlet, declare a dependency on the EJB
using @javax.ejb.EJB as shown
Invoke the EJB by uncommenting the code in "processRequest"
method and add "ejbClient.sayHell("Duke")" invocation as shown:
If the application is pre-deployed then saving this file will
auto-deploy it as shown in screencast
#27 . Otherwise right-click on the project and select "Deploy".
And finally invoking the servlet at
"https://localhost:8080/ReallySimpleEJB/EJBClient" shows the following
output:
EJBs in a WAR - simple and easy to use :)
Download GlassFish
v3 Prelude and get started!
Technorati: glassfish
v3 ejb netbeans
war ear
OSUM - Open Source University Meetup - awesome venue for students!
Posted by arungupta on January 19, 2009 at 04:14 PM | Permalink
| Comments (0)
If your university is not participating in the Sun
Campus Ambassador program, you can always create an Open Source University Meetup
(OSUM, pronounced "awesome") community. Sun Microsystems offers you the
complete range of Open Source software - OpenSolaris , OpenOffice , NetBeans , GlassFish , MySQL , and many others .
OSUM provides an opportunity to create a student club and:
* LEARN about Open Source Technologies
and how they are opening up new career opportunities for students
* ACCESS free online web courses, webinars, tutorials and other
resources to prepare for career enhancing certifications
* SHARE your technical knowledge with
other students around the world virtually and on campus
* COLLABORATE with a global community of
students via forum, campus events, webinars, etc.
* CONNECT and make friends with students
around the world who are committed to Open Source just like you!
Create your OSUM today
and join over 900 student clubs from over 80 countries!
If you are interested in talking about GlassFish, spotlight.dev.java.net/start
provides a comprehensive set of slides (with speaker notes), demos,
screencasts, training materials and other resources to get you started!
Technorati: glassfish
students
spotlight
osum campusambassador
TOTD #66: GlassFish Eclipse Plugin 1.0.16 - Install v3 Prelude from the IDE
Posted by arungupta on January 17, 2009 at 05:53 AM | Permalink
| Comments (1)
GlassFish
Plugins team released
ver 1.0.16 of Eclipse
plugin for GlassFish . The team has maintained pretty good
cadence in terms of adding features and fixing bugs in the plugin (16
releases in approx as many months ). However this particular
version has an exciting feature. It allows GlassFish
v3 Prelude to be
installed from within the IDE itself.
If you have not installed GlassFish plugin in your Eclipse earlier then
screencast
#28 shows how to get started. However the screencast requires
you to pre-install GlassFish outside the IDE. Instead, as explained in
this blog, you can skip
to here and install the Application Server from within the
IDE.
If you have a previous installation of GlassFish plugin, then it needs
to be updated using the steps described below. And finally install the
Application Server from wtihin the IDE.
Lets get started!
In Eclipse, go to "Help" menu item, "Software Updates ..." and it shows
the complete list of plugins installed along with their versions ...
GlassFish plugin version is 1.0.14 in this case. Click on "Available
Software" tab to show all the available updates as shown below:
The GlassFish plugin update site is automatically added to the list of
managed sites once you install the plugin, but it is not automatically
checked as active. The issue
#45 provide more details but in the mean while check the
website explicitly by clicking on "Manage Sites ..." and selecting
"https://ajax.dev.java.net/eclipse" as shown below ...
Click on "OK" and the list of "Available Software" is now updated to
include GlassFish server. Notice, the latest version (1.0.16 in this
case) is shown as well.
Select the plugin to be installed ...
Click on "Install ..."
Click on "Next >" and then "Finish". Now your Eclipse is updated
with the latest GlassFish plugin.
Lets add a new Server instance. In the "Servers" tab, right-click and
select "New", "Server" ...
Select "GlassFish v3 Prelude" after expanding the "GlassFish" tree ...
Name the server if you like or take default and click on "Next".
Notice "Install Server"
button, this is the new functionality added in
version 1.0.16 of the plugin. Specify a directory name and click on
"Install Server". This will automatically download the GlassFish v3
Prelude server and install in the specified directory.
Of course, you need to accept the License ...
Click on "Finish" and GlassFish is downloaded and installed for you
(finished in few seconds for me :) and shows the following window:
Clicking on "Next >" walks you through the standard GlassFish
configuration options:
More details on how to leverage the powerful GlassFish server are
available in the documentation .
The screencast
#28 shows some of the GlassFish/Eclipse integration features
in an easy to use manner.
Please ask any questions or send any feedback to users@glassfishplugins.dev.java.net .
Please leave suggestions on other TOTD (Tip Of The Day) that
you'd like to see.
A complete archive of all tips is available here .
Technorati: totd
glassfish
eclipse
v3
GlassFish Swimming to Singapore Tech Days
Posted by arungupta on January 16, 2009 at 05:51 AM | Permalink
| Comments (0)
Sun
Tech Days is traveling to Singapore next
week and I'll be there!
You'll find me at the pavilion hall, sessions, hallway, lunch,
reception, University Day, and else where. Stop by and say hello! Let
us know how you are using GlassFish
and how can we make it better for you.
Click on the map below to get the exact direction to Raffles
City Convention Centre .
Here are some important links:
Register
now!
Complete details about the event are available here .
There are scattered thunderstorms predicted through out the event. The
highest temperature is expected to be 89o and
the lowest 76o . This is going to be really balmy
compared to an average 55o in San Francisco Bay
Area around this time of the year. But hey, it's been 10o
warmer here too for past few days, so shouldn't be too bad :)
There is apparently a running track near by and I'd not like to break
my 16 days of run-a-day streak. Any other recommendations for good
running trails around the convention center ?
What are other fun things to do ?
Any Ruby Meetups who would like to know why GlassFish/NetBeans provide
an excellent alternative to WEBrick/Mongrel/Textmate ?
Technorati: conf
suntechdays
singapore
glassfish
GlassFish spotted on Salvador, Bahia - a Brazilian beach!
Posted by arungupta on January 16, 2009 at 05:50 AM | Permalink
| Comments (0)
Marcelo Souza (a GlassFish
team member) spotted GlassFish on Salvador,
Bahia beach in Brazil during his personal vacation :)
Thanks to Marcelo for taking this picture :)
Here are couple of shots of the beach itself:
Drop a comment on this blog if you would like to share any pictures of
GlassFish :)
Technorati: glassfish
brazil
salvadaor
GlassFish @ Manipal Institute of Technology, India - Go Campus Ambassadors!
Posted by arungupta on January 15, 2009 at 05:28 AM | Permalink
| Comments (0)
Here is yet
another (slightly dated) contribution by Vasudha Amrit
on GlassFish ,
Campus Ambassador
from Manipal
Institue of Technology, India .
She arranged a GlassFish talk in her campus and one of the GlassFish
team member delivered the talk (while on a personal visit :)! The blog
report provide details. The event was a huge success with 482
attendees. Here is an excerpt from the blog:
we had to put up extra
chairs all around the place and even then
people kept coming, so much so that we had to send people back. Some
people even volunteered to sit on the floor. There were a total of 482
students, HODs and faculties from four departments and the associate
director ( phew!!!!! :P )attending the talk when we did a head count
and that is not counting people who had gone back.
And some pictures (more in the original
blog ):
Thank you very much Vasudha for providing an opportunity to share the
details about best open source application server! Thank you Sudhir for
delivering the talk while on a personal visit!
Please drop a comment on this blog if you have talked about GlassFish
in your school/university/training. If you'd like to talk about it then
spotlight.dev.java.net/start
provides a comprehensive list of material (slides, demos, etc.) to get
you started!
Check out how widespread CAs are in this global
map . Follow their aggregated
blogs for details on what they are doing.
And occassionally we conduct contests
for students where prize money is awarded for the best
entries.
Technorati: glassfish students
spotlight
campusambassador
Blog Fan
Posted by arungupta on January 14, 2009 at 11:47 AM | Permalink
| Comments (0)
It is embarrassing to share the post below but certainly very
encouraging to know that readers like
the posts on my two blogs (weblogs.java.net/weblogs/java.net
and blogs.sun.com /arungupta ).
I've thoroughly enjoyed 544 posts on weblogs.java.net and 762 posts on
blogs.sun.com so far :)
Thanks for the continued readership and feel free to send suggestions
by leaving a comment on the blog!
Technorati: blogs
java.net
bsc milestogo
GlassFish @ University of Essex and Frankfurt - Go Campus Ambassadors!
Posted by arungupta on January 13, 2009 at 10:57 AM | Permalink
| Comments (0)
This blog highlights couple of contributions by Campus
Ambassadors (CA) from
University of Essex
and Frankfurt
towards GlassFish .
Jenya Kovalchuk (Campus Ambassador in the University of
Essex, UK) gave a talk
on GlassFish . The pre- and post-conditions of talk are really
compelling:
Pre-condition: No one out of 25 present ever heard about GlassFish
Post-condition: Everyone is looking forward to put their hands on, how
great it is! dear all, we are approaching labs where the software is
already installed…
That means there are approx 15 more students who are now trying their
hands on GlassFish :)
Igor Geier from University of Frankfurt developed a A
MySQL GlassFish application . The application is a
work-in-progress but it sure will show the ease-of-use of GlassFish and
tight integration with NetBeans.
Thank you very much for talking about/using GlassFish!
Please drop a comment on this blog if you have talked about GlassFish
in your school/university/training. If you'd like to talk about it then
spotlight.dev.java.net/start
provides a comprehensive list of material (slides, demos, etc.) to get
you started!
Check out how widespread CAs are in this global
map . Follow their aggregated
blogs for details on what they are doing.
And occassionally we conduct contests
for students where prize money is awarded for the best
entries.
Technorati: glassfish
mysql students
spotlight
campusambassador
TOTD #64: OpenSolaris 2008/11 using Virtual Box
Posted by arungupta on January 13, 2009 at 10:56 AM | Permalink
| Comments (0)
Here is a blog entry that was sitting in my Drafts folder for a long
time
(just because I didn't realize :). Anyway, it shows how to install Open Solaris 2008/11
on Virtual Box .
The original install was done using Virtual Box 2.0.6. I installed
Virtual Box 2.1 this morning and the image was easily recognized by the
updated Virtual Box.
Here are the basic steps.
Create a new VM ...
As part of the previous step, create a new Virtual Disk mapping to the
downloaded Open Solaris image ...
The generated VM settings are shown as below:
Click on "Start" and configure for the first run as:
Boot the Virtual Macine from the LiveCD shows the following GRUB:
Take the default for Language and Keyboard and then the following
screen is shown after the boot:
Click on "Install OpenSolaris" ...
Clicking on "Install" starts the installation ...
And finally the install is completed.
Click on "Reboot", select "Boot from Hard Disk" and press Enter ...
And then select if "full boot" or "text boot" is required as shown:
And the welcome screen is shown as:
Now you can develop your Rails
applications using the NetBeans
IDE and deploy them on GlassFish
and MySQL easily as
explained here .
There are multiple updates to the stack described earlier - JRuby 1.1.6 ,
Rails
2.2 , MySQL
Alpha 6.0.x , GlassFish
v3 Prelude , and Virtual Box
2.1 .
So go ahead and develop, deploy, and debug your Rails applications as
described in screencast
#26 . You can even manage your Rails applications using JMX as
described in TOTD #61 ,
#62 ,
and #63 .
Hwo do you follow the latest on each technology:
And, of course, this
blog talks about all of them :)
Please leave suggestions on other TOTD (Tip Of The Day) that
you'd like to see.
A complete archive of all tips is available here .
Technorati: totd
opensolaris
virtualbox
glassfish
netbeans
jruby rubyonrails
mysql
TOTD #63: jmx4r gem - How to manage/monitor your Rails/Merb applications on JRuby/GlassFish ?
Posted by arungupta on January 13, 2009 at 10:54 AM | Permalink
| Comments (0)
TOTD
#61 and TOTD
#62 shows how to use JMX APIs to locally/remotely
manage/monitor your Rails/Merb applications. This Tip Of The Day
extends TOTD #62 and shows how remote management can be done using jmx4r gem .
This gem provides a clean mapping between JMX APIs and Ruby. It allows
to write pure Ruby code to manage/monitor any Rails application. As a
result it removes all dependency on the Java code used in TOTD
#62 .
Lets first install the gem!
~ >gem
install jmx4r
JRuby limited openssl loaded. gem install jruby-openssl for full
support.
https://wiki.jruby.org/wiki/JRuby_Builtin_OpenSSL
Successfully installed jmx4r-0.0.6
1 gem installed
Installing ri documentation for jmx4r-0.0.6...
Installing RDoc documentation for jmx4r-0.0.6...
Here is the equivalent Ruby code to flush the class cache (as in TOTD
#62 ):
require 'rubygems'
require 'jmx4r'
JMX::MBean.establish_connection
:host => "129.145.133.163", :port => 8686
beans =
JMX::MBean.find_all_by_name "org.jruby:*"
beans.each { |bean|
service = bean.object_name["service"]
case service
when "ClassCache"
@cc_mbean = bean
when "Config"
@c_mbean = bean
end
}
# clear the cache if it's full
if @cc_mbean.full
printf "JIT Max: %d, JIT Threshold: %d, Class load count:
%d\n", @c_mbean.jit_max,
@c_mbean.jit_threshold,
@cc_mbean.class_load_count
@cc_mbean.flush
else
puts "Class Cache is not full"
printf "Loaded: %d, Reused: %d, Live: %d\n",
@cc_mbean.class_load_count,
@cc_mbean.class_reuse_count,
@cc_mbean.live_class_count
end
As with all Ruby code, really clean and simple!
The key parts of the code are highlighted in bold.
"JMX::MBean.establish_connection" establishes a connection with a JMX
agent running on a remote machine identified by the IP address and port
number specified. "JMX::MBean.find_all_by_name" queries the agent for
all the MBeans in "org.jruby" domain. And then the code is self
explanatory.
Just dump this code in a file and run it as:
to see the output similar to:
Class Cache is not full
Loaded: 76, Reused: 0, Live: 76
Make sure Rails/Merb application is running after setting JAVA_OPTS as
described in TOTD
#62 . For this blog, the JMX agent/Rails application ran on a
Mac and the JMX client on a Solaris box.
The jmxr
examples provides some more ways to use the gem.
There is also jmx
gem that provides similar functionality. It even allows to
create MBeans and provides a simple server where they can be
registered. Tom's
blog provide more details on usage and there is even a sample
included.
Subsequent blogs in this series will discuss:
How to
remotely manage your Rails/Merb applications using
JMX API ?
How to publish your own metrics that can be managed using
JMX API ?
How
to use jmx gem to manage/monitor ?
How to use VisualVM to get more information about the
underlying VM ?
How to use NewRelic/FiveRuns to manage/monitor an
application ?
Please leave suggestions on other TOTD (Tip Of The Day) that
you'd like to see.
A complete archive of all tips is available here .
Technorati: totd
glassfish
jruby
rubyonrails
merb
jmx jmx4r manage
monitor
TOTD #62: How to remotely manage/monitor your Rails/Merb applications on JRuby/GlassFish using JMX API ?
Posted by arungupta on January 08, 2009 at 10:21 AM | Permalink
| Comments (0)
TOTD
#61 showed how to manage/monitor a Rails/Merb application
running using JRuby/GlassFish using standard Java tools. Both the
application and the management tools are running on the same machine.
But that's never the case in a production environment. Instead remote
management of an application is required when running in production
mode. Fortunately, similar set of tools can be used for remote
management as well.
However the underlying Java Virtual Machine needs to be configured to
enable remote monitoring. This is achieved by setting JAVA_OPTS
environment variables as shown below:
Set up the following envinronment variable before running the
Rails/Merb application:
export JAVA_OPTS="-Dcom.sun.management.jmxremote
-Dcom.sun.management.jmxremote.port=8686
-Dcom.sun.management.jmxremote.authenticate=false
-Dcom.sun.management.jmxremote.ssl=false"
The first property enables the JMX remote agent (aka MBeans server) and
local monitoring. The second property configures the port number for
remote management using JMX/RMI connections. The third and fourth
properties, for simplicity only, disable access control and SSL for
remote monitoring. It is highly recommended to use them in a
production environment. Using
Password Authentication provide more details about
configuring passwords for access control. Using
SSL provide more details about configuring SSL.
Now for a Rails/Merb application running on GlassFish all the MBeans
are also available on the JMX agent running on port 8686. This agent
can be accessed using the standard
URL as shown below:
service:jmx:rmi:///jndi/rmi://192.168.124.1:8686/jmxrmi
"192.168.124.1" is the host's IP address on which the Rails/Merb
application is running and "8686" is the port configured in JAVA_OPTS.
More details about the URL are available here .
First, lets use jconsole on a different machine to monitor this
application. Start jconsole by typing the command in a shell as:
In the "New Connection" window, select "Remote Process" and enter the
URL defined above as shown
below:
And then the management data snapshot is captured as shown below:
And here is a snapshot from a remote Solaris machine:
Notice the URL, as opposed to "pid", is shown on the jconsole window.
This indicates that remote connection is being used instead of local
process id. TOTD
#61 further explains how jconsole can be used to
manage/monitor your Rails/Merb applications.
As mentioned in TOTD
#61 , JRuby runtime exposes 4 different MBeans - ClassCache,
Config, JITCompiler and ParserStats - all in "org.jruby" domain. Lets
write a client application that query these MBeans to monitor the state
of JRuby runtime and perform some management actions based upon the
returned results.
Here is the Ruby client code using Java
Management Extensions (JMX) APIs.
include Java
import java.io.IOException
import java.util.HashSet
import java.util.Set
import javax.management.JMRuntimeException
import javax.management.MBeanServerConnection
import javax.management.MalformedObjectNameException
import javax.management.ObjectName
import javax.management.JMX
import javax.management.remote.JMXConnector
import javax.management.remote.JMXConnectorFactory
import javax.management.remote.JMXServiceURL
import org.jruby.management.ClassCacheMBean
import org.jruby.management.ConfigMBean
url = JMXServiceURL.new
"service:jmx:rmi:///jndi/rmi://192.168.124.1:8686/jmxrmi"
mbsc = JMXConnectorFactory.connect(url, nil).get_mbean_server_connection
names = HashSet.new(mbsc.query_names(ObjectName.new("org.jruby:*"),
nil))
names.each { |name|
service =
name.get_key_property "service"
if service == "ClassCache"
@cc_mbean = JMX.new_mbean_proxy(mbsc, name,
Java::org.jruby.management.ClassCacheMBean.java_class)
elsif service == "Config"
@c_mbean = JMX.newMBeanProxy(mbsc, name,
Java::org.jruby.management.ConfigMBean.java_class)
end
}
# clear the cache if it's full
if @cc_mbean.is_full
puts @c_mbean.get_jit_max
puts @c_mbean.get_jit_threshold
puts @cc_mbean.get_class_load_count
@cc_mbean.flush
else
puts "Class Cache is not full"
printf "Loaded: %d, Reused: %d, Live:
%d\n", @cc_mbean.get_class_load_count,
@cc_mbean.get_class_reuse_count, @cc_mbean.get_live_class_count
end
Here are the main tasks achieved by this code:
Do include/import for Java classes
Connect with the JMX Agent where JRuby MBeans are
registered and obtain a MBean Server Connection (explained here )
Query for all the MBeans in "org.jruby" domain
Create proxies for ClassCache and Config MBeans
Flush the ClassCache if its full and print some debugging
information
These MBeans are part of JRuby runtime so provide relevant
management/montoring
information corresponding to that. But as you can see it's fairly
trivial to write a client to query MBeans and achieve dynamism using
standard Ruby code.
Each JRuby-exposed MBean has multiple attributes
that can be utilized to monitor your application and take appropriate
actions. For example, an application could detect
low memory and stop accepting new connections.
And you can continue to use GlassFish
for running your Rails and Merb applications (now
Sinatra as well )!
Subsequent blogs in this series will discuss:
How to
remotely manage your Rails/Merb applications using
JMX API ?
How to publish your own metrics that can be managed using
JMX API ?
How to use jmx gem to manage/monitor ?
How to use VisualVM to get more information about the
underlying VM ?
How to use NewRelic/FiveRuns to manage/monitor an
application ?
Please leave suggestions on other TOTD (Tip Of The Day) that
you'd like to see.
A complete archive of all tips is available here .
Technorati: totd
glassfish
jruby rubyonrails
merb jmx
manage
monitor
TOTD #61: How to locally manage/monitor your Rails/Merb applications on JRuby/GlassFish using JMX ?
Posted by arungupta on January 07, 2009 at 09:17 AM | Permalink
| Comments (1)
GlassFish
Gem can easily run both Rails and Merb application. Using JRuby , as opposed to MRI,
allows you to use standard Java monitoring framework and tools. Java
Management Extensions (JMX) is a standard
management and monitoring solution for Java platform. This T ip O f T he D ay
shows how to apply JMX techniques to monitor Rails/Merb applications.
The blog uses a trivial Rails/Merb application to demonstrate
monitoring but the
techniques can be applied to any Rails or Merb application.
FYI TOTD
#52 shows to create a simple Merb application and TOTD
#28 shows how to create a simple Rails scaffold.
This blog will focus on local monitoring, i.e. monitor a Rails/Merb
application
running on the same machine as monitoring tool. A subsequent blog will
demonstrate remote monitoring, i.e. monitor a Rails/Merb application
from a different machine.
There is no extra configuration required to enable monitoring if your
Rails/Merb application is running on GlassFish gem. You just need to
launch an additional tool to monitor the already running application.
jconsole
is a CLI bundled with JDK and launches a graphical tool to monitor and
manage Java applications on a local or remote machine. jconsole can be
used to monitor local application (those running on the same systems as
jconsole) and remote applications (systems other than running
jconsole).
Invoke "jconsole" in a shell as:
It shows the following window:
The window shows different Java process that can be managed/monitored
by jconsole. "org.jruby.Main -S glassfish" is the process corresponding
to our Rails/Merb application running using GlassFish Gem. Click on
that process (6179 in this case) and click "Connect".
The jconsole
interface explains the different tabs and meaning of
information displayed on each tab. Here is a snapshot of different tabs
captured
for a trivial Rails application.
It shows heap memory usage, threads, classes loaded, and CPU usage over
a period of time. The "Memory" tab tracks different GC
pools and shows their dynamic growth. Clicking on "Perform
GC" on top-right corner performs a garbage collection (more on this
later).
The "Threads" tab shows the highest number of threads since JVM started
and current number of live daemon and non-daemon threads. Clicking on a
particular thread shows it's current state and stack trace if it's
waiting.
MBeans tab shows different managed beans registered with the platform
MBean server, i.e. MBean server available in the JDK. As you can see
there are several standard MBeans displayed on the left-hand side from
java.lang and java.util.logging domains.
JRuby runtime also exposes 4 different MBeans - ClassCache, Config,
JITCompiler and ParserStats - all in "org.jruby" domain.
Clicking on
each MBean shows detailed information collected by that MBean as shown
below:
Clicking on "Attributes" node shows the current snapshot of all the
attributes exposed by the MBean as shown below:
Clicking on "Refresh" button will read the fresh values from the MBean.
Some MBeans expose functions as well. Such MBeans have "Operations"
node and clicking on them show the functions exposed as shown below:
These functions can be invoked by clicking on the button in right-hand
panel.
These snapshots are captured without even a single invocation of the
application. Accessing "https://localhost:3000/" in a browser updates
heap usage screenshot as shown below:
And permgen is increased because new classes are JITed by JRuby as
shown below:
After a Garbage Collection is performed (by clicking on "Perform GC"
button in "Memory" tab), the updated screenshot looks like:
As the snapshot indicates the "Heap Memory Usage" is back to normal
(which indicates no memory leak) and there is a spike in "CPU Usage"
because CPU cycles are used to perform GC.
Monitoring a Merb application is no different at all. The "Overview"
tab for a trivial Merb app looks like:
The wide range of JMX-compatible
tools is another advantage of using JRuby over MRI :)
Some other alternatives are using a combination of jps
and jstat.
The JMX
Home Page provides all details about JMX framework.
Subsequent blogs in this series will discuss:
How to remotely manage your Rails/Merb applications using
JMX API ?
How to publish your own metrics that can be managed using
JMX API ?
How to use VisualVM to get more information about the
underlying VM ?
How to use NewRelic/FiveRuns to manage/monitor an
application ?
How do you monitor your Rails or Merb applications ?
Please leave suggestions on other TOTD (Tip Of The Day) that
you'd like to see.
A complete archive of all tips is available here .
Technorati: totd
glassfish
jruby
rubyonrails
merb
jmx
manage
monitor
TOTD #60: Configure MySQL 6.0.x-alpha to NetBeans 6.5
Posted by arungupta on January 07, 2009 at 09:16 AM | Permalink
| Comments (0)
This T ip O f T he D ay answers the
following comment
on my blog:
How to Configure a MySql database to be able to connect Netbeans6.5.?
I've tried using mysql Server 6 many times, but it fails. Please, let me know how to fix that problem.
Download MySQL 6.0 from here .
Install and start MySQL 6.0 on Mac OSX using the clearly
written installation
instructions .
Basically the download is available in .tar or .dmg
format. Using .dmg format is the easiest way, double-click and follow
the instructions taking all defaults.
MySQL is installed in
"/usr/local/mysql-6.0.8-alpha-osx10.5-x86_64" and the soft link is
adjusted so that its available from "/usr/local/mysql". The directory
structure looks like:
lrwxr-xr-x 1 root wheel 32 Jan 5 14:00 mysql -> mysql-6.0.8-alpha-osx10.5-x86_64 drwxr-xr-x 3 root wheel 102 Jan 5 14:00 mysql-5.0.45-osx10.4-i686 drwxr-xr-x 17 root wheel 578 Nov 3 21:02 mysql-6.0.8-alpha-osx10.5-x86_64
Start MySQL server as: "sudo mysqld_safe" to see the
output as:
~ >sudo mysqld_safe
090105 14:20:51 mysqld_safe Logging to
'/usr/local/mysql/data/dhcp-usca14-133-38.SFBay.Sun.COM.err'.
090105 14:20:52 mysqld_safe Starting mysqld daemon with databases from
/usr/local/mysql/data
In NetBeans 6.5, Services tab, right-click on "Databases"
and click on "Register MySQL Server..." as shown below:
Take the default values, if your MySQL
instance is running on the default ports, as shown below:
and click on "OK". If your database is already running then NetBeans
will automatically connect with the database. If the database is not
running then start it as explained above, right-click on the newly
added database as shown below:
and the default databases are then shown as:
More details about configuring MySQL in NetBeans 6.5 are explained in
the official
documentation .
Please leave suggestions on other TOTD (T ip O f T he D ay) that
you'd like to see.
An archive of all the tips is available here .
Technorati: totd
netbeans
mysql
TOTD # 59: Alternative JSF implementations on GlassFish - MyFaces and Tomahawk
Posted by arungupta on December 11, 2008 at 09:10 AM | Permalink
| Comments (0)
GlassFish comes
bundled with an industry grade implementation of Java Server Faces
codenamed Mojarra .
It is the
most complete, up-to-date and well-tested JSF implementation
and used pretty
extensively . GlassFish v2 and v3 Prelude ships with JSF
1.2.x-compliant implementation that is defined as part of Java EE 5.
GlassFish v3 trunk contains JSF 2.0-compliant implementation that is
getting defined as part of Java EE 6. The latest version of Mojarra can
be installed from the Update
Center .
But GlassFish does not restrict
you to Mojarra
and instead it embraces other JSF implementations easily. This blog
uses MyFaces ,
an alternate JavaServer Faces implementation from Apache, to
demonstrate
that. If you are interested in a brief summary of what it takes to use
these alternate implementations on GlassFish then scroll to the end of
this entry.
MyFaces also provides several component
libraries such as Tomahawk, Trinidad, and Tobago for building web
applications. This blog
shows how MyFaces
Tomahawk samples
can be deployed on GlassFish v2 and v3. The basic integration hooks
between GlassFish and other JSF implementations remain the same and are
independent of the component library.
Lets get started and understand all the glory!
Download MyFaces Tomahawk samples from here .
The download consists of 4 WAR files and they are unzipeed in the
current
directory. So create a new directory and then unzip the bundle if you
want to organize it slightly better. The getting
Started instructions require you to copy "simple.war" where
as
the actual WAR filename is "myfaces-example-simple-1.1.8.war". Anyway,
we are going to deploy this sample on GlassFish v2, v3 Prelude, and v3
trunk and what needs to be done to use the MyFaces implementation
bundled within the WAR.
Deploy using Mojarra on GlassFish v2
Deploying "myfaces-example-simple-1.1.8.war" on GlassFish
v2 using "asadmin deploy myfaces-example-simple-1.1.8.war" and it shows
the following message:
[#|2008-12-05T11:00:43.710-0800|INFO|sun-appserver9.1|javax.enterprise.system.tools.deployment|_ThreadID=22;_ThreadName=Thread-43;|
deployed with moduleid = myfaces-example-simple-1.1.8|#]
[#|2008-12-05T11:00:44.296-0800|INFO|sun-appserver9.1|javax.enterprise.resource.webcontainer.jsf.config|_ThreadID=21;
_ThreadName=httpWorkerThread-4848-1;/myfaces-example-simple-1.1.8;|Initializing Sun's JavaServer
Faces implementation (1.2_04-b20-p03) for context
'/myfaces-example-simple-1.1.8'|#]
The
bold text indicates that Mojarra 1.2 bundled with GlassFish v2 is used
as the JSF runtime, the exact version is shown in the bold text. The
deployed web application is accessible at
"https://localhost:8080/myfaces-example-simple-1.1.8/home.jsf" and looks
like:
The following error message is shown as you click through the samples:
[#|2008-12-03T16:27:43.935-0800|INFO|sun-appserver9.1|javax.enterprise.system.stream.out|_ThreadID=24;_ThreadName=httpSSLWorkerThread-8080-1;|
2008-12-03
16:27:43,935 [httpSSLWorkerThread-8080-1] INFO
org.apache.myfaces.shared_tomahawk.config.MyfacesConfig - Starting up
Tomahawk on the MyFaces-JSF-Implementation
|#]
[#|2008-12-03T16:27:43.935-0800|INFO|sun-appserver9.1|javax.enterprise.system.stream.out|_ThreadID=24;_ThreadName=httpSSLWorkerThread-8080-1;|
2008-12-03
16:27:43,935 [httpSSLWorkerThread-8080-1] ERROR
org.apache.myfaces.shared_tomahawk.config.MyfacesConfig - Both MyFaces
and the RI are on your classpath. Please make sure to use only one of
the two JSF-implementations.
This error message is generated by MyFaces and may be ignored. I think
the message should be a WARNING instead of an ERROR.
Deploy using MyFaces on GlassFish v2
Create a directory "simple" and unjar
"myfaces-example-simple-1.1.8.war" in there.
Add "WEB-INF/sun-web.xml" and specify the contents as:
<?xml version="1.0"
encoding="UTF-8"?>
<!DOCTYPE
sun-web-app PUBLIC "-//Sun Microsystems, Inc.//DTD Application Server
8.1 Servlet 2.4//EN"
"https://www.sun.com/software/appserver/dtds/sun-web-app_2_4-1.dtd">
<sun-web-app>
<class-loader delegate="false"/>
<property
name="useMyFaces" value="true"/>
</sun-web-app>
The
key point to notice is the property name "useMyFaces". The name is
slightly mis-leading because the switch essentially tells GlassFish
runtime to use the bundled Java Server Faces runtime and is not
restricted to MyFaces only. This is fixed in GlassFish v3 and is
discussed later.
Create a WAR file in "simple" directory as "jar cvf
myfaces-simple-v2.war *".
Deploy the generated WAR on GlassFish v2 as "asadmin
deploy myfaces-simple-v2.war". It shows the following message:
. . .
[#|2008-12-05T11:11:25.615-0800|INFO|sun-appserver9.1|javax.enterprise.system.tools.deployment|_ThreadID=24;_ThreadName=Thread-257;|
deployed with moduleid = myfaces-simple-v2|#]
[#|2008-12-05T11:11:26.266-0800|INFO|sun-appserver9.1|javax.enterprise.system.stream.out|_ThreadID=21;_ThreadName=httpWorkerThread-4848-1;|
2008-12-05 11:11:26,266 [httpWorkerThread-4848-1] INFO org.apache.myfaces.config.FacesConfigurator
- Reading standard config
org/apache/myfaces/resource/standard-faces-config.xml
|#]
[#|2008-12-05T11:11:26.290-0800|INFO|sun-appserver9.1|javax.enterprise.system.stream.out|_ThreadID=21;_ThreadName=httpWorkerThread-4848-1;|
2008-12-05 11:11:26,290 [httpWorkerThread-4848-1] INFO
org.apache.myfaces.config.FacesConfigurator - Reading config
jar:file:/Users/arungupta/tools/glassfish/v2/ur2/glassfish/domains/domain1/applications/j2ee-modules/myfaces-simple-v2/WEB-INF/lib/tomahawk-1.1.8.jar!/
META-INF/faces-config.xml
|#]
[#|2008-12-05T11:11:26.309-0800|INFO|sun-appserver9.1|javax.enterprise.system.stream.out|_ThreadID=21;_ThreadName=httpWorkerThread-4848-1;|2008-12-05
11:11:26,308 [httpWorkerThread-4848-1] INFO
org.apache.myfaces.config.FacesConfigurator - Reading config
/WEB-INF/examples-config.xml
|#]
[#|2008-12-05T11:11:26.337-0800|INFO|sun-appserver9.1|javax.enterprise.system.stream.out|_ThreadID=21;_ThreadName=httpWorkerThread-4848-1;|2008-12-05
11:11:26,337 [httpWorkerThread-4848-1] INFO
org.apache.myfaces.config.FacesConfigurator - Reading config
/WEB-INF/testSuite-config.xml
|#]
[#|2008-12-05T11:11:26.349-0800|INFO|sun-appserver9.1|javax.enterprise.system.stream.out|_ThreadID=21;_ThreadName=httpWorkerThread-4848-1;|2008-12-05
11:11:26,349 [httpWorkerThread-4848-1] INFO
org.apache.myfaces.config.FacesConfigurator - Starting up MyFaces-package :
myfaces-api in version : 1.1.6
from path :
file:/Users/arungupta/tools/glassfish/v2/ur2/glassfish/domains/domain1/applications/j2ee-modules/myfaces-simple-v2/WEB-INF/lib/myfaces-api-1.1.6.jar
|#]
[#|2008-12-05T11:11:26.350-0800|INFO|sun-appserver9.1|javax.enterprise.system.stream.out|_ThreadID=21;_ThreadName=httpWorkerThread-4848-1;|2008-12-05
11:11:26,350 [httpWorkerThread-4848-1] INFO
org.apache.myfaces.config.FacesConfigurator - Starting up MyFaces-package :
myfaces-impl in version : 1.1.6
from path :
file:/Users/arungupta/tools/glassfish/v2/ur2/glassfish/domains/domain1/applications/j2ee-modules/myfaces-simple-v2/WEB-INF/lib/myfaces-impl-1.1.6.jar
|#]
[#|2008-12-05T11:11:26.350-0800|INFO|sun-appserver9.1|javax.enterprise.system.stream.out|_ThreadID=21;_ThreadName=httpWorkerThread-4848-1;|2008-12-05
11:11:26,350 [httpWorkerThread-4848-1] INFO
org.apache.myfaces.config.FacesConfigurator - MyFaces-package :
tomahawk-sandbox not found.
|#]
[#|2008-12-05T11:11:26.350-0800|INFO|sun-appserver9.1|javax.enterprise.system.stream.out|_ThreadID=21;_ThreadName=httpWorkerThread-4848-1;|2008-12-05
11:11:26,350 [httpWorkerThread-4848-1] INFO
org.apache.myfaces.config.FacesConfigurator - Starting up MyFaces-package :
tomahawk in version : 1.1.8
from path :
file:/Users/arungupta/tools/glassfish/v2/ur2/glassfish/domains/domain1/applications/j2ee-modules/myfaces-simple-v2/WEB-INF/lib/tomahawk-1.1.8.jar
|#]
. . .
[#|2008-12-05T11:11:27.069-0800|INFO|sun-appserver9.1|javax.enterprise.system.stream.out|_ThreadID=21;_ThreadName=httpWorkerThread-4848-1;|2008-12-05
11:11:27,069 [httpWorkerThread-4848-1] INFO
org.apache.myfaces.shared_impl.config.MyfacesConfig - Starting up Tomahawk on the
RI-JSF-Implementation .
|#]
[#|2008-12-05T11:11:27.069-0800|INFO|sun-appserver9.1|javax.enterprise.system.stream.out|_ThreadID=21;_ThreadName=httpWorkerThread-4848-1;|2008-12-05
11:11:27,069 [httpWorkerThread-4848-1] INFO
org.apache.myfaces.shared_impl.config.MyfacesConfig - Starting up Tomahawk on the
MyFaces-JSF-Implementation
|#]
[#|2008-12-05T11:11:27.070-0800|INFO|sun-appserver9.1|javax.enterprise.system.stream.out|_ThreadID=21;_ThreadName=httpWorkerThread-4848-1;|2008-12-05
11:11:27,070 [httpWorkerThread-4848-1] ERROR
org.apache.myfaces.shared_impl.config.MyfacesConfig - Both MyFaces and
the RI are on your classpath. Please make sure to use only one of the
two JSF-implementations.
|#]
[#|2008-12-05T11:11:27.070-0800|INFO|sun-appserver9.1|javax.enterprise.system.stream.out|_ThreadID=21;_ThreadName=httpWorkerThread-4848-1;|2008-12-05
11:11:27,070 [httpWorkerThread-4848-1] INFO
org.apache.myfaces.webapp.StartupServletContextListener - ServletContext
'/Users/arungupta/tools/glassfish/v2/ur2/glassfish/domains/domain1/applications/j2ee-modules/myfaces-simple-v2/'
initialized.
|#]
The first
thing to note is that the message "Initializing Sun's JavaServer Faces
implementation (1.2_04-b20-p03)" is not shown. That indicates Mojarra
is not used as the JSF runtime. Then you can see how MyFaces 1.1.6 API
and Implementation are loaded, Tomahaw 1.1.8 is loaded and finally
started using MyFaces JSF implementation.
The main page from this deployed application at
"https://localhost:8080/myfaces-simple-v2" is very similar as shown
below:
Deploy using Mojarra on GlassFish v3 Prelude - This is very
similar experience as with GlassFish v2.
Deploying "myfaces-example-simple-1.1.8.war" on GlassFish
v3 shows the following message:
Dec 5, 2008 11:27:17 AM
com.sun.faces.config.ConfigureListener contextInitialized
INFO: Initializing
Mojarra (1.2_10-b01-FCS) for context '/myfaces-example-simple-1.1.8'
Dec 5, 2008 11:27:18 AM com.sun.enterprise.web.WebApplication start
INFO: Loading application myfaces-example-simple-1.1.8 at
/myfaces-example-simple-1.1.8
Dec 5, 2008 11:27:18 AM org.glassfish.deployment.admin.DeployCommand
execute
INFO: Deployment of
myfaces-example-simple-1.1.8 done is 3470 ms
The
bold text clearly indicates that Mojarra 1.2 bundled, exact version
shown in the bold text, with GlassFish v3 is used as
the JSF runtime. The deployed web application is accessible at
"https://localhost:8080/myfaces-example-simple-1.1.8/home.jsf". Viewing
the sample in browser shows:
Dec 5, 2008 11:54:54 AM
INFO: 2008-12-05 11:54:54,083 [httpWorkerThread-8080-0] INFO
org.apache.myfaces.shared_tomahawk.config.MyfacesConfig - Starting up
Tomahawk on the RI-JSF-Implementation.
Dec 5, 2008 11:54:54 AM
INFO: 2008-12-05 11:54:54,083 [httpWorkerThread-8080-0] INFO
org.apache.myfaces.shared_tomahawk.config.MyfacesConfig - Starting up
Tomahawk on the MyFaces-JSF-Implementation
Dec 5, 2008 11:54:54 AM
INFO: 2008-12-05 11:54:54,083 [httpWorkerThread-8080-0] ERROR
org.apache.myfaces.shared_tomahawk.config.MyfacesConfig - Both MyFaces
and the RI are on your classpath. Please make sure to use only one of
the two JSF-implementations.
and may be ignored. None of the messages that indicate classloading, as
shown for GlassFish v2 above, are displayed. I suspect these are
standard messages displayed by MyFaces without taking into
consideration that an alternate JSF runtime can be used to run these
samples.
Deploy using MyFaces on GlassFish v3 Prelude - There is no
way to override JSF implementation with GlassFish v3 Prelude. So even
though deploying "myfaces-simple-v2.war" will work fine but viewing the
web page at "https://localhost:8080/myfaces-simple-v2/" will show the
following exception:
Basically, a web application cannot use MyFaces implementation on
GlassFish v3 Prelude. However Mojarra provides a fully-compliant and
feature-rich JSF implementation and is already baked in GlassFish v3
Prelude.
Deploy using Mojarra on GlassFish v3 Trunk
Pick your GlassFish
v3 Build Flavor , this blog uses the trunk.
Deploy the original sample as "asadmin deploy
myfaces-example-simple-1.1.8.war" and the following log messages are
shown:
Dec 5, 2008 12:35:17 PM
com.sun.faces.config.ConfigureListener contextInitialized
INFO: Initializing
Mojarra 2.0.0 (SNAPSHOT b05) for context '/myfaces-example-simple-1.1.8'
Dec 5, 2008 12:35:18 PM org.apache.catalina.core.ApplicationContext log
SEVERE: WebModule[/myfaces-example-simple-1.1.8]PWC1275: Exception
sending context initialized event to listener instance of class
com.sun.faces.config.ConfigureListener
java.lang.NoClassDefFoundError:
com/sun/facelets/tag/jsf/ComponentHandler
at java.lang.ClassLoader.defineClass1(Native Method)
at java.lang.ClassLoader.defineClass(ClassLoader.java:675)
at
java.security.SecureClassLoader.defineClass(SecureClassLoader.java:124)
at
org.glassfish.web.loader.WebappClassLoader.findClass(WebappClassLoader.java:974)
This happens because the application has dependencies on internal
classes of Facelets 1.1.x. That makes the application non-compatible
with Mojarra 2.x which comes bundled with Facelets 2.0.
Lets instruct the application to disable the Facelets 2.0
baked in Mojarra by adding the following application wide context
parameter in "web.xml":
<context-param>
<param-name>javax.faces.DISABLE_FACELET_JSF_VIEWHANDLER</param-name>
<param-value>true</param-value>
</context-param>
Now the Facelets 1.1.x classes bundled with the application are used.
With this change, the application gets deployed correctly and shows the
following log message:
Dec 5, 2008 2:50:21 PM
com.sun.faces.config.ConfigureListener contextInitialized
INFO:
Initializing Mojarra 2.0.0 (SNAPSHOT b05) for context
'/myfaces-simple-v3'
Dec 5, 2008 2:50:21 PM com.sun.enterprise.web.WebApplication start
INFO: Loading application myfaces-simple-v3 at /myfaces-simple-v3
Dec 5, 2008 2:50:21 PM org.glassfish.deployment.admin.DeployCommand
execute
INFO: Deployment of
myfaces-simple-v3 done is 1513 ms
The important thing to note here is that Mojarra 2.0.0 implementation
(as indicated by the bold text) is used as JSF runtime. This is the
newest and the greatest runtime that implements JSF
2.0 specification and baked in GlassFish v3 trunk. The main
page from this deployed application at
"https://localhost:8080/myfaces-simple-v3/" looks like:
Deploy using MyFaces on GlassFish v3 Trunk
Download the latest GlassFish
v3 Nightly .
Lets deploy the WAR file previously created as "asadmin
deploy myfaces-simple-v2.war". The main page of the application is
accessible at "https://localhost:8080/myfaces-simple-v2".
The "useMyFaces" property, as specified in
"sun-web.xml", is expected to work for any
bundled JSF implementation. The recommended way to deploy such a web
application in GlassFish v3 is to use the property "useBundledJsf". The
updated "sun-web.xml" is shown below:
<?xml version="1.0"
encoding="UTF-8"?>
<!DOCTYPE
sun-web-app PUBLIC "-//Sun Microsystems, Inc.//DTD Application Server
8.1 Servlet 2.4//EN"
"https://www.sun.com/software/appserver/dtds/sun-web-app_2_4-1.dtd">
<sun-web-app>
<class-loader delegate="false"/>
<property
name="useBundledJsf" value="true"/>
</sun-web-app>
Create a WAR file in "simple" directory as "jar cvf
myfaces-simple-v3-usebundled.war *".
Deploy the generated WAR on GlassFish v3 as "asadmin
deploy myfaces-simple-v3-usebundled.war". It shows the following
message:
. . .
Dec 5, 2008 3:19:54 PM
INFO: 2008-12-05 15:19:54,786 [httpWorkerThread-4848-1] INFO org.apache.myfaces.config.FacesConfigurator
- Reading config
jar:file:/Users/arungupta/tools/glassfish/v3/snapshot/glassfish/domains/domain1/applications/myfaces-simple-v3-usebundled/WEB-INF/lib/tomahawk-1.1.8.jar!/
META-INF/faces-config.xml
Dec 5, 2008 3:19:54 PM
INFO: 2008-12-05 15:19:54,806 [httpWorkerThread-4848-1] INFO
org.apache.myfaces.config.FacesConfigurator - Reading config
/WEB-INF/examples-config.xml
Dec 5, 2008 3:19:54 PM
INFO: 2008-12-05 15:19:54,828 [httpWorkerThread-4848-1] INFO
org.apache.myfaces.config.FacesConfigurator - Reading config
/WEB-INF/testSuite-config.xml
Dec 5, 2008 3:19:54 PM
INFO: 2008-12-05 15:19:54,841 [httpWorkerThread-4848-1] INFO
org.apache.myfaces.config.FacesConfigurator - Starting up MyFaces-package :
myfaces-api in version : 1.1.6
from path :
file:/Users/arungupta/tools/glassfish/v3/snapshot/glassfish/domains/domain1/applications/myfaces-simple-v3-usebundled/WEB-INF/lib/myfaces-api-1.1.6.jar
Dec 5, 2008 3:19:54 PM
INFO: 2008-12-05 15:19:54,841 [httpWorkerThread-4848-1] INFO
org.apache.myfaces.config.FacesConfigurator - Starting up MyFaces-package :
myfaces-impl in version : 1.1.6
from path :
file:/Users/arungupta/tools/glassfish/v3/snapshot/glassfish/domains/domain1/applications/myfaces-simple-v3-usebundled/WEB-INF/lib/myfaces-impl-1.1.6.jar
Dec 5, 2008 3:19:54 PM
INFO: 2008-12-05 15:19:54,841 [httpWorkerThread-4848-1] INFO
org.apache.myfaces.config.FacesConfigurator - MyFaces-package :
tomahawk-sandbox not found.
Dec 5, 2008 3:19:54 PM
INFO: 2008-12-05 15:19:54,841 [httpWorkerThread-4848-1] INFO
org.apache.myfaces.config.FacesConfigurator - Starting up MyFaces-package :
tomahawk in version : 1.1.8
from path :
file:/Users/arungupta/tools/glassfish/v3/snapshot/glassfish/domains/domain1/applications/myfaces-simple-v3-usebundled/WEB-INF/lib/tomahawk-1.1.8.jar
. . .
Dec 5, 2008 3:19:55 PM
INFO: 2008-12-05 15:19:55,763 [httpWorkerThread-4848-1] INFO
org.apache.myfaces.shared_impl.config.MyfacesConfig - Starting up
Tomahawk on the RI-JSF-Implementation.
Dec 5, 2008 3:19:55 PM
INFO: 2008-12-05 15:19:55,764 [httpWorkerThread-4848-1] INFO
org.apache.myfaces.shared_impl.config.MyfacesConfig - Starting up
Tomahawk on the MyFaces-JSF-Implementation
Dec 5, 2008 3:19:55 PM
INFO: 2008-12-05 15:19:55,764 [httpWorkerThread-4848-1] ERROR
org.apache.myfaces.shared_impl.config.MyfacesConfig - Both MyFaces and
the RI are on your classpath. Please make sure to use only one of the
two JSF-implementations.
Dec 5, 2008 3:19:55 PM
INFO: 2008-12-05 15:19:55,764 [httpWorkerThread-4848-1] INFO org.apache.myfaces.webapp.StartupServletContextListener
- ServletContext
'/Users/arungupta/tools/glassfish/v3/snapshot/glassfish/domains/domain1/applications/myfaces-simple-v3-usebundled/'
initialized.
Dec 5, 2008 3:19:55 PM com.sun.enterprise.web.WebApplication start
INFO: Loading application myfaces-simple-v3-usebundled at
/myfaces-simple-v3-usebundled
Dec 5, 2008 3:19:55 PM org.glassfish.deployment.admin.DeployCommand
execute
INFO: Deployment of
myfaces-simple-v3-usebundled done is 1994 ms
The first
thing to note is that the message "Initializing Sun's JavaServer Faces
implementation (1.2_04-b20-p03)" is not shown. That indicates Mojarra
is not used as the JSF runtime. Then you can see how MyFaces 1.1.6 API
and Implementation are loaded, Tomahawk 1.1.8 is loaded and finally
started using MyFaces JSF implementation.
The main page from this deployed application at
"https://localhost:8080/myfaces-simple-v3-usebundled" is very similar as
shown below:
Here is a brief summary of how MyFaces/Tomahawk sample is deployed
using Mojarra and MyFaces on GlassFish:
JSF Implementations
Mojarra
MyFaces
GlassFish v2
Default
"useMyFaces"
property in "sun-web.xml"
GlassFish v3 Prelude
Default
Not
supported
GlassFish v3 Trunk
Disable
Facelets 2.0 in "web.xml"
"useMyFaces"
OR "useBundledJsf" property in "sun-web.xml"
Disable Facelets 2.0 in "web.xml" (only for Facelets 1.1.x dependencies)
The steps described above for MyFaces can be used with alternate JSF
implementations as well. Which JSF implementation do you use ?
Just
like Tomahawk components, Trinidad and Tobago libraries should
work with Mojarra as well. Have you tried them ?
Technorati: glassfish
javaserverfaces
mojarra
apache
myfaces
tomahawk
JavaFX 1.0 launched - access services hosted on embedded GlassFish
Posted by arungupta on December 04, 2008 at 07:12 AM | Permalink
| Comments (0)
Today Sun announces the availability of Java
FX 1.0 .
JavaFX 1.0 is a rich client platform for creating and delivering Rich
Internet Applications across all screens (desktop, browser,
and mobile) of your life. It consists of the following key components:
JavaFX
SDK includes JavaFX script compiler and runtime
tools, and a host of libraries to create RIAs for desktop, browser and
mobile platforms, command-line tools & Ant tasks and other
goodies.
NetBeans
6.5 support (as plugin or bundled with IDE) that allows to
build, preview and debug JavaFX applications using NetBeans IDE. If you
prefer CLI support then SDK can be downloaded.
Production
Suite is a suite of tools and plugins for creative tools
(such as Illustrator CS3+) that allows graphical assets to be
exported to JavaFX applications.
The beauty of JavaFX is that its fully integrated with the Java Runtime
and takes advantage of the performance and ubiquity of Sun's Java
Runtime Environment that is installed on literally billions of devices
worldwide. Hence, JavaFX applications will run on any desktop, browser,
mobile device or any other connected device that runs the Java Runtime
Environment.
This blog shows how to create a simple JavaFX
application using NetBeans
IDE . The application plays a movie, allows the
viewer to cast a vote if they liked it, and see aggregate response from
other viewers. The application is developed using NetBeans 6.5, JavaFX
1.0 plugin, and coded using JavaFX Script. The voting engine
is deployed as a RESTful Web service using Jersey on GlassFish .
In terms of
user experience, running the NetBeans project shows a window playing
the movie. The first mouse hover over the window allows the viewer to
click
on "I love it" or "Not so great" and cast their vote as shown below:
Any subsequent
mouse hover shows aggregated
results from other viewers as shown below:
The results are not interesting if there is a single viewer of the
movie. But for a production environment, this movie will be played by
multiple users concurrently and the percentage numbers will be more
meaningful. You can close the window and run the project again to vote
again, as many times as you like :)
For those who like to see quick results, here is a 4-step guide to get
started:
In NetBeans 6.5 IDE, install JavaFX plugin as explained here and RESTful
Web services plugin as explained here . Both the
plugins may be installed in one step by selecting the required plugins
together.
Download NetBeans project for JavaFX client from here
and add Jersey dependencies as explained in bullet #5
below.
Download Web service endpoint Maven project from here
and deploy the endpoint as explained in bullet
#4 below.
Run the JavaFX application as explained here .
The remainder of this blog explains the details and shows how to
construct the demo from scratch.
Lets first create the JavaFX application that plays the video movie.
In NetBeans
6.5, install "JavaFX SDK" plugin. In
the "Tools"
menu, "Plugins", search on "JavaFX", select "JavaFX SDK" and click on
"Install".
Create a new project of type "JavaFX", "JavaFX Script
Application". Take the default values as shown below:
and click on "Finish".
The source code for this class can be downloaded from here
or alternatively constructed as explained in the sub-bullets.
In the newly created class, change the Stage (root area
for
all scene content) to:
Stage {
title: "GlassFish Media Player"
width: 625
height: 360
resizable: false
scene:
myScene
}
Create a scene that contains the view of the media to be
played and controls the display of the Vote or Result nodes:
var myScene: Scene = Scene {
content: MediaView {
fitWidth: 625
fitHeight: 360
mediaPlayer:
bind myPlayer
onMouseEntered: function( e: MouseEvent ):Void {
println("mouse entered");
if (voted == false) {
insert Vote{} into
myScene.content;
} else {
insert
Result{}
into myScene.content;
}
}
onMouseExited: function( e: MouseEvent ):Void {
delete myScene.content[1]
}
}
}
Create a Media Player to use with the scene:
var myPlayer: MediaPlayer = MediaPlayer{
autoPlay: true
media:
bind myMedia
};
Create the media object to be used with the Media Player:
var myMedia: Media = Media {
source:
"https://sun.edgeboss.net/download/sun/media/1460825906/1460825906_2957290001_DayEarth-Bluray.flv"
};
You can change the location of the movie here in the media player. For
example, changing it to
"https://mediacast.sun.com/users/ArunGupta/media/v3prelude-nb65-webapp.flv"
will start playing the screencast
#27 .
Create a Vote class that is a CustomNode and appears when
a
user's mouse enters the scene where the video is playing. The user can
select whether he likes the clip or not and the vote is recorded
making a Web service call using Jersey
Client APIs :
class Vote extends CustomNode {
override function create():Node {
return
Group {
content: [
Rectangle {
fill: Color.GREEN
x: 185
y: 145
width: 243
height: 38
arcWidth: 20
arcHeight: 20
},
Text {
x: 195
y: 170
fill: Color.WHITE
font: Font {
size: 18
}
content: "I love it"
},
Rectangle{
x: 191
y: 148
smooth: false
width: 73
height: 32
fill: Color.TRANSPARENT
onMouseClicked: function( e: MouseEvent ):Void {
println("clicked I love it");
voted = true;
wsClient.voteLoveIt();
delete myScene.content[1]
}
},
Text{
x: 305
y: 170
fill: Color.WHITE
font: Font {
size: 18
}
content: "Not so great"
},
Rectangle {
x: 301
y: 148
smooth: false
width: 118
height: 32
fill: Color.TRANSPARENT
onMouseClicked: function( e: MouseEvent ):Void {
voted = true;
println("clicked Not so great");
wsClient.voteNotSoGreat();
delete myScene.content[1]
}
}
]
}
}
};
Create a Result class that is a CustomNode and simply
reports on how many voters like this clip:
class Result extends CustomNode {
override function create():Node {
var resultPercent =
wsClient.showResults();
var resultString =
"{resultPercent} voters liked this clip";
return
Group {
content: [
Rectangle {
fill: Color.BLUE
x: 187
y: 145
width: 244
height: 38
arcWidth: 20
arcHeight: 20
onMouseClicked: function( e: MouseEvent ):Void {
delete myScene.content[1]
}
},
Text {
x: 199
y: 170
fill: Color.WHITE
font: Font {
size: 18
}
content:
resultString
}
]
}
}
};
Add two instance variables:
var voted = false;
var wsClient = new WebserviceClient;
The first variable captures if the viewer has already voted and the
second variable is an instance to the RESTful Web service client.
Add the following import statements:
import javafx.scene.*;
import javafx.scene.input.MouseEvent;
import javafx.scene.media.Media;
import javafx.scene.media.MediaPlayer;
import javafx.scene.media.MediaView;
import javafx.scene.paint.Color;
import javafx.scene.shape.Rectangle;
import javafx.scene.text.Font;
import javafx.scene.text.Text;
import javafx.stage.Stage;
"Fix Imports" should be able to fix them and bug
#154307 is already filed for that.
Create a new class that is used to capture the Vote as:
@javax.xml.bind.annotation.XmlRootElement
public class VoteBean {
public static enum VOTE { LOVE_IT,
NOT_SO_GREAT };
public VOTE vote;
public VoteBean() { vote = VOTE.LOVE_IT;
}
public VoteBean(VOTE vote) {
this.vote = vote;
}
}
This is a simple Javabean with a standard JAXB annotation.
This ensures that XML is used as the data format for transfering
results between client and endpoint. The source code for this class is
available here .
Add
Jersey libraries to the project by right-clicking on
Project, select Libraries, click on "Add Library...", select "JAX-RS
1.0" and "Jersey 1.0 (JAX-RS RI)", and click on "Add Library".
If these libraries
are not available then install the "RESTful Web
Services" plugin from the Plugin Center.
And finally add the class that invokes the RESTful
Webservice
endpoint:
public
class WebserviceClient {
private static com.sun.jersey.api.client.WebResource
createWebResource() {
return com.sun.jersey.api.client.Client.create() .
resource("https://localhost:8080/movie-feedback-webapp/webresources/myresource");
}
public static void voteLoveIt() {
createWebResource().type("application/json").
post(new
VoteBean(VoteBean.VOTE.LOVE_IT)) ;
}
public static void voteNotSoGreat() {
createWebResource().type("application/json").
post(new
VoteBean(VoteBean.VOTE.NOT_SO_GREAT)) ;
}
public static String showResults() {
return createWebResource().get(String.class) ;
}
}
The Webservice endpoint will be hosted at
"https://localhost:8080/movie-feedback-webapp/webresources/myresource".
A WebResource is created from the Client. The POST methods are used to
cast the user vote and GET method is used to retrieve the aggregated
results. The source code for this class is available here .
Now lets create the RESTful endpoint using Jersey and deploy on
GlassFish.
Create and deploy a RESTful Web service endpoint
Create a template RESTful Web service endpoint as
described in TOTD
#56 . Lets use the artifactId as "movie-feedback-webapp".
Create the bean "VoteBean" in "org.glassfish.samples"
package. This is the exactly same bean used earlier by the client:
@javax.xml.bind.annotation.XmlRootElement
public class VoteBean {
public static enum VOTE { LOVE_IT,
NOT_SO_GREAT };
public VOTE vote;
public VoteBean() { vote = VOTE.LOVE_IT;
}
public VoteBean(VOTE vote) {
this.vote = vote;
}
}
Update the generated resource
Add @com.sun.jersey.spi.resource.Singleton
as class annotation so that only one instance of the resource is
created for the entire web
application. This allows to save state (preferences from other users)
in the RESTful resource.
Add two instance variables:
int loveIt;
int noSoGreat;
Add a method that will process HTTP POST requests as:
@POST
public void postOneVote(VoteBean bean) {
if (bean.vote == VoteBean.VOTE.LOVE_IT) {
loveIt++;
} else {
noSoGreat++;
}
System.out.println("In POST: " + bean.vote);
}
This method stores the vote in the resource. The handling of POST
request messages by Jersey is explained in TOTD
#58 .
Add a method that will process HTTP GET requests as:
@GET
@Produces("text/plain")
public String getOpinion() {
if (loveIt == 0 && noSoGreat == 0)
return "No votes cast yet!";
return (loveIt * 100) / (loveIt + noSoGreat) + "%";
}
This method calculates the percentage of viewers who liked the movie.
Deploy the
endpoint using "mvn glassfish:run" in
"movie-feedback-webapp" directory.
Now run the JavaFX application by
right-clicking on the project and
selecting "Run Project" and start voting! The percentage
results will vary if the movie is voted upon more than once.
This blog showed:
How to install JavaFX capabilities to an existing NetBeans
6.5 installation
How to create a simple JavaFX application that plays media
files
Integrate it with existing Java libraries (Jersey client
libraries in this case)
Invoke services hosted on GlassFish
The steps followed in this blog allows for rapid development/debugging
of JavaFX application accessing resources using embeddable GlassFish
but are not ideal for production deployments. A future
blog will show how this JavaFX application can be deployed as a Java
Web Start application and scaled for mulitple users.
The javafx.com/samples
has loads of samples and javafx.com/tutorials
shows how to build your own applications. The JavaFX
Community Wiki is a great place to collaborate.
Send your Jersey questions to users@jersey.dev.java.net ,
GlassFish questions to GlassFish
Forum , and JavaFX questions to JavaFX
Forums .
Technorati:
glassfish
v3
jersey
webservices
javafx
LOTD #15: Deploying Merb application on GlassFish v3 using Warbler
Posted by arungupta on December 03, 2008 at 09:15 AM | Permalink
| Comments (1)
GlassFish
v3 with Merb and Warbler explains how to use Warbler to
deploy a Merb application on GlassFish
v3 . Here is a quote from the blog:
this lovely server had a
gem which you can use to fire up a Glassfish server. Easy as pie and
within no time at all we were developing our Merb app on Glassfish.
The blog requires some workaround for Warbler and Nick is
planning to fix them in the next rev. And other workaround is required
because of Webrat 's
recently introduced dependency on Nokogiri
which does not run on JRuby yet.
In addition, TOTD
#52 explains how to deploy a Merb application using GlassFish
gem and TOTD
#53 explains how to create a scaffold in Merb.
Submit your Merb/GlassFish bugs here ,
talk to us using GlassFish
Forum , and get the latest information on JRuby
wiki .
All previous entries in this series are archived at LOTD .
Technorati: lotd
glassfish
v3 gem warbler merb
TOTD #58: Jersey and GlassFish - how to process POST requests ?
Posted by arungupta on December 01, 2008 at 06:30 AM | Permalink
| Comments (0)
Lets extend the Jersey endpoint (TOTD#
56 ) and client (TOTD#
57 ) such that it can accept a POST request and then invoke it.
Add a new method to "MyResource.java" from TOTD#
56 as:
@POST
@Consumes("application/json")
@Produces("application/json")
public Greeting postIt(Greeting
greeting) {
System.out.println("In POST: " + greeting.greeting);
return greeting;
}
The first line indicates that the Java method will process HTTP POST
requests. The second and third line shows that the method consumes and
produces JSON data format.
Add a new method to "AppTest.java" from TOTD#
57 as:
public void
testPost() {
Greeting result = createResource().
type("application/json").
post(Greeting.class, new Greeting("yo!"));
assertTrue(result.greeting.equals("yo!"));
}
The main difference from the "testApp()" method is specifying the MIME
type of the generated outbound request as "application/json".
Running the test as "mvn test" shows the following output:
Running org.glassfish.samples.AppTest
1 * Out-bound request
1 > GET
https://localhost:8080/helloworld-webapp/webresources/myresource
1 >
1 < 200
1 < X-Powered-By: Servlet/2.5
1 < Transfer-Encoding: chunked
1 < Content-Type:
text/plain
1 < Server: GlassFish/v3
1 < Date: Tue, 25 Nov 2008 20:19:34 GMT
1 <
<?xml
version="1.0" encoding="UTF-8"
standalone="yes"?><greeting><greeting>Hi
there!</greeting></greeting>
1 * In-bound response
1 * Out-bound request
1 > POST
https://localhost:8080/helloworld-webapp/webresources/myresource
1 > Content-Type:
application/json
1 >
{"greeting":"yo!"}
1 < 200
1 < X-Powered-By: Servlet/2.5
1 < Transfer-Encoding: chunked
1 < Content-Type:
application/json
1 < Server: GlassFish/v3
1 < Date: Tue, 25 Nov 2008 20:19:34 GMT
1 <
{"greeting":"yo!"}
1 * In-bound response
Tests run: 2, Failures: 0, Errors: 0, Skipped: 0, Time elapsed: 1.191
sec
The output shows request/response messages when both the tests are run
together. Here are some highlights:
"GET" and "POST" methods are clearly highlighted.
The two "Content-Type" headers with value "text/plain"
and "application/json" are output from two tests. The output
from POST method has two Content-Type headers, one for outbound request
and another one for inbound response.
The body content of POST method is using JSON format.
Jersey and GlassFish
provides a complete server-side and client-side API and framework for
deploying and invoking RESTful Web service endpoints.
How are you using Jersey ?
Send all your questions to users@jersey.dev.java.net .
Please leave suggestions on other TOTD (T ip O f T he D ay) that
you'd like to see.
An archive of all the tips is available here .
Technorati: totd
glassfish
v3 embeddable
jersey
jsr311
rest json webservices
February 2009
Sun
Mon
Tue
Wed
Thu
Fri
Sat
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
Search this blog:
Categories
Community
Community: Glassfish
Community: Java Tools
Community: Java User Groups
Community: Java Web Services and XML
Community: NetBeans
Eclipse
J2EE
J2SE
JavaOne
JSR
Open Source
Tools
Web Applications
Web Services and XML
Archives
February 2009
January 2009
December 2008
November 2008
October 2008
September 2008
August 2008
July 2008
June 2008
May 2008
April 2008
March 2008
February 2008
January 2008
December 2007
November 2007
October 2007
September 2007
August 2007
July 2007
June 2007
May 2007
April 2007
March 2007
February 2007
January 2007
December 2006
November 2006
October 2006
September 2006
August 2006
July 2006
June 2006
May 2006
April 2006
March 2006
February 2006
December 2005
November 2005
October 2005
September 2005
August 2005
July 2005
June 2005
May 2005
April 2005
Recent Entries
GlassFish setup for 120 programmers in University of Copenhagen
Sun Tech Days Hyderabad 2009
TOTD #69: GlassFish High Availability/Clustering using Sun Web Server + Load Balancer Plugin on Windows Vista