Tuesday Dec 19, 2006

GlassFish and Ruby - Part II

In part I, a GlassFish server was dedicated to hosting a single RoR application running on a native Ruby interpreter. Starting with changes in build 29, GlassFish v2 is capable of hosting multiple RoR applications along with your other web/ejb applications. All you need to do is make a couple of minor tweaks
  • Specify the context root associated with the RoR application in the descriptor file and the 'stripRequestURI' initialization paramater along with others specified in part I as illustrated below.
         <servlet>
            <servlet-name>cgi</servlet-name>
            <servlet-class>org.apache.catalina.servlets.CGIServlet</servlet-class>
            ...
            <init-param>
              <-- stripRequestURI parameter value maps to context root -->
              <-- in this case - http://.../ror/${ror-request-URI} -->
              <param-name>stripRequestURI</param-name>
              <param-value>/ror/</param-value>
            <init-param>
            ...
        </servlet>
    
    
        <servlet-mapping>
              <servlet-name>cgi</servlet-name>
              <url-pattern>/ror/\*</url-pattern>
        </servlet-mapping>
    
  • Since Rails auto-generates links, you'll have to make the following change in config/routes.rb
      # Specify the context root as the relative URL for all requests
      ActionController::AbstractRequest.relative_url_root = "/ror"
    
      # Install the default route as the lowest priority.
      map.connect ':controller/:action/:id'
    
Rails application will be accessible @ http(s)://.../ror/...
Simply replicate the configuration with the customized value of context root and the 'cgiPathPrefix' initialization parameter pointing to each application's specific 'dispatch.cgi' to host multiple RoR applications !

Friday Dec 15, 2006

GlassFish and Ruby

GlassFish and JRuby are obviously a great match, since both run on the Java virtual machine which allows Ruby code running on JRuby to access Java framework and libraries and the possibilities are endless.

However, GlassFish is also capable of running Ruby code via a native Ruby interpreter. This is possible using CGI support in GlassFish. For this first post, I shall keep things simple and demonstrate how you could go about dedicating an entire instance of the GlassFish server for a single RoR application

All you'll need is to install GlassFish v2 build 29 or greater, the native Ruby interpreter with the Rails framework libraries and make some minor modifications to GlassFish configuration. Of course, you'll need to create your rails application. The minor modifications amount to modifying ${glassfish.home}/domains/${domain-name}/config/default-web.xml with the following CGI configuration enabled.

   <servlet>
        <servlet-name>cgi</servlet-name>
        <servlet-class>org.apache.catalina.servlets.CGIServlet</servlet-class>
        <init-param>
          <!-- in this case the path will be appended to
               ${glassfish.home}/domains/${domain-name}/docroot/ -->
          <param-name>cgiPathPrefix</param-name>
          <param-value>${rails-root-dir}/public/dispatch.cgi</param-value>
        </init-param>
        <init-param>
          <param-name>executable</param-name>
          <param-value>${path-to-ruby}</param-value>
        </init-param>
        <init-param>
          <param-name>passShellEnvironment</param-name>
          <param-value>true</param-value>
        </init-param>
        ...
    </servlet>

    <servlet-mapping>
        <servlet-name>cgi</servlet-name>
        <url-pattern>/\*</url-pattern>
    </servlet-mapping>

On UNIX make sure that the native Ruby interpreter is in the PATH and LD_LIBRARY_PATH is set to satisfy the native Ruby interpreter's/Rails dependencies in the GlassFish process's environment. This is the reason for configuring the 'passShellEnvironment' parameter to true.

That's pretty much all there is to it. Accessing http://${host}:${port}/ should bring up the default Rails page !

About

whacko

Search

Categories
Archives
« April 2014
SunMonTueWedThuFriSat
  
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
29
30
   
       
Today