From 37cadf3aa01248ee089dc0741e7a6c9a15f57693 Mon Sep 17 00:00:00 2001 From: remm Date: Thu, 17 Aug 2006 11:41:43 +0000 Subject: [PATCH] - Update to use two action code. - The attribute to advertise comet support remains for now. - No update to the comet interface at this time. git-svn-id: https://svn.apache.org/repos/asf/tomcat/tc6.0.x/trunk@432214 13f79535-47bb-0310-9956-ffa450edef68 --- .../apache/catalina/connector/CoyoteAdapter.java | 24 +++++++++++++--------- java/org/apache/coyote/ActionCode.java | 12 +++++++++++ .../apache/coyote/http11/Http11AprProcessor.java | 12 +++++------ 3 files changed, 31 insertions(+), 17 deletions(-) diff --git a/java/org/apache/catalina/connector/CoyoteAdapter.java b/java/org/apache/catalina/connector/CoyoteAdapter.java index 26261a66e..4b087cda0 100644 --- a/java/org/apache/catalina/connector/CoyoteAdapter.java +++ b/java/org/apache/catalina/connector/CoyoteAdapter.java @@ -128,7 +128,8 @@ public class CoyoteAdapter servlet = (CometProcessor) request.getWrapper().allocate(); } catch (Throwable t) { log.error(sm.getString("coyoteAdapter.service"), t); - request.removeAttribute("org.apache.tomcat.comet"); + request.recycle(); + response.recycle(); // Restore the context classloader Thread.currentThread().setContextClassLoader (CoyoteAdapter.class.getClassLoader()); @@ -140,7 +141,6 @@ public class CoyoteAdapter } else { if (!servlet.read(request.getRequest(), response.getResponse())) { error = true; - request.removeAttribute("org.apache.tomcat.comet"); try { servlet.error(request.getRequest(), response.getResponse()); } catch (Throwable th) { @@ -148,12 +148,15 @@ public class CoyoteAdapter } } } + if (response.isClosed()) { + res.action(ActionCode.ACTION_COMET_END, null); + } return (!error); } catch (Throwable t) { if (!(t instanceof IOException)) { log.error(sm.getString("coyoteAdapter.service"), t); } - request.removeAttribute("org.apache.tomcat.comet"); + error = true; try { servlet.error(request.getRequest(), response.getResponse()); } catch (Throwable th) { @@ -161,14 +164,14 @@ public class CoyoteAdapter } return false; } finally { + // Restore the context classloader + Thread.currentThread().setContextClassLoader + (CoyoteAdapter.class.getClassLoader()); // Recycle the wrapper request and response - if (request.getAttribute("org.apache.tomcat.comet") == null) { + if (error || response.isClosed()) { request.recycle(); response.recycle(); } - // Restore the context classloader - Thread.currentThread().setContextClassLoader - (CoyoteAdapter.class.getClassLoader()); } } return true; @@ -222,14 +225,15 @@ public class CoyoteAdapter connector.getContainer().getPipeline().getFirst().invoke(request, response); } - if (request.getAttribute("org.apache.tomcat.comet") == Boolean.TRUE - && request.getWrapper().allocate() instanceof CometProcessor) { + if (request.getWrapper().allocate() instanceof CometProcessor + && !response.isClosed()) { comet = true; + res.action(ActionCode.ACTION_COMET_BEGIN, null); } if (!comet) { response.finishResponse(); - req.action( ActionCode.ACTION_POST_REQUEST , null); + req.action(ActionCode.ACTION_POST_REQUEST , null); } } catch (IOException e) { diff --git a/java/org/apache/coyote/ActionCode.java b/java/org/apache/coyote/ActionCode.java index b5edb1934..e9f51338a 100644 --- a/java/org/apache/coyote/ActionCode.java +++ b/java/org/apache/coyote/ActionCode.java @@ -133,6 +133,18 @@ public final class ActionCode { public static final ActionCode ACTION_REQ_SET_BODY_REPLAY = new ActionCode(20); + /** + * Callback for begin Comet processing + */ + public static final ActionCode ACTION_COMET_BEGIN = new ActionCode(21); + + + /** + * Callback for begin Comet processing + */ + public static final ActionCode ACTION_COMET_END = new ActionCode(22); + + // ----------------------------------------------------------- Constructors int code; diff --git a/java/org/apache/coyote/http11/Http11AprProcessor.java b/java/org/apache/coyote/http11/Http11AprProcessor.java index 961f39f0c..88b316f5c 100644 --- a/java/org/apache/coyote/http11/Http11AprProcessor.java +++ b/java/org/apache/coyote/http11/Http11AprProcessor.java @@ -744,9 +744,6 @@ public class Http11AprProcessor implements ActionHook { try { rp.setStage(org.apache.coyote.Constants.STAGE_SERVICE); error = !adapter.event(request, response, error); - if (request.getAttribute("org.apache.tomcat.comet") == null) { - comet = false; - } } catch (InterruptedIOException e) { error = true; } catch (Throwable t) { @@ -875,10 +872,6 @@ public class Http11AprProcessor implements ActionHook { error = response.getErrorException() != null || statusDropsConnection(response.getStatus()); } - // Comet support - if (request.getAttribute("org.apache.tomcat.comet") != null) { - comet = true; - } } catch (InterruptedIOException e) { error = true; } catch (Throwable t) { @@ -1217,6 +1210,11 @@ public class Http11AprProcessor implements ActionHook { InternalAprInputBuffer internalBuffer = (InternalAprInputBuffer) request.getInputBuffer(); internalBuffer.addActiveFilter(savedBody); + + } else if (actionCode == ActionCode.ACTION_COMET_BEGIN) { + comet = true; + } else if (actionCode == ActionCode.ACTION_COMET_END) { + comet = false; } } -- 2.11.0