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 jdk.incubator.http; 27 28 import java.net.Authenticator; 29 import java.net.CookieManager; 30 import java.net.ProxySelector; 31 import java.util.concurrent.Executor; 32 import javax.net.ssl.SSLContext; 33 import javax.net.ssl.SSLParameters; 34 import jdk.incubator.http.internal.common.Utils; 35 import static java.util.Objects.requireNonNull; 36 37 class HttpClientBuilderImpl extends HttpClient.Builder { 38 39 CookieManager cookieManager; 40 HttpClient.Redirect followRedirects; 41 ProxySelector proxy; 42 Authenticator authenticator; 43 HttpClient.Version version; 44 Executor executor; 45 // Security parameters 46 SSLContext sslContext; 47 SSLParameters sslParams; 48 int priority = -1; 49 50 @Override 51 public HttpClientBuilderImpl cookieManager(CookieManager cookieManager) { 52 requireNonNull(cookieManager); 53 this.cookieManager = cookieManager; 54 return this; 55 } 56 57 58 @Override 59 public HttpClientBuilderImpl sslContext(SSLContext sslContext) { 60 requireNonNull(sslContext); 61 Utils.checkNetPermission("setSSLContext"); 62 this.sslContext = sslContext; 63 return this; 64 } 65 66 67 @Override 68 public HttpClientBuilderImpl sslParameters(SSLParameters sslParameters) { 69 requireNonNull(sslParameters); 70 this.sslParams = sslParameters; 71 return this; 72 } 73 74 75 @Override 76 public HttpClientBuilderImpl executor(Executor s) { 77 requireNonNull(s); 78 this.executor = s; 79 return this; 80 } 81 82 83 @Override 84 public HttpClientBuilderImpl followRedirects(HttpClient.Redirect policy) { 85 requireNonNull(policy); 86 this.followRedirects = policy; 87 return this; 88 } 89 90 91 @Override 92 public HttpClientBuilderImpl version(HttpClient.Version version) { 93 requireNonNull(version); 94 this.version = version; 95 return this; 96 } 97 98 99 @Override 100 public HttpClientBuilderImpl priority(int priority) { 101 if (priority < 1 || priority > 256) { 102 throw new IllegalArgumentException("priority must be between 1 and 256"); 103 } 104 this.priority = priority; 105 return this; 106 } 107 108 @Override 109 public HttpClientBuilderImpl proxy(ProxySelector proxy) { 110 requireNonNull(proxy); 111 this.proxy = proxy; 112 return this; 113 } 114 115 116 @Override 117 public HttpClientBuilderImpl authenticator(Authenticator a) { 118 requireNonNull(a); 119 this.authenticator = a; 120 return this; 121 } 122 123 @Override 124 public HttpClient build() { 125 return HttpClientImpl.create(this); 126 } 127 }