Rack support #1

Merged
merged 4 commits into from Feb 25, 2012
Jump to file or symbol
Failed to load files and symbols.
+97 −11
Diff settings

Always

Just for now

View
@@ -159,6 +159,13 @@ if @settings.jetty?
web_inf_dir = File.join(@path_to_project, "WEB-INF")
mkdir_p web_inf_dir
+ @listener = if @settings.rails?
+ "org.jruby.rack.rails.RailsServletContextListener"
+ else
+ # Rails does this for us, but jetty won't load if there is no log dir.
+ FileUtils.mkdir_p(File.join(@path_to_project, "log"))
+ "org.jruby.rack.RackServletContextListener"
+ end
overlay_files File.join(@jetpack_dir, "web_inf_files"), web_inf_dir
end
@@ -47,16 +47,18 @@
</Arg>
</Call>
- <!-- set the rails.env java system property based on the RAILS_ENV environment variable -->
- <!-- this is used by jruby-rack to set Rails.env -->
- <Call class="java.lang.System" name="setProperty">
- <Arg>rails.env</Arg>
- <Arg>
- <Call class="java.lang.System" name="getenv">
- <Arg>RAILS_ENV</Arg>
- </Call>
- </Arg>
- </Call>
+ <% if @settings.rails? %>
+ <!-- set the rails.env java system property based on the RAILS_ENV environment variable -->
+ <!-- this is used by jruby-rack to set Rails.env -->
+ <Call class="java.lang.System" name="setProperty">
+ <Arg>rails.env</Arg>
+ <Arg>
+ <Call class="java.lang.System" name="getenv">
+ <Arg>RAILS_ENV</Arg>
+ </Call>
+ </Arg>
+ </Call>
+ <% end %>
<Set name="handler">
<New id="Handlers" class="org.eclipse.jetty.server.handler.HandlerCollection">
View
@@ -37,6 +37,10 @@ def jetty?
respond_to?(:jetty)
end
+ def rails?
+ File.exists?(File.join(app_root, "config/environment.rb"))
+ end
+
def jetty_pid_path
File.join(app_root, "/vendor/jetty/run/jetty.pid")
end
View
@@ -0,0 +1,39 @@
+require "spec_helper"
+require "yaml"
+
+describe "jetpack - web start for rack app" do
+ before(:all) do
+ reset
+ @result = x!("bin/jetpack spec/sample_projects/rack_19")
+ end
+
+ after(:all) do
+ reset
+ end
+
+ it "runs" do
+ pid_to_kill = run_app("spec/sample_projects/rack_19")
+
+ #HTTP 4443 - intended to be proxied to from something listening on 443
+ x!("curl https://localhost:10443/hello --insecure")[:stdout].split("<br/>").first.strip.should == "Hello World"
+
+ #HTTP 9080 - intended for internal health checking
+ x!("curl http://localhost:10080/hello --insecure")[:stdout].split("<br/>").first.strip.should == "Hello World"
+
+ system("kill -9 #{pid_to_kill}")
+ end
+
+ def run_app(app)
+ jetty_pid = Process.spawn({'RAILS_ENV' => 'development'}, 'java', '-jar', 'start.jar', {:chdir => "#{app}/vendor/jetty"})
+ start_time = Time.now
+ loop do
+ begin
+ TCPSocket.open("localhost", 10443)
+ return jetty_pid
+ rescue Errno::ECONNREFUSED
+ raise "it's taking too long to start the server, something might be wrong" if Time.now - start_time > 60
+ sleep 0.1
+ end
+ end
+ end
+end
@@ -0,0 +1,3 @@
+source :rubygems
+
+gem 'rack'
@@ -0,0 +1,11 @@
+GEM
+ remote: http://rubygems.org/
+ specs:
+ rack (1.4.1)
+
+PLATFORMS
+ java
+ ruby
+
+DEPENDENCIES
+ rack
@@ -0,0 +1,8 @@
+hash_in_19_syntax = {
+ a: 1
+}
+
+run Proc.new {|env| [200,
+ {"Content-Type" => "application/json"},
+ ["Hello World"]
+]}
@@ -0,0 +1,6 @@
+jruby: "file://<%= File.expand_path('spec/local_mirror') %>/jruby-complete-1.6.4.jar"
+jetty: "file://<%= File.expand_path('spec/local_mirror') %>/jetty-hightide-7.4.5.v20110725.zip"
+jruby-rack: "file://<%= File.expand_path('spec/local_mirror') %>/jruby-rack-1.0.10.jar"
+http_port: 10080
+https_port: 10443
+ruby_version: 1.9
@@ -11,6 +11,12 @@
<param-value>1</param-value>
</context-param>
+ <context-param>
+ <param-name>jruby.compat.version</param-name>
+ <param-value><%= @settings.ruby_version %></param-value>
+ </context-param>
+
+
<context-param>
<param-name>rails.root</param-name>
<param-value>.</param-value>
@@ -42,6 +48,6 @@
</filter-mapping>
<listener>
- <listener-class>org.jruby.rack.rails.RailsServletContextListener</listener-class>
+ <listener-class><%= @listener %></listener-class>
</listener>
</web-app>