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