View Javadoc
1   /*
2    * #%L
3    * wcm.io
4    * %%
5    * Copyright (C) 2014 wcm.io
6    * %%
7    * Licensed under the Apache License, Version 2.0 (the "License");
8    * you may not use this file except in compliance with the License.
9    * 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, software
14   * distributed under the License is distributed on an "AS IS" BASIS,
15   * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16   * See the License for the specific language governing permissions and
17   * limitations under the License.
18   * #L%
19   */
20  package io.wcm.caravan.commons.httpclient;
21  
22  import org.apache.http.client.config.CookieSpecs;
23  import org.jetbrains.annotations.NotNull;
24  import org.jetbrains.annotations.Nullable;
25  import org.osgi.annotation.versioning.ConsumerType;
26  
27  /**
28   * HTTP Client configuration.
29   */
30  @ConsumerType
31  public interface HttpClientConfig {
32  
33    /**
34     * Default value for connection request timeout (in ms)
35     */
36    int CONNECTION_REQUEST_TIMEOUT_DEFAULT = 15000; // 15sec
37  
38    /**
39     * Default value for connection timeout (in ms)
40     */
41    int CONNECT_TIMEOUT_DEFAULT = 15000; // 15sec
42  
43    /**
44     * Default value for response timeout (in ms)
45     */
46    int SOCKET_TIMEOUT_DEFAULT = 60000; // 60sec
47  
48    /**
49     * Default value for default maximum connections per host
50     */
51    int MAX_CONNECTIONS_PER_HOST_DEFAULT = 50;
52  
53    /**
54     * Default value for maximum total connections
55     */
56    int MAX_TOTAL_CONNECTIONS_DEFAULT = 50;
57  
58    /**
59     * Default value for cookie specs.
60     */
61    String COOKIE_SPEC_DEFAULT = CookieSpecs.STANDARD;
62  
63    /**
64     * Configuration enabled.
65     * @return true if configuration is enabled.
66     */
67    boolean isEnabled();
68  
69    /**
70     * Connection request timeout in ms.
71     * @return Connection request timeout in ms.
72     */
73    default int getConnectionRequestTimeout() {
74      return CONNECTION_REQUEST_TIMEOUT_DEFAULT;
75    }
76  
77    /**
78     * Connection timeout in ms.
79     * @return Connection timeout in ms.
80     */
81    int getConnectTimeout();
82  
83    /**
84     * Response timeout in ms.
85     * @return Response timeout in ms.
86     */
87    int getSocketTimeout();
88  
89    /**
90     * Maximal HTTP connections per host.
91     * @return Maximal HTTP connections per host.
92     */
93    int getMaxConnectionsPerHost();
94  
95    /**
96     * Maximal total HTTP connections.
97     * @return Maximal total HTTP connections.
98     */
99    int getMaxTotalConnections();
100 
101   /**
102    * Standard cookie specification for HttpClient.
103    * @return Cookie spec
104    */
105   @NotNull
106   default String getCookieSpec() {
107     return HttpClientConfig.COOKIE_SPEC_DEFAULT;
108   }
109 
110   /**
111    * Http basic authentication user (optional).
112    * @return Http user or null.
113    */
114   @Nullable
115   String getHttpUser();
116 
117   /**
118    * Http basic authentication password (optional).
119    * @return Http password or null.
120    */
121   @Nullable
122   String getHttpPassword();
123 
124   /**
125    * Proxy host (optional).
126    * @return Proxy host or null.
127    */
128   @Nullable
129   String getProxyHost();
130 
131   /**
132    * Proxy port (optional).
133    * @return Proxy port or 0.
134    */
135   int getProxyPort();
136 
137   /**
138    * Proxy user (optional).
139    * @return Proxy user or null.
140    */
141   @Nullable
142   String getProxyUser();
143 
144   /**
145    * Proxy password (optional).
146    * @return Proxy password or null.
147    */
148   @Nullable
149   String getProxyPassword();
150 
151   /**
152    * Check if this configuration should be applied to a given host name.
153    * @param host Host name
154    * @return true if configuration matches.
155    */
156   boolean matchesHost(@Nullable String host);
157 
158   /**
159    * Check if this configuration should be applied for a given WS addressing to URI.
160    * @param addressingToUri Web service address
161    * @return true if configuration matches.
162    */
163   boolean matchesWsAddressingToUri(@Nullable String addressingToUri);
164 
165   /**
166    * Check if this configuration should be applied for a given path of the target URL
167    * @param path Path part
168    * @return true if configuration matches
169    */
170   default boolean matchesPath(@Nullable String path) {
171     return true;
172   }
173 
174   /**
175    * @return SSL context type (default: TLS)
176    */
177   @NotNull
178   String getSslContextType();
179 
180   /**
181    * @return Key manager type (default: SunX509)
182    */
183   @NotNull
184   String getKeyManagerType();
185 
186   /**
187    * @return Key store type (default: PKCS12)
188    */
189   @NotNull
190   String getKeyStoreType();
191 
192   /**
193    * @return Key store provider (default: null = use first matching security provider)
194    */
195   @Nullable
196   default String getKeyStoreProvider() {
197     return null;
198   }
199 
200   /**
201    * @return Key store file path
202    */
203   @Nullable
204   String getKeyStorePath();
205 
206   /**
207    * @return Key store password
208    */
209   @Nullable
210   String getKeyStorePassword();
211 
212   /**
213    * @return Trust manager type (default: SunX509)
214    */
215   @NotNull
216   String getTrustManagerType();
217 
218   /**
219    * @return Trust store type (default: JKS)
220    */
221   @NotNull
222   String getTrustStoreType();
223 
224   /**
225    * @return Trust store provider (default: null = use first matching security provider)
226    */
227   @Nullable
228   default String getTrustStoreProvider() {
229     return null;
230   }
231 
232   /**
233    * @return Trust store file path
234    */
235   @Nullable
236   String getTrustStorePath();
237 
238   /**
239    * @return Trust store password
240    */
241   @Nullable
242   String getTrustStorePassword();
243 
244 }