SlideShare ist ein Scribd-Unternehmen logo
1 von 40
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

Weitere ähnliche Inhalte

Was ist angesagt?

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 classpathAlexis Hassler
 
Oredev 2015 - Taming Java Agents
Oredev 2015 - Taming Java AgentsOredev 2015 - Taming Java Agents
Oredev 2015 - Taming Java AgentsAnton 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 developergicappa
 
Taking Apache Camel For A Ride
Taking Apache Camel For A RideTaking Apache Camel For A Ride
Taking Apache Camel For A RideBruce 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 QueryPathMatt 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 javascriptMohd 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 JavassistAnton Arhipov
 
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 classpathAlexis Hassler
 

Was ist angesagt? (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
 

Andere mochten auch (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
 

Ähnlich wie Spring into 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 2010Arun Gupta
 
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
 
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
 
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 6Arun Gupta
 
Dropwizard and Friends
Dropwizard and FriendsDropwizard and Friends
Dropwizard and FriendsYun Zhi Lin
 
JavaOne India 2011 - Servlets 3.0
JavaOne India 2011 - Servlets 3.0JavaOne India 2011 - Servlets 3.0
JavaOne India 2011 - Servlets 3.0Arun Gupta
 
Android Automated Testing
Android Automated TestingAndroid Automated Testing
Android Automated Testingroisagiv
 
Ajax, JSF, Facelets, Eclipse & Maven tutorials
Ajax, JSF, Facelets, Eclipse & Maven tutorialsAjax, JSF, Facelets, Eclipse & Maven tutorials
Ajax, JSF, Facelets, Eclipse & Maven tutorialsRaghavan Mohan
 
Asynchronous Interfaces
Asynchronous InterfacesAsynchronous Interfaces
Asynchronous Interfacesmaccman
 
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 Javascriptaglemann
 
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 middlewareAlona 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 forCorneil 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 hassleAnton Arhipov
 
Pom configuration java xml
Pom configuration java xmlPom configuration java xml
Pom configuration java xmlakmini
 
Belfast JUG 23-10-2013
Belfast JUG 23-10-2013Belfast JUG 23-10-2013
Belfast JUG 23-10-2013eamonnlong
 
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 RpmMartin Jackson
 

Ähnlich wie 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 = 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...
 
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
 
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 configuration java xml
Pom configuration java xmlPom configuration java xml
Pom configuration java xml
 
Pom
PomPom
Pom
 
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
 

Kürzlich hochgeladen

ADOPTING WEB 3 FOR YOUR BUSINESS: A STEP-BY-STEP GUIDE
ADOPTING WEB 3 FOR YOUR BUSINESS: A STEP-BY-STEP GUIDEADOPTING WEB 3 FOR YOUR BUSINESS: A STEP-BY-STEP GUIDE
ADOPTING WEB 3 FOR YOUR BUSINESS: A STEP-BY-STEP GUIDELiveplex
 
Machine Learning Model Validation (Aijun Zhang 2024).pdf
Machine Learning Model Validation (Aijun Zhang 2024).pdfMachine Learning Model Validation (Aijun Zhang 2024).pdf
Machine Learning Model Validation (Aijun Zhang 2024).pdfAijun Zhang
 
UiPath Studio Web workshop series - Day 8
UiPath Studio Web workshop series - Day 8UiPath Studio Web workshop series - Day 8
UiPath Studio Web workshop series - Day 8DianaGray10
 
The Data Metaverse: Unpacking the Roles, Use Cases, and Tech Trends in Data a...
The Data Metaverse: Unpacking the Roles, Use Cases, and Tech Trends in Data a...The Data Metaverse: Unpacking the Roles, Use Cases, and Tech Trends in Data a...
The Data Metaverse: Unpacking the Roles, Use Cases, and Tech Trends in Data a...Aggregage
 
Linked Data in Production: Moving Beyond Ontologies
Linked Data in Production: Moving Beyond OntologiesLinked Data in Production: Moving Beyond Ontologies
Linked Data in Production: Moving Beyond OntologiesDavid Newbury
 
UiPath Solutions Management Preview - Northern CA Chapter - March 22.pdf
UiPath Solutions Management Preview - Northern CA Chapter - March 22.pdfUiPath Solutions Management Preview - Northern CA Chapter - March 22.pdf
UiPath Solutions Management Preview - Northern CA Chapter - March 22.pdfDianaGray10
 
Videogame localization & technology_ how to enhance the power of translation.pdf
Videogame localization & technology_ how to enhance the power of translation.pdfVideogame localization & technology_ how to enhance the power of translation.pdf
Videogame localization & technology_ how to enhance the power of translation.pdfinfogdgmi
 
Comparing Sidecar-less Service Mesh from Cilium and Istio
Comparing Sidecar-less Service Mesh from Cilium and IstioComparing Sidecar-less Service Mesh from Cilium and Istio
Comparing Sidecar-less Service Mesh from Cilium and IstioChristian Posta
 
Nanopower In Semiconductor Industry.pdf
Nanopower  In Semiconductor Industry.pdfNanopower  In Semiconductor Industry.pdf
Nanopower In Semiconductor Industry.pdfPedro Manuel
 
UiPath Studio Web workshop series - Day 6
UiPath Studio Web workshop series - Day 6UiPath Studio Web workshop series - Day 6
UiPath Studio Web workshop series - Day 6DianaGray10
 
NIST Cybersecurity Framework (CSF) 2.0 Workshop
NIST Cybersecurity Framework (CSF) 2.0 WorkshopNIST Cybersecurity Framework (CSF) 2.0 Workshop
NIST Cybersecurity Framework (CSF) 2.0 WorkshopBachir Benyammi
 
UiPath Platform: The Backend Engine Powering Your Automation - Session 1
UiPath Platform: The Backend Engine Powering Your Automation - Session 1UiPath Platform: The Backend Engine Powering Your Automation - Session 1
UiPath Platform: The Backend Engine Powering Your Automation - Session 1DianaGray10
 
UiPath Studio Web workshop series - Day 7
UiPath Studio Web workshop series - Day 7UiPath Studio Web workshop series - Day 7
UiPath Studio Web workshop series - Day 7DianaGray10
 
Bird eye's view on Camunda open source ecosystem
Bird eye's view on Camunda open source ecosystemBird eye's view on Camunda open source ecosystem
Bird eye's view on Camunda open source ecosystemAsko Soukka
 
UWB Technology for Enhanced Indoor and Outdoor Positioning in Physiological M...
UWB Technology for Enhanced Indoor and Outdoor Positioning in Physiological M...UWB Technology for Enhanced Indoor and Outdoor Positioning in Physiological M...
UWB Technology for Enhanced Indoor and Outdoor Positioning in Physiological M...UbiTrack UK
 
Meet the new FSP 3000 M-Flex800™
Meet the new FSP 3000 M-Flex800™Meet the new FSP 3000 M-Flex800™
Meet the new FSP 3000 M-Flex800™Adtran
 
Artificial Intelligence & SEO Trends for 2024
Artificial Intelligence & SEO Trends for 2024Artificial Intelligence & SEO Trends for 2024
Artificial Intelligence & SEO Trends for 2024D Cloud Solutions
 
Secure your environment with UiPath and CyberArk technologies - Session 1
Secure your environment with UiPath and CyberArk technologies - Session 1Secure your environment with UiPath and CyberArk technologies - Session 1
Secure your environment with UiPath and CyberArk technologies - Session 1DianaGray10
 
IaC & GitOps in a Nutshell - a FridayInANuthshell Episode.pdf
IaC & GitOps in a Nutshell - a FridayInANuthshell Episode.pdfIaC & GitOps in a Nutshell - a FridayInANuthshell Episode.pdf
IaC & GitOps in a Nutshell - a FridayInANuthshell Episode.pdfDaniel Santiago Silva Capera
 

Kürzlich hochgeladen (20)

ADOPTING WEB 3 FOR YOUR BUSINESS: A STEP-BY-STEP GUIDE
ADOPTING WEB 3 FOR YOUR BUSINESS: A STEP-BY-STEP GUIDEADOPTING WEB 3 FOR YOUR BUSINESS: A STEP-BY-STEP GUIDE
ADOPTING WEB 3 FOR YOUR BUSINESS: A STEP-BY-STEP GUIDE
 
Machine Learning Model Validation (Aijun Zhang 2024).pdf
Machine Learning Model Validation (Aijun Zhang 2024).pdfMachine Learning Model Validation (Aijun Zhang 2024).pdf
Machine Learning Model Validation (Aijun Zhang 2024).pdf
 
UiPath Studio Web workshop series - Day 8
UiPath Studio Web workshop series - Day 8UiPath Studio Web workshop series - Day 8
UiPath Studio Web workshop series - Day 8
 
The Data Metaverse: Unpacking the Roles, Use Cases, and Tech Trends in Data a...
The Data Metaverse: Unpacking the Roles, Use Cases, and Tech Trends in Data a...The Data Metaverse: Unpacking the Roles, Use Cases, and Tech Trends in Data a...
The Data Metaverse: Unpacking the Roles, Use Cases, and Tech Trends in Data a...
 
Linked Data in Production: Moving Beyond Ontologies
Linked Data in Production: Moving Beyond OntologiesLinked Data in Production: Moving Beyond Ontologies
Linked Data in Production: Moving Beyond Ontologies
 
UiPath Solutions Management Preview - Northern CA Chapter - March 22.pdf
UiPath Solutions Management Preview - Northern CA Chapter - March 22.pdfUiPath Solutions Management Preview - Northern CA Chapter - March 22.pdf
UiPath Solutions Management Preview - Northern CA Chapter - March 22.pdf
 
Videogame localization & technology_ how to enhance the power of translation.pdf
Videogame localization & technology_ how to enhance the power of translation.pdfVideogame localization & technology_ how to enhance the power of translation.pdf
Videogame localization & technology_ how to enhance the power of translation.pdf
 
20230104 - machine vision
20230104 - machine vision20230104 - machine vision
20230104 - machine vision
 
Comparing Sidecar-less Service Mesh from Cilium and Istio
Comparing Sidecar-less Service Mesh from Cilium and IstioComparing Sidecar-less Service Mesh from Cilium and Istio
Comparing Sidecar-less Service Mesh from Cilium and Istio
 
Nanopower In Semiconductor Industry.pdf
Nanopower  In Semiconductor Industry.pdfNanopower  In Semiconductor Industry.pdf
Nanopower In Semiconductor Industry.pdf
 
UiPath Studio Web workshop series - Day 6
UiPath Studio Web workshop series - Day 6UiPath Studio Web workshop series - Day 6
UiPath Studio Web workshop series - Day 6
 
NIST Cybersecurity Framework (CSF) 2.0 Workshop
NIST Cybersecurity Framework (CSF) 2.0 WorkshopNIST Cybersecurity Framework (CSF) 2.0 Workshop
NIST Cybersecurity Framework (CSF) 2.0 Workshop
 
UiPath Platform: The Backend Engine Powering Your Automation - Session 1
UiPath Platform: The Backend Engine Powering Your Automation - Session 1UiPath Platform: The Backend Engine Powering Your Automation - Session 1
UiPath Platform: The Backend Engine Powering Your Automation - Session 1
 
UiPath Studio Web workshop series - Day 7
UiPath Studio Web workshop series - Day 7UiPath Studio Web workshop series - Day 7
UiPath Studio Web workshop series - Day 7
 
Bird eye's view on Camunda open source ecosystem
Bird eye's view on Camunda open source ecosystemBird eye's view on Camunda open source ecosystem
Bird eye's view on Camunda open source ecosystem
 
UWB Technology for Enhanced Indoor and Outdoor Positioning in Physiological M...
UWB Technology for Enhanced Indoor and Outdoor Positioning in Physiological M...UWB Technology for Enhanced Indoor and Outdoor Positioning in Physiological M...
UWB Technology for Enhanced Indoor and Outdoor Positioning in Physiological M...
 
Meet the new FSP 3000 M-Flex800™
Meet the new FSP 3000 M-Flex800™Meet the new FSP 3000 M-Flex800™
Meet the new FSP 3000 M-Flex800™
 
Artificial Intelligence & SEO Trends for 2024
Artificial Intelligence & SEO Trends for 2024Artificial Intelligence & SEO Trends for 2024
Artificial Intelligence & SEO Trends for 2024
 
Secure your environment with UiPath and CyberArk technologies - Session 1
Secure your environment with UiPath and CyberArk technologies - Session 1Secure your environment with UiPath and CyberArk technologies - Session 1
Secure your environment with UiPath and CyberArk technologies - Session 1
 
IaC & GitOps in a Nutshell - a FridayInANuthshell Episode.pdf
IaC & GitOps in a Nutshell - a FridayInANuthshell Episode.pdfIaC & GitOps in a Nutshell - a FridayInANuthshell Episode.pdf
IaC & GitOps in a Nutshell - a FridayInANuthshell Episode.pdf
 

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