1 /* 2 * Copyright (c) 2015, 2017, 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.CookieHandler; 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 CookieHandler cookieHandler; 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 cookieHandler(CookieHandler cookieHandler) { 52 requireNonNull(cookieHandler); 53 this.cookieHandler = cookieHandler; 54 return this; 55 } 56 57 58 @Override 59 public HttpClientBuilderImpl sslContext(SSLContext sslContext) { 60 requireNonNull(sslContext); 61 this.sslContext = sslContext; 62 return this; 63 } 64 65 66 @Override 67 public HttpClientBuilderImpl sslParameters(SSLParameters sslParameters) { 68 requireNonNull(sslParameters); 69 this.sslParams = Utils.copySSLParameters(sslParameters); 70 return this; 71 } 72 73 74 @Override 75 public HttpClientBuilderImpl executor(Executor s) { 76 requireNonNull(s); 77 this.executor = s; 78 return this; 79 } 80 81 82 @Override 83 public HttpClientBuilderImpl followRedirects(HttpClient.Redirect policy) { 84 requireNonNull(policy); 85 this.followRedirects = policy; 86 return this; 87 } 88 89 90 @Override 91 public HttpClientBuilderImpl version(HttpClient.Version version) { 92 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 > 256) { 101 throw new IllegalArgumentException("priority must be between 1 and 256"); 102 } 103 this.priority = priority; 104 return this; 105 } 106 107 @Override 108 public HttpClientBuilderImpl proxy(ProxySelector proxy) { 109 requireNonNull(proxy); 110 this.proxy = proxy; 111 return this; 112 } 113 114 115 @Override 116 public HttpClientBuilderImpl authenticator(Authenticator a) { 117 requireNonNull(a); 118 this.authenticator = a; 119 return this; 120 } 121 122 @Override 123 public HttpClient build() { 124 return HttpClientImpl.create(this); 125 } 126 }