View Javadoc
1   /*
2    * ====================================================================
3    * Licensed to the Apache Software Foundation (ASF) under one
4    * or more contributor license agreements.  See the NOTICE file
5    * distributed with this work for additional information
6    * regarding copyright ownership.  The ASF licenses this file
7    * to you under the Apache License, Version 2.0 (the
8    * "License"); you may not use this file except in compliance
9    * with the License.  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,
14   * software distributed under the License is distributed on an
15   * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16   * KIND, either express or implied.  See the License for the
17   * specific language governing permissions and limitations
18   * under the License.
19   * ====================================================================
20   *
21   * This software consists of voluntary contributions made by many
22   * individuals on behalf of the Apache Software Foundation.  For more
23   * information on the Apache Software Foundation, please see
24   * <http://www.apache.org/>.
25   *
26   */
27  
28  package org.apache.hc.client5.http;
29  
30  import org.apache.hc.client5.http.auth.AuthCache;
31  import org.apache.hc.client5.http.auth.AuthScheme;
32  import org.apache.hc.client5.http.auth.AuthSchemeFactory;
33  import org.apache.hc.client5.http.auth.CredentialsProvider;
34  import org.apache.hc.client5.http.auth.UsernamePasswordCredentials;
35  import org.apache.hc.client5.http.cookie.CookieSpecFactory;
36  import org.apache.hc.client5.http.cookie.CookieStore;
37  import org.apache.hc.client5.http.impl.DefaultSchemePortResolver;
38  import org.apache.hc.client5.http.protocol.HttpClientContext;
39  import org.apache.hc.core5.http.HttpHost;
40  import org.apache.hc.core5.http.config.Lookup;
41  
42  /**
43   * {@link HttpClientContext} builder.
44   *
45   * @since 5.2
46   */
47  public class ContextBuilder extends AbstractClientContextBuilder<HttpClientContext> {
48  
49      protected ContextBuilder(final SchemePortResolver schemePortResolver) {
50          super(schemePortResolver);
51      }
52  
53      public static ContextBuilder create(final SchemePortResolver schemePortResolver) {
54          return new ContextBuilder(schemePortResolver);
55      }
56  
57      public static ContextBuilder create() {
58          return new ContextBuilder(DefaultSchemePortResolver.INSTANCE);
59      }
60  
61      @Override
62      public ContextBuilder useCookieSpecRegistry(final Lookup<CookieSpecFactory> cookieSpecRegistry) {
63          super.useCookieSpecRegistry(cookieSpecRegistry);
64          return this;
65      }
66  
67      @Override
68      public ContextBuilder useAuthSchemeRegistry(final Lookup<AuthSchemeFactory> authSchemeRegistry) {
69          super.useAuthSchemeRegistry(authSchemeRegistry);
70          return this;
71      }
72  
73      @Override
74      public ContextBuilder useCookieStore(final CookieStore cookieStore) {
75          super.useCookieStore(cookieStore);
76          return this;
77      }
78  
79      @Override
80      public ContextBuilder useCredentialsProvider(final CredentialsProvider credentialsProvider) {
81          super.useCredentialsProvider(credentialsProvider);
82          return this;
83      }
84  
85      @Override
86      public ContextBuilder useAuthCache(final AuthCache authCache) {
87          super.useAuthCache(authCache);
88          return this;
89      }
90  
91      @Override
92      public ContextBuilder preemptiveAuth(final HttpHost host, final AuthScheme authScheme) {
93          super.preemptiveAuth(host, authScheme);
94          return this;
95      }
96  
97      @Override
98      public ContextBuilder preemptiveBasicAuth(final HttpHost host, final UsernamePasswordCredentials credentials) {
99          super.preemptiveBasicAuth(host, credentials);
100         return this;
101     }
102 
103     @Override
104     protected HttpClientContext createContext() {
105         return HttpClientContext.create();
106     }
107 
108 }