1 /* |
|
2 * Copyright (c) 2015, 2016, Oracle and/or its affiliates. All rights reserved. |
|
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. |
|
4 * |
|
5 * This code is free software; you can redistribute it and/or modify it |
|
6 * under the terms of the GNU General Public License version 2 only, as |
|
7 * published by the Free Software Foundation. Oracle designates this |
|
8 * particular file as subject to the "Classpath" exception as provided |
|
9 * by Oracle in the LICENSE file that accompanied this code. |
|
10 * |
|
11 * This code is distributed in the hope that it will be useful, but WITHOUT |
|
12 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or |
|
13 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License |
|
14 * version 2 for more details (a copy is included in the LICENSE file that |
|
15 * accompanied this code). |
|
16 * |
|
17 * You should have received a copy of the GNU General Public License version |
|
18 * 2 along with this work; if not, write to the Free Software Foundation, |
|
19 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. |
|
20 * |
|
21 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA |
|
22 * or visit www.oracle.com if you need additional information or have any |
|
23 * questions. |
|
24 */ |
|
25 |
|
26 package java.net.http; |
|
27 |
|
28 import java.net.Authenticator; |
|
29 import java.net.CookieManager; |
|
30 import java.net.ProxySelector; |
|
31 import java.util.Objects; |
|
32 import java.util.concurrent.ExecutorService; |
|
33 import javax.net.ssl.SSLContext; |
|
34 import javax.net.ssl.SSLParameters; |
|
35 |
|
36 class HttpClientBuilderImpl extends HttpClient.Builder { |
|
37 |
|
38 CookieManager cookieManager; |
|
39 HttpClient.Redirect followRedirects; |
|
40 ProxySelector proxy; |
|
41 Authenticator authenticator; |
|
42 HttpClient.Version version = HttpClient.Version.HTTP_1_1; |
|
43 ExecutorService executor; |
|
44 // Security parameters |
|
45 SSLContext sslContext; |
|
46 SSLParameters sslParams; |
|
47 int priority = -1; |
|
48 |
|
49 @Override |
|
50 public HttpClientBuilderImpl cookieManager(CookieManager manager) { |
|
51 Objects.requireNonNull(manager); |
|
52 this.cookieManager = manager; |
|
53 return this; |
|
54 } |
|
55 |
|
56 |
|
57 @Override |
|
58 public HttpClientBuilderImpl sslContext(SSLContext sslContext) { |
|
59 Objects.requireNonNull(sslContext); |
|
60 Utils.checkNetPermission("setSSLContext"); |
|
61 this.sslContext = sslContext; |
|
62 return this; |
|
63 } |
|
64 |
|
65 |
|
66 @Override |
|
67 public HttpClientBuilderImpl sslParameters(SSLParameters sslParameters) { |
|
68 Objects.requireNonNull(sslParameters); |
|
69 this.sslParams = sslParameters; |
|
70 return this; |
|
71 } |
|
72 |
|
73 |
|
74 @Override |
|
75 public HttpClientBuilderImpl executorService(ExecutorService s) { |
|
76 Objects.requireNonNull(s); |
|
77 this.executor = s; |
|
78 return this; |
|
79 } |
|
80 |
|
81 |
|
82 @Override |
|
83 public HttpClientBuilderImpl followRedirects(HttpClient.Redirect policy) { |
|
84 Objects.requireNonNull(policy); |
|
85 this.followRedirects = policy; |
|
86 return this; |
|
87 } |
|
88 |
|
89 |
|
90 @Override |
|
91 public HttpClientBuilderImpl version(HttpClient.Version version) { |
|
92 Objects.requireNonNull(version); |
|
93 this.version = version; |
|
94 return this; |
|
95 } |
|
96 |
|
97 |
|
98 @Override |
|
99 public HttpClientBuilderImpl priority(int priority) { |
|
100 if (priority < 1 || priority > 255) { |
|
101 throw new IllegalArgumentException("priority must be between 1 and 255"); |
|
102 } |
|
103 this.priority = priority; |
|
104 return this; |
|
105 } |
|
106 |
|
107 |
|
108 @Override |
|
109 public HttpClientBuilderImpl pipelining(boolean enable) { |
|
110 //To change body of generated methods, choose Tools | Templates. |
|
111 throw new UnsupportedOperationException("Not supported yet."); |
|
112 } |
|
113 |
|
114 |
|
115 @Override |
|
116 public HttpClientBuilderImpl proxy(ProxySelector proxy) { |
|
117 Objects.requireNonNull(proxy); |
|
118 this.proxy = proxy; |
|
119 return this; |
|
120 } |
|
121 |
|
122 |
|
123 @Override |
|
124 public HttpClientBuilderImpl authenticator(Authenticator a) { |
|
125 Objects.requireNonNull(a); |
|
126 this.authenticator = a; |
|
127 return this; |
|
128 } |
|
129 |
|
130 @Override |
|
131 public HttpClient build() { |
|
132 return HttpClientImpl.create(this); |
|
133 } |
|
134 } |
|