This is an automated email from the ASF dual-hosted git repository.
reta pushed a commit to branch 3.2.x-fixes
in repository https://gitbox.apache.org/repos/asf/cxf.git
The following commit(s) were added to refs/heads/3.2.x-fixes by this push:
new c5f18c0 CXF-8235 Handle null continuation in AsyncResponseImpl
instead of throwing a NullPointerException (#649)
c5f18c0 is described below
commit c5f18c09de23ad06e273bd6ba9032ea125c96991
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 | 27 ++++++++++++++++++++++
2 files changed, 32 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 eb3a8d2..ae2d0e3 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
@@ -303,6 +303,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 f1706f2..852e3d6 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
@@ -159,4 +159,31 @@ public class AsyncResponseImplTest extends Assert {
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);
+ }
}