Rack Servlet Example: Jetty

A JRuby servlet for Rack applications.

License

License

Categories

Categories

Jetty Container Application Servers Square Business Logic Libraries Financial
GroupId

GroupId

com.squareup.rack
ArtifactId

ArtifactId

rack-servlet-example-jetty
Last Version

Last Version

1.8
Release Date

Release Date

Type

Type

jar
Description

Description

Rack Servlet Example: Jetty
A JRuby servlet for Rack applications.
Project Organization

Project Organization

Square, Inc.

Download rack-servlet-example-jetty

How to add to project

<!-- https://jarcasting.com/artifacts/com.squareup.rack/rack-servlet-example-jetty/ -->
<dependency>
    <groupId>com.squareup.rack</groupId>
    <artifactId>rack-servlet-example-jetty</artifactId>
    <version>1.8</version>
</dependency>
// https://jarcasting.com/artifacts/com.squareup.rack/rack-servlet-example-jetty/
implementation 'com.squareup.rack:rack-servlet-example-jetty:1.8'
// https://jarcasting.com/artifacts/com.squareup.rack/rack-servlet-example-jetty/
implementation ("com.squareup.rack:rack-servlet-example-jetty:1.8")
'com.squareup.rack:rack-servlet-example-jetty:jar:1.8'
<dependency org="com.squareup.rack" name="rack-servlet-example-jetty" rev="1.8">
  <artifact name="rack-servlet-example-jetty" type="jar" />
</dependency>
@Grapes(
@Grab(group='com.squareup.rack', module='rack-servlet-example-jetty', version='1.8')
)
libraryDependencies += "com.squareup.rack" % "rack-servlet-example-jetty" % "1.8"
[com.squareup.rack/rack-servlet-example-jetty "1.8"]

Dependencies

compile (4)

Group / Artifact Type Version
com.squareup.rack : rack-servlet jar 1.8
org.eclipse.jetty : jetty-server jar 9.0.4.v20130625
org.eclipse.jetty : jetty-servlet jar 9.0.4.v20130625
org.jruby : jruby-complete jar 1.7.4

test (4)

Group / Artifact Type Version
junit : junit jar 4.10
org.apache.httpcomponents : httpclient jar 4.2.1
org.easytesting : fest-assert-core jar 2.0M10
org.slf4j : slf4j-simple jar 1.7.5

Project Modules

There are no modules declared in this project.

Rack Servlet Build Status

Embed JRuby Rack applications in your Java container.

Download

In a Maven project, add rack-servlet and jruby-complete to your pom.xml:

<dependencies>
  <dependency>
    <groupId>com.squareup.rack</groupId>
    <artifactId>rack-servlet</artifactId>
    <version>${rack.servlet.version}</version>
  </dependency>
  <dependency>
    <groupId>org.jruby</groupId>
    <artifactId>jruby-complete</artifactId>
    <version>${jruby.version}</version>
  </dependency>
</dependencies>

Quick Start

// Use JRuby to build your Rack application:
ScriptingContainer ruby = new ScriptingContainer();
IRubyObject application = ruby.parse("lambda { |env| [200, {}, ['Hello, World!']] }").run();

// Build a RackServlet with that Rack application:
Servlet servlet = new RackServlet(new JRubyRackApplication(application));

// Install that servlet in your container...
// (See our examples directory for concrete code.)

In Depth

  • Gems: You can use the gem-maven-plugin to put gems in your pom.xml on your test classpath. For production deployments, you'll need to be a little more clever.
  • Frameworks: We're successfully running Sinatra applications on Rack Servlet. We've not yet tried Rails. At any rate, you'll need to make separate arrangements for any database connections you may need.
  • Logging: rack.logger and rack.errors use slf4j, so that you can choose your logging backend. Log messages are written to com.squareup.rack.RackLogger and com.squareup.rack.RackErrors, respectively.

Support

Alternatives

Rack Servlet grew out of our desire to embed Rack applications in Square's Java service container, in order to take advantage of our sophisticated infrastructure.

There are other options in the "run Rack applications on the JVM" space, all of which are shaped somewhat differently:

  • Kirk is a Rack server, like Mongrel or Unicorn.
  • Warbler bundles your Rack application into a WAR file.
  • jruby-rack is close in intent to Rack Servlet. It offers amazing support for instantiating and pooling your Rack application objects, though its custom embedding story is less clear.
com.squareup.rack

Square

Versions

Version
1.8
1.7
1.6
1.5
1.4
1.3
1.2
1.1
1.0