1
|
|
/* Generated by AspectJ version 1.0.5 */
|
2
|
|
package org.apache.cactus.util;
|
3
|
|
import org.apache.commons.httpclient.HttpMethod;
|
4
|
|
import org.apache.commons.httpclient.Header;
|
5
|
|
import org.apache.commons.httpclient.HttpMethodBase;
|
6
|
|
import java.io.IOException;
|
7
|
|
import java.io.InputStream;
|
8
|
|
import java.io.OutputStream;
|
9
|
|
import java.net.URL;
|
10
|
|
import java.net.ProtocolException;
|
11
|
|
import java.security.Permission;
|
12
|
|
|
13
|
|
/**
|
14
|
|
* Provides a <code>HttpURLConnection</code> wrapper around HttpClient
|
15
|
|
* <code>HttpMethod</code>. This allows existing code to easily switch to
|
16
|
|
* HttpClieht without breaking existing interfaces using the JDK
|
17
|
|
* <code>HttpURLConnection<code>.
|
18
|
|
*
|
19
|
|
* Note: It is a best try effort as different version of the JDK have different
|
20
|
|
* behaviours for <code>HttpURLConnection</code> (And I'm not even including
|
21
|
|
* the numerous <code>HttpURLConnection</code> bugs!).
|
22
|
|
*
|
23
|
|
* @author <a href="mailto:vmassol@apache.org">Vincent Massol</a>
|
24
|
|
*
|
25
|
|
* @version $Id: HttpURLConnection.html,v 1.1 2003/04/14 12:27:33 sinisa Exp $
|
26
|
|
*/
|
27
|
|
public class HttpURLConnection extends java.net.HttpURLConnection {
|
28
|
|
/**
|
29
|
|
* The <code>HttpMethod</code> object that was used to connect to the
|
30
|
|
* HTTP server. It contains all the returned data.
|
31
|
|
*/
|
32
|
|
private HttpMethod method;
|
33
|
|
/**
|
34
|
|
* The URL to which we are connected
|
35
|
|
*/
|
36
|
|
private URL url;
|
37
|
|
/**
|
38
|
|
* Creates an <code>HttpURLConnection</code> from a
|
39
|
|
* <code>HttpMethod</code>.
|
40
|
|
*
|
41
|
|
* @param theMethod the theMethod that was used to connect to the HTTP
|
42
|
|
* server and which contains the returned data.
|
43
|
|
* @param theURL the URL to which we are connected (includes query string)
|
44
|
|
*/
|
45
|
660
|
public HttpURLConnection(HttpMethod theMethod, URL theURL) {
|
46
|
660
|
super(theURL);
|
47
|
|
;
|
48
|
660
|
this.method = theMethod;
|
49
|
660
|
this.url = theURL;
|
50
|
|
}
|
51
|
|
/**
|
52
|
|
* @see java.net.HttpURLConnection#HttpURLConnection(URL)
|
53
|
|
*/
|
54
|
0
|
protected HttpURLConnection(URL theURL) {
|
55
|
0
|
super(theURL);
|
56
|
|
;
|
57
|
0
|
throw new RuntimeException(
|
58
|
|
"An HTTP URL connection can only be constructed from a HttpMethod class");
|
59
|
|
}
|
60
|
|
/**
|
61
|
|
* @see java.net.HttpURLConnection#getInputStream()
|
62
|
|
*/
|
63
|
660
|
public InputStream getInputStream() throws IOException {
|
64
|
660
|
return this.method.getResponseBodyAsStream();
|
65
|
|
}
|
66
|
|
|
67
|
|
/**
|
68
|
|
* @see java.net.HttpURLConnection#getErrorStream()
|
69
|
|
*/
|
70
|
0
|
public InputStream getErrorStream() {
|
71
|
0
|
throw new RuntimeException("Not implemented yet");
|
72
|
|
}
|
73
|
|
|
74
|
|
/**
|
75
|
|
* @see java.net.HttpURLConnection#disconnect()
|
76
|
|
*/
|
77
|
0
|
public void disconnect() {
|
78
|
0
|
throw new RuntimeException("Not implemented yet");
|
79
|
|
}
|
80
|
|
|
81
|
|
/**
|
82
|
|
* @see java.net.HttpURLConnection#connect()
|
83
|
|
*/
|
84
|
0
|
public void connect() throws IOException {
|
85
|
0
|
throw new RuntimeException("This class can only be used with alreadyretrieved data");
|
86
|
|
}
|
87
|
|
|
88
|
|
/**
|
89
|
|
* @see java.net.HttpURLConnection#usingProxy()
|
90
|
|
*/
|
91
|
0
|
public boolean usingProxy() {
|
92
|
0
|
throw new RuntimeException("Not implemented yet");
|
93
|
|
}
|
94
|
|
|
95
|
|
/**
|
96
|
|
* @see java.net.HttpURLConnection#getRequestMethod()
|
97
|
|
*/
|
98
|
0
|
public String getRequestMethod() {
|
99
|
0
|
return this.method.getName();
|
100
|
|
}
|
101
|
|
|
102
|
|
/**
|
103
|
|
* @see java.net.HttpURLConnection#getResponseCode()
|
104
|
|
*/
|
105
|
10
|
public int getResponseCode() throws IOException {
|
106
|
10
|
return this.method.getStatusCode();
|
107
|
|
}
|
108
|
|
|
109
|
|
/**
|
110
|
|
* @see java.net.HttpURLConnection#getResponseMessage()
|
111
|
|
*/
|
112
|
0
|
public String getResponseMessage() throws IOException {
|
113
|
0
|
return this.method.getStatusText();
|
114
|
|
}
|
115
|
|
|
116
|
|
/**
|
117
|
|
* @see java.net.HttpURLConnection#getHeaderField(String)
|
118
|
|
*/
|
119
|
677
|
public String getHeaderField(String theName) {
|
120
|
677
|
Header[] headers = this.method.getResponseHeaders();
|
121
|
677
|
for (int i = headers.length - 1; i >= 0; i--) {
|
122
|
2499
|
if (headers[i].getName().equalsIgnoreCase(theName)) {
|
123
|
412
|
return headers[i].getValue();
|
124
|
|
}
|
125
|
|
}
|
126
|
265
|
return ((String)(null));
|
127
|
|
}
|
128
|
|
|
129
|
|
/**
|
130
|
|
* @see java.net.HttpURLConnection#getHeaderFieldKey(int)
|
131
|
|
*/
|
132
|
84
|
public String getHeaderFieldKey(int theKeyPosition) {
|
133
|
84
|
if (theKeyPosition == 0) {
|
134
|
5
|
return ((String)(null));
|
135
|
|
}
|
136
|
79
|
Header[] headers = this.method.getResponseHeaders();
|
137
|
79
|
if (theKeyPosition < 0 || theKeyPosition >= headers.length) {
|
138
|
10
|
return ((String)(null));
|
139
|
|
}
|
140
|
69
|
return headers[theKeyPosition - 1].getName();
|
141
|
|
}
|
142
|
|
|
143
|
|
/**
|
144
|
|
* @see java.net.HttpURLConnection#getHeaderField(int)
|
145
|
|
*/
|
146
|
66
|
public String getHeaderField(int thePosition) {
|
147
|
66
|
if (thePosition == 0) {
|
148
|
15
|
if (((HttpMethodBase)this.method).isHttp11()) {
|
149
|
15
|
return "HTTP/1.1 " + this.method.getStatusCode() + " " + this.method.getStatusText();
|
150
|
|
} else {
|
151
|
0
|
return "HTTP/1.0 " + this.method.getStatusCode() + " " + this.method.getStatusText();
|
152
|
|
}
|
153
|
|
}
|
154
|
51
|
Header[] headers = this.method.getResponseHeaders();
|
155
|
51
|
if (thePosition < 0 || thePosition >= headers.length) {
|
156
|
5
|
return ((String)(null));
|
157
|
|
}
|
158
|
46
|
return headers[thePosition - 1].getValue();
|
159
|
|
}
|
160
|
|
|
161
|
|
/**
|
162
|
|
* @see java.net.HttpURLConnection#getURL()
|
163
|
|
*/
|
164
|
20
|
public URL getURL() {
|
165
|
20
|
return this.url;
|
166
|
|
}
|
167
|
|
|
168
|
|
/**
|
169
|
|
* @see java.net.HttpURLConnection#setInstanceFollowRedirects(boolean)
|
170
|
|
*/
|
171
|
0
|
public void setInstanceFollowRedirects(boolean isFollowingRedirects) {
|
172
|
0
|
throw new RuntimeException("This class can only be used with alreadyretrieved data");
|
173
|
|
}
|
174
|
|
|
175
|
|
/**
|
176
|
|
* @see java.net.HttpURLConnection#getInstanceFollowRedirects()
|
177
|
|
*/
|
178
|
0
|
public boolean getInstanceFollowRedirects() {
|
179
|
0
|
throw new RuntimeException("Not implemented yet");
|
180
|
|
}
|
181
|
|
|
182
|
|
/**
|
183
|
|
* @see java.net.HttpURLConnection#setRequestMethod(String)
|
184
|
|
*/
|
185
|
0
|
public void setRequestMethod(String theMethod) throws ProtocolException {
|
186
|
0
|
throw new RuntimeException("This class can only be used with alreadyretrieved data");
|
187
|
|
}
|
188
|
|
|
189
|
|
/**
|
190
|
|
* @see java.net.HttpURLConnection#getPermission()
|
191
|
|
*/
|
192
|
0
|
public Permission getPermission() throws IOException {
|
193
|
0
|
throw new RuntimeException("Not implemented yet");
|
194
|
|
}
|
195
|
|
|
196
|
|
/**
|
197
|
|
* @see java.net.HttpURLConnection#getContent()
|
198
|
|
*/
|
199
|
0
|
public Object getContent() throws IOException {
|
200
|
0
|
throw new RuntimeException("Not implemented yet");
|
201
|
|
}
|
202
|
|
|
203
|
|
/**
|
204
|
|
* @see java.net.HttpURLConnection#getContent(Class[])
|
205
|
|
*/
|
206
|
0
|
public Object getContent(Class[] theClasses) throws IOException {
|
207
|
0
|
throw new RuntimeException("Not implemented yet");
|
208
|
|
}
|
209
|
|
|
210
|
|
/**
|
211
|
|
* @see java.net.HttpURLConnection#getOutputStream()
|
212
|
|
*/
|
213
|
0
|
public OutputStream getOutputStream() throws IOException {
|
214
|
0
|
throw new RuntimeException("This class can only be used with alreadyretrieved data");
|
215
|
|
}
|
216
|
|
|
217
|
|
/**
|
218
|
|
* @see java.net.HttpURLConnection#setDoInput(boolean)
|
219
|
|
*/
|
220
|
0
|
public void setDoInput(boolean isInput) {
|
221
|
0
|
throw new RuntimeException("This class can only be used with alreadyretrieved data");
|
222
|
|
}
|
223
|
|
|
224
|
|
/**
|
225
|
|
* @see java.net.HttpURLConnection#getDoInput()
|
226
|
|
*/
|
227
|
0
|
public boolean getDoInput() {
|
228
|
0
|
throw new RuntimeException("Not implemented yet");
|
229
|
|
}
|
230
|
|
|
231
|
|
/**
|
232
|
|
* @see java.net.HttpURLConnection#setDoOutput(boolean)
|
233
|
|
*/
|
234
|
0
|
public void setDoOutput(boolean isOutput) {
|
235
|
0
|
throw new RuntimeException("This class can only be used with alreadyretrieved data");
|
236
|
|
}
|
237
|
|
|
238
|
|
/**
|
239
|
|
* @see java.net.HttpURLConnection#getDoOutput()
|
240
|
|
*/
|
241
|
0
|
public boolean getDoOutput() {
|
242
|
0
|
throw new RuntimeException("Not implemented yet");
|
243
|
|
}
|
244
|
|
|
245
|
|
/**
|
246
|
|
* @see java.net.HttpURLConnection#setAllowUserInteraction(boolean)
|
247
|
|
*/
|
248
|
0
|
public void setAllowUserInteraction(boolean isAllowInteraction) {
|
249
|
0
|
throw new RuntimeException("This class can only be used with alreadyretrieved data");
|
250
|
|
}
|
251
|
|
|
252
|
|
/**
|
253
|
|
* @see java.net.HttpURLConnection#getAllowUserInteraction()
|
254
|
|
*/
|
255
|
0
|
public boolean getAllowUserInteraction() {
|
256
|
0
|
throw new RuntimeException("Not implemented yet");
|
257
|
|
}
|
258
|
|
|
259
|
|
/**
|
260
|
|
* @see java.net.HttpURLConnection#setUseCaches(boolean)
|
261
|
|
*/
|
262
|
0
|
public void setUseCaches(boolean isUsingCaches) {
|
263
|
0
|
throw new RuntimeException("This class can only be used with alreadyretrieved data");
|
264
|
|
}
|
265
|
|
|
266
|
|
/**
|
267
|
|
* @see java.net.HttpURLConnection#getUseCaches()
|
268
|
|
*/
|
269
|
0
|
public boolean getUseCaches() {
|
270
|
0
|
throw new RuntimeException("Not implemented yet");
|
271
|
|
}
|
272
|
|
|
273
|
|
/**
|
274
|
|
* @see java.net.HttpURLConnection#setIfModifiedSince(long)
|
275
|
|
*/
|
276
|
0
|
public void setIfModifiedSince(long theModificationDate) {
|
277
|
0
|
throw new RuntimeException("This class can only be used with alreadyretrieved data");
|
278
|
|
}
|
279
|
|
|
280
|
|
/**
|
281
|
|
* @see java.net.HttpURLConnection#getIfModifiedSince()
|
282
|
|
*/
|
283
|
0
|
public long getIfModifiedSince() {
|
284
|
0
|
throw new RuntimeException("Not implemented yet");
|
285
|
|
}
|
286
|
|
|
287
|
|
/**
|
288
|
|
* @see java.net.HttpURLConnection#getDefaultUseCaches()
|
289
|
|
*/
|
290
|
0
|
public boolean getDefaultUseCaches() {
|
291
|
0
|
throw new RuntimeException("Not implemented yet");
|
292
|
|
}
|
293
|
|
|
294
|
|
/**
|
295
|
|
* @see java.net.HttpURLConnection#setDefaultUseCaches(boolean)
|
296
|
|
*/
|
297
|
0
|
public void setDefaultUseCaches(boolean isUsingCaches) {
|
298
|
0
|
throw new RuntimeException("This class can only be used with alreadyretrieved data");
|
299
|
|
}
|
300
|
|
|
301
|
|
/**
|
302
|
|
* @see java.net.HttpURLConnection#setRequestProperty(String, String)
|
303
|
|
*/
|
304
|
0
|
public void setRequestProperty(String theKey, String theValue) {
|
305
|
0
|
throw new RuntimeException("This class can only be used with alreadyretrieved data");
|
306
|
|
}
|
307
|
|
|
308
|
|
/**
|
309
|
|
* @see java.net.HttpURLConnection#getRequestProperty(String)
|
310
|
|
*/
|
311
|
0
|
public String getRequestProperty(String theKey) {
|
312
|
0
|
throw new RuntimeException("Not implemented yet");
|
313
|
|
}
|
314
|
|
|
315
|
|
}
|