 |
WAR-based Packaging and Deployment of Rails on GlassFish - Goldspike, RailServlet, Warbler, Rack, ...
Posted by arungupta on May 15, 2008 at 06:32 AM | Comments (0)
WAR-based
packaging and dispatching of Rails application on Java Application
Servers is going through third iteration based what is used for
packaging and dispatching:
- Goldspike + RailsServlet: The first iteration was
WAR-packaging of Rails app as defined by Goldspike
plugin (nee Rails-integration) and using RailsServlet (part
of Goldspike) for dispatching.
- Warbler + RailsServlet: The second iteration (slightly
short lived) overcame the shortcomings
of Goldspike (packaging with sane defaults, fast,
light-weight, and flexible configuration) by using Warbler
for packaging. It decoupled packaging and dispatching by doing only
packaging and allowing for pluggable dispatching mechanism.
RailsServlet continues to be the default Servlet binding mechanism.
This is the version currently supported by GlassFish
v2 Update Center.
- Warbler + Rack:
Nick released JRuby-Rack
(JRuby version of Rack,
also see Introducing
Rack and Docs)
last week. And so the third iteration is using Warbler packaging and
Rack-based dispatching. JRuby-Rack provides a more seamless connection
between the Servlet environment and Rack.
The JRuby-Rack
wiki says "JRuby-Rack
is a lightweight adapter for the Java servlet environment that allows
any Rack-based application to run unmodified in a Java servlet
container. JRuby-Rack supports Rails, Merb, as well as any
Rack-compatible Ruby web framework.".
This means that,
other than Rails, conceptually Merb applications (which also use Rack
for deployment) can now also be deployed on GlassFish. This blog
entry explains how to deploy a simple Rack-based Rails application.
- Install Rails and JRuby-Rack (as part of Warbler)
as:
~/testbed/jruby-1.1.1
>bin/jruby -S gem
install rails warbler --no-ri --no-rdoc
JRuby limited openssl loaded. gem install jruby-openssl for full
support.
http://wiki.jruby.org/wiki/JRuby_Builtin_OpenSSL
Updating metadata for 289 gems from http://gems.rubyforge.org/
..............................................................................................................................
..............................................................................................................................
.....................................
complete
Successfully installed activesupport-2.0.2
Successfully installed activerecord-2.0.2
Successfully installed actionpack-2.0.2
Successfully installed actionmailer-2.0.2
Successfully installed activeresource-2.0.2
Successfully installed rails-2.0.2
Successfully installed warbler-0.9.9
7 gems installed |
- Create a template Rails app as:
~/testbed/jruby-1.1.1/samples/rails
>../../bin/jruby
-S rails hello -d mysql
create
create
app/controllers
create
app/helpers
create
app/models
create
app/views/layouts
create
config/environments
. . .
create
doc/README_FOR_APP
create
log/server.log
create
log/production.log
create
log/development.log
create
log/test.log |
- Disable database access from the application by
uncommenting line 21 (remove "#" at the beginning) from
"config/environment.rb" as:
|
config.frameworks -= [ :active_record, :active_resource, :action_mailer
] |
- Create a WAR file as:
~/testbed/jruby-1.1.1/samples/rails/hello
>../../../bin/jruby
-S warble
JRuby limited openssl loaded. gem install jruby-openssl for full
support.
http://wiki.jruby.org/wiki/JRuby_Builtin_OpenSSL
jar cf hello.war -C tmp/war . |
A new file "hello.war" is generated in the current directory.
- The generated WAR file can be easily deployed on GlassFish.
- Download and Install GlassFish v2 UR2 from here.
- Start GlassFish Application Server as:
~/testbed/glassfish/v2ur2/glassfish
>bin/asadmin
start-domain --verbose
Starting Domain domain1, please wait.
May 13, 2008 11:23:44 AM
com.sun.enterprise.admin.servermgmt.launch.ASLauncher buildCommand
INFO:
/System/Library/Frameworks/JavaVM.framework/Versions/1.5.0/Home/bin/java
. . .
[#|2008-05-13T11:34:13.252-0700|INFO|sun-appserver9.1|javax.enterprise.system.container.web|_ThreadID=10;_ThreadName=main;4848;|WEB0712:
Starting Sun-Java-System/Application-Server HTTP/1.1 on 4848|#]
[#|2008-05-13T11:34:13.691-0700|INFO|sun-appserver9.1|javax.enterprise.system.core.selfmanagement|_ThreadID=10;_ThreadName=main;|SMGT0007:
Self Management Rules service is enabled|#]
[#|2008-05-13T11:34:13.718-0700|INFO|sun-appserver9.1|javax.enterprise.system.core|_ThreadID=10;_ThreadName=main;|Application
server startup complete.|#] |
- Deploy the WAR on GlassFish as:
~/testbed/jruby-1.1.1/samples/rails/hello
>~/testbed/glassfish/v2ur2/glassfish/bin/asadmin
deploy hello.war
Command deploy executed successfully. |
The output in the GlassFish console looks like:
[#|2008-05-13T11:34:23.330-0700|INFO|sun-appserver9.1|javax.enterprise.system.tools.admin|_ThreadID=14;_ThreadName=httpWorkerThread-4848-0;/private/tmp/s1astempdomain1server1547440193/hello.war;|ADM1006:Uploading
the file to:[/private/tmp/s1astempdomain1server1547440193/hello.war]|#]
[#|2008-05-13T11:34:26.019-0700|INFO|sun-appserver9.1|javax.enterprise.system.tools.deployment|_ThreadID=15;_ThreadName=Thread-30;|deployed
with moduleid = hello|#]
[#|2008-05-13T11:34:30.626-0700|INFO|sun-appserver9.1|javax.enterprise.system.container.web|_ThreadID=16;_ThreadName=httpWorkerThread-4848-1;|PWC1412:
WebModule[/hello] ServletContext.log():Info: using runtime pool timeout
of 30 seconds|#]
[#|2008-05-13T11:34:30.626-0700|INFO|sun-appserver9.1|javax.enterprise.system.container.web|_ThreadID=16;_ThreadName=httpWorkerThread-4848-1;|PWC1412:
WebModule[/hello] ServletContext.log():Warning: no initial runtimes
specified.|#]
[#|2008-05-13T11:34:30.627-0700|INFO|sun-appserver9.1|javax.enterprise.system.container.web|_ThreadID=16;_ThreadName=httpWorkerThread-4848-1;|PWC1412:
WebModule[/hello] ServletContext.log():Warning: no max runtimes
specified.|#] |
- The default Rails page is now visible at
"http://localhost:8080/hello" as shown below:

- Add some functionality to the application to show Servlet
and Rack integration
- Add a Controller and View as
~/testbed/jruby-1.1.1/samples/rails/hello
>../../../bin/jruby
script/generate controller home index
JRuby limited openssl loaded. gem install jruby-openssl for full
support.
http://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 "index" helper method in
"app/controllers/home_controller.rb" as:
def
index
@greeting = "Hello from Rack!!"
# access Servlet Context
@server_info = $servlet_context.get_server_info
# alternative way to get Servlet Context
#@server_info2 = request.env['java.servlet_context'].get_server_info
# access Servlet Request
@method = request.env['java.servlet_request'].get_method
@request_uri = request.env['java.servlet_request'].get_request_uri
@protocol = request.env['java.servlet_request'].get_protocol
@port = request.env['java.servlet_request'].get_server_port
end |
- Add the following fragment as the last line in
"app/views/home/index.html.erb":
<%=
@greeting %><br><br>
Hosted on "<%= @server_info %>" on port "<%= @port
%>"<br>
<%= @method %> <%= @request_uri %>
<%= @protocol %> |
- Re-create and deploy the WAR file
- Re-create the WAR file as explained in step 4.
- Re-deploy the WAR file as explained in step 5.3.
- Now "http://localhost:8080/hello/home/index" shows the
output as:

The magic fragment in "tmp/war/WEB-INF/web.xml" is:
<filter>
<filter-name>RackFilter</filter-name>
<filter-class>org.jruby.rack.RackFilter</filter-class>
</filter>
<filter-mapping>
<filter-name>RackFilter</filter-name>
<url-pattern>/*</url-pattern>
</filter-mapping>
<listener>
<listener-class>org.jruby.rack.rails.RailsServletContextListener</listener-class>
</listener> |
And also "WEB-INF/lib/jruby-rack-0.9.jar" is bundled in the WAR.
Let us know if you try Rack-based deployment of Merb applications on
GlassFish.
Technorati: rubyonrails
jruby ruby rack merb glassfish
Bookmark blog post: del.icio.us Digg DZone Furl Reddit
Comments
Comments are listed in date ascending order (oldest first) | Post Comment
|