001/** 002 * Copyright (C) 2006-2018 Talend Inc. - www.talend.com 003 * 004 * Licensed under the Apache License, Version 2.0 (the "License"); 005 * you may not use this file except in compliance with the License. 006 * You may obtain a copy of the License at 007 * 008 * http://www.apache.org/licenses/LICENSE-2.0 009 * 010 * Unless required by applicable law or agreed to in writing, software 011 * distributed under the License is distributed on an "AS IS" BASIS, 012 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 013 * See the License for the specific language governing permissions and 014 * limitations under the License. 015 */ 016package org.talend.sdk.component.api.service.http; 017 018/** 019 * Callback to configure the connection more deeply. Typically used to configure timeouts. 020 */ 021public interface Configurer { 022 023 /** 024 * @param connection the current connection to customize. 025 * @param configuration the configuration of the invocation if any. 026 */ 027 void configure(Connection connection, ConfigurerConfiguration configuration); 028 029 /** 030 * Represents actions doable on a connection. 031 */ 032 interface Connection { 033 034 /** 035 * Adds a header to the request. 036 * 037 * @param name header name. 038 * @param value header value. 039 * @return current connection. 040 */ 041 Connection withHeader(String name, String value); 042 043 /** 044 * Sets the read timeout of the connection. 045 * 046 * @param timeout timeout value in milliseconds. 047 * @return current connection. 048 */ 049 Connection withReadTimeout(int timeout); 050 051 /** 052 * Sets the connection timeout of the connection. 053 * 054 * @param timeout timeout value in milliseconds. 055 * @return current connection. 056 */ 057 Connection withConnectionTimeout(int timeout); 058 } 059 060 /** 061 * Represents the potential {@link ConfigurerOption} parameters of the invocation. 062 */ 063 interface ConfigurerConfiguration { 064 065 /** 066 * @return all options at once. 067 */ 068 Object[] configuration(); 069 070 /** 071 * @param name the option name. 072 * @param type the expected type of the option. 073 * @param <T> the type of the option. 074 * @return the option value or null if missing. 075 */ 076 <T> T get(String name, Class<T> type); 077 } 078}