SlideShare a Scribd company logo
Spring into Rails
Hiro Asari
Engine Yard, Inc.
Imagine…


Maintaining enterprise
web application written
in Java…
Imagine…
public class FooTest {
    static Foo foo;

    public FooTest() {
    }

    @BeforeClass
    public static void setUpClass() throws Exception {
    }

    @AfterClass
    public static void tearDownClass() throws Exception {
    }

    @Before
    public void setUp() {
        foo = new Foo();
    }

    @Test
    public void testReturn42() {
        assertEquals(…, …);

    }
}
public class FooTest {
    static Foo foo;

    public FooTest() {
    }

    @BeforeClass
    public static void setUpClass() throws Exception {
    }

    @AfterClass
    public static void tearDownClass() throws Exception {
    }

    @Before
    public void setUp() {
        foo = new Foo();
    }

    @Test
    public void testReturn42() {
        assertEquals(42, foo.return42());

    }
}
public class FooTest {
    static Foo foo;

    public FooTest() {
    }

    @BeforeClass
    public static void setUpClass() throws Exception {
    }

    @AfterClass
    public static void tearDownClass() throws Exception {
    }

    @Before
    public void setUp() {
        foo = new Foo();
    }

    @Test
    public void testReturn42() {
        assertEquals(42, foo.return42());
        # or is it assertEquals(foo.return42(), 42) ?
    }
}
What if…


You didn’t have to
write in Java?
JRuby
A Ruby language
implementation on JVM

10 years (+ 1 day) since
the first recorded commit

Supporting Rails since
May, 2006

Latest release is 1.6.4 (22
August, 2011)
JRuby Jam Session




            15:00 BST 15 Setembro, 2011
  http://pages.engineyard.com/JRubyInDepth.html
Warbler

From a Ruby/Rails/
Merb/Rack application,
create a WAR file for
use with Java
application container
such as Tomcat and
Glassfish


                    http://www.pbase.com/wwcsig/image/59657656
Application Servers


Trinidad (Tomcat-based)

TorqueBox (JBoss-based)

Kirk (Jetty-based)
$ jruby -S bundle install
Using backports (2.0.3)
Using builder (3.0.0)
⋮
Using cucumber (0.10.2)
Using cucumber-rails (0.4.0)
Using database_cleaner (0.6.6)
Using launchy (1.0.0) from https://github.com/copiousfreetime/launchy.git (at v1.0.0)
Using monkey-lib (0.5.4)
Using rspec-core (2.1.0)
Using rspec-expectations (2.1.0)
Using rspec-mocks (2.1.0)
Using rspec (2.1.0)
Using rspec-rails (2.1.0)
Using tilt (1.2.2)
Using sinatra (1.2.1)
Using sinatra-sugar (0.5.0)
Using sinatra-advanced-routes (0.5.1)
Using sinatra-reloader (0.5.0)
Using spoon (0.0.1)
Using bundler (1.0.17)
Your bundle is complete! It was installed into ./bundler
Rack

http://rack.rubyforge.org/

Specifications for how Ruby-based web
applications should behave

jruby-rack 1.0.10 (based on rack 1.3.2)
Pet Clinic


             Example database-
             backed web app for
             Spring framework
Enterprise software


Long-running projects with legacy codebases

  Easy maintenance is important

  Testing is critical
Refactoring


Write test first
RSpec


http://relishapp.com/rspec

Behavior-driven development tool for Ruby
RSpec
# bowling_spec.rb
require 'bowling'

describe Bowling, "#score" do
  it "returns 0 for all gutter game" do
    bowling = Bowling.new
    20.times { bowling.hit(0) }
    bowling.score.should == 0
  end
end
Cucumber


http://cukes.info

Testing framework for describing software
behavior in plain English
Cucumber
Feature: Pets

  Scenario: Edit Pet
    Given I am on the owners search page
    And I press "Find Owners"
    And I follow "George Franklin"
    And I follow "Edit Pet"
    When I fill in "Name" with "Leoni"
    And press "Update Pet"
    Then I should see "Leoni"
http://bit.ly/refactoring-to-rails
Small refactoring
Give Ruby a foot in the door
Requests



/   /vets       Java/
                Spring

    App
Requests


                     JRuby

/   /vets   /rack/   Java/
                     Spring

    App
Cucumber test
diff --git a/src/main/webapp/WEB-INF/jsp/vets.jsp b/src/main/webapp/WEB-INF/jsp/vets.jsp
index cff2154..0d99817 100644
--- a/src/main/webapp/WEB-INF/jsp/vets.jsp
+++ b/src/main/webapp/WEB-INF/jsp/vets.jsp
@@ -23,7 +23,7 @@
  <table class="table-buttons">
    <tr>
      <td>
-        <a href="<spring:url value="/vets.xml" htmlEscape="true" />">View as XML</a>
+        <a href="<spring:url value="/rack/vets.xml" htmlEscape="true" />">View as XML</a>
      </td>
    </tr>
  </table>
Cucumber test
Stand by while Tomcat finishes booting...
Using the default profile...
............................................................F-.............

(::) failed steps (::)

expected: /xml/,
      got: "text/html;charset=utf-8" (using =~)
Diff:
@@ -1,2 +1,2 @@
-/xml/
+text/html;charset=utf-8
 (RSpec::Expectations::ExpectationNotMetError)
