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.protocol;
29
30 import java.io.IOException;
31 import java.util.ArrayList;
32 import java.util.Iterator;
33 import java.util.List;
34
35 import org.apache.http.HttpException;
36 import org.apache.http.HttpRequest;
37 import org.apache.http.HttpRequestInterceptor;
38 import org.apache.http.HttpResponse;
39 import org.apache.http.HttpResponseInterceptor;
40 import org.apache.http.util.Args;
41
42
43
44
45
46
47
48
49
50
51
52 @Deprecated
53 public final class BasicHttpProcessor implements
54 HttpProcessor, HttpRequestInterceptorList, HttpResponseInterceptorList, Cloneable {
55
56
57 protected final List<HttpRequestInterceptor> requestInterceptors = new ArrayList<HttpRequestInterceptor>();
58 protected final List<HttpResponseInterceptor> responseInterceptors = new ArrayList<HttpResponseInterceptor>();
59
60 @Override
61 public void addRequestInterceptor(final HttpRequestInterceptor itcp) {
62 if (itcp == null) {
63 return;
64 }
65 this.requestInterceptors.add(itcp);
66 }
67
68 @Override
69 public void addRequestInterceptor(
70 final HttpRequestInterceptor itcp, final int index) {
71 if (itcp == null) {
72 return;
73 }
74 this.requestInterceptors.add(index, itcp);
75 }
76
77 @Override
78 public void addResponseInterceptor(
79 final HttpResponseInterceptor itcp, final int index) {
80 if (itcp == null) {
81 return;
82 }
83 this.responseInterceptors.add(index, itcp);
84 }
85
86 @Override
87 public void removeRequestInterceptorByClass(final Class<? extends HttpRequestInterceptor> clazz) {
88 for (final Iterator<HttpRequestInterceptor> it = this.requestInterceptors.iterator();
89 it.hasNext(); ) {
90 final Object request = it.next();
91 if (request.getClass().equals(clazz)) {
92 it.remove();
93 }
94 }
95 }
96
97 @Override
98 public void removeResponseInterceptorByClass(final Class<? extends HttpResponseInterceptor> clazz) {
99 for (final Iterator<HttpResponseInterceptor> it = this.responseInterceptors.iterator();
100 it.hasNext(); ) {
101 final Object request = it.next();
102 if (request.getClass().equals(clazz)) {
103 it.remove();
104 }
105 }
106 }
107
108 public void addInterceptor(final HttpRequestInterceptor interceptor) {
109 addRequestInterceptor(interceptor);
110 }
111
112 public void addInterceptor(final HttpRequestInterceptor interceptor, final int index) {
113 addRequestInterceptor(interceptor, index);
114 }
115
116 @Override
117 public int getRequestInterceptorCount() {
118 return this.requestInterceptors.size();
119 }
120
121 @Override
122 public HttpRequestInterceptor getRequestInterceptor(final int index) {
123 if ((index < 0) || (index >= this.requestInterceptors.size())) {
124 return null;
125 }
126 return this.requestInterceptors.get(index);
127 }
128
129 @Override
130 public void clearRequestInterceptors() {
131 this.requestInterceptors.clear();
132 }
133
134 @Override
135 public void addResponseInterceptor(final HttpResponseInterceptor itcp) {
136 if (itcp == null) {
137 return;
138 }
139 this.responseInterceptors.add(itcp);
140 }
141
142 public void addInterceptor(final HttpResponseInterceptor interceptor) {
143 addResponseInterceptor(interceptor);
144 }
145
146 public void addInterceptor(final HttpResponseInterceptor interceptor, final int index) {
147 addResponseInterceptor(interceptor, index);
148 }
149
150 @Override
151 public int getResponseInterceptorCount() {
152 return this.responseInterceptors.size();
153 }
154
155 @Override
156 public HttpResponseInterceptor getResponseInterceptor(final int index) {
157 if ((index < 0) || (index >= this.responseInterceptors.size())) {
158 return null;
159 }
160 return this.responseInterceptors.get(index);
161 }
162
163 @Override
164 public void clearResponseInterceptors() {
165 this.responseInterceptors.clear();
166 }
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185 @Override
186 public void setInterceptors(final List<?> list) {
187 Args.notNull(list, "Inteceptor list");
188 this.requestInterceptors.clear();
189 this.responseInterceptors.clear();
190 for (final Object obj : list) {
191 if (obj instanceof HttpRequestInterceptor) {
192 addInterceptor((HttpRequestInterceptor) obj);
193 }
194 if (obj instanceof HttpResponseInterceptor) {
195 addInterceptor((HttpResponseInterceptor) obj);
196 }
197 }
198 }
199
200
201
202
203 public void clearInterceptors() {
204 clearRequestInterceptors();
205 clearResponseInterceptors();
206 }
207
208 @Override
209 public void process(
210 final HttpRequest request,
211 final HttpContext context)
212 throws IOException, HttpException {
213 for (final HttpRequestInterceptor interceptor : this.requestInterceptors) {
214 interceptor.process(request, context);
215 }
216 }
217
218 @Override
219 public void process(
220 final HttpResponse response,
221 final HttpContext context)
222 throws IOException, HttpException {
223 for (final HttpResponseInterceptor interceptor : this.responseInterceptors) {
224 interceptor.process(response, context);
225 }
226 }
227
228
229
230
231
232
233
234 protected void copyInterceptors(final BasicHttpProcessor target) {
235 target.requestInterceptors.clear();
236 target.requestInterceptors.addAll(this.requestInterceptors);
237 target.responseInterceptors.clear();
238 target.responseInterceptors.addAll(this.responseInterceptors);
239 }
240
241
242
243
244
245
246 public BasicHttpProcessor copy() {
247 final BasicHttpProcessorssor.html#BasicHttpProcessor">BasicHttpProcessor clone = new BasicHttpProcessor();
248 copyInterceptors(clone);
249 return clone;
250 }
251
252 @Override
253 public Object clone() throws CloneNotSupportedException {
254 final BasicHttpProcessor/org/apache/http/protocol/BasicHttpProcessor.html#BasicHttpProcessor">BasicHttpProcessor clone = (BasicHttpProcessor) super.clone();
255 copyInterceptors(clone);
256 return clone;
257 }
258
259 }