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.async.methods;
29  
30  import java.net.URI;
31  
32  import org.apache.hc.core5.http.HttpHost;
33  import org.apache.hc.core5.http.Method;
34  import org.apache.hc.core5.http.message.BasicHttpRequest;
35  
36  /**
37   * Common HTTP methods using {@link BasicHttpRequest} as a HTTP request message representation.
38   *
39   * @since 5.0
40   *
41   * @deprecated Use {@link org.apache.hc.core5.http.support.BasicRequestBuilder}.
42   */
43  @Deprecated
44  public final class BasicHttpRequests {
45  
46      /**
47       * Creates a new BasicHttpRequest for the given {@code method} and {@code String} URI.
48       *
49       * @param method A method supported by this class.
50       * @param uri a non-null request string URI.
51       * @return A new BasicHttpRequest.
52       */
53      public static BasicHttpRequest create(final String method, final String uri) {
54          return create(Method.normalizedValueOf(method), uri);
55      }
56  
57      /**
58       * Creates a new BasicHttpRequest for the given {@code method} and {@code URI}.
59       *
60       * @param method A method supported by this class.
61       * @param uri a non-null request URI.
62       * @return A new BasicHttpRequest.
63       */
64      public static BasicHttpRequest create(final String method, final URI uri) {
65          return create(Method.normalizedValueOf(method), uri);
66      }
67  
68      /**
69       * Creates a new DELETE {@link BasicHttpRequest}.
70       *
71       * @param uri a non-null URI.
72       * @return a new BasicHttpRequest
73       */
74      public static BasicHttpRequest delete(final String uri) {
75          return delete(URI.create(uri));
76      }
77  
78      /**
79       * Creates a new DELETE {@link BasicHttpRequest}.
80       *
81       * @param uri a non-null URI.
82       * @return a new BasicHttpRequest
83       */
84      public static BasicHttpRequest delete(final URI uri) {
85          return create(Method.DELETE, uri);
86      }
87  
88      /**
89       * Creates a new DELETE {@link BasicHttpRequest}.
90       *
91       * @param host HTTP host.
92       * @param path request path.
93       * @return a new BasicHttpRequest
94       */
95      public static BasicHttpRequest delete(final HttpHost host, final String path) {
96          return create(Method.DELETE, host, path);
97      }
98  
99      /**
100      * Creates a new GET {@link BasicHttpRequest}.
101      *
102      * @param uri a non-null URI.
103      * @return a new BasicHttpRequest
104      */
105     public static BasicHttpRequest get(final String uri) {
106         return get(URI.create(uri));
107     }
108 
109     /**
110      * Creates a new GET {@link BasicHttpRequest}.
111      *
112      * @param uri a non-null URI.
113      * @return a new BasicHttpRequest
114      */
115     public static BasicHttpRequest get(final URI uri) {
116         return create(Method.GET, uri);
117     }
118 
119     /**
120      * Creates a new HEAD {@link BasicHttpRequest}.
121      *
122      * @param host HTTP host.
123      * @param path request path.
124      * @return a new BasicHttpRequest
125      */
126     public static BasicHttpRequest get(final HttpHost host, final String path) {
127         return create(Method.GET, host, path);
128     }
129 
130     /**
131      * Creates a new HEAD {@link BasicHttpRequest}.
132      *
133      * @param uri a non-null URI.
134      * @return a new BasicHttpRequest
135      */
136     public static BasicHttpRequest head(final String uri) {
137         return head(URI.create(uri));
138     }
139 
140     /**
141      * Creates a new HEAD {@link BasicHttpRequest}.
142      *
143      * @param uri a non-null URI.
144      * @return a new BasicHttpRequest
145      */
146     public static BasicHttpRequest head(final URI uri) {
147         return create(Method.HEAD, uri);
148     }
149 
150     /**
151      * Creates a new HEAD {@link BasicHttpRequest}.
152      *
153      * @param host HTTP host.
154      * @param path request path.
155      * @return a new BasicHttpRequest
156      */
157     public static BasicHttpRequest head(final HttpHost host, final String path) {
158         return create(Method.HEAD, host, path);
159     }
160 
161     /**
162      * Creates a new OPTIONS {@link BasicHttpRequest}.
163      *
164      * @param uri a non-null URI.
165      * @return a new BasicHttpRequest
166      */
167     public static BasicHttpRequest options(final String uri) {
168         return options(URI.create(uri));
169     }
170 
171     /**
172      * Creates a new OPTIONS {@link BasicHttpRequest}.
173      *
174      * @param uri a non-null URI.
175      * @return a new BasicHttpRequest
176      */
177     public static BasicHttpRequest options(final URI uri) {
178         return create(Method.OPTIONS, uri);
179     }
180 
181     /**
182      * Creates a new OPTIONS {@link BasicHttpRequest}.
183      *
184      * @param host HTTP host.
185      * @param path request path.
186      * @return a new BasicHttpRequest
187      */
188     public static BasicHttpRequest options(final HttpHost host, final String path) {
189         return create(Method.OPTIONS, host, path);
190     }
191 
192     /**
193      * Creates a new PATCH {@link BasicHttpRequest}.
194      *
195      * @param uri a non-null URI.
196      * @return a new BasicHttpRequest
197      */
198     public static BasicHttpRequest patch(final String uri) {
199         return patch(URI.create(uri));
200     }
201 
202     /**
203      * Creates a new PATCH {@link BasicHttpRequest}.
204      *
205      * @param uri a non-null URI.
206      * @return a new BasicHttpRequest
207      */
208     public static BasicHttpRequest patch(final URI uri) {
209         return create(Method.PATCH, uri);
210     }
211 
212     /**
213      * Creates a new PATCH {@link BasicHttpRequest}.
214      *
215      * @param host HTTP host.
216      * @param path request path.
217      * @return a new BasicHttpRequest
218      */
219     public static BasicHttpRequest patch(final HttpHost host, final String path) {
220         return create(Method.PATCH, host, path);
221     }
222 
223     /**
224      * Creates a new POST {@link BasicHttpRequest}.
225      *
226      * @param uri a non-null URI.
227      * @return a new BasicHttpRequest
228      */
229     public static BasicHttpRequest post(final String uri) {
230         return post(URI.create(uri));
231     }
232 
233     /**
234      * Creates a new POST {@link BasicHttpRequest}.
235      *
236      * @param uri a non-null URI.
237      * @return a new BasicHttpRequest
238      */
239     public static BasicHttpRequest post(final URI uri) {
240         return create(Method.POST, uri);
241     }
242 
243     /**
244      * Creates a new POST {@link BasicHttpRequest}.
245      *
246      * @param host HTTP host.
247      * @param path request path.
248      * @return a new BasicHttpRequest
249      */
250     public static BasicHttpRequest post(final HttpHost host, final String path) {
251         return create(Method.POST, host, path);
252     }
253 
254     /**
255      * Creates a new PUT {@link BasicHttpRequest}.
256      *
257      * @param uri a non-null URI.
258      * @return a new BasicHttpRequest
259      */
260     public static BasicHttpRequest put(final String uri) {
261         return put(URI.create(uri));
262     }
263 
264     /**
265      * Creates a new PUT {@link BasicHttpRequest}.
266      *
267      * @param uri a non-null URI.
268      * @return a new BasicHttpRequest
269      */
270     public static BasicHttpRequest put(final URI uri) {
271         return create(Method.PUT, uri);
272     }
273 
274     /**
275      * Creates a new PUT {@link BasicHttpRequest}.
276      *
277      * @param host HTTP host.
278      * @param path request path.
279      * @return a new BasicHttpRequest
280      */
281     public static BasicHttpRequest put(final HttpHost host, final String path) {
282         return create(Method.PUT, host, path);
283     }
284 
285     /**
286      * Creates a new TRACE {@link BasicHttpRequest}.
287      *
288      * @param uri a non-null URI.
289      * @return a new BasicHttpRequest
290      */
291     public static BasicHttpRequest trace(final String uri) {
292         return trace(URI.create(uri));
293     }
294 
295     /**
296      * Creates a new TRACE {@link BasicHttpRequest}.
297      *
298      * @param uri a non-null URI.
299      * @return a new BasicHttpRequest
300      */
301     public static BasicHttpRequest trace(final URI uri) {
302         return create(Method.TRACE, uri);
303     }
304 
305     /**
306      * Creates a new TRACE {@link BasicHttpRequest}.
307      *
308      * @param host HTTP host.
309      * @param path request path.
310      * @return a new BasicHttpRequest
311      */
312     public static BasicHttpRequest trace(final HttpHost host, final String path) {
313         return create(Method.TRACE, host, path);
314     }
315 
316     /**
317      * Creates a new {@link BasicHttpRequest}.
318      *
319      * @param method a non-null HTTP method.
320      * @param uri a non-null URI String.
321      * @return a new BasicHttpRequest
322      */
323     public static BasicHttpRequest create(final Method method, final String uri) {
324         return create(method, URI.create(uri));
325     }
326 
327     /**
328      * Creates a new {@link BasicHttpRequest}.
329      *
330      * @param method a non-null HTTP method.
331      * @param uri a non-null URI.
332      * @return a new BasicHttpRequest
333      */
334     public static BasicHttpRequest create(final Method method, final URI uri) {
335         return new BasicHttpRequest(method, uri);
336     }
337 
338     /**
339      * Creates a new {@link BasicHttpRequest}.
340      *
341      * @param method a non-null HTTP method.
342      * @param host HTTP host.
343      * @param path request path.
344      * @return a new subclass of BasicHttpRequest
345      */
346     public static BasicHttpRequest create(final Method method, final HttpHost host, final String path) {
347         return new BasicHttpRequest(method, host, path);
348     }
349 
350 }