Author: remy.maucherat(a)jboss.com
Date: 2012-04-16 06:24:28 -0400 (Mon, 16 Apr 2012)
New Revision: 2025
Added:
trunk/test/java/org/jboss/web/upgrade/Upgrade00ServletTest.java
Modified:
trunk/java/org/apache/catalina/connector/Response.java
trunk/java/org/apache/catalina/connector/ResponseFacade.java
trunk/java/org/apache/coyote/http11/Http11AprProcessor.java
trunk/java/org/jboss/servlet/http/UpgradableHttpServletResponse.java
trunk/webapps/docs/changelog.xml
Log:
JBWEB-238: Add a semi hack to allow some flexibility during the upgrade.
Modified: trunk/java/org/apache/catalina/connector/Response.java
===================================================================
--- trunk/java/org/apache/catalina/connector/Response.java 2012-04-13 22:47:49 UTC (rev
2024)
+++ trunk/java/org/apache/catalina/connector/Response.java 2012-04-16 10:24:28 UTC (rev
2025)
@@ -1342,6 +1342,29 @@
}
+ public void startUpgrade() {
+
+ if (isCommitted())
+ throw new IllegalStateException
+ (sm.getString("coyoteResponse.upgrade.ise"));
+
+ if (!connector.hasIoEvents())
+ throw new IllegalStateException
+ (sm.getString("coyoteResponse.upgrade.noEvents"));
+
+ if (!request.isEventMode() || request.getAsyncContext() != null)
+ throw new IllegalStateException
+ (sm.getString("coyoteResponse.upgrade.noHttpEventServlet"));
+
+ // Ignore any call from an included servlet
+ if (included)
+ return;
+
+ request.getCoyoteRequest().action(ActionCode.UPGRADE, null);
+
+ }
+
+
public void sendUpgrade()
throws IOException {
@@ -1361,9 +1384,6 @@
if (included)
return;
- // Clear any data content that has been buffered
- resetBuffer();
-
// Output required by RFC2616. Protocol specific headers should have
// already been set.
setStatus(HttpServletResponse.SC_SWITCHING_PROTOCOLS);
Modified: trunk/java/org/apache/catalina/connector/ResponseFacade.java
===================================================================
--- trunk/java/org/apache/catalina/connector/ResponseFacade.java 2012-04-13 22:47:49 UTC
(rev 2024)
+++ trunk/java/org/apache/catalina/connector/ResponseFacade.java 2012-04-16 10:24:28 UTC
(rev 2025)
@@ -455,6 +455,16 @@
}
+ public void startUpgrade() {
+
+ if (isCommitted())
+ throw new IllegalStateException
+ (/*sm.getString("responseBase.reset.ise")*/);
+
+ response.startUpgrade();
+
+ }
+
public void sendUpgrade()
throws IOException {
Modified: trunk/java/org/apache/coyote/http11/Http11AprProcessor.java
===================================================================
--- trunk/java/org/apache/coyote/http11/Http11AprProcessor.java 2012-04-13 22:47:49 UTC
(rev 2024)
+++ trunk/java/org/apache/coyote/http11/Http11AprProcessor.java 2012-04-16 10:24:28 UTC
(rev 2025)
@@ -1657,7 +1657,7 @@
}
int statusCode = response.getStatus();
- if ((statusCode == 101) || (statusCode == 204) || (statusCode == 205)
+ if ((statusCode == 204) || (statusCode == 205)
|| (statusCode == 304)) {
// No entity body
outputBuffer.addActiveFilter
@@ -1665,6 +1665,10 @@
entityBody = false;
contentDelimitation = true;
}
+ if (statusCode >= 100 && statusCode < 200) {
+ entityBody = false;
+ contentDelimitation = true;
+ }
MessageBytes methodMB = request.method();
if (methodMB.equals("HEAD")) {
Modified: trunk/java/org/jboss/servlet/http/UpgradableHttpServletResponse.java
===================================================================
--- trunk/java/org/jboss/servlet/http/UpgradableHttpServletResponse.java 2012-04-13
22:47:49 UTC (rev 2024)
+++ trunk/java/org/jboss/servlet/http/UpgradableHttpServletResponse.java 2012-04-16
10:24:28 UTC (rev 2025)
@@ -31,6 +31,17 @@
*/
public interface UpgradableHttpServletResponse {
+ /**
+ * Start the connection upgrade process. After calling this method,
+ * data will be available raw from the connection. Calling this method
+ * is optional if no read/write are needed during the upgrade process.
+ */
+ public void startUpgrade();
+
+ /**
+ * Send the switching protocol HTTP status and commit the response by
+ * flushing the buffer.
+ */
public void sendUpgrade()
throws IOException;
Added: trunk/test/java/org/jboss/web/upgrade/Upgrade00ServletTest.java
===================================================================
--- trunk/test/java/org/jboss/web/upgrade/Upgrade00ServletTest.java
(rev 0)
+++ trunk/test/java/org/jboss/web/upgrade/Upgrade00ServletTest.java 2012-04-16 10:24:28
UTC (rev 2025)
@@ -0,0 +1,120 @@
+/*
+ * JBoss, Home of Professional Open Source
+ * Copyright 2012, JBoss Inc., and individual contributors as indicated
+ * by the @authors tag. See the copyright.txt in the distribution for a
+ * full listing of individual contributors.
+ *
+ * This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This software is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site:
http://www.fsf.org.
+ */
+
+
+package org.jboss.web.upgrade;
+
+import java.io.IOException;
+import java.io.OutputStream;
+
+import javax.servlet.ServletException;
+import javax.servlet.ServletInputStream;
+import javax.servlet.ServletOutputStream;
+import javax.servlet.annotation.WebServlet;
+import javax.servlet.http.HttpServlet;
+import javax.servlet.http.HttpServletResponse;
+
+import org.jboss.servlet.http.HttpEvent;
+import org.jboss.servlet.http.HttpEventServlet;
+import org.jboss.servlet.http.UpgradableHttpServletResponse;
+
+@WebServlet("/upgrade00")
+public class Upgrade00ServletTest extends HttpServlet implements HttpEventServlet {
+
+ int count = 0;
+
+ public void event(HttpEvent event) throws IOException, ServletException {
+ System.out.println("[" +
event.getHttpServletRequest().getSession(true).getId() + "] " +
event.getType());
+ ServletInputStream is = null;
+ ServletOutputStream os = null;
+ switch (event.getType()) {
+ case BEGIN:
+ event.setTimeout(20000);
+ HttpServletResponse response = event.getHttpServletResponse();
+ if (response instanceof UpgradableHttpServletResponse) {
+ ((UpgradableHttpServletResponse) response).startUpgrade();
+ } else {
+ throw new IllegalStateException("Cannot upgrade connection");
+ }
+ is = event.getHttpServletRequest().getInputStream();
+ byte[] buf = new byte[1024];
+ int n = is.read(buf);
+ // Do something with the content
+ os = event.getHttpServletResponse().getOutputStream();
+ os.println("Read: " + n);
+ if (n > 0) {
+ os.write(buf, 0, n);
+ }
+ response.setHeader("Upgrade", "WebSocket");
+ response.setHeader("Sec-WebSocket-Protocol", "sample");
+ response.setHeader("Connection", "Upgrade");
+ ((UpgradableHttpServletResponse) response).sendUpgrade();
+ break;
+ case END:
+ break;
+ case ERROR:
+ event.close();
+ break;
+ case EVENT:
+ os = event.getHttpServletResponse().getOutputStream();
+ // Using while (true): Not checking if the connection is available to writing
immediately
+ // will cause the write to be performed in blocking mode.
+ // boolean b = true;
+ // while (b) {
+ while (event.isWriteReady()) {
+ if (count % 100 == 0) {
+ os.println((count++) + " ");
+ } else {
+ os.print((count++) + " ");
+ }
+ }
+ //if (event.ready())
+ // os.flush();
+ break;
+ case READ:
+ is = event.getHttpServletRequest().getInputStream();
+ // Using while (true): Not checking if input is available will trigger a
blocking
+ // read. No other event should be triggered (the current READ event will be
in progress
+ // until the read timeouts, which will trigger an ERROR event due to an
IOException).
+ // while (true) {
+ while (is.available() > 0) {
+ int c = is.read();
+ if (c > 0) {
+ System.out.print((char) c);
+ } else {
+ System.out.print(c);
+ break;
+ }
+ }
+ System.out.println();
+ break;
+ case TIMEOUT:
+ // This will cause a generic event to be sent to the servlet every time the
connection is idle for
+ // a while.
+ event.resume();
+ break;
+ case WRITE:
+ break;
+ }
+ }
+
+}
Modified: trunk/webapps/docs/changelog.xml
===================================================================
--- trunk/webapps/docs/changelog.xml 2012-04-13 22:47:49 UTC (rev 2024)
+++ trunk/webapps/docs/changelog.xml 2012-04-16 10:24:28 UTC (rev 2025)
@@ -17,6 +17,19 @@
<body>
<section name="JBoss Web 7.2.0.Alpha1 (remm)">
+ <subsection name="Catalina">
+ <changelog>
+ <fix>
+ <jboss-jira>AS7-4469</jboss-jira>: Rebase SSL valve used by
mod_headers. (remm)
+ </fix>
+ <fix>
+ <jboss-jira>AS7-4469</jboss-jira>: Fix SSL session id attribute name
(standardized in Servlet 3). (remm)
+ </fix>
+ <fix>
+ Use the thread listener bind/unbind in the background process. (remm)
+ </fix>
+ </changelog>
+ </subsection>
<subsection name="Coyote">
<changelog>
<fix>
@@ -31,15 +44,6 @@
<add>
Protocol upgrade API. (remm)
</add>
- <fix>
- <jboss-jira>AS7-4469</jboss-jira>: Rebase SSL valve used by
mod_headers. (remm)
- </fix>
- <fix>
- <jboss-jira>AS7-4469</jboss-jira>: Fix SSL session id attribute name
(standardized in Servlet 3). (remm)
- </fix>
- <fix>
- Use the thread listener bind/unbind in the background process. (remm)
- </fix>
</changelog>
</subsection>
<subsection name="Jasper">