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.http.client;
29  
30  import org.apache.http.HttpHost;
31  import org.apache.http.HttpRequest;
32  import org.apache.http.HttpResponse;
33  import org.apache.http.client.methods.HttpUriRequest;
34  import org.apache.http.conn.ClientConnectionManager;
35  import org.apache.http.params.HttpParams;
36  import org.apache.http.protocol.HttpContext;
37  
38  import java.io.IOException;
39  
40  /**
41   * This interface represents only the most basic contract for HTTP request
42   * execution. It imposes no restrictions or particular details on the request
43   * execution process and leaves the specifics of state management,
44   * authentication and redirect handling up to individual implementations.
45   *
46   * @since 4.0
47   */
48  @SuppressWarnings("deprecation")
49  public interface HttpClient {
50  
51  
52      /**
53       * Obtains the parameters for this client.
54       * These parameters will become defaults for all requests being
55       * executed with this client, and for the parameters of
56       * dependent objects in this client.
57       *
58       * @return  the default parameters
59       *
60       * @deprecated (4.3) use
61       *   {@link org.apache.http.client.config.RequestConfig}.
62       */
63      @Deprecated
64      HttpParams getParams();
65  
66      /**
67       * Obtains the connection manager used by this client.
68       *
69       * @return  the connection manager
70       *
71       * @deprecated (4.3) use
72       *   {@link org.apache.http.impl.client.HttpClientBuilder}.
73       */
74      @Deprecated
75      ClientConnectionManager getConnectionManager();
76  
77      /**
78       * Executes HTTP request using the default context.
79       *
80       * @param request   the request to execute
81       *
82       * @return  the response to the request. This is always a final response,
83       *          never an intermediate response with an 1xx status code.
84       *          Whether redirects or authentication challenges will be returned
85       *          or handled automatically depends on the implementation and
86       *          configuration of this client.
87       * @throws IOException in case of a problem or the connection was aborted
88       * @throws ClientProtocolException in case of an http protocol error
89       */
90      HttpResponse execute(HttpUriRequest request)
91          throws IOException, ClientProtocolException;
92  
93      /**
94       * Executes HTTP request using the given context.
95       *
96       * @param request   the request to execute
97       * @param context   the context to use for the execution, or
98       *                  <code>null</code> to use the default context
99       *
100      * @return  the response to the request. This is always a final response,
101      *          never an intermediate response with an 1xx status code.
102      *          Whether redirects or authentication challenges will be returned
103      *          or handled automatically depends on the implementation and
104      *          configuration of this client.
105      * @throws IOException in case of a problem or the connection was aborted
106      * @throws ClientProtocolException in case of an http protocol error
107      */
108     HttpResponse execute(HttpUriRequest request, HttpContext context)
109         throws IOException, ClientProtocolException;
110 
111     /**
112      * Executes HTTP request using the default context.
113      *
114      * @param target    the target host for the request.
115      *                  Implementations may accept <code>null</code>
116      *                  if they can still determine a route, for example
117      *                  to a default target or by inspecting the request.
118      * @param request   the request to execute
119      *
120      * @return  the response to the request. This is always a final response,
121      *          never an intermediate response with an 1xx status code.
122      *          Whether redirects or authentication challenges will be returned
123      *          or handled automatically depends on the implementation and
124      *          configuration of this client.
125      * @throws IOException in case of a problem or the connection was aborted
126      * @throws ClientProtocolException in case of an http protocol error
127      */
128     HttpResponse execute(HttpHost target, HttpRequest request)
129         throws IOException, ClientProtocolException;
130 
131     /**
132      * Executes HTTP request using the given context.
133      *
134      * @param target    the target host for the request.
135      *                  Implementations may accept <code>null</code>
136      *                  if they can still determine a route, for example
137      *                  to a default target or by inspecting the request.
138      * @param request   the request to execute
139      * @param context   the context to use for the execution, or
140      *                  <code>null</code> to use the default context
141      *
142      * @return  the response to the request. This is always a final response,
143      *          never an intermediate response with an 1xx status code.
144      *          Whether redirects or authentication challenges will be returned
145      *          or handled automatically depends on the implementation and
146      *          configuration of this client.
147      * @throws IOException in case of a problem or the connection was aborted
148      * @throws ClientProtocolException in case of an http protocol error
149      */
150     HttpResponse execute(HttpHost target, HttpRequest request,
151                          HttpContext context)
152         throws IOException, ClientProtocolException;
153 
154     /**
155      * Executes HTTP request using the default context and processes the
156      * response using the given response handler.
157      * <p/>
158      * Implementing classes are required to ensure that the content entity
159      * associated with the response is fully consumed and the underlying
160      * connection is released back to the connection manager automatically
161      * in all cases relieving individual {@link ResponseHandler}s from
162      * having to manage resource deallocation internally.
163      *
164      * @param request   the request to execute
165      * @param responseHandler the response handler
166      *
167      * @return  the response object as generated by the response handler.
168      * @throws IOException in case of a problem or the connection was aborted
169      * @throws ClientProtocolException in case of an http protocol error
170      */
171     <T> T execute(
172             HttpUriRequest request,
173             ResponseHandler<? extends T> responseHandler)
174         throws IOException, ClientProtocolException;
175 
176     /**
177      * Executes HTTP request using the given context and processes the
178      * response using the given response handler.
179      * <p/>
180      * Implementing classes are required to ensure that the content entity
181      * associated with the response is fully consumed and the underlying
182      * connection is released back to the connection manager automatically
183      * in all cases relieving individual {@link ResponseHandler}s from
184      * having to manage resource deallocation internally.
185      *
186      * @param request   the request to execute
187      * @param responseHandler the response handler
188      * @param context   the context to use for the execution, or
189      *                  <code>null</code> to use the default context
190      *
191      * @return  the response object as generated by the response handler.
192      * @throws IOException in case of a problem or the connection was aborted
193      * @throws ClientProtocolException in case of an http protocol error
194      */
195     <T> T execute(
196             HttpUriRequest request,
197             ResponseHandler<? extends T> responseHandler,
198             HttpContext context)
199         throws IOException, ClientProtocolException;
200 
201     /**
202      * Executes HTTP request to the target using the default context and
203      * processes the response using the given response handler.
204      * <p/>
205      * Implementing classes are required to ensure that the content entity
206      * associated with the response is fully consumed and the underlying
207      * connection is released back to the connection manager automatically
208      * in all cases relieving individual {@link ResponseHandler}s from
209      * having to manage resource deallocation internally.
210      *
211      * @param target    the target host for the request.
212      *                  Implementations may accept <code>null</code>
213      *                  if they can still determine a route, for example
214      *                  to a default target or by inspecting the request.
215      * @param request   the request to execute
216      * @param responseHandler the response handler
217      *
218      * @return  the response object as generated by the response handler.
219      * @throws IOException in case of a problem or the connection was aborted
220      * @throws ClientProtocolException in case of an http protocol error
221      */
222     <T> T execute(
223             HttpHost target,
224             HttpRequest request,
225             ResponseHandler<? extends T> responseHandler)
226         throws IOException, ClientProtocolException;
227 
228     /**
229      * Executes HTTP request to the target using the given context and
230      * processes the response using the given response handler.
231      * <p/>
232      * Implementing classes are required to ensure that the content entity
233      * associated with the response is fully consumed and the underlying
234      * connection is released back to the connection manager automatically
235      * in all cases relieving individual {@link ResponseHandler}s from
236      * having to manage resource deallocation internally.
237      *
238      * @param target    the target host for the request.
239      *                  Implementations may accept <code>null</code>
240      *                  if they can still determine a route, for example
241      *                  to a default target or by inspecting the request.
242      * @param request   the request to execute
243      * @param responseHandler the response handler
244      * @param context   the context to use for the execution, or
245      *                  <code>null</code> to use the default context
246      *
247      * @return  the response object as generated by the response handler.
248      * @throws IOException in case of a problem or the connection was aborted
249      * @throws ClientProtocolException in case of an http protocol error
250      */
251     <T> T execute(
252             HttpHost target,
253             HttpRequest request,
254             ResponseHandler<? extends T> responseHandler,
255             HttpContext context)
256         throws IOException, ClientProtocolException;
257 
258 }