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     public static HttpUriRequest delete(final String uri) {
116         return delete(URI.create(uri));
117     }
118 
119     public static HttpUriRequest delete(final URI uri) {
120         return new HttpDelete(uri);
121     }
122 
123     public static HttpUriRequest get(final String uri) {
124         return get(URI.create(uri));
125     }
126 
127     public static HttpUriRequest get(final URI uri) {
128         return new HttpGet(uri);
129     }
130 
131     public static HttpUriRequest head(final String uri) {
132         return head(URI.create(uri));
133     }
134 
135     public static HttpUriRequest head(final URI uri) {
136         return new HttpHead(uri);
137     }
138 
139     public static HttpUriRequest options(final String uri) {
140         return options(URI.create(uri));
141     }
142 
143     public static HttpUriRequest options(final URI uri) {
144         return new HttpOptions(uri);
145     }
146 
147     public static HttpUriRequest patch(final String uri) {
148         return patch(URI.create(uri));
149     }
150 
151     public static HttpUriRequest patch(final URI uri) {
152         return new HttpPatch(uri);
153     }
154 
155     public static HttpUriRequest post(final String uri) {
156         return post(URI.create(uri));
157     }
158 
159     public static HttpUriRequest post(final URI uri) {
160         return new HttpPost(uri);
161     }
162 
163     public static HttpUriRequest put(final String uri) {
164         return put(URI.create(uri));
165     }
166 
167     public static HttpUriRequest put(final URI uri) {
168         return new HttpPut(uri);
169     }
170 
171     public static HttpUriRequest trace(final String uri) {
172         return trace(URI.create(uri));
173     }
174 
175     public static HttpUriRequest trace(final URI uri) {
176         return new HttpTrace(uri);
177     }
178 
179 }