View Javadoc

1   package com.atlassian.httpclient.apache.httpcomponents.proxy;
2   
3   
4   import com.atlassian.fugue.Option;
5   import com.google.common.collect.Iterables;
6   import org.apache.http.HttpHost;
7   import org.apache.http.auth.AuthScope;
8   import org.apache.http.auth.Credentials;
9   
10  import java.net.ProxySelector;
11  
12  public abstract class ProxyConfig {
13      public Option<HttpHost> getProxyHost() {
14          final HttpHost httpHost = Iterables.getFirst(getProxyHosts(), null);
15          if (httpHost != null) {
16              return Option.some(new HttpHost(httpHost.getHostName(), httpHost.getPort()));
17          } else {
18              return Option.none();
19          }
20      }
21  
22      abstract Iterable<HttpHost> getProxyHosts();
23  
24      public abstract Iterable<AuthenticationInfo> getAuthenticationInfo();
25  
26      /**
27       * @return the {@link ProxySelector} equivalent of this this proxy configuration
28       */
29      public abstract ProxySelector toProxySelector();
30  
31      public static class AuthenticationInfo {
32          private final AuthScope authScope;
33          private final Option<Credentials> credentials;
34  
35          public AuthenticationInfo(final AuthScope authScope, final Option<Credentials> credentials) {
36              this.authScope = authScope;
37              this.credentials = credentials;
38          }
39  
40          public AuthScope getAuthScope() {
41              return authScope;
42          }
43  
44          public Option<Credentials> getCredentials() {
45              return credentials;
46          }
47      }
48  }