<commit_before># JRuby-Rack

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 as well as any Rack-compatible Ruby web framework.

For more information on Rack, visit http://rack.rubyforge.org.

**NOTE:** JRuby-Rack 1.1.x aims to be compatible with JRuby 1.6/1.7, the next
major version of ours (likely 1.2.x) will be compatible with JRuby 1.7+ only.

[![Build Status][0]](http://travis-ci.org/jruby/jruby-rack)

## Getting Started

The most-common way to use JRuby-Rack is to get [Warbler][1].
Warbler depends on the latest version of JRuby-Rack and ensures it gets placed
in your WAR file when it gets built.

If you're assembling your own WAR using other means, you can install the
**jruby-rack** gem. It provides a method to locate the jar file:

    require 'jruby-rack'
    FileUtils.cp JRubyJars.jruby_rack_jar_path, '.'

Otherwise you'll need to download the latest [jar release][2], drop it into the
*WEB-INF/lib* directory and configure the `RackFilter` in your application's
*web.xml* (see following examples).

Alternatively you can use a server built upon JRuby-Rack such as [Trinidad][3]
with sensible defaults, without the need to configure a deployment descriptor.

### Rails

Here's sample *web.xml* configuration for Rails. Note the environment and
min/max runtime parameters. For **multi-threaded** (a.k.a. `threadsafe!`)
Rails with a single runtime, set min/max both to 1. Otherwise, define the size
of the runtime pool as you wish.

    <context-param>
      <param-name>rails.env</param-name>
      <param-value>production</param-value>
    </context-param>
    <context-param>
      <param-name>jruby.min.runtimes</param-name>
      <param-value>1</param-value>
    </context-param>
    <context-param>
      <param-name>jruby.max.runtimes</param-name>
      <param-value>1</param-value>
    </context-param>

    <filter>
      <filter-name>RackFilter</filter-name>
      <filter-class>org.jruby.rack.RackFilter</filter-class>
      <!-- optional filter configuration init-params : -->
      <init-param>
        <param-name>resetUnhandledResponse</param-name>
        <param-value>true</param-value> <!-- true (default), false or buffer -->
      </init-param>
      <init-param>
        <param-name>addsHtmlToPathInfo</param-name>
        <param-value>true</param-value> <!-- true (default), false -->
      </init-param>
      <init-param>
        <param-name>verifiesHtmlResource</param-name>
        <param-value>false</param-value> <!-- true, false (default) -->
      </init-param>
    </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>

### (Other) Rack Applications

The main difference when using a non-Rails Rack application is that JRuby-Rack
looks for a "rackup" file named **config.ru** in  `WEB-INF/config.ru` or
`WEB-INF/*/config.ru`. Here's a sample *web.xml* configuration :

    <filter>
      <filter-name>RackFilter</filter-name>
      <filter-class>org.jruby.rack.RackFilter</filter-class>
      <!-- optional filter configuration init-params (@see above) -->
    </filter>
    <filter-mapping>
      <filter-name>RackFilter</filter-name>
      <url-pattern>/*</url-pattern>
    </filter-mapping>

    <listener>
      <listener-class>org.jruby.rack.RackServletContextListener</listener-class>
    </listener>

If you don't have a *config.ru* or don't want to include it in your web app, you
can embed it directly in the *web.xml* as follows (using Sinatra as an example):

    <context-param>
      <param-name>rackup</param-name>
      <param-value>
        require 'rubygems'
        gem 'sinatra', '~&gt; 1.3'
        require './lib/app'
        set :run, false
        set :environment, :production
        run Sinatra::Application
      </param-value>
    </context-param>

Be sure to escape angle-brackets for XML !


## Servlet Filter

JRuby-Rack's main mode of operation is as a filter. This allows requests for
static content to pass through and be served by the application server.
Dynamic requests only happen for URLs that don't have a corresponding file, much
like many Ruby/Rack applications expect. The (default) filter we recommend
using is `org.jruby.rack.RackFilter`, the filter supports the following
(optional) init-params:

- **responseNotHandledStatuses** which statuses (when a filter chain returns)
  should be considered that the response has not been handled (default value:
  "403,404,405") and should be dispatched as a Rack application
- **resetUnhandledResponse** whether an unhandled response from the filter chain
  gets reset (accepts  values "true", "false" and "buffer" to reset the buffer
  only), by default "true"
- **addsHtmlToPathInfo** controls whether the .html suffix is added to the URI
  when checking if the request is for a static page
- **verifiesHtmlResource** used with the previous parameter to makee sure the
  requested static resource exist before adding the .html request URI suffix

The application can also be configured to dispatch through a servlet instead of
a filter, the servlet class name is `org.jruby.rack.RackServlet`.

## Servlet Environment Integration

- servlet context is accessible to any application through the Rack environment
  variable *java.servlet_context* (as well as the `$servlet_context` global).
- the (native) servlet request and response objects could be obtained via the
  *java.servlet_request* and *java.servlet_response* keys
- all servlet request attributes are passed through to the Rack environment (and
  thus might override request headers or Rack environment variables)
- servlet sessions can be used as a (java) session store for Rails, session
  attributes with String keys (and String, numeric, boolean, or java
  object values) are automatically copied to the servlet session for you.

## Rails

Several aspects of Rails are automatically set up for you.

- `ActionController::Base.relative_url_root` is set for you automatically
  according to the context root where your webapp is deployed.
- `Rails.logger` output is redirected to the application server log.
- Page caching and asset directories are configured appropriately.

## JRuby Runtime Management
<commit_msg>Fix typos in README<commit_after># JRuby-Rack

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 as well as any Rack-compatible Ruby web framework.

For more information on Rack, visit http://rack.rubyforge.org.

**NOTE:** JRuby-Rack 1.1.x aims to be compatible with JRuby 1.6/1.7, the next
major version of ours (likely 1.2.x) will be compatible with JRuby 1.7+ only.

[![Build Status][0]](http://travis-ci.org/jruby/jruby-rack)

## Getting Started

The most-common way to use JRuby-Rack is to get [Warbler][1].
Warbler depends on the latest version of JRuby-Rack and ensures it gets placed
in your WAR file when it gets built.

If you're assembling your own WAR using other means, you can install the
**jruby-rack** gem. It provides a method to locate the jar file:

    require 'jruby-rack'
    FileUtils.cp JRubyJars.jruby_rack_jar_path, '.'

Otherwise you'll need to download the latest [jar release][2], drop it into the
*WEB-INF/lib* directory and configure the `RackFilter` in your application's
*web.xml* (see following examples).

Alternatively you can use a server built upon JRuby-Rack such as [Trinidad][3]
with sensible defaults, without the need to configure a deployment descriptor.

### Rails

Here's sample *web.xml* configuration for Rails. Note the environment and
min/max runtime parameters. For **multi-threaded** (a.k.a. `threadsafe!`)
Rails with a single runtime, set min/max both to 1. Otherwise, define the size
of the runtime pool as you wish.

    <context-param>
      <param-name>rails.env</param-name>
      <param-value>production</param-value>
    </context-param>
    <context-param>
      <param-name>jruby.min.runtimes</param-name>
      <param-value>1</param-value>
    </context-param>
    <context-param>
      <param-name>jruby.max.runtimes</param-name>
      <param-value>1</param-value>
    </context-param>

    <filter>
      <filter-name>RackFilter</filter-name>
      <filter-class>org.jruby.rack.RackFilter</filter-class>
      <!-- optional filter configuration init-params : -->
      <init-param>
        <param-name>resetUnhandledResponse</param-name>
        <param-value>true</param-value> <!-- true (default), false or buffer -->
      </init-param>
      <init-param>
        <param-name>addsHtmlToPathInfo</param-name>
        <param-value>true</param-value> <!-- true (default), false -->
      </init-param>
      <init-param>
        <param-name>verifiesHtmlResource</param-name>
        <param-value>false</param-value> <!-- true, false (default) -->
      </init-param>
    </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>

### (Other) Rack Applications

The main difference when using a non-Rails Rack application is that JRuby-Rack
looks for a "rackup" file named **config.ru** in  `WEB-INF/config.ru` or
`WEB-INF/*/config.ru`. Here's a sample *web.xml* configuration :

    <filter>
      <filter-name>RackFilter</filter-name>
      <filter-class>org.jruby.rack.RackFilter</filter-class>
      <!-- optional filter configuration init-params (@see above) -->
    </filter>
    <filter-mapping>
      <filter-name>RackFilter</filter-name>
      <url-pattern>/*</url-pattern>
    </filter-mapping>

    <listener>
      <listener-class>org.jruby.rack.RackServletContextListener</listener-class>
    </listener>

If you don't have a *config.ru* or don't want to include it in your web app, you
can embed it directly in the *web.xml* as follows (using Sinatra as an example):

    <context-param>
      <param-name>rackup</param-name>
      <param-value>
        require 'rubygems'
        gem 'sinatra', '~&gt; 1.3'
        require './lib/app'
        set :run, false
        set :environment, :production
        run Sinatra::Application
      </param-value>
    </context-param>

Be sure to escape angle-brackets for XML !


## Servlet Filter

JRuby-Rack's main mode of operation is as a filter. This allows requests for
static content to pass through and be served by the application server.
Dynamic requests only happen for URLs that don't have a corresponding file, much
like many Ruby/Rack applications expect. The (default) filter we recommend
using is `org.jruby.rack.RackFilter`, the filter supports the following
(optional) init-params:

- **responseNotHandledStatuses** which statuses (when a filter chain returns)
  should be considered that the response has not been handled (default value:
  "403,404,405") and should be dispatched as a Rack application
- **resetUnhandledResponse** whether an unhandled response from the filter chain
  gets reset (accepts  values "true", "false" and "buffer" to reset the buffer
  only), by default "true"
- **addsHtmlToPathInfo** controls whether the .html suffix is added to the URI
  when checking if the request is for a static page
- **verifiesHtmlResource** used with the previous parameter to make sure the
  requested static resource exists before adding the .html request URI suffix

The application can also be configured to dispatch through a servlet instead of
a filter, the servlet class name is `org.jruby.rack.RackServlet`.

## Servlet Environment Integration

- servlet context is accessible to any application through the Rack environment
  variable *java.servlet_context* (as well as the `$servlet_context` global).
- the (native) servlet request and response objects could be obtained via the
  *java.servlet_request* and *java.servlet_response* keys
- all servlet request attributes are passed through to the Rack environment (and
  thus might override request headers or Rack environment variables)
- servlet sessions can be used as a (java) session store for Rails, session
  attributes with String keys (and String, numeric, boolean, or java
  object values) are automatically copied to the servlet session for you.

## Rails

Several aspects of Rails are automatically set up for you.

- `ActionController::Base.relative_url_root` is set for you automatically
  according to the context root where your webapp is deployed.
- `Rails.logger` output is redirected to the application server log.
- Page caching and asset directories are configured appropriately.

## JRuby Runtime Management

{'fraction_non_alphanumeric': 0.10134821013482101, 'fraction_numerical': 0.004339067100573377, 'mean_word_length': 3.6428057553956834, 'pattern_counts': {'":': 0, '<': 161, '<?xml version=': 0, '>': 161, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 8}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 2, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '156170', 'n_tokens_mistral': 3899, 'n_tokens_neox': 3680, 'n_words': 1389}