1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28 package org.apache.http.nio.protocol;
29
30 import java.io.IOException;
31 import java.io.InputStream;
32 import java.io.OutputStream;
33
34 import org.apache.http.ConnectionReuseStrategy;
35 import org.apache.http.HttpEntity;
36 import org.apache.http.HttpException;
37 import org.apache.http.HttpRequest;
38 import org.apache.http.HttpResponse;
39 import org.apache.http.annotation.Immutable;
40 import org.apache.http.nio.ContentDecoder;
41 import org.apache.http.nio.ContentEncoder;
42 import org.apache.http.nio.NHttpClientConnection;
43 import org.apache.http.nio.NHttpClientHandler;
44 import org.apache.http.nio.entity.BufferingNHttpEntity;
45 import org.apache.http.nio.entity.ConsumingNHttpEntity;
46 import org.apache.http.nio.util.ByteBufferAllocator;
47 import org.apache.http.nio.util.HeapByteBufferAllocator;
48 import org.apache.http.params.HttpParams;
49 import org.apache.http.protocol.HttpContext;
50 import org.apache.http.protocol.HttpProcessor;
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72 @Deprecated
73 @Immutable
74 public class BufferingHttpClientHandler implements NHttpClientHandler {
75
76 private final AsyncNHttpClientHandler asyncHandler;
77
78 public BufferingHttpClientHandler(
79 final HttpProcessor httpProcessor,
80 final HttpRequestExecutionHandler execHandler,
81 final ConnectionReuseStrategy connStrategy,
82 final ByteBufferAllocator allocator,
83 final HttpParams params) {
84 this.asyncHandler = new AsyncNHttpClientHandler(
85 httpProcessor,
86 new ExecutionHandlerAdaptor(execHandler),
87 connStrategy,
88 allocator,
89 params);
90 }
91
92 public BufferingHttpClientHandler(
93 final HttpProcessor httpProcessor,
94 final HttpRequestExecutionHandler execHandler,
95 final ConnectionReuseStrategy connStrategy,
96 final HttpParams params) {
97 this(httpProcessor, execHandler, connStrategy,
98 HeapByteBufferAllocator.INSTANCE, params);
99 }
100
101 public void setEventListener(final EventListener eventListener) {
102 this.asyncHandler.setEventListener(eventListener);
103 }
104
105 public void connected(final NHttpClientConnection conn, final Object attachment) {
106 this.asyncHandler.connected(conn, attachment);
107 }
108
109 public void closed(final NHttpClientConnection conn) {
110 this.asyncHandler.closed(conn);
111 }
112
113 public void requestReady(final NHttpClientConnection conn) {
114 this.asyncHandler.requestReady(conn);
115 }
116
117 public void inputReady(final NHttpClientConnection conn, final ContentDecoder decoder) {
118 this.asyncHandler.inputReady(conn, decoder);
119 }
120
121 public void outputReady(final NHttpClientConnection conn, final ContentEncoder encoder) {
122 this.asyncHandler.outputReady(conn, encoder);
123 }
124
125 public void responseReceived(final NHttpClientConnection conn) {
126 this.asyncHandler.responseReceived(conn);
127 }
128
129 public void exception(final NHttpClientConnection conn, final HttpException httpex) {
130 this.asyncHandler.exception(conn, httpex);
131 }
132
133 public void exception(final NHttpClientConnection conn, final IOException ioex) {
134 this.asyncHandler.exception(conn, ioex);
135 }
136
137 public void timeout(final NHttpClientConnection conn) {
138 this.asyncHandler.timeout(conn);
139 }
140
141 static class ExecutionHandlerAdaptor implements NHttpRequestExecutionHandler {
142
143 private final HttpRequestExecutionHandler execHandler;
144
145 public ExecutionHandlerAdaptor(final HttpRequestExecutionHandler execHandler) {
146 super();
147 this.execHandler = execHandler;
148 }
149
150 public void initalizeContext(final HttpContext context, final Object attachment) {
151 this.execHandler.initalizeContext(context, attachment);
152 }
153 public void finalizeContext(final HttpContext context) {
154 this.execHandler.finalizeContext(context);
155 }
156
157 public HttpRequest submitRequest(final HttpContext context) {
158 return this.execHandler.submitRequest(context);
159 }
160
161 public ConsumingNHttpEntity responseEntity(
162 final HttpResponse response,
163 final HttpContext context) throws IOException {
164 return new BufferingNHttpEntity(
165 response.getEntity(),
166 HeapByteBufferAllocator.INSTANCE);
167 }
168
169 public void handleResponse(
170 final HttpResponse response,
171 final HttpContext context) throws IOException {
172 this.execHandler.handleResponse(response, context);
173 }
174
175 }
176
177 }