1 /* |
|
2 * Copyright (c) 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.io.IOException; |
|
29 import java.lang.ref.Reference; |
|
30 import java.net.Authenticator; |
|
31 import java.net.CookieHandler; |
|
32 import java.net.ProxySelector; |
|
33 import java.net.URI; |
|
34 import java.util.Optional; |
|
35 import java.util.concurrent.CompletableFuture; |
|
36 import java.util.concurrent.Executor; |
|
37 import javax.net.ssl.SSLContext; |
|
38 import javax.net.ssl.SSLParameters; |
|
39 import jdk.incubator.http.HttpResponse.BodyHandler; |
|
40 import jdk.incubator.http.HttpResponse.PushPromiseHandler; |
|
41 |
|
42 /** |
|
43 * An HttpClientFacade is a simple class that wraps an HttpClient implementation |
|
44 * and delegates everything to its implementation delegate. |
|
45 */ |
|
46 final class HttpClientFacade extends HttpClient { |
|
47 |
|
48 final HttpClientImpl impl; |
|
49 |
|
50 /** |
|
51 * Creates an HttpClientFacade. |
|
52 */ |
|
53 HttpClientFacade(HttpClientImpl impl) { |
|
54 this.impl = impl; |
|
55 } |
|
56 |
|
57 @Override |
|
58 public Optional<CookieHandler> cookieHandler() { |
|
59 return impl.cookieHandler(); |
|
60 } |
|
61 |
|
62 @Override |
|
63 public Redirect followRedirects() { |
|
64 return impl.followRedirects(); |
|
65 } |
|
66 |
|
67 @Override |
|
68 public Optional<ProxySelector> proxy() { |
|
69 return impl.proxy(); |
|
70 } |
|
71 |
|
72 @Override |
|
73 public SSLContext sslContext() { |
|
74 return impl.sslContext(); |
|
75 } |
|
76 |
|
77 @Override |
|
78 public SSLParameters sslParameters() { |
|
79 return impl.sslParameters(); |
|
80 } |
|
81 |
|
82 @Override |
|
83 public Optional<Authenticator> authenticator() { |
|
84 return impl.authenticator(); |
|
85 } |
|
86 |
|
87 @Override |
|
88 public HttpClient.Version version() { |
|
89 return impl.version(); |
|
90 } |
|
91 |
|
92 @Override |
|
93 public Optional<Executor> executor() { |
|
94 return impl.executor(); |
|
95 } |
|
96 |
|
97 @Override |
|
98 public <T> HttpResponse<T> |
|
99 send(HttpRequest req, HttpResponse.BodyHandler<T> responseBodyHandler) |
|
100 throws IOException, InterruptedException |
|
101 { |
|
102 try { |
|
103 return impl.send(req, responseBodyHandler); |
|
104 } finally { |
|
105 Reference.reachabilityFence(this); |
|
106 } |
|
107 } |
|
108 |
|
109 @Override |
|
110 public <T> CompletableFuture<HttpResponse<T>> |
|
111 sendAsync(HttpRequest req, HttpResponse.BodyHandler<T> responseBodyHandler) { |
|
112 try { |
|
113 return impl.sendAsync(req, responseBodyHandler); |
|
114 } finally { |
|
115 Reference.reachabilityFence(this); |
|
116 } |
|
117 } |
|
118 |
|
119 @Override |
|
120 public <T> CompletableFuture<HttpResponse<T>> |
|
121 sendAsync(HttpRequest req, |
|
122 BodyHandler<T> responseBodyHandler, |
|
123 PushPromiseHandler<T> pushPromiseHandler){ |
|
124 try { |
|
125 return impl.sendAsync(req, responseBodyHandler, pushPromiseHandler); |
|
126 } finally { |
|
127 Reference.reachabilityFence(this); |
|
128 } |
|
129 } |
|
130 |
|
131 @Override |
|
132 public WebSocket.Builder newWebSocketBuilder() { |
|
133 try { |
|
134 return impl.newWebSocketBuilder(); |
|
135 } finally { |
|
136 Reference.reachabilityFence(this); |
|
137 } |
|
138 } |
|
139 |
|
140 @Override |
|
141 public String toString() { |
|
142 // Used by tests to get the client's id. |
|
143 return impl.toString(); |
|
144 } |
|
145 } |
|