Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
PojavLauncherTeam
GitHub Repository: PojavLauncherTeam/jdk17u
Path: blob/master/src/java.net.http/share/classes/jdk/internal/net/http/HttpClientFacade.java
67707 views
1
/*
2
* Copyright (c) 2017, 2018, 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.internal.net.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.time.Duration;
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 java.net.http.HttpClient;
40
import java.net.http.HttpRequest;
41
import java.net.http.HttpResponse;
42
import java.net.http.HttpResponse.BodyHandler;
43
import java.net.http.HttpResponse.PushPromiseHandler;
44
import java.net.http.WebSocket;
45
import jdk.internal.net.http.common.OperationTrackers.Trackable;
46
import jdk.internal.net.http.common.OperationTrackers.Tracker;
47
48
/**
49
* An HttpClientFacade is a simple class that wraps an HttpClient implementation
50
* and delegates everything to its implementation delegate.
51
*/
52
public final class HttpClientFacade extends HttpClient implements Trackable {
53
54
final HttpClientImpl impl;
55
56
/**
57
* Creates an HttpClientFacade.
58
*/
59
HttpClientFacade(HttpClientImpl impl) {
60
this.impl = impl;
61
}
62
63
@Override // for tests
64
public Tracker getOperationsTracker() {
65
return impl.getOperationsTracker();
66
}
67
68
@Override
69
public Optional<CookieHandler> cookieHandler() {
70
return impl.cookieHandler();
71
}
72
73
@Override
74
public Optional<Duration> connectTimeout() {
75
return impl.connectTimeout();
76
}
77
78
@Override
79
public Redirect followRedirects() {
80
return impl.followRedirects();
81
}
82
83
@Override
84
public Optional<ProxySelector> proxy() {
85
return impl.proxy();
86
}
87
88
@Override
89
public SSLContext sslContext() {
90
return impl.sslContext();
91
}
92
93
@Override
94
public SSLParameters sslParameters() {
95
return impl.sslParameters();
96
}
97
98
@Override
99
public Optional<Authenticator> authenticator() {
100
return impl.authenticator();
101
}
102
103
@Override
104
public HttpClient.Version version() {
105
return impl.version();
106
}
107
108
@Override
109
public Optional<Executor> executor() {
110
return impl.executor();
111
}
112
113
public Executor theExecutor() {
114
return impl.theExecutor();
115
}
116
117
@Override
118
public <T> HttpResponse<T>
119
send(HttpRequest req, HttpResponse.BodyHandler<T> responseBodyHandler)
120
throws IOException, InterruptedException
121
{
122
try {
123
return impl.send(req, responseBodyHandler);
124
} finally {
125
Reference.reachabilityFence(this);
126
}
127
}
128
129
@Override
130
public <T> CompletableFuture<HttpResponse<T>>
131
sendAsync(HttpRequest req, HttpResponse.BodyHandler<T> responseBodyHandler) {
132
try {
133
return impl.sendAsync(req, responseBodyHandler);
134
} finally {
135
Reference.reachabilityFence(this);
136
}
137
}
138
139
@Override
140
public <T> CompletableFuture<HttpResponse<T>>
141
sendAsync(HttpRequest req,
142
BodyHandler<T> responseBodyHandler,
143
PushPromiseHandler<T> pushPromiseHandler){
144
try {
145
return impl.sendAsync(req, responseBodyHandler, pushPromiseHandler);
146
} finally {
147
Reference.reachabilityFence(this);
148
}
149
}
150
151
@Override
152
public WebSocket.Builder newWebSocketBuilder() {
153
try {
154
return impl.newWebSocketBuilder();
155
} finally {
156
Reference.reachabilityFence(this);
157
}
158
}
159
160
@Override
161
public String toString() {
162
// Used by tests to get the client's id.
163
return impl.toString();
164
}
165
}
166
167