org/jruby/RubyProc.java:268:in `call'
./features/step_definitions/xml_json_steps.rb:12:in `(root)':in `/^I should see
an XML document$/'
features/vets.feature:6:in `Then I should see an XML document'

Failing Scenarios:
cucumber features/vets.feature:3 # Scenario: View vets as XML

13 scenarios (1 failed, 12 passed)
75 steps (1 failed, 1 skipped, 73 passed)
0m7.709s
rake aborted!
Cucumber failed
diff --git a/pom.xml b/pom.xml
index 9e22f83..0810701 100644
--- a/pom.xml
+++ b/pom.xml
@@ -211,6 +211,18 @@
                        <scope>provided</scope>
                </dependency>

+                <!-- JRuby and JRuby-Rack -->
+                <dependency>
+                        <groupId>org.jruby</groupId>
+                        <artifactId>jruby-complete</artifactId>
+                        <version>1.6.0</version>
+                </dependency>
+                <dependency>
+                        <groupId>org.jruby.rack</groupId>
+                        <artifactId>jruby-rack</artifactId>
+                        <version>1.0.8</version>
+                </dependency>
+
                <!-- Test dependencies -->
                <dependency>
                        <groupId>org.junit</groupId>
diff --git a/src/main/webapp/WEB-INF/web.xml b/src/main/webapp/WEB-INF/web.xml
index 8d02684..60ed6cb 100644
--- a/src/main/webapp/WEB-INF/web.xml
+++ b/src/main/webapp/WEB-INF/web.xml
@@ -87,6 +87,21 @@
        <listener>
                <listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>
        </listener>
+
+        <listener>
+                <listener-class>org.jruby.rack.RackServletContextListener</listener-class>
+        </listener>
+
+        <servlet>
+                <servlet-name>rack</servlet-name>
+                <servlet-class>org.jruby.rack.RackServlet</servlet-class>
+        </servlet>
+
+        <servlet-mapping>
+                <servlet-name>rack</servlet-name>
+                <url-pattern>/rack/*</url-pattern>
+        </servlet-mapping>
+

        <!--
                Defines the 'default' servlet (usually for service static resources).
diff --git a/src/main/webapp/WEB-INF/lib/app.rb b/src/main/webapp/WEB-INF/lib/
app.rb
index 6ab5b3c..4398fb4 100644
--- a/src/main/webapp/WEB-INF/lib/app.rb
+++ b/src/main/webapp/WEB-INF/lib/app.rb
@@ -1,6 +1,33 @@
  require 'builder'
  require 'erb'
+require 'spring_helpers'
+
+helpers do
+ include Spring
+end

 get '/rack/' do
   '<h1>Sinatra</h1>'
 end
+
+get '/rack/vets.xml' do
+ content_type 'application/vnd.petclinic+xml'
+ builder do |xml|
+    xml.instruct!
+    xml.vets do
+      clinic.vets.each do |vet|
+        xml.vetList do
+          xml.id vet.id
+          xml.firstName vet.firstName
+          xml.lastName vet.lastName
+          vet.specialties.each do |spec|
+            xml.specialties do
+              xml.id spec.id
+              xml.name spec.name
+            end
+          end
+        end
+      end
+    end
+ end
+end
Medium refactoring
Layer on the Rails
Requests


                     JRuby

/   /vets   /rack/   Java/
                     Spring

    App
Requests




                      /owners    Java/
/   /vets   /owners    /1/pets   Spring


        App
Requests



/   /vets                        JRuby

                      /owners    Java/
/   /vets   /owners    /1/pets   Spring


        App
diff --git a/src/main/webapp/WEB-INF/web.xml b/src/main/webapp/WEB-INF/web.xml
index 60ed6cb..f64b34d 100644
--- a/src/main/webapp/WEB-INF/web.xml
+++ b/src/main/webapp/WEB-INF/web.xml
@@ -92,16 +92,6 @@
                 <listener-class>org.jruby.rack.RackServletContextListener</listener-class>
         </listener>

-        <servlet>
-                <servlet-name>rack</servlet-name>
-                <servlet-class>org.jruby.rack.RackServlet</servlet-class>
-        </servlet>
-
-        <servlet-mapping>
-                <servlet-name>rack</servlet-name>
-                <url-pattern>/rack/*</url-pattern>
-        </servlet-mapping>
-

        <!--
                Defines the 'default' servlet (usually for service static resources).
@@ -162,6 +152,16 @@
                <url-pattern>/</url-pattern>
        </servlet-mapping>

+        <filter>
+                <filter-name>RackFilter</filter-name>
+                <filter-class>org.jruby.rack.RubyFirstRackFilter</filter-class>
+        </filter>
+
+        <filter-mapping>
+                <filter-name>RackFilter</filter-name>
+                <url-pattern>/*</url-pattern>
+        </filter-mapping>
+
        <filter>
                   <filter-name>httpMethodFilter</filter-name>
                   <filter-class>org.springframework.web.filter.HiddenHttpMethodFilter</filter-class>
Large refactoring
Full-on Rails development
Large refactoring

Change directory structure; move files from
WEB-INF/* to Rails directory structure

In Rails initializer, create a Spring context to boot
the Spring app

Ensure classpath includes Spring jars.
Large refactoring


Configure warbler to ensure necessary files are
included in WAR file
TMTOWTDI
                           <html>
                             <head>
                             </head>
                  JSP        <body>
                               ###
                             </body>
Mixing JSP and             </html>
JRuby output       +

                           <div>
                 Sinatra     <h1>App</h1>
                           </div>
Questions?
          Twitter @hiro_asari
      G+ http://gplus.to/hiroasari
LinkedIn http://linkedin.com/in/hiroasari

         asari.ruby@gmail.com
        hasari@engineyard.com

     http://github.com/banzaiman

                                            http://www.flickr.com/photos/42033648@N00/372887164
Obligado!
          Twitter @hiro_asari
      G+ http://gplus.to/hiroasari
LinkedIn http://linkedin.com/in/hiroasari

         asari.ruby@gmail.com
        hasari@engineyard.com

     http://github.com/banzaiman

                                            http://www.flickr.com/photos/42033648@N00/372887164

More Related Content

What's hot

Why Doesn't Java Has Instant Turnaround - Con-FESS 2012
Why Doesn't Java Has Instant Turnaround - Con-FESS 2012Why Doesn't Java Has Instant Turnaround - Con-FESS 2012
Why Doesn't Java Has Instant Turnaround - Con-FESS 2012Anton Arhipov
 
Mastering java bytecode with ASM - GeeCON 2012
Mastering java bytecode with ASM - GeeCON 2012Mastering java bytecode with ASM - GeeCON 2012
Mastering java bytecode with ASM - GeeCON 2012Anton Arhipov
 
Easy Enterprise Integration Patterns with Apache Camel, ActiveMQ and ServiceMix
Easy Enterprise Integration Patterns with Apache Camel, ActiveMQ and ServiceMixEasy Enterprise Integration Patterns with Apache Camel, ActiveMQ and ServiceMix
Easy Enterprise Integration Patterns with Apache Camel, ActiveMQ and ServiceMixelliando dias
 
Soft-Shake 2016 : Jigsaw est prêt à tuer le classpath
Soft-Shake 2016 : Jigsaw  est prêt à tuer le classpathSoft-Shake 2016 : Jigsaw  est prêt à tuer le classpath
Soft-Shake 2016 : Jigsaw est prêt à tuer le classpath
Alexis Hassler
 
Oredev 2015 - Taming Java Agents
Oredev 2015 - Taming Java AgentsOredev 2015 - Taming Java Agents
Oredev 2015 - Taming Java Agents
Anton Arhipov
 
ZK_Arch_notes_20081121
ZK_Arch_notes_20081121ZK_Arch_notes_20081121
ZK_Arch_notes_20081121WANGCHOU LU
 
Ruby on Rails survival guide of an aged Java developer
Ruby on Rails survival guide of an aged Java developerRuby on Rails survival guide of an aged Java developer
Ruby on Rails survival guide of an aged Java developer
gicappa
 
Debugging on rails
Debugging on railsDebugging on rails
Debugging on rails
Mykhaylo Sorochan
 
Taking Apache Camel For A Ride
Taking Apache Camel For A RideTaking Apache Camel For A Ride
Taking Apache Camel For A Ride
Bruce Snyder
 
Aura Project for PHP
Aura Project for PHPAura Project for PHP
Aura Project for PHPHari K T
 
Remedie: Building a desktop app with HTTP::Engine, SQLite and jQuery
Remedie: Building a desktop app with HTTP::Engine, SQLite and jQueryRemedie: Building a desktop app with HTTP::Engine, SQLite and jQuery
Remedie: Building a desktop app with HTTP::Engine, SQLite and jQueryTatsuhiko Miyagawa
 
Mashups with Drupal and QueryPath
Mashups with Drupal and QueryPathMashups with Drupal and QueryPath
Mashups with Drupal and QueryPath
Matt Butcher
 
Getting started with ES6 : Future of javascript
Getting started with ES6 : Future of javascriptGetting started with ES6 : Future of javascript
Getting started with ES6 : Future of javascript
Mohd Saeed
 
Con-FESS 2015 - Having Fun With Javassist
Con-FESS 2015 - Having Fun With JavassistCon-FESS 2015 - Having Fun With Javassist
Con-FESS 2015 - Having Fun With Javassist
Anton Arhipov
 
Immutant
ImmutantImmutant
Immutant
Norman Richards
 
PyCon US 2012 - State of WSGI 2
PyCon US 2012 - State of WSGI 2PyCon US 2012 - State of WSGI 2
PyCon US 2012 - State of WSGI 2Graham Dumpleton
 
LyonJUG : Comment Jigsaw est prêt à tuer le classpath
LyonJUG : Comment Jigsaw est prêt à tuer le classpathLyonJUG : Comment Jigsaw est prêt à tuer le classpath
LyonJUG : Comment Jigsaw est prêt à tuer le classpath
Alexis Hassler
 
Intro to PSGI and Plack
Intro to PSGI and PlackIntro to PSGI and Plack
Intro to PSGI and Plack
Tatsuhiko Miyagawa
 

What's hot (20)

Why Doesn't Java Has Instant Turnaround - Con-FESS 2012
Why Doesn't Java Has Instant Turnaround - Con-FESS 2012Why Doesn't Java Has Instant Turnaround - Con-FESS 2012
Why Doesn't Java Has Instant Turnaround - Con-FESS 2012
 
Mastering java bytecode with ASM - GeeCON 2012
Mastering java bytecode with ASM - GeeCON 2012Mastering java bytecode with ASM - GeeCON 2012
Mastering java bytecode with ASM - GeeCON 2012
 
Easy Enterprise Integration Patterns with Apache Camel, ActiveMQ and ServiceMix
Easy Enterprise Integration Patterns with Apache Camel, ActiveMQ and ServiceMixEasy Enterprise Integration Patterns with Apache Camel, ActiveMQ and ServiceMix
Easy Enterprise Integration Patterns with Apache Camel, ActiveMQ and ServiceMix
 
Soft-Shake 2016 : Jigsaw est prêt à tuer le classpath
Soft-Shake 2016 : Jigsaw  est prêt à tuer le classpathSoft-Shake 2016 : Jigsaw  est prêt à tuer le classpath
Soft-Shake 2016 : Jigsaw est prêt à tuer le classpath
 
Oredev 2015 - Taming Java Agents
Oredev 2015 - Taming Java AgentsOredev 2015 - Taming Java Agents
Oredev 2015 - Taming Java Agents
 
Scala active record
Scala active recordScala active record
Scala active record
 
ZK_Arch_notes_20081121
ZK_Arch_notes_20081121ZK_Arch_notes_20081121
ZK_Arch_notes_20081121
 
Ruby on Rails survival guide of an aged Java developer
Ruby on Rails survival guide of an aged Java developerRuby on Rails survival guide of an aged Java developer
Ruby on Rails survival guide of an aged Java developer
 
Debugging on rails
Debugging on railsDebugging on rails
Debugging on rails
 
Taking Apache Camel For A Ride
Taking Apache Camel For A RideTaking Apache Camel For A Ride
Taking Apache Camel For A Ride
 
Aura Project for PHP
Aura Project for PHPAura Project for PHP
Aura Project for PHP
 
Remedie: Building a desktop app with HTTP::Engine, SQLite and jQuery
Remedie: Building a desktop app with HTTP::Engine, SQLite and jQueryRemedie: Building a desktop app with HTTP::Engine, SQLite and jQuery
Remedie: Building a desktop app with HTTP::Engine, SQLite and jQuery
 
Mashups with Drupal and QueryPath
Mashups with Drupal and QueryPathMashups with Drupal and QueryPath
Mashups with Drupal and QueryPath
 
Getting started with ES6 : Future of javascript
Getting started with ES6 : Future of javascriptGetting started with ES6 : Future of javascript
Getting started with ES6 : Future of javascript
 
Con-FESS 2015 - Having Fun With Javassist
Con-FESS 2015 - Having Fun With JavassistCon-FESS 2015 - Having Fun With Javassist
Con-FESS 2015 - Having Fun With Javassist
 
Immutant
ImmutantImmutant
Immutant
 
Rails Performance
Rails PerformanceRails Performance
Rails Performance
 
PyCon US 2012 - State of WSGI 2
PyCon US 2012 - State of WSGI 2PyCon US 2012 - State of WSGI 2
PyCon US 2012 - State of WSGI 2
 
LyonJUG : Comment Jigsaw est prêt à tuer le classpath
LyonJUG : Comment Jigsaw est prêt à tuer le classpathLyonJUG : Comment Jigsaw est prêt à tuer le classpath
LyonJUG : Comment Jigsaw est prêt à tuer le classpath
 
Intro to PSGI and Plack
Intro to PSGI and PlackIntro to PSGI and Plack
Intro to PSGI and Plack
 

Viewers also liked

Espacio geográfico y de la división político territorial
Espacio geográfico y de la división político territorialEspacio geográfico y de la división político territorial
Espacio geográfico y de la división político territorial
yjvp14
 
Espacios geografico
Espacios geograficoEspacios geografico
Espacios geografico
fundaescolar
 
Abraham,modelo de vision y amor
Abraham,modelo de vision y amorAbraham,modelo de vision y amor
Abraham,modelo de vision y amor
Ministerio Infantil Arcoiris
 
éL vivió entre nosotros 6 – ministerio de jesús #3
éL vivió entre nosotros 6 – ministerio de jesús #3éL vivió entre nosotros 6 – ministerio de jesús #3
éL vivió entre nosotros 6 – ministerio de jesús #3Ministerio Infantil Arcoiris
 
Clasificación de las redes
Clasificación de las redesClasificación de las redes
Clasificación de las redesRicardo Reyes
 
Tu verdadero valor
Tu verdadero valorTu verdadero valor
Tu verdadero valorEl del Alma
 
Vinayam
VinayamVinayam
Vinayam
nprasannam
 
Dn11 u3 a6_loc
Dn11 u3 a6_locDn11 u3 a6_loc
Dn11 u3 a6_loccrisktti
 
Gramaticas
GramaticasGramaticas
Gramaticas
Jose Ibadango
 
Contribuciones espeeciales
Contribuciones  espeecialesContribuciones  espeeciales
Contribuciones espeeciales
carola71prada
 
Vgu PräSentation 19.11.2008 Vgu Rieck
Vgu PräSentation 19.11.2008 Vgu RieckVgu PräSentation 19.11.2008 Vgu Rieck
Vgu PräSentation 19.11.2008 Vgu Rieckguestadb71d
 

Viewers also liked (20)

Espacio geográfico y de la división político territorial
Espacio geográfico y de la división político territorialEspacio geográfico y de la división político territorial
Espacio geográfico y de la división político territorial
 
Espacios geografico
Espacios geograficoEspacios geografico
Espacios geografico
 
Año 1 semana-2
Año 1 semana-2Año 1 semana-2
Año 1 semana-2
 
Abraham,modelo de vision y amor
Abraham,modelo de vision y amorAbraham,modelo de vision y amor
Abraham,modelo de vision y amor
 
4 chamado permanente -español-
4 chamado permanente -español-4 chamado permanente -español-
4 chamado permanente -español-
 
éL vivió entre nosotros 6 – ministerio de jesús #3
éL vivió entre nosotros 6 – ministerio de jesús #3éL vivió entre nosotros 6 – ministerio de jesús #3
éL vivió entre nosotros 6 – ministerio de jesús #3
 
Ruth a love story spanish pda
Ruth a love story spanish pdaRuth a love story spanish pda
Ruth a love story spanish pda
 
Dialeb Review_Issue 5_Nov 2016
Dialeb Review_Issue 5_Nov 2016Dialeb Review_Issue 5_Nov 2016
Dialeb Review_Issue 5_Nov 2016
 
Clasificación de las redes
Clasificación de las redesClasificación de las redes
Clasificación de las redes
 
Calidad mu
Calidad muCalidad mu
Calidad mu
 
William Gilbert
William GilbertWilliam Gilbert
William Gilbert
 
13 joias -español-
13 joias -español-13 joias -español-
13 joias -español-
 
Tu verdadero valor
Tu verdadero valorTu verdadero valor
Tu verdadero valor
 
Weihnachtstradition
WeihnachtstraditionWeihnachtstradition
Weihnachtstradition
 
Dios te bendiga
Dios te bendigaDios te bendiga
Dios te bendiga
 
Vinayam
VinayamVinayam
Vinayam
 
Dn11 u3 a6_loc
Dn11 u3 a6_locDn11 u3 a6_loc
Dn11 u3 a6_loc
 
Gramaticas
GramaticasGramaticas
Gramaticas
 
Contribuciones espeeciales
Contribuciones  espeecialesContribuciones  espeeciales
Contribuciones espeeciales
 
Vgu PräSentation 19.11.2008 Vgu Rieck
Vgu PräSentation 19.11.2008 Vgu RieckVgu PräSentation 19.11.2008 Vgu Rieck
Vgu PräSentation 19.11.2008 Vgu Rieck
 

Similar to Spring into rails

Play vs Rails
Play vs RailsPlay vs Rails
Play vs Rails
Daniel Cukier
 
Servlets 3.0 - Asynchronous, Extensibility, Ease-of-use @ JavaOne Brazil 2010
Servlets 3.0 - Asynchronous, Extensibility, Ease-of-use @ JavaOne Brazil 2010Servlets 3.0 - Asynchronous, Extensibility, Ease-of-use @ JavaOne Brazil 2010
Servlets 3.0 - Asynchronous, Extensibility, Ease-of-use @ JavaOne Brazil 2010
Arun Gupta
 
Java EE 6 - Deep Dive - Indic Threads, Pune - 2010
Java EE 6 - Deep Dive - Indic Threads, Pune - 2010Java EE 6 - Deep Dive - Indic Threads, Pune - 2010
Java EE 6 - Deep Dive - Indic Threads, Pune - 2010Jagadish Prasath
 
Java EE 6 = Less Code + More Power (Tutorial) [5th IndicThreads Conference O...
Java EE 6 = Less Code + More Power (Tutorial)  [5th IndicThreads Conference O...Java EE 6 = Less Code + More Power (Tutorial)  [5th IndicThreads Conference O...
Java EE 6 = Less Code + More Power (Tutorial) [5th IndicThreads Conference O...
IndicThreads
 
Boston 2011 OTN Developer Days - Java EE 6
Boston 2011 OTN Developer Days - Java EE 6Boston 2011 OTN Developer Days - Java EE 6
Boston 2011 OTN Developer Days - Java EE 6
Arun Gupta
 
Dropwizard and Friends
Dropwizard and FriendsDropwizard and Friends
Dropwizard and Friends
Yun Zhi Lin
 
JavaOne India 2011 - Servlets 3.0
JavaOne India 2011 - Servlets 3.0JavaOne India 2011 - Servlets 3.0
JavaOne India 2011 - Servlets 3.0
Arun Gupta
 
Android Automated Testing
Android Automated TestingAndroid Automated Testing
Android Automated Testing
roisagiv
 
Ajax, JSF, Facelets, Eclipse & Maven tutorials
Ajax, JSF, Facelets, Eclipse & Maven tutorialsAjax, JSF, Facelets, Eclipse & Maven tutorials
Ajax, JSF, Facelets, Eclipse & Maven tutorials
Raghavan Mohan
 
Asynchronous Interfaces
Asynchronous InterfacesAsynchronous Interfaces
Asynchronous Interfaces
maccman
 
JRuby + Rails = Awesome Java Web Framework at Jfokus 2011
JRuby + Rails = Awesome Java Web Framework at Jfokus 2011JRuby + Rails = Awesome Java Web Framework at Jfokus 2011
JRuby + Rails = Awesome Java Web Framework at Jfokus 2011Nick Sieger
 
Beyond DOMReady: Ultra High-Performance Javascript
Beyond DOMReady: Ultra High-Performance JavascriptBeyond DOMReady: Ultra High-Performance Javascript
Beyond DOMReady: Ultra High-Performance Javascript
aglemann
 
Using and scaling Rack and Rack-based middleware
Using and scaling Rack and Rack-based middlewareUsing and scaling Rack and Rack-based middleware
Using and scaling Rack and Rack-based middleware
Alona Mekhovova
 
Gradle: The Build system you have been waiting for
Gradle: The Build system you have been waiting forGradle: The Build system you have been waiting for
Gradle: The Build system you have been waiting for
Corneil du Plessis
 
GeeCON 2017 - TestContainers. Integration testing without the hassle
GeeCON 2017 - TestContainers. Integration testing without the hassleGeeCON 2017 - TestContainers. Integration testing without the hassle
GeeCON 2017 - TestContainers. Integration testing without the hassle
Anton Arhipov
 
Pom
PomPom
Pom
akmini
 
Pom configuration java xml
Pom configuration java xmlPom configuration java xml
Pom configuration java xml
akmini
 
Belfast JUG 23-10-2013
Belfast JUG 23-10-2013Belfast JUG 23-10-2013
Belfast JUG 23-10-2013
eamonnlong
 
Innovation and Security in Ruby on Rails
Innovation and Security in Ruby on RailsInnovation and Security in Ruby on Rails
Innovation and Security in Ruby on Railstielefeld
 
Automated Java Deployments With Rpm
Automated Java Deployments With RpmAutomated Java Deployments With Rpm
Automated Java Deployments With Rpm
Martin Jackson
 

Similar to Spring into rails (20)

Play vs Rails
Play vs RailsPlay vs Rails
Play vs Rails
 
Servlets 3.0 - Asynchronous, Extensibility, Ease-of-use @ JavaOne Brazil 2010
Servlets 3.0 - Asynchronous, Extensibility, Ease-of-use @ JavaOne Brazil 2010Servlets 3.0 - Asynchronous, Extensibility, Ease-of-use @ JavaOne Brazil 2010
Servlets 3.0 - Asynchronous, Extensibility, Ease-of-use @ JavaOne Brazil 2010
 
Java EE 6 - Deep Dive - Indic Threads, Pune - 2010
Java EE 6 - Deep Dive - Indic Threads, Pune - 2010Java EE 6 - Deep Dive - Indic Threads, Pune - 2010
Java EE 6 - Deep Dive - Indic Threads, Pune - 2010
 
Java EE 6 = Less Code + More Power (Tutorial) [5th IndicThreads Conference O...
Java EE 6 = Less Code + More Power (Tutorial)  [5th IndicThreads Conference O...Java EE 6 = Less Code + More Power (Tutorial)  [5th IndicThreads Conference O...
Java EE 6 = Less Code + More Power (Tutorial) [5th IndicThreads Conference O...
 
Boston 2011 OTN Developer Days - Java EE 6
Boston 2011 OTN Developer Days - Java EE 6Boston 2011 OTN Developer Days - Java EE 6
Boston 2011 OTN Developer Days - Java EE 6
 
Dropwizard and Friends
Dropwizard and FriendsDropwizard and Friends
Dropwizard and Friends
 
JavaOne India 2011 - Servlets 3.0
JavaOne India 2011 - Servlets 3.0JavaOne India 2011 - Servlets 3.0
JavaOne India 2011 - Servlets 3.0
 
Android Automated Testing
Android Automated TestingAndroid Automated Testing
Android Automated Testing
 
Ajax, JSF, Facelets, Eclipse & Maven tutorials
Ajax, JSF, Facelets, Eclipse & Maven tutorialsAjax, JSF, Facelets, Eclipse & Maven tutorials
Ajax, JSF, Facelets, Eclipse & Maven tutorials
 
Asynchronous Interfaces
Asynchronous InterfacesAsynchronous Interfaces
Asynchronous Interfaces
 
JRuby + Rails = Awesome Java Web Framework at Jfokus 2011
JRuby + Rails = Awesome Java Web Framework at Jfokus 2011JRuby + Rails = Awesome Java Web Framework at Jfokus 2011
JRuby + Rails = Awesome Java Web Framework at Jfokus 2011
 
Beyond DOMReady: Ultra High-Performance Javascript
Beyond DOMReady: Ultra High-Performance JavascriptBeyond DOMReady: Ultra High-Performance Javascript
Beyond DOMReady: Ultra High-Performance Javascript
 
Using and scaling Rack and Rack-based middleware
Using and scaling Rack and Rack-based middlewareUsing and scaling Rack and Rack-based middleware
Using and scaling Rack and Rack-based middleware
 
Gradle: The Build system you have been waiting for
Gradle: The Build system you have been waiting forGradle: The Build system you have been waiting for
Gradle: The Build system you have been waiting for
 
GeeCON 2017 - TestContainers. Integration testing without the hassle
GeeCON 2017 - TestContainers. Integration testing without the hassleGeeCON 2017 - TestContainers. Integration testing without the hassle
GeeCON 2017 - TestContainers. Integration testing without the hassle
 
Pom
PomPom
Pom
 
Pom configuration java xml
Pom configuration java xmlPom configuration java xml
Pom configuration java xml
 
Belfast JUG 23-10-2013
Belfast JUG 23-10-2013Belfast JUG 23-10-2013
Belfast JUG 23-10-2013
 
Innovation and Security in Ruby on Rails
Innovation and Security in Ruby on RailsInnovation and Security in Ruby on Rails
Innovation and Security in Ruby on Rails
 
Automated Java Deployments With Rpm
Automated Java Deployments With RpmAutomated Java Deployments With Rpm
Automated Java Deployments With Rpm
 

Recently uploaded

FIDO Alliance Osaka Seminar: Passkeys at Amazon.pdf
FIDO Alliance Osaka Seminar: Passkeys at Amazon.pdfFIDO Alliance Osaka Seminar: Passkeys at Amazon.pdf
FIDO Alliance Osaka Seminar: Passkeys at Amazon.pdf
FIDO Alliance
 
De-mystifying Zero to One: Design Informed Techniques for Greenfield Innovati...
De-mystifying Zero to One: Design Informed Techniques for Greenfield Innovati...De-mystifying Zero to One: Design Informed Techniques for Greenfield Innovati...
De-mystifying Zero to One: Design Informed Techniques for Greenfield Innovati...
Product School
 
Welocme to ViralQR, your best QR code generator.
Welocme to ViralQR, your best QR code generator.Welocme to ViralQR, your best QR code generator.
Welocme to ViralQR, your best QR code generator.
ViralQR
 
State of ICS and IoT Cyber Threat Landscape Report 2024 preview
State of ICS and IoT Cyber Threat Landscape Report 2024 previewState of ICS and IoT Cyber Threat Landscape Report 2024 preview
State of ICS and IoT Cyber Threat Landscape Report 2024 preview
Prayukth K V
 
Elizabeth Buie - Older adults: Are we really designing for our future selves?
Elizabeth Buie - Older adults: Are we really designing for our future selves?Elizabeth Buie - Older adults: Are we really designing for our future selves?
Elizabeth Buie - Older adults: Are we really designing for our future selves?
Nexer Digital
 
Le nuove frontiere dell'AI nell'RPA con UiPath Autopilot™
Le nuove frontiere dell'AI nell'RPA con UiPath Autopilot™Le nuove frontiere dell'AI nell'RPA con UiPath Autopilot™
Le nuove frontiere dell'AI nell'RPA con UiPath Autopilot™
UiPathCommunity
 
Essentials of Automations: Optimizing FME Workflows with Parameters
Essentials of Automations: Optimizing FME Workflows with ParametersEssentials of Automations: Optimizing FME Workflows with Parameters
Essentials of Automations: Optimizing FME Workflows with Parameters
Safe Software
 
SAP Sapphire 2024 - ASUG301 building better apps with SAP Fiori.pdf
SAP Sapphire 2024 - ASUG301 building better apps with SAP Fiori.pdfSAP Sapphire 2024 - ASUG301 building better apps with SAP Fiori.pdf
SAP Sapphire 2024 - ASUG301 building better apps with SAP Fiori.pdf
Peter Spielvogel
 
GDG Cloud Southlake #33: Boule & Rebala: Effective AppSec in SDLC using Deplo...
GDG Cloud Southlake #33: Boule & Rebala: Effective AppSec in SDLC using Deplo...GDG Cloud Southlake #33: Boule & Rebala: Effective AppSec in SDLC using Deplo...
GDG Cloud Southlake #33: Boule & Rebala: Effective AppSec in SDLC using Deplo...
James Anderson
 
Key Trends Shaping the Future of Infrastructure.pdf
Key Trends Shaping the Future of Infrastructure.pdfKey Trends Shaping the Future of Infrastructure.pdf
Key Trends Shaping the Future of Infrastructure.pdf
Cheryl Hung
 
Generative AI Deep Dive: Advancing from Proof of Concept to Production
Generative AI Deep Dive: Advancing from Proof of Concept to ProductionGenerative AI Deep Dive: Advancing from Proof of Concept to Production
Generative AI Deep Dive: Advancing from Proof of Concept to Production
Aggregage
 
Securing your Kubernetes cluster_ a step-by-step guide to success !
Securing your Kubernetes cluster_ a step-by-step guide to success !Securing your Kubernetes cluster_ a step-by-step guide to success !
Securing your Kubernetes cluster_ a step-by-step guide to success !
KatiaHIMEUR1
 
FIDO Alliance Osaka Seminar: The WebAuthn API and Discoverable Credentials.pdf
FIDO Alliance Osaka Seminar: The WebAuthn API and Discoverable Credentials.pdfFIDO Alliance Osaka Seminar: The WebAuthn API and Discoverable Credentials.pdf
FIDO Alliance Osaka Seminar: The WebAuthn API and Discoverable Credentials.pdf
FIDO Alliance
 
Builder.ai Founder Sachin Dev Duggal's Strategic Approach to Create an Innova...
Builder.ai Founder Sachin Dev Duggal's Strategic Approach to Create an Innova...Builder.ai Founder Sachin Dev Duggal's Strategic Approach to Create an Innova...
Builder.ai Founder Sachin Dev Duggal's Strategic Approach to Create an Innova...
Ramesh Iyer
 
A tale of scale & speed: How the US Navy is enabling software delivery from l...
A tale of scale & speed: How the US Navy is enabling software delivery from l...A tale of scale & speed: How the US Navy is enabling software delivery from l...
A tale of scale & speed: How the US Navy is enabling software delivery from l...
sonjaschweigert1
 
Free Complete Python - A step towards Data Science
Free Complete Python - A step towards Data ScienceFree Complete Python - A step towards Data Science
Free Complete Python - A step towards Data Science
RinaMondal9
 
LF Energy Webinar: Electrical Grid Modelling and Simulation Through PowSyBl -...
LF Energy Webinar: Electrical Grid Modelling and Simulation Through PowSyBl -...LF Energy Webinar: Electrical Grid Modelling and Simulation Through PowSyBl -...
LF Energy Webinar: Electrical Grid Modelling and Simulation Through PowSyBl -...
DanBrown980551
 
GenAISummit 2024 May 28 Sri Ambati Keynote: AGI Belongs to The Community in O...
GenAISummit 2024 May 28 Sri Ambati Keynote: AGI Belongs to The Community in O...GenAISummit 2024 May 28 Sri Ambati Keynote: AGI Belongs to The Community in O...
GenAISummit 2024 May 28 Sri Ambati Keynote: AGI Belongs to The Community in O...
Sri Ambati
 
GraphRAG is All You need? LLM & Knowledge Graph
GraphRAG is All You need? LLM & Knowledge GraphGraphRAG is All You need? LLM & Knowledge Graph
GraphRAG is All You need? LLM & Knowledge Graph
Guy Korland
 
The Future of Platform Engineering
The Future of Platform EngineeringThe Future of Platform Engineering
The Future of Platform Engineering
Jemma Hussein Allen
 

Recently uploaded (20)

FIDO Alliance Osaka Seminar: Passkeys at Amazon.pdf
FIDO Alliance Osaka Seminar: Passkeys at Amazon.pdfFIDO Alliance Osaka Seminar: Passkeys at Amazon.pdf
FIDO Alliance Osaka Seminar: Passkeys at Amazon.pdf
 
De-mystifying Zero to One: Design Informed Techniques for Greenfield Innovati...
De-mystifying Zero to One: Design Informed Techniques for Greenfield Innovati...De-mystifying Zero to One: Design Informed Techniques for Greenfield Innovati...
De-mystifying Zero to One: Design Informed Techniques for Greenfield Innovati...
 
Welocme to ViralQR, your best QR code generator.
Welocme to ViralQR, your best QR code generator.Welocme to ViralQR, your best QR code generator.
Welocme to ViralQR, your best QR code generator.
 
State of ICS and IoT Cyber Threat Landscape Report 2024 preview
State of ICS and IoT Cyber Threat Landscape Report 2024 previewState of ICS and IoT Cyber Threat Landscape Report 2024 preview
State of ICS and IoT Cyber Threat Landscape Report 2024 preview
 
Elizabeth Buie - Older adults: Are we really designing for our future selves?
Elizabeth Buie - Older adults: Are we really designing for our future selves?Elizabeth Buie - Older adults: Are we really designing for our future selves?
Elizabeth Buie - Older adults: Are we really designing for our future selves?
 
Le nuove frontiere dell'AI nell'RPA con UiPath Autopilot™
Le nuove frontiere dell'AI nell'RPA con UiPath Autopilot™Le nuove frontiere dell'AI nell'RPA con UiPath Autopilot™
Le nuove frontiere dell'AI nell'RPA con UiPath Autopilot™
 
Essentials of Automations: Optimizing FME Workflows with Parameters
Essentials of Automations: Optimizing FME Workflows with ParametersEssentials of Automations: Optimizing FME Workflows with Parameters
Essentials of Automations: Optimizing FME Workflows with Parameters
 
SAP Sapphire 2024 - ASUG301 building better apps with SAP Fiori.pdf
SAP Sapphire 2024 - ASUG301 building better apps with SAP Fiori.pdfSAP Sapphire 2024 - ASUG301 building better apps with SAP Fiori.pdf
SAP Sapphire 2024 - ASUG301 building better apps with SAP Fiori.pdf
 
GDG Cloud Southlake #33: Boule & Rebala: Effective AppSec in SDLC using Deplo...
GDG Cloud Southlake #33: Boule & Rebala: Effective AppSec in SDLC using Deplo...GDG Cloud Southlake #33: Boule & Rebala: Effective AppSec in SDLC using Deplo...
GDG Cloud Southlake #33: Boule & Rebala: Effective AppSec in SDLC using Deplo...
 
Key Trends Shaping the Future of Infrastructure.pdf
Key Trends Shaping the Future of Infrastructure.pdfKey Trends Shaping the Future of Infrastructure.pdf
Key Trends Shaping the Future of Infrastructure.pdf
 
Generative AI Deep Dive: Advancing from Proof of Concept to Production
Generative AI Deep Dive: Advancing from Proof of Concept to ProductionGenerative AI Deep Dive: Advancing from Proof of Concept to Production
Generative AI Deep Dive: Advancing from Proof of Concept to Production
 
Securing your Kubernetes cluster_ a step-by-step guide to success !
Securing your Kubernetes cluster_ a step-by-step guide to success !Securing your Kubernetes cluster_ a step-by-step guide to success !
Securing your Kubernetes cluster_ a step-by-step guide to success !
 
FIDO Alliance Osaka Seminar: The WebAuthn API and Discoverable Credentials.pdf
FIDO Alliance Osaka Seminar: The WebAuthn API and Discoverable Credentials.pdfFIDO Alliance Osaka Seminar: The WebAuthn API and Discoverable Credentials.pdf
FIDO Alliance Osaka Seminar: The WebAuthn API and Discoverable Credentials.pdf
 
Builder.ai Founder Sachin Dev Duggal's Strategic Approach to Create an Innova...
Builder.ai Founder Sachin Dev Duggal's Strategic Approach to Create an Innova...Builder.ai Founder Sachin Dev Duggal's Strategic Approach to Create an Innova...
Builder.ai Founder Sachin Dev Duggal's Strategic Approach to Create an Innova...
 
A tale of scale & speed: How the US Navy is enabling software delivery from l...
A tale of scale & speed: How the US Navy is enabling software delivery from l...A tale of scale & speed: How the US Navy is enabling software delivery from l...
A tale of scale & speed: How the US Navy is enabling software delivery from l...
 
Free Complete Python - A step towards Data Science
Free Complete Python - A step towards Data ScienceFree Complete Python - A step towards Data Science
Free Complete Python - A step towards Data Science
 
LF Energy Webinar: Electrical Grid Modelling and Simulation Through PowSyBl -...
LF Energy Webinar: Electrical Grid Modelling and Simulation Through PowSyBl -...LF Energy Webinar: Electrical Grid Modelling and Simulation Through PowSyBl -...
LF Energy Webinar: Electrical Grid Modelling and Simulation Through PowSyBl -...
 
GenAISummit 2024 May 28 Sri Ambati Keynote: AGI Belongs to The Community in O...
GenAISummit 2024 May 28 Sri Ambati Keynote: AGI Belongs to The Community in O...GenAISummit 2024 May 28 Sri Ambati Keynote: AGI Belongs to The Community in O...
GenAISummit 2024 May 28 Sri Ambati Keynote: AGI Belongs to The Community in O...
 
GraphRAG is All You need? LLM & Knowledge Graph
GraphRAG is All You need? LLM & Knowledge GraphGraphRAG is All You need? LLM & Knowledge Graph
GraphRAG is All You need? LLM & Knowledge Graph
 
The Future of Platform Engineering
The Future of Platform EngineeringThe Future of Platform Engineering
The Future of Platform Engineering
 

Spring into rails

  • 1. Spring into Rails Hiro Asari Engine Yard, Inc.
  • 4. public class FooTest { static Foo foo; public FooTest() { } @BeforeClass public static void setUpClass() throws Exception { } @AfterClass public static void tearDownClass() throws Exception { } @Before public void setUp() { foo = new Foo(); } @Test public void testReturn42() { assertEquals(…, …); } }
  • 5. public class FooTest { static Foo foo; public FooTest() { } @BeforeClass public static void setUpClass() throws Exception { } @AfterClass public static void tearDownClass() throws Exception { } @Before public void setUp() { foo = new Foo(); } @Test public void testReturn42() { assertEquals(42, foo.return42()); } }
  • 6. public class FooTest { static Foo foo; public FooTest() { } @BeforeClass public static void setUpClass() throws Exception { } @AfterClass public static void tearDownClass() throws Exception { } @Before public void setUp() { foo = new Foo(); } @Test public void testReturn42() { assertEquals(42, foo.return42()); # or is it assertEquals(foo.return42(), 42) ? } }
  • 7. What if… You didn’t have to write in Java?
  • 8. JRuby A Ruby language implementation on JVM 10 years (+ 1 day) since the first recorded commit Supporting Rails since May, 2006 Latest release is 1.6.4 (22 August, 2011)
  • 9. JRuby Jam Session 15:00 BST 15 Setembro, 2011 http://pages.engineyard.com/JRubyInDepth.html
  • 10. Warbler From a Ruby/Rails/ Merb/Rack application, create a WAR file for use with Java application container such as Tomcat and Glassfish http://www.pbase.com/wwcsig/image/59657656
  • 11. Application Servers Trinidad (Tomcat-based) TorqueBox (JBoss-based) Kirk (Jetty-based)
  • 12. $ jruby -S bundle install Using backports (2.0.3) Using builder (3.0.0) ⋮ Using cucumber (0.10.2) Using cucumber-rails (0.4.0) Using database_cleaner (0.6.6) Using launchy (1.0.0) from https://github.com/copiousfreetime/launchy.git (at v1.0.0) Using monkey-lib (0.5.4) Using rspec-core (2.1.0) Using rspec-expectations (2.1.0) Using rspec-mocks (2.1.0) Using rspec (2.1.0) Using rspec-rails (2.1.0) Using tilt (1.2.2) Using sinatra (1.2.1) Using sinatra-sugar (0.5.0) Using sinatra-advanced-routes (0.5.1) Using sinatra-reloader (0.5.0) Using spoon (0.0.1) Using bundler (1.0.17) Your bundle is complete! It was installed into ./bundler
  • 13. Rack http://rack.rubyforge.org/ Specifications for how Ruby-based web applications should behave jruby-rack 1.0.10 (based on rack 1.3.2)
  • 14. Pet Clinic Example database- backed web app for Spring framework
  • 15. Enterprise software Long-running projects with legacy codebases Easy maintenance is important Testing is critical
  • 18. RSpec # bowling_spec.rb require 'bowling' describe Bowling, "#score" do it "returns 0 for all gutter game" do bowling = Bowling.new 20.times { bowling.hit(0) } bowling.score.should == 0 end end
  • 19. Cucumber http://cukes.info Testing framework for describing software behavior in plain English
  • 20. Cucumber Feature: Pets Scenario: Edit Pet Given I am on the owners search page And I press "Find Owners" And I follow "George Franklin" And I follow "Edit Pet" When I fill in "Name" with "Leoni" And press "Update Pet" Then I should see "Leoni"
  • 22. Small refactoring Give Ruby a foot in the door
  • 23. Requests / /vets Java/ Spring App
  • 24. Requests JRuby / /vets /rack/ Java/ Spring App
  • 25. Cucumber test diff --git a/src/main/webapp/WEB-INF/jsp/vets.jsp b/src/main/webapp/WEB-INF/jsp/vets.jsp index cff2154..0d99817 100644 --- a/src/main/webapp/WEB-INF/jsp/vets.jsp +++ b/src/main/webapp/WEB-INF/jsp/vets.jsp @@ -23,7 +23,7 @@ <table class="table-buttons"> <tr> <td> - <a href="<spring:url value="/vets.xml" htmlEscape="true" />">View as XML</a> + <a href="<spring:url value="/rack/vets.xml" htmlEscape="true" />">View as XML</a> </td> </tr> </table>
  • 26. Cucumber test Stand by while Tomcat finishes booting... Using the default profile... ............................................................F-............. (::) failed steps (::) expected: /xml/, got: "text/html;charset=utf-8" (using =~) Diff: @@ -1,2 +1,2 @@ -/xml/ +text/html;charset=utf-8 (RSpec::Expectations::ExpectationNotMetError) org/jruby/RubyProc.java:268:in `call' ./features/step_definitions/xml_json_steps.rb:12:in `(root)':in `/^I should see an XML document$/' features/vets.feature:6:in `Then I should see an XML document' Failing Scenarios: cucumber features/vets.feature:3 # Scenario: View vets as XML 13 scenarios (1 failed, 12 passed) 75 steps (1 failed, 1 skipped, 73 passed) 0m7.709s rake aborted! Cucumber failed
  • 27. diff --git a/pom.xml b/pom.xml index 9e22f83..0810701 100644 --- a/pom.xml +++ b/pom.xml @@ -211,6 +211,18 @@ <scope>provided</scope> </dependency> + <!-- JRuby and JRuby-Rack --> + <dependency> + <groupId>org.jruby</groupId> + <artifactId>jruby-complete</artifactId> + <version>1.6.0</version> + </dependency> + <dependency> + <groupId>org.jruby.rack</groupId> + <artifactId>jruby-rack</artifactId> + <version>1.0.8</version> + </dependency> + <!-- Test dependencies --> <dependency> <groupId>org.junit</groupId>
  • 28. diff --git a/src/main/webapp/WEB-INF/web.xml b/src/main/webapp/WEB-INF/web.xml index 8d02684..60ed6cb 100644 --- a/src/main/webapp/WEB-INF/web.xml +++ b/src/main/webapp/WEB-INF/web.xml @@ -87,6 +87,21 @@ <listener> <listener-class>org.springframework.web.context.ContextLoaderListener</listener-class> </listener> + + <listener> + <listener-class>org.jruby.rack.RackServletContextListener</listener-class> + </listener> + + <servlet> + <servlet-name>rack</servlet-name> + <servlet-class>org.jruby.rack.RackServlet</servlet-class> + </servlet> + + <servlet-mapping> + <servlet-name>rack</servlet-name> + <url-pattern>/rack/*</url-pattern> + </servlet-mapping> + <!-- Defines the 'default' servlet (usually for service static resources).
  • 29. diff --git a/src/main/webapp/WEB-INF/lib/app.rb b/src/main/webapp/WEB-INF/lib/ app.rb index 6ab5b3c..4398fb4 100644 --- a/src/main/webapp/WEB-INF/lib/app.rb +++ b/src/main/webapp/WEB-INF/lib/app.rb @@ -1,6 +1,33 @@ require 'builder' require 'erb' +require 'spring_helpers' + +helpers do + include Spring +end get '/rack/' do '<h1>Sinatra</h1>' end + +get '/rack/vets.xml' do + content_type 'application/vnd.petclinic+xml' + builder do |xml| + xml.instruct! + xml.vets do + clinic.vets.each do |vet| + xml.vetList do + xml.id vet.id + xml.firstName vet.firstName + xml.lastName vet.lastName + vet.specialties.each do |spec| + xml.specialties do + xml.id spec.id + xml.name spec.name + end + end + end + end + end + end +end
  • 31. Requests JRuby / /vets /rack/ Java/ Spring App
  • 32. Requests /owners Java/ / /vets /owners /1/pets Spring App
  • 33. Requests / /vets JRuby /owners Java/ / /vets /owners /1/pets Spring App
  • 34. diff --git a/src/main/webapp/WEB-INF/web.xml b/src/main/webapp/WEB-INF/web.xml index 60ed6cb..f64b34d 100644 --- a/src/main/webapp/WEB-INF/web.xml +++ b/src/main/webapp/WEB-INF/web.xml @@ -92,16 +92,6 @@ <listener-class>org.jruby.rack.RackServletContextListener</listener-class> </listener> - <servlet> - <servlet-name>rack</servlet-name> - <servlet-class>org.jruby.rack.RackServlet</servlet-class> - </servlet> - - <servlet-mapping> - <servlet-name>rack</servlet-name> - <url-pattern>/rack/*</url-pattern> - </servlet-mapping> - <!-- Defines the 'default' servlet (usually for service static resources). @@ -162,6 +152,16 @@ <url-pattern>/</url-pattern> </servlet-mapping> + <filter> + <filter-name>RackFilter</filter-name> + <filter-class>org.jruby.rack.RubyFirstRackFilter</filter-class> + </filter> + + <filter-mapping> + <filter-name>RackFilter</filter-name> + <url-pattern>/*</url-pattern> + </filter-mapping> + <filter> <filter-name>httpMethodFilter</filter-name> <filter-class>org.springframework.web.filter.HiddenHttpMethodFilter</filter-class>
  • 36. Large refactoring Change directory structure; move files from WEB-INF/* to Rails directory structure In Rails initializer, create a Spring context to boot the Spring app Ensure classpath includes Spring jars.
  • 37. Large refactoring Configure warbler to ensure necessary files are included in WAR file
  • 38. TMTOWTDI <html> <head> </head> JSP <body> ### </body> Mixing JSP and </html> JRuby output + <div> Sinatra <h1>App</h1> </div>
  • 39. Questions? Twitter @hiro_asari G+ http://gplus.to/hiroasari LinkedIn http://linkedin.com/in/hiroasari asari.ruby@gmail.com hasari@engineyard.com http://github.com/banzaiman http://www.flickr.com/photos/42033648@N00/372887164
  • 40. Obligado! Twitter @hiro_asari G+ http://gplus.to/hiroasari LinkedIn http://linkedin.com/in/hiroasari asari.ruby@gmail.com hasari@engineyard.com http://github.com/banzaiman http://www.flickr.com/photos/42033648@N00/372887164