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;
29
30 import java.io.IOException;
31
32 import org.apache.hc.client5.http.impl.ChainElement;
33 import org.apache.hc.client5.http.impl.classic.HttpClientBuilder;
34 import org.apache.hc.client5.http.impl.classic.HttpRequestRetryExec;
35 import org.apache.hc.core5.annotation.Contract;
36 import org.apache.hc.core5.annotation.ThreadingBehavior;
37 import org.apache.hc.core5.http.ClassicHttpRequest;
38 import org.apache.hc.core5.http.ClassicHttpResponse;
39 import org.apache.hc.core5.http.HttpException;
40
41 /**
42 * Abstract request execution handler in a classic client side request execution chain.
43 * Handlers can either be a decorator around another element that implements a cross
44 * cutting aspect or a self-contained executor capable of producing a response
45 * for the given request.
46 * <p>
47 * Important: please note it is required for decorators that implement post execution aspects
48 * or response post-processing of any sort to release resources associated with the response
49 * by calling {@link ClassicHttpResponse#close()} methods in case of an I/O, protocol or
50 * runtime exception, or in case the response is not propagated to the caller.
51 * </p>
52 * <p>
53 * For information regarding the handler chain behaviour in case of a request re-execution,
54 * please refer to the {@link HttpRequestRetryExec} javadoc.
55 * </p>
56 *<p>
57 * Well known request execution handlers could be referred to by name using one of the
58 * {@link ChainElement} enum values.
59 *</p>
60 *
61 * @since 4.3
62 * @see ChainElement
63 * @see HttpClientBuilder#addExecInterceptorFirst(String, ExecChainHandler)
64 * @see HttpClientBuilder#addExecInterceptorBefore(String, String, ExecChainHandler)
65 * @see HttpClientBuilder#addExecInterceptorAfter(String, String, ExecChainHandler)
66 * @see HttpClientBuilder#addExecInterceptorLast(String, ExecChainHandler)
67 */
68 @Contract(threading = ThreadingBehavior.STATELESS)
69 public interface ExecChainHandler {
70
71 /**
72 * Executes the actual HTTP request. The handler can choose to return
73 * a response message or delegate request execution to the next element
74 * in the execution chain.
75 *
76 * @param request the actual request.
77 * @param scope the execution scope .
78 * @param chain the next element in the request execution chain.
79 */
80 ClassicHttpResponse execute(
81 ClassicHttpRequest request,
82 ExecChain.Scope scope,
83 ExecChain chain) throws IOException, HttpException;
84
85 }