View Javadoc
1   /*
2    * ====================================================================
3    * Licensed to the Apache Software Foundation (ASF) under one
4    * or more contributor license agreements.  See the NOTICE file
5    * distributed with this work for additional information
6    * regarding copyright ownership.  The ASF licenses this file
7    * to you under the Apache License, Version 2.0 (the
8    * "License"); you may not use this file except in compliance
9    * with the License.  You may obtain a copy of the License at
10   *
11   *   http://www.apache.org/licenses/LICENSE-2.0
12   *
13   * Unless required by applicable law or agreed to in writing,
14   * software distributed under the License is distributed on an
15   * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16   * KIND, either express or implied.  See the License for the
17   * specific language governing permissions and limitations
18   * under the License.
19   * ====================================================================
20   *
21   * This software consists of voluntary contributions made by many
22   * individuals on behalf of the Apache Software Foundation.  For more
23   * information on the Apache Software Foundation, please see
24   * <http://www.apache.org/>.
25   *
26   */
27  
28  package org.apache.hc.client5.http.classic.methods;
29  
30  import java.net.URI;
31  
32  import org.apache.hc.core5.http.Method;
33  import org.apache.hc.core5.util.Args;
34  
35  /**
36   * Common HTTP methods using {@link HttpUriRequest} as a HTTP request message representation.
37   * <p>
38   * Each static method creates a request object of the exact subclass of {@link HttpUriRequest}
39   * with a non-null URI.
40   *
41   * @since 5.0
42   *
43   * @deprecated Use {@link org.apache.hc.core5.http.io.support.ClassicRequestBuilder}
44   */
45  @Deprecated
46  public final class ClassicHttpRequests {
47  
48      /**
49       * Creates a new HttpUriRequest for the given {@code Method} and {@code String} URI.
50       *
51       * @param method A method.
52       * @param uri a URI.
53       * @return a new HttpUriRequest.
54       */
55      public static HttpUriRequest create(final Method method, final String uri) {
56          return create(method, URI.create(uri));
57      }
58  
59      /**
60       * Creates a new HttpUriRequest for the given {@code Method} and {@code URI}.
61       *
62       * @param method A method.
63       * @param uri a URI.
64       * @return a new HttpUriRequest.
65       */
66      public static HttpUriRequest create(final Method method, final URI uri) {
67          switch (Args.notNull(method, "method")) {
68          case DELETE:
69              return delete(uri);
70          case GET:
71              return get(uri);
72          case HEAD:
73              return head(uri);
74          case OPTIONS:
75              return options(uri);
76          case PATCH:
77              return patch(uri);
78          case POST:
79              return post(uri);
80          case PUT:
81              return put(uri);
82          case TRACE:
83              return trace(uri);
84          default:
85              throw new IllegalArgumentException(method.toString());
86          }
87      }
88  
89      /**
90       * Creates a new HttpUriRequest for the given {@code method} and {@code String} URI.
91       *
92       * @param method A method supported by this class.
93       * @param uri a non-null request string URI.
94       * @throws IllegalArgumentException if the method is not supported.
95       * @throws IllegalArgumentException if the string URI is null.
96       * @return A new HttpUriRequest.
97       */
98      public static HttpUriRequest create(final String method, final String uri) {
99          return create(Method.normalizedValueOf(method), uri);
100     }
101 
102     /**
103      * Creates a new HttpUriRequest for the given {@code method} and {@code URI}.
104      *
105      * @param method A method supported by this class.
106      * @param uri a non-null request URI.
107      * @throws IllegalArgumentException if the method is not supported.
108      * @throws IllegalArgumentException if the URI is null.
109      * @return A new HttpUriRequest.
110      */
111     public static HttpUriRequest create(final String method, final URI uri) {
112         return create(Method.normalizedValueOf(method), uri);
113     }
114 
115     /**
116      * Constructs a new {@code "DELETE"} HttpUriRequest initialized with the given URI.
117      *
118      * @param uri a non-null request URI.
119      * @return a new "DELETE" HttpUriRequest.
120      * @throws IllegalArgumentException if the URI is null.
121      */
122     public static HttpUriRequest delete(final String uri) {
123         return delete(URI.create(uri));
124     }
125 
126     /**
127      * Constructs a new {@code "DELETE"} HttpUriRequest initialized with the given URI.
128      *
129      * @param uri a non-null request URI.
130      * @return a new "DELETE" HttpUriRequest.
131      * @throws IllegalArgumentException if the URI is null.
132      */
133     public static HttpUriRequest delete(final URI uri) {
134         return new HttpDelete(uri);
135     }
136 
137     /**
138      * Constructs a new {@code "GET"} HttpUriRequest initialized with the given URI.
139      *
140      * @param uri a non-null request URI.
141      * @return a new "GET" HttpUriRequest.
142      * @throws IllegalArgumentException if the URI is null.
143      */
144     public static HttpUriRequest get(final String uri) {
145         return get(URI.create(uri));
146     }
147 
148     /**
149      * Constructs a new {@code "GET"} HttpUriRequest initialized with the given URI.
150      *
151      * @param uri a non-null request URI.
152      * @return a new "GET" HttpUriRequest.
153      * @throws IllegalArgumentException if the URI is null.
154      */
155     public static HttpUriRequest get(final URI uri) {
156         return new HttpGet(uri);
157     }
158 
159     /**
160      * Constructs a new {@code "HEAD"} HttpUriRequest initialized with the given URI.
161      *
162      * @param uri a non-null request URI.
163      * @return a new "HEAD" HttpUriRequest.
164      * @throws IllegalArgumentException if the URI is null.
165      */
166     public static HttpUriRequest head(final String uri) {
167         return head(URI.create(uri));
168     }
169 
170     /**
171      * Constructs a new {@code "HEAD"} HttpUriRequest initialized with the given URI.
172      *
173      * @param uri a non-null request URI.
174      * @return a new "HEAD" HttpUriRequest.
175      * @throws IllegalArgumentException if the URI is null.
176      */
177     public static HttpUriRequest head(final URI uri) {
178         return new HttpHead(uri);
179     }
180 
181     /**
182      * Constructs a new {@code "OPTIONS"} HttpUriRequest initialized with the given URI.
183      *
184      * @param uri a non-null request URI.
185      * @return a new "OPTIONS" HttpUriRequest.
186      * @throws IllegalArgumentException if the URI is null.
187      */
188     public static HttpUriRequest options(final String uri) {
189         return options(URI.create(uri));
190     }
191 
192     /**
193      * Constructs a new {@code "OPTIONS"} HttpUriRequest initialized with the given URI.
194      *
195      * @param uri a non-null request URI.
196      * @return a new "OPTIONS" HttpUriRequest.
197      * @throws IllegalArgumentException if the URI is null.
198      */
199     public static HttpUriRequest options(final URI uri) {
200         return new HttpOptions(uri);
201     }
202 
203     /**
204      * Constructs a new {@code "PATCH"} HttpUriRequest initialized with the given URI.
205      *
206      * @param uri a non-null request URI.
207      * @return a new "PATCH" HttpUriRequest.
208      * @throws IllegalArgumentException if the URI is null.
209      */
210     public static HttpUriRequest patch(final String uri) {
211         return patch(URI.create(uri));
212     }
213 
214     /**
215      * Constructs a new {@code "PATCH"} HttpUriRequest initialized with the given URI.
216      *
217      * @param uri a non-null request URI.
218      * @return a new "PATCH" HttpUriRequest.
219      * @throws IllegalArgumentException if the URI is null.
220      */
221     public static HttpUriRequest patch(final URI uri) {
222         return new HttpPatch(uri);
223     }
224 
225     /**
226      * Constructs a new {@code "POST"} HttpUriRequest initialized with the given URI.
227      *
228      * @param uri a non-null request URI.
229      * @return a new "POST" HttpUriRequest.
230      * @throws IllegalArgumentException if the URI is null.
231      */
232     public static HttpUriRequest post(final String uri) {
233         return post(URI.create(uri));
234     }
235 
236     /**
237      * Constructs a new {@code "POST"} HttpUriRequest initialized with the given URI.
238      *
239      * @param uri a non-null request URI.
240      * @return a new "POST" HttpUriRequest.
241      * @throws IllegalArgumentException if the URI is null.
242      */
243     public static HttpUriRequest post(final URI uri) {
244         return new HttpPost(uri);
245     }
246 
247     /**
248      * Constructs a new {@code "PUT"} HttpUriRequest initialized with the given URI.
249      *
250      * @param uri a non-null request URI.
251      * @return a new "PUT" HttpUriRequest.
252      * @throws IllegalArgumentException if the URI is null.
253      */
254     public static HttpUriRequest put(final String uri) {
255         return put(URI.create(uri));
256     }
257 
258     /**
259      * Constructs a new {@code "PUT"} HttpUriRequest initialized with the given URI.
260      *
261      * @param uri a non-null request URI.
262      * @return a new "PUT" HttpUriRequest.
263      * @throws IllegalArgumentException if the URI is null.
264      */
265     public static HttpUriRequest put(final URI uri) {
266         return new HttpPut(uri);
267     }
268 
269     /**
270      * Constructs a new {@code "TRACE"} HttpUriRequest initialized with the given URI.
271      *
272      * @param uri a non-null request URI.
273      * @return a new "TRACE" HttpUriRequest.
274      * @throws IllegalArgumentException if the URI is null.
275      */
276     public static HttpUriRequest trace(final String uri) {
277         return trace(URI.create(uri));
278     }
279 
280     /**
281      * Constructs a new {@code "TRACE"} HttpUriRequest initialized with the given URI.
282      *
283      * @param uri a non-null request URI.
284      * @return a new "TRACE" HttpUriRequest.
285      * @throws IllegalArgumentException if the URI is null.
286      */
287     public static HttpUriRequest trace(final URI uri) {
288         return new HttpTrace(uri);
289     }
290 
291 }