001/* 002 * ==================================================================== 003 * Licensed to the Apache Software Foundation (ASF) under one 004 * or more contributor license agreements. See the NOTICE file 005 * distributed with this work for additional information 006 * regarding copyright ownership. The ASF licenses this file 007 * to you under the Apache License, Version 2.0 (the 008 * "License"); you may not use this file except in compliance 009 * with the License. You may obtain a copy of the License at 010 * 011 * http://www.apache.org/licenses/LICENSE-2.0 012 * 013 * Unless required by applicable law or agreed to in writing, 014 * software distributed under the License is distributed on an 015 * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 016 * KIND, either express or implied. See the License for the 017 * specific language governing permissions and limitations 018 * under the License. 019 * ==================================================================== 020 * 021 * This software consists of voluntary contributions made by many 022 * individuals on behalf of the Apache Software Foundation. For more 023 * information on the Apache Software Foundation, please see 024 * <http://www.apache.org/>. 025 * 026 */ 027 028package org.apache.http.impl.execchain; 029 030import java.io.IOException; 031 032import org.apache.http.HttpException; 033import org.apache.http.client.methods.CloseableHttpResponse; 034import org.apache.http.client.methods.HttpExecutionAware; 035import org.apache.http.client.methods.HttpRequestWrapper; 036import org.apache.http.client.protocol.HttpClientContext; 037import org.apache.http.conn.routing.HttpRoute; 038 039/** 040 * This interface represents an element in the HTTP request execution chain. Each element can 041 * either be a decorator around another element that implements a cross cutting aspect or 042 * a self-contained executor capable of producing a response for the given request. 043 * <p> 044 * Important: please note it is required for decorators that implement post execution aspects 045 * or response post-processing of any sort to release resources associated with the response 046 * by calling {@link CloseableHttpResponse#close()} methods in case of an I/O, protocol or 047 * runtime exception, or in case the response is not propagated to the caller. 048 * </p> 049 * 050 * @since 4.3 051 */ 052public interface ClientExecChain { 053 054 /** 055 * Executes th request either by transmitting it to the target server or 056 * by passing it onto the next executor in the request execution chain. 057 * 058 * @param route connection route. 059 * @param request current request. 060 * @param clientContext current HTTP context. 061 * @param execAware receiver of notifications of blocking I/O operations. 062 * @return HTTP response either received from the opposite endpoint 063 * or generated locally. 064 * @throws IOException in case of a I/O error. 065 * (this type of exceptions are potentially recoverable). 066 * @throws HttpException in case of an HTTP protocol error 067 * (usually this type of exceptions are non-recoverable). 068 */ 069 CloseableHttpResponse execute( 070 HttpRoute route, 071 HttpRequestWrapper request, 072 HttpClientContext clientContext, 073 HttpExecutionAware execAware) throws IOException, HttpException; 074 075}