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
29
30
31
32 package org.apache.commons.httpclient.methods;
33
34 import org.apache.commons.httpclient.HttpUrlMethod;
35 import org.apache.commons.httpclient.util.URIUtil;
36
37 import java.io.File;
38 import java.net.MalformedURLException;
39
40 /***
41 * Implements the URL version of GetMethod. It serves the
42 * same purpose as GetMethod but it takes URL instead of
43 * a path.
44 *
45 * @deprecated use GetMethod
46 *
47 * @author Marc A. Saegesser
48 * @author <a href="mailto:mbowler@GargoyleSoftware.com">Mike Bowler</a>
49 */
50 public class UrlGetMethod extends GetMethod implements HttpUrlMethod {
51
52 /*** The URL */
53 private String url;
54
55 /***
56 * No-arg constructor.
57 */
58 public UrlGetMethod() {
59 super();
60 }
61
62 /***
63 * Create an instance with the specified URL
64 * @param url The URL
65 * @throws MalformedURLException If the url isn't valid.
66 */
67 public UrlGetMethod(String url) throws MalformedURLException {
68 super(URIUtil.getPath(url));
69 setUrl(url);
70 }
71
72 /***
73 * Create an instance with the specified URL and temporary directory.
74 * @param url The URL
75 * @param tempDir The temporary directory
76 * @throws MalformedURLException If the url isn't valid.
77 */
78 public UrlGetMethod(String url, String tempDir) throws MalformedURLException {
79 super(URIUtil.getPath(url), tempDir);
80 setUrl(url);
81 }
82
83 /***
84 * Constructor.
85 * @param url the path of the request
86 * @param tempDir the directory in which to store temporary files
87 * @param tempFile the file (under tempDir) to buffer contents to
88 * @throws MalformedURLException If the url isn't valid.
89 */
90 public UrlGetMethod(String url, String tempDir, String tempFile)
91 throws MalformedURLException {
92 super(URIUtil.getPath(url), tempDir, tempFile);
93 setUrl(url);
94 }
95
96 /***
97 * Constructor.
98 * @param url the path of the request
99 * @param fileData the file to buffer contents to
100 * @throws MalformedURLException If the url isn't valid.
101 */
102 public UrlGetMethod(String url, File fileData)
103 throws MalformedURLException {
104 super(URIUtil.getPath(url), fileData);
105 setUrl(url);
106 }
107
108 /***
109 * Sets the URL. Calls the underlying HttpMethod.setPath()
110 * with the url's path. If the url contains a query string
111 * the underlying HttpMethod.setQueryString() is called.
112 *
113 * @param url - the URL for this request.
114 * @throws MalformedURLException If the url isn't valid.
115 */
116 public void setUrl(String url) throws MalformedURLException {
117 super.setPath(URIUtil.getPath(url));
118 this.url = url;
119 String query = URIUtil.getQuery(url);
120 if (query != null && query.length() > 0) {
121 super.setQueryString(query);
122 }
123 }
124
125 /***
126 * Returns this request's URL.
127 *
128 * @return the request's URL.
129 */
130 public String getUrl() {
131 return url;
132 }
133 }