001// *************************************************************************************************************************** 002// * Licensed to the Apache Software Foundation (ASF) under one or more contributor license agreements. See the NOTICE file * 003// * distributed with this work for additional information regarding copyright ownership. The ASF licenses this file * 004// * to you under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance * 005// * with the License. You may obtain a copy of the License at * 006// * * 007// * http://www.apache.org/licenses/LICENSE-2.0 * 008// * * 009// * Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an * 010// * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the * 011// * specific language governing permissions and limitations under the License. * 012// *************************************************************************************************************************** 013package org.apache.juneau.rest.client; 014 015import org.apache.http.*; 016 017/** 018 * Used to intercept http connection responses to allow modification of that response before processing and for 019 * listening for call lifecycle events. 020 * 021 * <p> 022 * Useful if you want to prevent {@link RestCallException RestCallExceptions} from being thrown on error conditions. 023 */ 024public abstract class RestCallInterceptor { 025 026 /** 027 * Called when {@link RestCall} object is created. 028 * 029 * @param restCall The restCall object invoking this method. 030 */ 031 public void onInit(RestCall restCall) {} 032 033 /** 034 * Called immediately after an HTTP response has been received. 035 * 036 * @param statusCode The HTTP status code received. 037 * @param restCall The restCall object invoking this method. 038 * @param req The HTTP request object. 039 * @param res The HTTP response object. 040 */ 041 public void onConnect(RestCall restCall, int statusCode, HttpRequest req, HttpResponse res) {} 042 043 /** 044 * Called if retry is going to be attempted. 045 * 046 * @param statusCode The HTTP status code received. 047 * @param restCall The restCall object invoking this method. 048 * @param req The HTTP request object. 049 * @param res The HTTP response object. 050 * @param ex The exception thrown from the client. 051 */ 052 public void onRetry(RestCall restCall, int statusCode, HttpRequest req, HttpResponse res, Exception ex) {} 053 054 /** 055 * Called when {@link RestCall#close()} is called. 056 * 057 * @param restCall The restCall object invoking this method. 058 * @throws RestCallException Error occurred during call. 059 */ 060 public void onClose(RestCall restCall) throws RestCallException {} 061}