This is an automated email from the ASF dual-hosted git repository.

reta pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/cxf.git


The following commit(s) were added to refs/heads/master by this push:
     new 2f9c529  CXF-8235 Handle null continuation in AsyncResponseImpl 
instead of throwing a NullPointerException (#649)
2f9c529 is described below

commit 2f9c529ed514d05c30b8727433362fe5e2ac201a
Author: Adam Anderson <[email protected]>
AuthorDate: Tue Mar 10 18:53:51 2020 -0500

    CXF-8235 Handle null continuation in AsyncResponseImpl instead of throwing 
a NullPointerException (#649)
---
 .../apache/cxf/jaxrs/impl/AsyncResponseImpl.java   |  5 ++++
 .../cxf/jaxrs/impl/AsyncResponseImplTest.java      | 28 ++++++++++++++++++++++
 2 files changed, 33 insertions(+)

diff --git 
a/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/impl/AsyncResponseImpl.java
 
b/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/impl/AsyncResponseImpl.java
index 3b1cd9b..e2d2a6d 100644
--- 
a/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/impl/AsyncResponseImpl.java
+++ 
b/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/impl/AsyncResponseImpl.java
@@ -302,6 +302,11 @@ public class AsyncResponseImpl implements AsyncResponse, 
ContinuationCallback {
     private void initContinuation() {
         ContinuationProvider provider =
             
(ContinuationProvider)inMessage.get(ContinuationProvider.class.getName());
+        if (provider == null) {
+            throw new IllegalArgumentException(
+                "Continuation not supported. " 
+                + "Please ensure that all servlets and servlet filters support 
async operations");
+        }
         cont = provider.getContinuation();
         initialSuspend = true;
     }
diff --git 
a/rt/frontend/jaxrs/src/test/java/org/apache/cxf/jaxrs/impl/AsyncResponseImplTest.java
 
b/rt/frontend/jaxrs/src/test/java/org/apache/cxf/jaxrs/impl/AsyncResponseImplTest.java
index 979dde4..4fa061f 100644
--- 
a/rt/frontend/jaxrs/src/test/java/org/apache/cxf/jaxrs/impl/AsyncResponseImplTest.java
+++ 
b/rt/frontend/jaxrs/src/test/java/org/apache/cxf/jaxrs/impl/AsyncResponseImplTest.java
@@ -33,6 +33,7 @@ import 
org.apache.cxf.transport.http.Servlet3ContinuationProvider;
 
 import org.easymock.EasyMock;
 import org.easymock.IMocksControl;
+import org.junit.Assert;
 import org.junit.Before;
 import org.junit.Test;
 
@@ -161,4 +162,31 @@ public class AsyncResponseImplTest {
         assertEquals("AsynchResponse.isSuspended() returned a different 
response after canceling a second time",
                      isSuspended, impl.isSuspended());
     }
+    
+    /**
+     * Test that creatinging an AsyncResponse with a null continuation throws
+     * an IllegalArgumentException instead of a NullPointer Exception.
+     */
+    @Test
+    public void testNullContinutaion() {
+        HttpServletRequest req = control.createMock(HttpServletRequest.class);
+        AsyncContext asyncCtx = control.createMock(AsyncContext.class);
+        Message msg = new MessageImpl();
+        msg.setExchange(new ExchangeImpl());
+
+        req.startAsync();
+        EasyMock.expectLastCall().andReturn(asyncCtx);
+        control.replay();
+
+        AsyncResponse impl;
+        try {
+            impl = new AsyncResponseImpl(msg);
+        } catch (IllegalArgumentException e) {
+            assertEquals("Continuation not supported. " 
+                             + "Please ensure that all servlets and servlet 
filters support async operations",
+                         e.getMessage());
+            return;
+        }
+        Assert.fail("Expected IllegalArgumentException, but instead got valid 
AsyncResponse, " + impl);
+    }
 }
\ No newline at end of file

Reply via email to