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