You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@hc.apache.org by ol...@apache.org on 2017/05/09 20:04:08 UTC

[20/22] httpcomponents-core git commit: HTTPCORE-228: Fixed NPE in AsyncNHttpServiceHandler caused by entity enclosing requests if no matching request handler can be found

HTTPCORE-228: Fixed NPE in AsyncNHttpServiceHandler caused by entity enclosing requests if no matching request handler can be found


git-svn-id: https://svn.apache.org/repos/asf/httpcomponents/httpcore/branches/4.0.x@959933 13f79535-47bb-0310-9956-ffa450edef68


Project: http://git-wip-us.apache.org/repos/asf/httpcomponents-core/repo
Commit: http://git-wip-us.apache.org/repos/asf/httpcomponents-core/commit/c4b80f38
Tree: http://git-wip-us.apache.org/repos/asf/httpcomponents-core/tree/c4b80f38
Diff: http://git-wip-us.apache.org/repos/asf/httpcomponents-core/diff/c4b80f38

Branch: refs/heads/4.0.x
Commit: c4b80f3830005146a87b387a59ccc3fff62f9c0f
Parents: 6822b0c
Author: Oleg Kalnichevski <ol...@apache.org>
Authored: Fri Jul 2 10:07:51 2010 +0000
Committer: Oleg Kalnichevski <ol...@apache.org>
Committed: Fri Jul 2 10:07:51 2010 +0000

----------------------------------------------------------------------
 RELEASE_NOTES.txt                               |  4 ++++
 .../nio/protocol/AsyncNHttpServiceHandler.java  | 22 ++++++++++----------
 2 files changed, 15 insertions(+), 11 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/httpcomponents-core/blob/c4b80f38/RELEASE_NOTES.txt
----------------------------------------------------------------------
diff --git a/RELEASE_NOTES.txt b/RELEASE_NOTES.txt
index 5a00c20..c40a741 100644
--- a/RELEASE_NOTES.txt
+++ b/RELEASE_NOTES.txt
@@ -1,5 +1,9 @@
 Changes since 4.0.1
 
+* [HTTPCORE-228] Fixed NPE in AsyncNHttpServiceHandler caused by entity enclosing requests
+  if no matching request handler can be found.  
+  Contributed by Oleg Kalnichevski <olegk at apache.org>
+
 * [HTTPCORE-222] Fixed OSGi Import-Package
   Contributed by Willem Jiang <willem.jiang at gmail.com>
 

http://git-wip-us.apache.org/repos/asf/httpcomponents-core/blob/c4b80f38/httpcore-nio/src/main/java/org/apache/http/nio/protocol/AsyncNHttpServiceHandler.java
----------------------------------------------------------------------
diff --git a/httpcore-nio/src/main/java/org/apache/http/nio/protocol/AsyncNHttpServiceHandler.java b/httpcore-nio/src/main/java/org/apache/http/nio/protocol/AsyncNHttpServiceHandler.java
index cf84174..37ff4a3 100644
--- a/httpcore-nio/src/main/java/org/apache/http/nio/protocol/AsyncNHttpServiceHandler.java
+++ b/httpcore-nio/src/main/java/org/apache/http/nio/protocol/AsyncNHttpServiceHandler.java
@@ -177,7 +177,8 @@ public class AsyncNHttpServiceHandler extends NHttpHandlerBase
         try {
 
             if (request instanceof HttpEntityEnclosingRequest) {
-                if (((HttpEntityEnclosingRequest) request).expectContinue()) {
+                HttpEntityEnclosingRequest entityRequest = (HttpEntityEnclosingRequest) request;
+                if (entityRequest.expectContinue()) {
                     response = this.responseFactory.newHttpResponse(
                             ver, HttpStatus.SC_CONTINUE, context);
                     response.setParams(
@@ -207,20 +208,19 @@ public class AsyncNHttpServiceHandler extends NHttpHandlerBase
                     }
                 }
                 // Request content is expected.
-                HttpEntity entity = ((HttpEntityEnclosingRequest) request).getEntity();
+                ConsumingNHttpEntity consumingEntity = null;
 
                 // Lookup request handler for this request
                 if (requestHandler != null) {
-                    ConsumingNHttpEntity consumingEntity = requestHandler.entityRequest(
-                            (HttpEntityEnclosingRequest) request, context);
-                    if (consumingEntity == null) {
-                        consumingEntity = new ConsumingNHttpEntityTemplate(
-                                entity,
-                                new SkipContentListener(this.allocator));
-                    }
-                    ((HttpEntityEnclosingRequest) request).setEntity(consumingEntity);
-                    connState.setConsumingEntity(consumingEntity);
+                    consumingEntity = requestHandler.entityRequest(entityRequest, context);
+                }
+                if (consumingEntity == null) {
+                    consumingEntity = new ConsumingNHttpEntityTemplate(
+                            entityRequest.getEntity(),
+                            new SkipContentListener(this.allocator));
                 }
+                entityRequest.setEntity(consumingEntity);
+                connState.setConsumingEntity(consumingEntity);
 
             } else {
                 // No request content is expected.