Title: [868] trunk/rails-integration: Fix for empty responses being sent.
- Revision
- 868
- Author
- tantalon
- Date
- 2008-01-05 18:30:41 -0500 (Sat, 05 Jan 2008)
Log Message
Fix for empty responses being sent.
It looks like Rails is not calling close on the IO object in certain cases, so I've added a check to RailsServlet to ensure that it's closed if it was not already.
Modified Paths
Diff
Modified: trunk/rails-integration/pom.xml (867 => 868)
--- trunk/rails-integration/pom.xml 2008-01-05 14:08:05 UTC (rev 867)
+++ trunk/rails-integration/pom.xml 2008-01-05 23:30:41 UTC (rev 868)
@@ -4,7 +4,7 @@
<groupId>org.jruby.extras</groupId>
<artifactId>goldspike</artifactId>
<packaging>jar</packaging>
- <version>1.4</version>
+ <version>1.4-SNAPSHOT</version>
<name>GoldSpike</name>
<description>GoldSpike allows you to deploy your standard Rails web application to a J2EE server. You can package up your application as a WAR file for distribution, or simply run it in an expanded form.</description>
@@ -192,6 +192,8 @@
</extension>
</extensions>
<plugins>
+<!--
+ This plugin depends on snapshot builds which are not available - Robert
<plugin>
<groupId>org.jruby.plugins</groupId>
<artifactId>jruby-rake-plugin</artifactId>
@@ -208,6 +210,7 @@
</execution>
</executions>
</plugin>
+-->
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
Modified: trunk/rails-integration/src/main/java/org/jruby/webapp/HttpOutput.java (867 => 868)
--- trunk/rails-integration/src/main/java/org/jruby/webapp/HttpOutput.java 2008-01-05 14:08:05 UTC (rev 867)
+++ trunk/rails-integration/src/main/java/org/jruby/webapp/HttpOutput.java 2008-01-05 23:30:41 UTC (rev 868)
@@ -143,11 +143,7 @@
}
public void flush() throws IOException {
- if (output != null) {
- output.flush();
- } else {
- writeHeaders();
- }
+ getOutput().flush();
response.flushBuffer();
}
Modified: trunk/rails-integration/src/main/java/org/jruby/webapp/RailsServlet.java (867 => 868)
--- trunk/rails-integration/src/main/java/org/jruby/webapp/RailsServlet.java 2008-01-05 14:08:05 UTC (rev 867)
+++ trunk/rails-integration/src/main/java/org/jruby/webapp/RailsServlet.java 2008-01-05 23:30:41 UTC (rev 868)
@@ -77,7 +77,7 @@
// setup the environment
setupEnvironment(runtime, request);
-
+
// variables to expose
runtime.defineReadonlyVariable("$stdin", stdin);
runtime.defineReadonlyVariable("$java_servlet_request", JavaEmbedUtils.javaToRuby(runtime, request));
@@ -99,9 +99,16 @@
if (dispatcher == null) throw new ServletException("The rails dispatcher could not be found");
// dispatch the request
- RubyHash sessionOptions = getDefaultSessionOptions(runtime);
- IRubyObject[] args = { cgi, sessionOptions, output};
- dispatcher.callMethod(runtime.getCurrentContext(), "dispatch", args);
+ try {
+ RubyHash sessionOptions = getDefaultSessionOptions(runtime);
+ IRubyObject[] args = { cgi, sessionOptions, output};
+ dispatcher.callMethod(runtime.getCurrentContext(), "dispatch", args);
+ } finally {
+ // ensure the response is sent
+ if (!output.closed().isTrue()) {
+ output.close();
+ }
+ }
}
protected IRubyObject createCgi(Ruby runtime) {
Modified: trunk/rails-integration/src/test/java/org/jruby/webapp/HttpOutputTest.java (867 => 868)
--- trunk/rails-integration/src/test/java/org/jruby/webapp/HttpOutputTest.java 2008-01-05 14:08:05 UTC (rev 867)
+++ trunk/rails-integration/src/test/java/org/jruby/webapp/HttpOutputTest.java 2008-01-05 23:30:41 UTC (rev 868)
@@ -78,6 +78,7 @@
"Status: 304 Not Modified\r\n" +
"\r\n";
// setup expectations
+ control.expectAndReturn(response.getOutputStream(), new BufferServletOutputStream());
response.setStatus(304);
response.setContentType("text/html; charset=utf-8");
response.addHeader("Set-Cookie", "_rebates_session=413aa062523b7b9fe0d491beff1ccc0d; path=/");
@@ -95,5 +96,19 @@
control.verify();
}
+ public void testOnlyHeaders() throws IOException {
+ String input = "Status: 304 Not Modified";
+ // setup expectations
+ control.expectAndReturn(response.getOutputStream(), new BufferServletOutputStream());
+ response.setStatus(304);
+ response.flushBuffer();
+ control.replay();
+ // execute the action
+ HttpOutput httpOutput = new HttpOutput(response);
+ httpOutput.write(input.getBytes());
+ httpOutput.flush();
+ // verify the results
+ control.verify();
+ }
}
_______________________________________________
Jruby-extras-devel mailing list
[email protected]
http://rubyforge.org/mailman/listinfo/jruby-extras-devel