From 512f48dedc8ceeb5d4707754c2d7a4cfbb582633 Mon Sep 17 00:00:00 2001 From: gaodayue Date: Thu, 30 Aug 2018 21:35:19 +0800 Subject: [PATCH] BytesFullResponseHandler should only consume readableBytes of ChannelBuffer --- .../authentication/BytesFullResponseHandler.java | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/extensions-core/druid-basic-security/src/main/java/org/apache/druid/security/basic/authentication/BytesFullResponseHandler.java b/extensions-core/druid-basic-security/src/main/java/org/apache/druid/security/basic/authentication/BytesFullResponseHandler.java index fa00a92cf2e2..0f75ae2f3726 100644 --- a/extensions-core/druid-basic-security/src/main/java/org/apache/druid/security/basic/authentication/BytesFullResponseHandler.java +++ b/extensions-core/druid-basic-security/src/main/java/org/apache/druid/security/basic/authentication/BytesFullResponseHandler.java @@ -22,6 +22,7 @@ import org.apache.druid.java.util.http.client.response.ClientResponse; import org.apache.druid.java.util.http.client.response.FullResponseHolder; import org.apache.druid.java.util.http.client.response.HttpResponseHandler; +import org.jboss.netty.buffer.ChannelBuffer; import org.jboss.netty.handler.codec.http.HttpChunk; import org.jboss.netty.handler.codec.http.HttpResponse; @@ -36,7 +37,7 @@ public ClientResponse handleResponse(HttpResponse response) null ); - holder.addChunk(response.getContent().array()); + holder.addChunk(getContentBytes(response.getContent())); return ClientResponse.unfinished( holder @@ -55,7 +56,7 @@ public ClientResponse handleChunk( return ClientResponse.finished(null); } - holder.addChunk(chunk.getContent().array()); + holder.addChunk(getContentBytes(chunk.getContent())); return response; } @@ -72,4 +73,11 @@ public void exceptionCaught( { // Its safe to Ignore as the ClientResponse returned in handleChunk were unfinished } + + private byte[] getContentBytes(ChannelBuffer content) + { + byte[] contentBytes = new byte[content.readableBytes()]; + content.readBytes(contentBytes); + return contentBytes; + } }