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