Arun Gupta is a Technology Evangelist for Web Services and Web 2.0 Apps 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.
This blog has published good
amount of content on how Ruby-on-Rails
applications can be deployed on GlassFish.
Grails is another
popular MVC-based framework that leverages the Groovy
language. Basically, Grails : Groovy :: Rails : Ruby.
Starting today, I plan to start publishing content on Grails and talk
about how GlassFish
v3 is turning out to be a home for several scripting
languages - Ruby/JRuby/Rails, JavaScript/Phobos,
Groovy/Grails and more to be added.
This blog shows how to get started with Grails and deploy a simple
application on GlassFish v3. Lets go!
Welcome to Grails 1.0.2 - https://grails.org/
Licensed under Apache Standard License 2.0
Grails home is set to: /Users/arungupta/testbed/grails-1.0.2
Base Directory: /Users/arungupta/testbed/grails-1.0.2/samples
Note: No plugin scripts found
Running script
/Users/arungupta/testbed/grails-1.0.2/scripts/CreateApp.groovy
Environment set to development
[mkdir] Created dir:
/Users/arungupta/testbed/grails-1.0.2/samples/helloworld/src
[mkdir] Created dir:
/Users/arungupta/testbed/grails-1.0.2/samples/helloworld/src/java
[mkdir] Created dir:
/Users/arungupta/testbed/grails-1.0.2/samples/helloworld/src/groovy
[mkdir] Created dir:
/Users/arungupta/testbed/grails-1.0.2/samples/helloworld/grails-app
[mkdir] Created dir:
/Users/arungupta/testbed/grails-1.0.2/samples/helloworld/grails-app/controllers
[mkdir] Created dir:
/Users/arungupta/testbed/grails-1.0.2/samples/helloworld/grails-app/services
[mkdir] Created dir:
/Users/arungupta/testbed/grails-1.0.2/samples/helloworld/grails-app/domain
[mkdir] Created dir:
/Users/arungupta/testbed/grails-1.0.2/samples/helloworld/grails-app/taglib
[mkdir] Created dir:
/Users/arungupta/testbed/grails-1.0.2/samples/helloworld/grails-app/utils
[mkdir] Created dir:
/Users/arungupta/testbed/grails-1.0.2/samples/helloworld/grails-app/views
[mkdir] Created dir:
/Users/arungupta/testbed/grails-1.0.2/samples/helloworld/grails-app/views/layouts
[mkdir] Created dir:
/Users/arungupta/testbed/grails-1.0.2/samples/helloworld/grails-app/i18n
[mkdir] Created dir:
/Users/arungupta/testbed/grails-1.0.2/samples/helloworld/grails-app/conf
[mkdir] Created dir:
/Users/arungupta/testbed/grails-1.0.2/samples/helloworld/test
[mkdir] Created dir:
/Users/arungupta/testbed/grails-1.0.2/samples/helloworld/test/unit
[mkdir] Created dir:
/Users/arungupta/testbed/grails-1.0.2/samples/helloworld/test/integration
[mkdir] Created dir:
/Users/arungupta/testbed/grails-1.0.2/samples/helloworld/scripts
[mkdir] Created dir:
/Users/arungupta/testbed/grails-1.0.2/samples/helloworld/web-app
[mkdir] Created dir:
/Users/arungupta/testbed/grails-1.0.2/samples/helloworld/web-app/js
[mkdir] Created dir:
/Users/arungupta/testbed/grails-1.0.2/samples/helloworld/web-app/css
[mkdir] Created dir:
/Users/arungupta/testbed/grails-1.0.2/samples/helloworld/web-app/images
[mkdir] Created dir:
/Users/arungupta/testbed/grails-1.0.2/samples/helloworld/web-app/META-INF
[mkdir] Created dir:
/Users/arungupta/testbed/grails-1.0.2/samples/helloworld/lib
[mkdir] Created dir:
/Users/arungupta/testbed/grails-1.0.2/samples/helloworld/grails-app/conf/spring
[mkdir] Created dir:
/Users/arungupta/testbed/grails-1.0.2/samples/helloworld/grails-app/conf/hibernate
[propertyfile] Creating new property file:
/Users/arungupta/testbed/grails-1.0.2/samples/helloworld/application.properties
[copy] Copying 2 files to
/Users/arungupta/testbed/grails-1.0.2/samples/helloworld
[copy] Copying 2 files to
/Users/arungupta/testbed/grails-1.0.2/samples/helloworld/web-app/WEB-INF
[copy] Copying 5 files to
/Users/arungupta/testbed/grails-1.0.2/samples/helloworld/web-app/WEB-INF/tld
[copy] Copying 87 files to
/Users/arungupta/testbed/grails-1.0.2/samples/helloworld/web-app
[copy] Copying 17 files to
/Users/arungupta/testbed/grails-1.0.2/samples/helloworld/grails-app
[copy] Copying 1 file to
/Users/arungupta/testbed/grails-1.0.2/samples/helloworld
[copy] Copying 1 file to
/Users/arungupta/testbed/grails-1.0.2/samples/helloworld
[copy] Copying 1 file to
/Users/arungupta/testbed/grails-1.0.2/samples/helloworld
[propertyfile] Updating property file:
/Users/arungupta/testbed/grails-1.0.2/samples/helloworld/application.properties
Created Grails Application at
/Users/arungupta/testbed/grails-1.0.2/samples/helloworld
Welcome to Grails 1.0.2 - https://grails.org/
Licensed under Apache Standard License 2.0
Grails home is set to: /Users/arungupta/testbed/grails-1.0.2
Base Directory: /Users/arungupta/testbed/grails-1.0.2/samples/helloworld
Note: No plugin scripts found
Running script
/Users/arungupta/testbed/grails-1.0.2/scripts/RunApp.groovy
Environment set to development
[mkdir] Created dir:
/Users/arungupta/.grails/1.0.2/projects/helloworld/classes
[groovyc] Compiling 6 source files to
/Users/arungupta/.grails/1.0.2/projects/helloworld/classes
[mkdir] Created dir:
/Users/arungupta/.grails/1.0.2/projects/helloworld/resources/grails-app/i18n
[native2ascii] Converting 10 files from
/Users/arungupta/testbed/grails-1.0.2/samples/helloworld/grails-app/i18n
to
/Users/arungupta/.grails/1.0.2/projects/helloworld/resources/grails-app/i18n
[copy] Copying 1 file to
/Users/arungupta/.grails/1.0.2/projects/helloworld/classes
[copy] Copying 1 file to
/Users/arungupta/.grails/1.0.2/projects/helloworld/resources
[copy] Copying 1 file to
/Users/arungupta/.grails/1.0.2/projects/helloworld
Running Grails application..
2008-04-10 10:47:51.501::INFO: Logging to STDERR via
org.mortbay.log.StdErrLog
2008-04-10 10:47:51.603::INFO: jetty-6.1.4
2008-04-10 10:47:51.755::INFO: No Transaction manager found -
if your webapp requires one, please configure one.
2008-04-10 10:47:52.503:/helloworld:INFO: Set web app root
system property: 'helloworld' =
[/Users/arungupta/testbed/grails-1.0.2/samples/helloworld/web-app/]
2008-04-10 10:47:52.503:/helloworld:INFO: Initializing Log4J
from
[file:/Users/arungupta/.grails/1.0.2/projects/helloworld/resources/log4j.properties]
2008-04-10 10:47:52.582:/helloworld:INFO: Initializing Spring
root WebApplicationContext
[0] spring.GrailsWebApplicationContext Refreshing
org.codehaus.groovy.grails.commons.spring.GrailsWebApplicationContext@dccb42:
display name
[org.codehaus.groovy.grails.commons.spring.GrailsWebApplicationContext@dccb42];
startup date [Thu Apr 10 10:47:53 PDT 2008]; parent:
org.springframework.web.context.support.XmlWebApplicationContext@188af2
[0] spring.GrailsWebApplicationContext Bean factory for application
context
[org.codehaus.groovy.grails.commons.spring.GrailsWebApplicationContext@dccb42]:
org.springframework.beans.factory.support.DefaultListableBeanFactory@413ebc
2008-04-10 10:47:55.602:/helloworld:INFO: Initializing Spring
FrameworkServlet 'grails'
2008-04-10 10:47:55.652::INFO: Started
SelectChannelConnector@0.0.0.0:8080
Server running. Browse to https://localhost:8080/helloworld
2008-04-10 10:48:15.133:/helloworld:INFO: GSP servlet
initialized
The output in the browser looks like:
Jetty is used as the development environment server but soon GlassFish
v3 can be used, stay tuned on that!
Anyway, the WAR format is used for deployment. Lets see how
this app can be easily deployed as a WAR file on GlassFish
v3.
GlassFish certainly supports WAR-based deployment
of Grails apps but direct deployment (aka native or directory-based
deployment) of Grails applications will
be supported soon as well. Anyway, for now, create a WAR file of the
application as:
~/testbed/grails-1.0.2/samples/helloworld
>grails war
Welcome to Grails 1.0.2 - https://grails.org/
Licensed under Apache Standard License 2.0
Grails home is set to: /Users/arungupta/testbed/grails-1.0.2
Base Directory: /Users/arungupta/testbed/grails-1.0.2/samples/helloworld
Note: No plugin scripts found
Running script /Users/arungupta/testbed/grails-1.0.2/scripts/War.groovy
Environment set to production
[delete] Deleting:
/Users/arungupta/.grails/1.0.2/projects/helloworld/resources/web.xml
[delete] Deleting directory
/Users/arungupta/.grails/1.0.2/projects/helloworld/classes
[delete] Deleting directory
/Users/arungupta/.grails/1.0.2/projects/helloworld/resources
[mkdir] Created dir:
/Users/arungupta/.grails/1.0.2/projects/helloworld/classes
[groovyc] Compiling 6 source files to
/Users/arungupta/.grails/1.0.2/projects/helloworld/classes
[mkdir] Created dir:
/Users/arungupta/.grails/1.0.2/projects/helloworld/resources/grails-app/i18n
[native2ascii] Converting 10 files from
/Users/arungupta/testbed/grails-1.0.2/samples/helloworld/grails-app/i18n
to
/Users/arungupta/.grails/1.0.2/projects/helloworld/resources/grails-app/i18n
[copy] Copying 1 file to
/Users/arungupta/.grails/1.0.2/projects/helloworld/classes
[copy] Copying 1 file to
/Users/arungupta/.grails/1.0.2/projects/helloworld/resources
[mkdir] Created dir:
/Users/arungupta/testbed/grails-1.0.2/samples/helloworld/staging
[copy] Copying 93 files to
/Users/arungupta/testbed/grails-1.0.2/samples/helloworld/staging
[copy] Copied 19 empty
directories to 1 empty directory under
/Users/arungupta/testbed/grails-1.0.2/samples/helloworld/staging
[copy] Copying 12 files to
/Users/arungupta/testbed/grails-1.0.2/samples/helloworld/staging/WEB-INF/grails-app
[copy] Copying 26 files to
/Users/arungupta/testbed/grails-1.0.2/samples/helloworld/staging/WEB-INF/classes
[mkdir] Created dir:
/Users/arungupta/testbed/grails-1.0.2/samples/helloworld/staging/WEB-INF/spring
[copy] Copying 1 file to
/Users/arungupta/testbed/grails-1.0.2/samples/helloworld/staging/WEB-INF/classes
[mkdir] Created dir:
/Users/arungupta/testbed/grails-1.0.2/samples/helloworld/staging/WEB-INF/templates/scaffolding
[copy] Copying 6 files to
/Users/arungupta/testbed/grails-1.0.2/samples/helloworld/staging/WEB-INF/templates/scaffolding
[copy] Copying 49 files to
/Users/arungupta/testbed/grails-1.0.2/samples/helloworld/staging/WEB-INF/lib
[copy] Copying 1 file to
/Users/arungupta/testbed/grails-1.0.2/samples/helloworld/staging/WEB-INF
[delete] Deleting:
/Users/arungupta/.grails/1.0.2/projects/helloworld/resources/web.xml
[copy] Warning:
/Users/arungupta/testbed/grails-1.0.2/samples/helloworld/plugins not
found.
[propertyfile] Updating property file:
/Users/arungupta/testbed/grails-1.0.2/samples/helloworld/staging/WEB-INF/classes/application.properties
[mkdir] Created dir:
/Users/arungupta/testbed/grails-1.0.2/samples/helloworld/staging/WEB-INF/plugins
[copy] Warning:
/Users/arungupta/testbed/grails-1.0.2/samples/helloworld/plugins not
found.
[jar] Building jar:
/Users/arungupta/testbed/grails-1.0.2/samples/helloworld/helloworld-0.1.war
[delete] Deleting directory
/Users/arungupta/testbed/grails-1.0.2/samples/helloworld/staging
Done creating WAR
/Users/arungupta/testbed/grails-1.0.2/samples/helloworld/helloworld-0.1.war
The create WAR file is 18,012,069
bytes.
Start the GlassFish container as:
~/testbed/glassfish/v3/p2-b08/glassfish
>bin/startserv
--verbose
Apr 10, 2008 11:03:28 AM
com.sun.enterprise.admin.launcher.GFLauncherLogger info
INFO: JVM invocation command line:
/System/Library/Frameworks/JavaVM.framework/Versions/1.5.0/Home/bin/java
-cp
/Users/arungupta/testbed/glassfish/v3/p2-b08/glassfish/modules/glassfish-10.0-SNAPSHOT.jar
. . .
INFO: Listening on port 8080
Apr 10, 2008 11:03:29 AM
com.sun.enterprise.v3.services.impl.GrizzlyEmbeddedHttpConfigurator
configureSSL
WARNING: HTTP listener on port: 8181 is secured, but SSL configuration
is not found!
Apr 10, 2008 11:03:29 AM
com.sun.enterprise.v3.services.impl.GrizzlyProxy start
INFO: Listening on port 8181
Apr 10, 2008 11:03:29 AM
com.sun.enterprise.v3.services.impl.GrizzlyProxy start
INFO: Listening on port 4848
Apr 10, 2008 11:03:29 AM
com.sun.enterprise.v3.admin.adapter.AdminConsoleAdapter setContextRoot
INFO: Admin Console Adapter: context root: /admin
Apr 10, 2008 11:03:29 AM com.sun.enterprise.v3.server.AppServerStartup
run
INFO: com.sun.enterprise.v3.services.impl.GrizzlyService@b24c9a startup
done in 681 ms
Apr 10, 2008 11:03:29 AM
com.sun.enterprise.v3.services.impl.ApplicationLoaderService
postConstruct
INFO: loader service postConstruct started at 1207850609785
Apr 10, 2008 11:03:29 AM com.sun.enterprise.v3.server.AppServerStartup
run
INFO: Application Loader startup done in 717 ms
Apr 10, 2008 11:03:29 AM com.sun.enterprise.v3.server.AppServerStartup
run
INFO: Glassfish v3
started in 717 ms
Apr 10, 2008 11:03:29 AM
com.sun.enterprise.v3.admin.adapter.AdminConsoleAdapter ready
INFO: AdminConsoleAdapter is ready ...
Welcome to Grails 1.0.2 - https://grails.org/
Licensed under Apache Standard License 2.0
Grails home is set to: /Users/arungupta/testbed/grails-1.0.2
Base Directory: /Users/arungupta/testbed/grails-1.0.2/samples/helloworld
Note: No plugin scripts found
Running script
/Users/arungupta/testbed/grails-1.0.2/scripts/CreateController.groovy
Environment set to development
[copy] Copying 1 file to
/Users/arungupta/testbed/grails-1.0.2/samples/helloworld/grails-app/controllers
Created Controller for Hello
[mkdir] Created dir:
/Users/arungupta/testbed/grails-1.0.2/samples/helloworld/grails-app/views/hello
[copy] Copying 1 file to
/Users/arungupta/testbed/grails-1.0.2/samples/helloworld/test/integration
Created ControllerTests for Hello
JRuby 1.1 is released
and ready for production use today. You can unleash the potential in 3
simple steps - download,
unzip & get
started. Here is a quote from the announcement:
more and more reports of
applications exceeding Ruby 1.8.6 performance; we are even beating Ruby
1.9 in some microbenchmarks
This is validated by 1
(Oct 2007), 2
(Nov 2007), 3
(Feb 2008), 4
(Feb 2008) and many other hidden/unknown reports. You can easily
configure JRuby 1.1 as the platform of your choice in NetBeans 6.1 as
described in TOTD
#27.
Now, match this blazing performance of JRuby with GlassFish
v3 gem (only 2.4 Mb) which provides a superior
solution for developing and deploying Rails application. The
main reasons for using GlassFish instead of WEBrick/Mongrel/LightTPD
are:
Identical development and deployment environments
Handles multiple requests by maintaining JRuby runtimes and
database connection pools
Ability to redploy an application without restarting
container
In-built Clustering, Load Balancing, and High Availability
support
Allows to leverage investment in a Java EE infrastructure
and cohosting Ruby-on-Rails and Java EE applications
If you are attending JavaOne
2008, then LAB
8400 will show how to develop and deploy Rails applications
using NetBeans
and deploy them on GlassFish.
LAB
4520 will teach you more about the modular and pluggable GlassFish
v3 architecture.
Part
1 of this tri-series blog explained how a Java EE
Servlet and Rails application can be packaged together as WAR file
using Goldspike
plugin and deployed on GlassFish
v2 UR1. There are few issues with Goldspike as explained here.
A better and recommended option is to use Warbler
for packaging which provides a minimal, flexible and Ruby-like way to
create WAR. Warbler really cleans up the packagingof WAR, for example
excluding .svn directories, tests and migrations - really nice. For
now, it uses RailsServlet for dispatching but even that is pluggable.
This blog, Part 2, will explain how to generate a WAR file using
Warbler. Rails
powered by GlassFish provides all the details on why
GlassFish provides an industry-grade and functionally-rich Application
Server.
Now detailed steps:
In an existing JRuby
1.1 installation (enabled with Rails), install Warbler gem:
~/testbed/jruby-1.1
>bin/jruby -S gem
install warbler
JRuby limited openssl loaded. gem install jruby-openssl for full
support.
https://wiki.jruby.org/wiki/JRuby_Builtin_OpenSSL
Updating metadata for 35 gems from https://gems.rubyforge.org
...................................
complete
Successfully installed warbler-0.9.4
1 gem installed
Installing ri documentation for warbler-0.9.4...
Installing RDoc documentation for warbler-0.9.4...
In order to keep it simple, this application will not be using any
database so uncomment the following line from
"config/environment.rb"(by removing "#" from beginning of the line):
The bundled Servlet is now accessible at
"https://localhost:8080/railsee2/hello". The default browser output
looks like:
And passing a parameter to the URL as
"https://localhost:8080/railsee2/hello?name=Arun" shows the output as:
With this, your Java EE Servlet is now bundled with your Rails
application deployed on GlassFish v2 UR1.
Now, lets add Controller and View to Rails application and invoke this
servlet from there to show complete integration with Rails.
Create a new Controller and View as
~/testbed/jruby-1.1/samples/rails/railsee2
>../../../bin/jruby
script/generate controller home index
JRuby limited openssl loaded. gem install jruby-openssl for full
support.
https://wiki.jruby.org/wiki/JRuby_Builtin_OpenSSL
exists
app/controllers/
exists
app/helpers/
create
app/views/home
exists
test/functional/
create
app/controllers/home_controller.rb
create
test/functional/home_controller_test.rb
create
app/helpers/home_helper.rb
create
app/views/home/index.html.erb
Change the generated controller in
"app/controllers/home_controller.rb" to:
class
HomeController < ApplicationController
include Java
def index
url = java.net.URL.new("https://localhost:8080/railsee2/hello");
conn = url.open_connection;
reader =
java.io.BufferedReader.new(java.io.InputStreamReader.new(conn.get_input_stream));
@servlet_output = "";
input_line = reader.read_line;
while input_line != nil
@servlet_output << input_line;
input_line = reader.read_line;
end
reader.close;
end
end
Change the generated view in
"app/views/home/index.rhtml.erb" to:
<h1>Home#index</h1>
<p>Find me in
app/views/home/index.html.erb</p>
<%= @servlet_output %>
Re-create the WAR as describd in bullet # 5 above. And now
"https://localhost:8080/railsee2/home/index" shows the output as shown:
This blog explained how a Java EE 5 Servlet and Rails application can
be packaged Warbler and deployed on GlassFish. Warbler
docs provide detail about usage, configuration, web.xml and
other details.
The next blog in this tri-series blog will explain how such an
application can be deployed on GlassFish v3. And the cool thing there
is that you don't need Goldspike, Warbler or any other additional
plugins - total native deployment, stay tuned!
Interested
in understanding the nitty gritty details of how Metro in GlassFish
provides Secure, Reliable, Transactional and .NET 3.0 interoperable Web
services ? You can certainly read all about it in Metro Users Guide,
post questions to Metro
Forum, subscribe to Metro Blogs
or The
Aquarium.
But now there is a new 5 hours Web-based course, WTMB-SAS-1500,
from Sun Training.
The course content is organized in 5 different modules:
WMT-SAS-1543:Adding Quality of Service and .NET
Interoperability to Web Services
WMT-SAS-2544: Creating Reliable and Secure
Interoperable Web Services
WMT-SAS-2545: Creating Transactional Web Services
WMT-SAS-2546: Working With the Web Services Policy
WMT-SAS-2547: Brokered Trust
Each module explains What/Why/How of each technology and then shows a
complete demo using NetBeans on how to use that feature. The course can
be taken within 365 days after the purchase. Read more details here.
One of the several
advantages of deploying Rails
applications on GlassFish
is - co-hosting Rails and Java EE applications in the same container.
The screencast
#web9 shows how Rails applications can be easily deployed on
GlassFish.
This blog takes the JRuby-on-Rails (jRoR) and Java EE integration to
the next level. It show how a Java EE Servlet can be co-bundled within
a jRoR application. And then it shows how such a servlet can be easily
invoked from a Rails view. It uses WAR-based
mode for deploying jRoR applications on GlassFish.
Here are the detailed steps:
In an existing JRuby
1.1 RC3 installation (enabled with Rails), install the
required gems:
~/testbed/jruby-1.1RC3
>bin/jruby -S gem
install
activerecord-jdbc-adapter
JRuby limited openssl loaded. gem install jruby-openssl for full
support.
https://wiki.jruby.org/wiki/JRuby_Builtin_OpenSSL
Successfully installed activerecord-jdbc-adapter-0.8
1 gem installed
Installing ri documentation for activerecord-jdbc-adapter-0.8...
Installing RDoc documentation for activerecord-jdbc-adapter-0.8...
~/testbed/jruby-1.1RC3/samples/rails/railsee1
>../../../bin/jruby
script/plugin install
svn://rubyforge.org/var/svn/jruby-extras/trunk/rails-integration/plugins/goldspike
A
/Users/arungupta/testbed/jruby-1.1RC3/samples/rails/railsee1/vendor/plugins/goldspike
A
/Users/arungupta/testbed/jruby-1.1RC3/samples/rails/railsee1/vendor/plugins/goldspike/test
A
/Users/arungupta/testbed/jruby-1.1RC3/samples/rails/railsee1/vendor/plugins/goldspike/test/war_config_test_config.rb
A
/Users/arungupta/testbed/jruby-1.1RC3/samples/rails/railsee1/vendor/plugins/goldspike/test/test_java_library.rb
A
/Users/arungupta/testbed/jruby-1.1RC3/samples/rails/railsee1/vendor/plugins/goldspike/test/test_maven_library.rb
A
/Users/arungupta/testbed/jruby-1.1RC3/samples/rails/railsee1/vendor/plugins/goldspike/test/test_create_war.rb
A
/Users/arungupta/testbed/jruby-1.1RC3/samples/rails/railsee1/vendor/plugins/goldspike/Rakefile
A
/Users/arungupta/testbed/jruby-1.1RC3/samples/rails/railsee1/vendor/plugins/goldspike/init.rb
A
/Users/arungupta/testbed/jruby-1.1RC3/samples/rails/railsee1/vendor/plugins/goldspike/tasks
A
/Users/arungupta/testbed/jruby-1.1RC3/samples/rails/railsee1/vendor/plugins/goldspike/tasks/war.rake
A
/Users/arungupta/testbed/jruby-1.1RC3/samples/rails/railsee1/vendor/plugins/goldspike/lib
A
/Users/arungupta/testbed/jruby-1.1RC3/samples/rails/railsee1/vendor/plugins/goldspike/lib/util.rb
A
/Users/arungupta/testbed/jruby-1.1RC3/samples/rails/railsee1/vendor/plugins/goldspike/lib/war_config.rb
A
/Users/arungupta/testbed/jruby-1.1RC3/samples/rails/railsee1/vendor/plugins/goldspike/lib/run.rb
A
/Users/arungupta/testbed/jruby-1.1RC3/samples/rails/railsee1/vendor/plugins/goldspike/lib/java_library.rb
A
/Users/arungupta/testbed/jruby-1.1RC3/samples/rails/railsee1/vendor/plugins/goldspike/lib/packer.rb
A
/Users/arungupta/testbed/jruby-1.1RC3/samples/rails/railsee1/vendor/plugins/goldspike/lib/create_war.rb
A
/Users/arungupta/testbed/jruby-1.1RC3/samples/rails/railsee1/vendor/plugins/goldspike/install.rb
A
/Users/arungupta/testbed/jruby-1.1RC3/samples/rails/railsee1/vendor/plugins/goldspike/generators
A
/Users/arungupta/testbed/jruby-1.1RC3/samples/rails/railsee1/vendor/plugins/goldspike/generators/goldspike
A
/Users/arungupta/testbed/jruby-1.1RC3/samples/rails/railsee1/vendor/plugins/goldspike/generators/goldspike/goldspike_generator.rb
A
/Users/arungupta/testbed/jruby-1.1RC3/samples/rails/railsee1/vendor/plugins/goldspike/generators/goldspike/templates
A
/Users/arungupta/testbed/jruby-1.1RC3/samples/rails/railsee1/vendor/plugins/goldspike/generators/goldspike/templates/web.xml.erb
A
/Users/arungupta/testbed/jruby-1.1RC3/samples/rails/railsee1/vendor/plugins/goldspike/generators/goldspike/templates/war.rb
A
/Users/arungupta/testbed/jruby-1.1RC3/samples/rails/railsee1/vendor/plugins/goldspike/README
Exported revision 960.
exists
config
create
config/war.rb
create
WEB-INF
create
WEB-INF/web.xml.erb
Optionally Warbler
may be used for packaging and Goldspike for dispatching.
Create a Java library with Servlet code
Using NetBeans IDE, create a project of type "Java Class
Library" and
specify the name "HelloServlet".
Right-click on the project, select "New" and
"Servlet...". Enter the
class name as "HelloServlet" and package as "server" as shown below:
Right-click on the project, select Properties and in
"Libraries", "Compile Tab Libraries" add
"javaee.jar" from GlassFish
v2 UR1 "lib" directory.
Change the "try" block in "processRequest" method to
following:
String
name = request.getParameter("name");
if (name == null || name.equals(""))
name = "Duke";
out.println("<h1>Servlet HelloServlet at " +
request.getContextPath () + " says Hello " + name +
"!</h1>");
Right-click on the project and select "Clean and Build".
Configure Rails app for Servlet
In your Rails application directory, add the following
fragments to "WEB-INF/web.xml.erb":
The bundled Servlet is now accessible at
"https://localhost:8080/railsee1/hello". The default browser output
looks like:
And passing a parameter to the URL as
"https://localhost:8080/railsee1/hello?name=Arun" shows the output as:
With this, your Java EE Servlet is now bundled with your Rails
application deployed on GlassFish v2 UR1.
Now, lets add Controller and View to Rails application and invoke this
servlet from there to show complete integration with Rails.
Create a new Controller and View as
~/testbed/jruby-1.1RC3/samples/rails/railsee1
>../../../bin/jruby
script/generate controller home index
JRuby limited openssl loaded. gem install jruby-openssl for full
support.
https://wiki.jruby.org/wiki/JRuby_Builtin_OpenSSL
exists
app/controllers/
exists
app/helpers/
create
app/views/home
exists
test/functional/
create
app/controllers/home_controller.rb
create
test/functional/home_controller_test.rb
create
app/helpers/home_helper.rb
create
app/views/home/index.html.erb
Change the generated controller in
"app/controllers/home_controller.rb" to:
class
HomeController < ApplicationController
include Java
def index
url = java.net.URL.new("https://localhost:8080/railsee1/hello");
conn = url.open_connection;
reader =
java.io.BufferedReader.new(java.io.InputStreamReader.new(conn.get_input_stream));
@servlet_output = "";
input_line = reader.read_line;
while input_line != nil
@servlet_output << input_line;
input_line = reader.read_line;
end
reader.close;
end
end
Change the generated view in
"app/views/home/index.rhtml.erb" to:
<h1>Home#index</h1>
<p>Find me in
app/views/home/index.html.erb</p>
<%= @servlet_output %>
Re-create & re-deploy the WAR as describd in bullet
# 6 above. And
now
"https://localhost:8080/railsee1/home/index" shows the output as shown:
This shows how a Java EE 5 Servlet can be easily invoked from a Rails
application deployed on GlassFish. JRuby-on-Rails and GlassFish allows
you to leverage business knowledge that exists in Java EE applications
very easily and still providing Rails agility.
This blog provides how you can get started with Merb on JRuby
1.1 RC3.
Merb is another MVC framework (just like Rails) but with a pluggable
ORM, JavaScript library and Template language. Rails has built-in
support for these using ActiveRecord, Script.aculo.us
and ERB
templates. Making it pluggable keeps the core very lightweight and
still providing support for a particular feature using plugins. Another
big advantage of Merb is that unlike Rails it's thread-safe.
There
are already third party supports for ActiveRecord, DataMapper and
Sequel ORMs. I will hopefully be able to build support for Java
Persistence API ORM in Merb. Until then, here is how you
install and get started with Merb on JRuby 1.1 RC3.
Install Merb on JRuby as:
Macintosh-187:jruby-1.1RC3
arungupta$ bin/jruby -S
gem install merb mongrel
JRuby limited openssl loaded. gem install jruby-openssl for full
support.
https://wiki.jruby.org/wiki/JRuby_Builtin_OpenSSL
Updating metadata for 339 gems from https://gems.rubyforge.org
.........................................................................................................
.........................................................................................................
.........................................................................................................
........................
complete
Successfully installed abstract-1.0.0
Successfully installed erubis-2.5.0
Successfully installed json_pure-1.1.2
Successfully installed rack-0.3.0
Successfully installed hpricot-0.6-java
Successfully installed mime-types-1.15
Successfully installed merb-core-0.9.2
Successfully installed merb-action-args-0.9.2
Successfully installed merb-assets-0.9.2
Successfully installed activesupport-2.0.2
Successfully installed rubigen-1.2.4
Successfully installed merb-gen-0.9.2
Successfully installed merb-haml-0.9.2
Successfully installed merb-builder-0.9.2
Successfully installed mailfactory-1.2.3
Successfully installed merb-mailer-0.9.2
Successfully installed merb-parts-0.9.2
Successfully installed merb-cache-0.9.2
Successfully installed merb-more-0.9.2
Successfully installed merb-0.9.2
Successfully installed gem_plugin-0.2.3
Successfully installed mongrel-1.1.4-java
22 gems installed
Installing ri documentation for json_pure-1.1.2...
Installing ri documentation for rack-0.3.0...
Installing ri documentation for hpricot-0.6-java...
Installing ri documentation for mime-types-1.15...
Installing ri documentation for merb-core-0.9.2...
Installing ri documentation for merb-action-args-0.9.2...
Installing ri documentation for merb-assets-0.9.2...
Installing ri documentation for activesupport-2.0.2...
Installing ri documentation for rubigen-1.2.4...
Installing ri documentation for merb-gen-0.9.2...
Installing ri documentation for merb-haml-0.9.2...
Installing ri documentation for merb-builder-0.9.2...
Installing ri documentation for mailfactory-1.2.3...
Installing ri documentation for merb-mailer-0.9.2...
Installing ri documentation for merb-parts-0.9.2...
Installing ri documentation for merb-cache-0.9.2...
Installing ri documentation for gem_plugin-0.2.3...
Installing ri documentation for mongrel-1.1.4-java...
Installing RDoc documentation for json_pure-1.1.2...
Installing RDoc documentation for rack-0.3.0...
Installing RDoc documentation for hpricot-0.6-java...
Installing RDoc documentation for mime-types-1.15...
Installing RDoc documentation for merb-core-0.9.2...
Installing RDoc documentation for merb-action-args-0.9.2...
Installing RDoc documentation for merb-assets-0.9.2...
Installing RDoc documentation for activesupport-2.0.2...
Installing RDoc documentation for rubigen-1.2.4...
Installing RDoc documentation for merb-gen-0.9.2...
Installing RDoc documentation for merb-haml-0.9.2...
Installing RDoc documentation for merb-builder-0.9.2...
Installing RDoc documentation for mailfactory-1.2.3...
Installing RDoc documentation for merb-mailer-0.9.2...
Installing RDoc documentation for merb-parts-0.9.2...
Installing RDoc documentation for merb-cache-0.9.2...
Installing RDoc documentation for gem_plugin-0.2.3...
Installing RDoc documentation for mongrel-1.1.4-java...
This is so much simpler than couple of weeks ago where all the
dependencies had to be explicitly
installed. Now create a sample application as:
Macintosh-187:hello
arungupta$ ../../../bin/jruby
-S merb
JRuby limited openssl loaded. gem install jruby-openssl for full
support.
https://wiki.jruby.org/wiki/JRuby_Builtin_OpenSSL
~ Loaded DEVELOPMENT Environment...
~ Compiling routes...
~ Using 'share-nothing' cookie sessions (4kb limit per client)
~ Using Mongrel adapter
And the default app is hosted at "https://localhost:4000/" and shown in
the browser as:
There is a wealth
of information available to get you going after this. Here
are couple of things to try:
If possible, use WARbler to package Merb app and deploy on GlassFish.
Microsoft BizTalk R11
CTP was released last week and now contains a sample that is
based on GlassFish,
Metro and NetBeans. Even though
today is April 1st, this is not intended to be an April
Fool's Day joke. Read more about the sample in this blog
entry. The relevant bits from the entry are quoted below:
The sample shows how to
use the BizTalk Services Identity Security Token Service (STS) to
secure the communication between a Java client and a Java service
providing federated authentication and claims-based authorization. The
sample, which you can find in
./Samples/OtherPlatforms/StandaloneAccessControl/JavaEE5 once you
installed the SDK, is a pure
Java sample not requiring any of our bits on either the
service or client side. The interaction
with our services is purely happening on the wire.
The Metro team over at
Sun Microsystems has made
a very significant contribution to making this all work.
Before we started making changes to accommodate Java, there would have
been very little hope for anyone to get this seemingly simple scenario
to work. We had to make quite a few changes even though our service did
follow the specs.
As a result of this
collaboration, Metro
1.2 is going to
be a better and more interoperable release for the Sun's customers and
the greater Java community and BizTalk Services as well as
our future identity products will be better and more interoperable,
too. Win-Win. Thank you,
Sun.
Thank you Microsoft for adding this sample to the BizTalk Services SDK.
Metro team demonstrated a similar
demo at JavaOne
2007. The demo shows how an Excel 2007 client can invoke a
secure and reliable endpoint deployed on GlassFish. The entire source
code for the sample, along with instructions to build, are available here.
I presented on GlassFish
and Metro
in Developer Update meetings in St
Louis & Kansas
City. The slides are available here.
The demos shown in the talk can be seen at:
The healthcare scenario explained in the talk can be seen as a demo here
and the associated source code can be downloaded here.
The flight out of Kansas City got cancelled because of a hydraulic pump
failure and finally reached home around mid night :( I was at least
glad to come back home the same night!
As announced
earlier, Ruby
Developer Center is a new page launched earlier today and
provides all the resources to get started with Ruby, JRuby,
Ruby-on-Rails @ Sun.
Ruby Developer
Center is a new page launched today that is a one stop page
for any thing & everything about Ruby, JRuby, Rails and all
related efforts @ Sun
Microsystems. Here are couple of new articles to get you
started:
The site is divided into 4 tabs - Overview, Reference, Community,
Download.
The Overview
tab provides a pointers to Getting Started and key Ruby events. In the Reference tab, you
can find out about documentation about using Ruby with
Solaris, NetBeans, GlassFish, Databases (MySQL, PostgreSQL &
JavaDB). The Community
tab gives pointers to blogs, forums and participation opportunities.
Finally Download
tab provides a single page to download all related Tools &
Platforms.
A popular statement for Las Vegas is What happens in
Vegas, Stays in Vegas! But I promise to share all the slides
& demos with you so that you can enjoy at least the technical
part of it ;-)
This is your last chance to report any issues before JRuby 1.1 goes
final. And I encourage you to try out GlassFish
v3 Gem (ver
0.1.2) on this JRuby version and file any issues.
I delivered my Maki
as an Ajax Mashup Framework talk and the slides are available
here.
Lots of attendees came by afterwards and told me that they enjoyed the
demo. The talk showed how jMaki
Webtop provides a lightweight mashup framework that runs in
the browser. Here is a pictorial representation of the demo shown:
jMaki Webtop is basically a jMaki widget that can be embedded in a JSP
or PHP page. This widget provides the framework for managing widgets
and users, ability to persist the Webtop on client-side using Google
Gears or server-side using backend database, layouts and other
functionality. In JSP case, the widget uses JPA for performing all the
CRUD operations with the back-end MySQL database. The resulting WAR
file is deployed on GlassFish
(can be any other Servlet container as well). If you are interested in
a Java version of Webtop then the recommended path is:
jMaki webtop for widget deployment & customization
It really is an evolution of jMaki - using all the infrastructure that
has built over 2 years. You can experience it yourself at jmaki.com/webtop
which is running a PHP version of the app. See the coverage here.
The code will be available soon!
I attended few more talks and took notes in some of them to share:
This was an early morning talk (7:30am) and I reached few minutes late.
But it was basically talking about JavaScript vulnerabilities such as
Script injection
No difference between user & guest scripts
Scripts exempt from same-origin policy
No modularity (global access to everything on the page)
And also DOM vulnerability because every node in the tree has access to
every other node. This lacks modularity and causes a potential security
risk.
Doug recommended 3-step plan to fix the Web:
Safe JavaScript subset
JSLint.com
provides a safe subset of JavaScript that removes all features that are
unsafe or suspect such as no global vars or functions
Google Caja & Cajita provide a similar subet but
they use transformation instead of validation
Minor browser improvements
Scripts are exempt from same-origin policy. This allows a
dynamic <script> tag to make a GET request from a server.
Instead use JSONRequest (part of json.org).
ES4
(the upcoming JavaScript standard) is not good enough because it
maintains backwards compatibility and adds complexity.
Major browser improvements
Replace JavaScript & DOM in browsers. The
approach is to start with JSLint and add safe features as required.
The Object Capability System (where objects are given
explicit access to be used) needs to be enforced to make it secure.
In Doug's opinion, if the Web is not fixed then JavaFX, Silverlight
& AIR
(all vastly superior but lacking adoption) will displace the web.
The talk started with a "not too long back" introduction of the
technology space. Well, it started with 1991 and the timeline (and
associated technology advances in that year) kept shuffling 1995, 1989,
2001 .... and so on. Jeff talked about how/why Tim Berners Lee invented
WWW and covered a myriad of terms after that including but not limited
to - Web 1.0, Netscape, Mosaic, marc Andreeeseen (sp?), Java, java Web
Start, Applets, W3C, CGI, J2EE, JCP, C#, JBoss, SOA, JavaFX,
Silverlight, AIR and many others. For a 50 minute talk, that was quite a long
introduction.
After that introduction, he word "Ajax" was mentioned almost
30 minutes (8:51am to be precise) in the talk. And then the word
"Appcelerator" was mentioned at 9:06am. Finally, I realized that I'm in
the right talk ;)
Appcelerator
like to pitch themselves as RIA + SOA company and allows true
decoupling of the rich client from it's services. Their services is
very similar to jMaki but they use event handling + Ajax + DHTML to
achieve it. They also run on Ruby, PHP, Java and other languages.
All in all, it was a good walk through the memory lane!
The talk explained the basic concepts of REST
- Resource, URI, Representation, URL & Methods (GET, PUT, POST
& DELETE). It also explained the idempotency and safety of each
method type. Overall a good decent introduction.
Then it explained the limitations with current web-based forms:
The URIs in the action attribute cannot be changed
dynamically
Most browsers recognize only GET/POST methods
Limited ecodings - for example generating JSON encoding
requires extra work.
It provided a REST framework checklist:
Does it have resource-based approach ?
Acknowledges existing of representation ?
need multiple of them
Solid engineering & community support ?
The three frameworks discussed in the talk were:
Apache
Cocoon - based on XML pipelines & URL patterns,
powerful but steep learning curve
RESTlet
- Like Servlet for REST, good for existing model
Apache
Sling - Based on JCR with server-side scripting support
The talk did not mention anything about Jersey which is
turning out to be a great implementation and very well meets all the
critieria mentioned above.
The speaker recommended Apache Sling with µjax
for all REST + Ajax needs. But I'd strongly encourage you to have a
look at Jersey. The JSON representation generated out of Jersey can now
be directly consumed by jMaki as described here
- a true combination of REST & Ajax :)
And then the last talk where I took notes is Understanding
the Top Web 2.0 Attack Vectors. I'll provides notes from the
last 5 slides of the talk which essentially captured the essence. These
slides talked about fundamental issues with Ajax and described concerns
and possible attacks in each issue. I'll need to understand some of
these attacks better myself but at least I have a list to begin with :)
Authorization & Authentication in complex
environment
Attacks
Traditional
Information disclosure, Logical attributes,
Denial-of-service
Command Injection
LDAP, SQL, XPath etc.
OpenAjax Alliance
talk about Gadgets & Widgets was nice. The alliance is working
on creating standards for widget metadata, communication across widgets
and other similar tasks. The goal is to enable successful adoption of
open and interoperable Ajax-based Web technologies.
Dave Ferraiolo (from OpenAjax) particularly expressed thanks to jMaki
for deriving the first set of Open Ajax Data Model specs from jMaki
data models.