diff --git a/rt/transports/http/src/main/java/org/apache/cxf/transport/http/AbstractHTTPDestination.java b/rt/transports/http/src/main/java/org/apache/cxf/transport/http/AbstractHTTPDestination.java index 2beaf93aeb9..4e1d635c4cc 100644 --- a/rt/transports/http/src/main/java/org/apache/cxf/transport/http/AbstractHTTPDestination.java +++ b/rt/transports/http/src/main/java/org/apache/cxf/transport/http/AbstractHTTPDestination.java @@ -35,7 +35,6 @@ import javax.servlet.ServletConfig; import javax.servlet.ServletContext; -import javax.servlet.ServletRequest; import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletResponse; import javax.xml.namespace.QName; @@ -120,7 +119,6 @@ public abstract class AbstractHTTPDestination protected boolean fixedParameterOrder; protected boolean multiplexWithAddress; protected CertConstraints certConstraints; - protected boolean isServlet3; protected boolean decodeBasicAuthWithIso8859; protected ContinuationProviderFactory cproviderFactory; protected boolean enableWebSocket; @@ -147,12 +145,6 @@ public AbstractHTTPDestination(Bus b, this.bus = b; this.registry = registry; this.path = path; - try { - ServletRequest.class.getMethod("isAsyncSupported"); - isServlet3 = true; - } catch (Throwable t) { - //servlet 2.5 or earlier, no async support - } decodeBasicAuthWithIso8859 = PropertyUtils.isTrue(bus.getProperty(DECODE_BASIC_AUTH_WITH_ISO8859)); initConfig(); @@ -460,12 +452,6 @@ private String setEncoding(final Message inMessage, return contentType; } protected Message retrieveFromContinuation(HttpServletRequest req) { - if (!isServlet3) { - if (cproviderFactory != null) { - return cproviderFactory.retrieveFromContinuation(req); - } - return null; - } return retrieveFromServlet3Async(req); } @@ -482,7 +468,7 @@ protected void setupContinuation(Message inMessage, final HttpServletRequest req, final HttpServletResponse resp) { try { - if (isServlet3 && req.isAsyncSupported()) { + if (req.isAsyncSupported()) { inMessage.put(ContinuationProvider.class.getName(), new Servlet3ContinuationProvider(req, resp, inMessage)); } else if (cproviderFactory != null) { diff --git a/rt/transports/http/src/main/java/org/apache/cxf/transport/http/Servlet3ContinuationProvider.java b/rt/transports/http/src/main/java/org/apache/cxf/transport/http/Servlet3ContinuationProvider.java index 9492489fc02..508f848d8c2 100644 --- a/rt/transports/http/src/main/java/org/apache/cxf/transport/http/Servlet3ContinuationProvider.java +++ b/rt/transports/http/src/main/java/org/apache/cxf/transport/http/Servlet3ContinuationProvider.java @@ -29,7 +29,6 @@ import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletResponse; -import org.apache.cxf.common.classloader.ClassLoaderUtils; import org.apache.cxf.common.util.PropertyUtils; import org.apache.cxf.continuations.Continuation; import org.apache.cxf.continuations.ContinuationCallback; @@ -41,22 +40,10 @@ * */ public class Servlet3ContinuationProvider implements ContinuationProvider { - static final boolean IS_31; - static { - boolean is31 = false; - try { - ClassLoaderUtils.loadClass("javax.servlet.WriteListener", HttpServletRequest.class); - is31 = true; - } catch (Throwable t) { - is31 = false; - } - IS_31 = is31; - } - HttpServletRequest req; HttpServletResponse resp; Message inMessage; - Servlet3Continuation continuation; + Servlet31Continuation continuation; public Servlet3ContinuationProvider(HttpServletRequest req, HttpServletResponse resp, @@ -73,7 +60,6 @@ public void complete() { } } - /** {@inheritDoc}*/ public Continuation getContinuation() { if (inMessage.getExchange().isOneWay()) { @@ -81,14 +67,14 @@ public Continuation getContinuation() { } if (continuation == null) { - continuation = IS_31 ? new Servlet31Continuation() : new Servlet3Continuation(); + continuation = new Servlet31Continuation(); } else { continuation.startAsyncAgain(); } return continuation; } - public class Servlet3Continuation implements Continuation, AsyncListener { + public class Servlet31Continuation implements Continuation, AsyncListener { private static final String BLOCK_RESTART = "org.apache.cxf.continuation.block.restart"; AsyncContext context; volatile boolean isNew = true; @@ -99,8 +85,8 @@ public class Servlet3Continuation implements Continuation, AsyncListener { volatile Object obj; private ContinuationCallback callback; private boolean blockRestart; - - public Servlet3Continuation() { + + public Servlet31Continuation() { req.setAttribute(AbstractHTTPDestination.CXF_CONTINUATION_MESSAGE, inMessage.getExchange().getInMessage()); callback = inMessage.getExchange().get(ContinuationCallback.class); @@ -139,7 +125,15 @@ public boolean suspend(long timeout) { return true; } protected void updateMessageForSuspend() { - inMessage.getExchange().getInMessage().getInterceptorChain().suspend(); + Message currentMessage = PhaseInterceptorChain.getCurrentMessage(); + if (currentMessage.get(WriteListener.class) != null) { + // CXF Continuation WriteListener will likely need to be introduced + // for NIO supported with non-Servlet specific mechanisms + getOutputStream().setWriteListener(currentMessage.get(WriteListener.class)); + currentMessage.getInterceptorChain().suspend(); + } else { + inMessage.getExchange().getInMessage().getInterceptorChain().suspend(); + } } public void redispatch() { if (!isComplete) { @@ -240,7 +234,7 @@ private boolean isClientDisconnected(Throwable ex) { @Override public boolean isReadyForWrite() { - return true; + return getOutputStream().isReady(); } protected ServletOutputStream getOutputStream() { @@ -256,26 +250,4 @@ public boolean isTimeout() { return isTimeout; } } - public class Servlet31Continuation extends Servlet3Continuation { - public Servlet31Continuation() { - } - - @Override - protected void updateMessageForSuspend() { - Message currentMessage = PhaseInterceptorChain.getCurrentMessage(); - if (currentMessage.get(WriteListener.class) != null) { - // CXF Continuation WriteListener will likely need to be introduced - // for NIO supported with non-Servlet specific mechanisms - getOutputStream().setWriteListener(currentMessage.get(WriteListener.class)); - currentMessage.getInterceptorChain().suspend(); - } else { - inMessage.getExchange().getInMessage().getInterceptorChain().suspend(); - } - } - - @Override - public boolean isReadyForWrite() { - return getOutputStream().isReady(); - } - } -} +} \ No newline at end of file