Author: remy.maucherat(a)jboss.com
Date: 2012-03-14 13:31:01 -0400 (Wed, 14 Mar 2012)
New Revision: 2002
Added:
trunk/java/org/jboss/web/upgrade/
trunk/java/org/jboss/web/upgrade/ProtocolHandler.java
trunk/java/org/jboss/web/upgrade/WebConnection.java
Modified:
trunk/java/org/apache/catalina/connector/LocalStrings.properties
trunk/java/org/apache/catalina/connector/Response.java
trunk/java/org/apache/catalina/connector/ResponseFacade.java
trunk/java/org/apache/coyote/ActionCode.java
Log:
Add an API for protocol upgrade based on a mix between the current Servlet draft and the
HTTP events capabilities.
Modified: trunk/java/org/apache/catalina/connector/LocalStrings.properties
===================================================================
--- trunk/java/org/apache/catalina/connector/LocalStrings.properties 2012-03-14 15:15:05
UTC (rev 2001)
+++ trunk/java/org/apache/catalina/connector/LocalStrings.properties 2012-03-14 17:31:01
UTC (rev 2002)
@@ -39,6 +39,8 @@
coyoteResponse.sendFile.ise=Cannot call sendFile() after the response has been committed
coyoteResponse.sendFile.no=Sendfile is disabled
coyoteResponse.sendFile.path=Invalid path
+coyoteResponse.upgrade.ise=Cannot call sendUpgrade() after the response has been
committed
+coyoteResponse.upgrade.noEvents=Cannot upgrade from HTTP/1.1 without IO events
#
# CoyoteRequest
Modified: trunk/java/org/apache/catalina/connector/Response.java
===================================================================
--- trunk/java/org/apache/catalina/connector/Response.java 2012-03-14 15:15:05 UTC (rev
2001)
+++ trunk/java/org/apache/catalina/connector/Response.java 2012-03-14 17:31:01 UTC (rev
2002)
@@ -47,6 +47,7 @@
import org.apache.catalina.util.CharsetMapper;
import org.apache.catalina.util.DateTool;
import org.apache.catalina.util.StringManager;
+import org.apache.coyote.ActionCode;
import org.apache.naming.resources.CacheEntry;
import org.apache.naming.resources.ProxyDirContext;
import org.apache.tomcat.util.buf.CharChunk;
@@ -1341,6 +1342,29 @@
}
+ public void sendUpgrade(org.jboss.web.upgrade.ProtocolHandler protocolHandler)
+ throws IOException {
+
+ if (isCommitted())
+ throw new IllegalStateException
+ (sm.getString("coyoteResponse.upgrade.ise"));
+
+ if (!connector.hasIoEvents())
+ throw new IllegalStateException
+ (sm.getString("coyoteResponse.upgrade.noEvents"));
+
+ request.getCoyoteRequest().action(ActionCode.UPGRADE, protocolHandler);
+
+ // Output required by RFC2616. Protocol specific headers should have
+ // already been set.
+ setStatus(HttpServletResponse.SC_SWITCHING_PROTOCOLS);
+
+ // Cause the response to be finished (from the application perspective)
+ setSuspended(true);
+
+ }
+
+
public void sendFile(String path, String absolutePath, long start, long end) {
if (isCommitted())
Modified: trunk/java/org/apache/catalina/connector/ResponseFacade.java
===================================================================
--- trunk/java/org/apache/catalina/connector/ResponseFacade.java 2012-03-14 15:15:05 UTC
(rev 2001)
+++ trunk/java/org/apache/catalina/connector/ResponseFacade.java 2012-03-14 17:31:01 UTC
(rev 2002)
@@ -454,6 +454,19 @@
}
+ public void sendUpgrade(org.jboss.web.upgrade.ProtocolHandler protocolHandler)
+ throws IOException {
+
+ if (isCommitted())
+ throw new IllegalStateException
+ (/*sm.getString("responseBase.reset.ise")*/);
+
+ response.setAppCommitted(true);
+
+ response.sendUpgrade(protocolHandler);
+
+ }
+
public void setDateHeader(String name, long date) {
if (isCommitted())
Modified: trunk/java/org/apache/coyote/ActionCode.java
===================================================================
--- trunk/java/org/apache/coyote/ActionCode.java 2012-03-14 15:15:05 UTC (rev 2001)
+++ trunk/java/org/apache/coyote/ActionCode.java 2012-03-14 17:31:01 UTC (rev 2002)
@@ -171,6 +171,11 @@
*/
public static final ActionCode ACTION_EVENT_WRITE = new ActionCode(27);
+ /**
+ * Ask for a protocol upgrade
+ */
+ public static final ActionCode UPGRADE = new ActionCode(28);
+
// ----------------------------------------------------------- Constructors
int code;
Added: trunk/java/org/jboss/web/upgrade/ProtocolHandler.java
===================================================================
--- trunk/java/org/jboss/web/upgrade/ProtocolHandler.java (rev 0)
+++ trunk/java/org/jboss/web/upgrade/ProtocolHandler.java 2012-03-14 17:31:01 UTC (rev
2002)
@@ -0,0 +1,34 @@
+/*
+ * JBoss, Home of Professional Open Source.
+ * Copyright 2012, Red Hat, Inc., and individual contributors
+ * as indicated by the @author tags. See the copyright.txt file 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;
+
+public interface ProtocolHandler {
+ public void init(WebConnection wc);
+ public void destroy(WebConnection wc);
+ public void inputAvailable(WebConnection wc);
+ public void outputReady(WebConnection wc);
+ public void resume(WebConnection wc);
+ public void timeout(WebConnection wc);
+ public void error(WebConnection wc);
+ public void eof(WebConnection wc);
+}
Added: trunk/java/org/jboss/web/upgrade/WebConnection.java
===================================================================
--- trunk/java/org/jboss/web/upgrade/WebConnection.java (rev 0)
+++ trunk/java/org/jboss/web/upgrade/WebConnection.java 2012-03-14 17:31:01 UTC (rev
2002)
@@ -0,0 +1,37 @@
+/*
+ * JBoss, Home of Professional Open Source.
+ * Copyright 2012, Red Hat, Inc., and individual contributors
+ * as indicated by the @author tags. See the copyright.txt file 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;
+
+public interface WebConnection {
+ public boolean isReadReady();
+ public boolean isWriteReady();
+ public void setTimeout(int timeout);
+ public void suspend();
+ public void close() throws IOException;
+ public int read(byte[] b, int off, int len)
+ throws IOException;
+ public void write(byte[] b, int off, int len)
+ throws IOException;
+}