Skip to content

Instantly share code, notes, and snippets.

@mkristian
Created June 19, 2012 07:19
Show Gist options
  • Save mkristian/2952760 to your computer and use it in GitHub Desktop.
Save mkristian/2952760 to your computer and use it in GitHub Desktop.
jruby-rack-1.1.x can not handle PUT request
// use jruby
$ ruby -v
jruby 1.6.4 (ruby-1.8.7-p330) (2011-08-23 17ea768) (JamVM 1.6.0_24) [linux-amd64-java]
$ gem install jetty-run
$ gem install rails
$ rails new dummy
$ cd dummy
$ rails g scaffold account name:string
$ rake db:mgrate
$ jetty-run
// other terminal for version 1.1.5 and 1.1.6 - other versions below
$ curl -X PUT -d "something=blabla&somethingelse=blaha" http://localhost:8080/accounts -i
HTTP/1.1 405 HTTP method PUT is not supported by this URL
Content-Length: 0
Server: Jetty(7.6.4.v20120524)
// add Mavenfile (see below) and restart jetty - this mean jruby-rack 1.0.10 (or you can change to version 1.1.1 as well or version 1.1.4 also works)
$ curl -X PUT -d "something=blabla&somethingelse=blaha" http://localhost:8080/accounts/1 -i
HTTP/1.1 404 Not Found
Content-Type: text/html;charset=UTF-8
Content-Length: 15392
X-Request-Id: cd74288ca99d4c6ecc0fa6b511858450
X-Runtime: 0.489000
Server: Jetty(7.6.4.v20120524)
// with jruby-rack-1.1.2 (just change the version in Mavenfile)
$ curl -X PUT -d "something=blabla&somethingelse=blaha" http://localhost:8080/accounts/1 -i
HTTP/1.1 200 OK
Content-Type: text/html;charset=UTF-8
Content-Length: 15388
X-Request-Id: 95be9099686de5ef25445157e6b20001
X-Runtime: 0.159000
Server: Jetty(7.6.4.v20120524)
curl: (18) transfer closed with 15388 bytes remaining to read
// with jruby-rack-1.1.3 (just change the version in Mavenfile)
// BUT t reaches RAILS with expected
// ActiveRecord::RecordNotFound (Couldn't find Account with id=1):
$ curl -X PUT -d "something=blabla&somethingelse=blaha" http://localhost:8080/accounts/1 -i
HTTP/1.1 200 OK
Content-Type: text/html;charset=UTF-8
Content-Length: 15388
X-Request-Id: 95be9099686de5ef25445157e6b20001
X-Runtime: 0.159000
Server: Jetty(7.6.4.v20120524)
curl: (18) transfer closed with 15388 bytes remaining to read
jar 'org.jruby.rack:jruby-rack', '1.0.10'
<!DOCTYPE web-app PUBLIC
"-//Sun Microsystems, Inc.//DTD Web Application 2.3//EN"
"http://java.sun.com/dtd/web-app_2_3.dtd">
<web-app>
<welcome-file-list>
<welcome-file>/Rsl2/Rsl2.html</welcome-file>
</welcome-file-list>
<context-param>
<param-name>jruby.max.runtimes</param-name>
<param-value>1</param-value>
</context-param>
<context-param>
<param-name>jruby.min.runtimes</param-name>
<param-value>1</param-value>
</context-param>
<context-param>
<param-name>rails.root</param-name>
<param-value>.</param-value>
</context-param>
<context-param>
<param-name>gem.path</param-name>
<param-value>./target/rubygems</param-value>
</context-param>
<context-param>
<param-name>rails.env</param-name>
<param-value>development</param-value>
</context-param>
<context-param>
<param-name>jruby.rack.logging</param-name>
<param-value>stdout</param-value>
</context-param>
<context-param>
<param-name>jruby.rack.layout_class</param-name>
<param-value>JRuby::Rack::RailsFilesystemLayout</param-value>
</context-param>
<filter>
<filter-name>RackFilter</filter-name>
<filter-class>org.jruby.rack.RackFilter</filter-class>
</filter>
<filter-mapping>
<filter-name>RackFilter</filter-name>
<url-pattern>/*</url-pattern>
</filter-mapping>
<listener>
<listener-class>org.jruby.rack.rails.RailsServletContextListener</listener-class>
</listener>
</web-app>
@kares
Copy link

kares commented Jun 20, 2012

try the following if you need to use the filter (otherwise you might go with the RackServlet instead) :

  <filter>
    <filter-name>RackFilter</filter-name>
    <filter-class>org.jruby.rack.RackFilter</filter-class>
    <init-param> 
      <param-name>responseNotHandledStatuses</param-name>
      <param-value>404,405</param-value> <!-- 404, 403 by default -->
    </init-param>
  </filter>

@mkristian
Copy link
Author

mkristian commented Jun 20, 2012 via email

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment