author | mbaesken |
Thu, 28 Nov 2019 13:02:39 +0100 | |
changeset 59323 | ae2eb76c486d |
parent 51364 | 31d9e82b2e64 |
child 56868 | 67c7659ecda5 |
permissions | -rw-r--r-- |
42460
7133f144981a
8170648: Move java.net.http package out of Java SE to incubator namespace
michaelm
parents:
diff
changeset
|
1 |
/* |
49765 | 2 |
* Copyright (c) 2015, 2018, Oracle and/or its affiliates. All rights reserved. |
42460
7133f144981a
8170648: Move java.net.http package out of Java SE to incubator namespace
michaelm
parents:
diff
changeset
|
3 |
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. |
7133f144981a
8170648: Move java.net.http package out of Java SE to incubator namespace
michaelm
parents:
diff
changeset
|
4 |
* |
7133f144981a
8170648: Move java.net.http package out of Java SE to incubator namespace
michaelm
parents:
diff
changeset
|
5 |
* This code is free software; you can redistribute it and/or modify it |
7133f144981a
8170648: Move java.net.http package out of Java SE to incubator namespace
michaelm
parents:
diff
changeset
|
6 |
* under the terms of the GNU General Public License version 2 only, as |
7133f144981a
8170648: Move java.net.http package out of Java SE to incubator namespace
michaelm
parents:
diff
changeset
|
7 |
* published by the Free Software Foundation. Oracle designates this |
7133f144981a
8170648: Move java.net.http package out of Java SE to incubator namespace
michaelm
parents:
diff
changeset
|
8 |
* particular file as subject to the "Classpath" exception as provided |
7133f144981a
8170648: Move java.net.http package out of Java SE to incubator namespace
michaelm
parents:
diff
changeset
|
9 |
* by Oracle in the LICENSE file that accompanied this code. |
7133f144981a
8170648: Move java.net.http package out of Java SE to incubator namespace
michaelm
parents:
diff
changeset
|
10 |
* |
7133f144981a
8170648: Move java.net.http package out of Java SE to incubator namespace
michaelm
parents:
diff
changeset
|
11 |
* This code is distributed in the hope that it will be useful, but WITHOUT |
7133f144981a
8170648: Move java.net.http package out of Java SE to incubator namespace
michaelm
parents:
diff
changeset
|
12 |
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or |
7133f144981a
8170648: Move java.net.http package out of Java SE to incubator namespace
michaelm
parents:
diff
changeset
|
13 |
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License |
7133f144981a
8170648: Move java.net.http package out of Java SE to incubator namespace
michaelm
parents:
diff
changeset
|
14 |
* version 2 for more details (a copy is included in the LICENSE file that |
7133f144981a
8170648: Move java.net.http package out of Java SE to incubator namespace
michaelm
parents:
diff
changeset
|
15 |
* accompanied this code). |
7133f144981a
8170648: Move java.net.http package out of Java SE to incubator namespace
michaelm
parents:
diff
changeset
|
16 |
* |
7133f144981a
8170648: Move java.net.http package out of Java SE to incubator namespace
michaelm
parents:
diff
changeset
|
17 |
* You should have received a copy of the GNU General Public License version |
7133f144981a
8170648: Move java.net.http package out of Java SE to incubator namespace
michaelm
parents:
diff
changeset
|
18 |
* 2 along with this work; if not, write to the Free Software Foundation, |
7133f144981a
8170648: Move java.net.http package out of Java SE to incubator namespace
michaelm
parents:
diff
changeset
|
19 |
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. |
7133f144981a
8170648: Move java.net.http package out of Java SE to incubator namespace
michaelm
parents:
diff
changeset
|
20 |
* |
7133f144981a
8170648: Move java.net.http package out of Java SE to incubator namespace
michaelm
parents:
diff
changeset
|
21 |
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA |
7133f144981a
8170648: Move java.net.http package out of Java SE to incubator namespace
michaelm
parents:
diff
changeset
|
22 |
* or visit www.oracle.com if you need additional information or have any |
7133f144981a
8170648: Move java.net.http package out of Java SE to incubator namespace
michaelm
parents:
diff
changeset
|
23 |
* questions. |
7133f144981a
8170648: Move java.net.http package out of Java SE to incubator namespace
michaelm
parents:
diff
changeset
|
24 |
*/ |
7133f144981a
8170648: Move java.net.http package out of Java SE to incubator namespace
michaelm
parents:
diff
changeset
|
25 |
|
49765 | 26 |
package jdk.internal.net.http; |
42460
7133f144981a
8170648: Move java.net.http package out of Java SE to incubator namespace
michaelm
parents:
diff
changeset
|
27 |
|
7133f144981a
8170648: Move java.net.http package out of Java SE to incubator namespace
michaelm
parents:
diff
changeset
|
28 |
import java.net.InetSocketAddress; |
7133f144981a
8170648: Move java.net.http package out of Java SE to incubator namespace
michaelm
parents:
diff
changeset
|
29 |
import java.nio.channels.SocketChannel; |
7133f144981a
8170648: Move java.net.http package out of Java SE to incubator namespace
michaelm
parents:
diff
changeset
|
30 |
import java.util.concurrent.CompletableFuture; |
51364
31d9e82b2e64
8208391: Differentiate response and connect timeouts in HTTP Client API
chegar
parents:
49944
diff
changeset
|
31 |
import java.util.function.Function; |
31d9e82b2e64
8208391: Differentiate response and connect timeouts in HTTP Client API
chegar
parents:
49944
diff
changeset
|
32 |
import jdk.internal.net.http.common.MinimalFuture; |
49765 | 33 |
import jdk.internal.net.http.common.SSLTube; |
34 |
import jdk.internal.net.http.common.Utils; |
|
42460
7133f144981a
8170648: Move java.net.http package out of Java SE to incubator namespace
michaelm
parents:
diff
changeset
|
35 |
|
7133f144981a
8170648: Move java.net.http package out of Java SE to incubator namespace
michaelm
parents:
diff
changeset
|
36 |
/** |
7133f144981a
8170648: Move java.net.http package out of Java SE to incubator namespace
michaelm
parents:
diff
changeset
|
37 |
* Asynchronous version of SSLConnection. |
7133f144981a
8170648: Move java.net.http package out of Java SE to incubator namespace
michaelm
parents:
diff
changeset
|
38 |
*/ |
46157 | 39 |
class AsyncSSLConnection extends AbstractAsyncSSLConnection { |
42460
7133f144981a
8170648: Move java.net.http package out of Java SE to incubator namespace
michaelm
parents:
diff
changeset
|
40 |
|
44854
5a486e0acd29
8175814: Update default HttpClient protocol version and optional request version
michaelm
parents:
42460
diff
changeset
|
41 |
final PlainHttpConnection plainConnection; |
48083 | 42 |
final PlainHttpPublisher writePublisher; |
43 |
private volatile SSLTube flow; |
|
42460
7133f144981a
8170648: Move java.net.http package out of Java SE to incubator namespace
michaelm
parents:
diff
changeset
|
44 |
|
48083 | 45 |
AsyncSSLConnection(InetSocketAddress addr, |
46 |
HttpClientImpl client, |
|
47 |
String[] alpn) { |
|
49765 | 48 |
super(addr, client, Utils.getServerName(addr), addr.getPort(), alpn); |
44854
5a486e0acd29
8175814: Update default HttpClient protocol version and optional request version
michaelm
parents:
42460
diff
changeset
|
49 |
plainConnection = new PlainHttpConnection(addr, client); |
48083 | 50 |
writePublisher = new PlainHttpPublisher(); |
44854
5a486e0acd29
8175814: Update default HttpClient protocol version and optional request version
michaelm
parents:
42460
diff
changeset
|
51 |
} |
5a486e0acd29
8175814: Update default HttpClient protocol version and optional request version
michaelm
parents:
42460
diff
changeset
|
52 |
|
46157 | 53 |
@Override |
51364
31d9e82b2e64
8208391: Differentiate response and connect timeouts in HTTP Client API
chegar
parents:
49944
diff
changeset
|
54 |
public CompletableFuture<Void> connectAsync(Exchange<?> exchange) { |
48083 | 55 |
return plainConnection |
51364
31d9e82b2e64
8208391: Differentiate response and connect timeouts in HTTP Client API
chegar
parents:
49944
diff
changeset
|
56 |
.connectAsync(exchange) |
48083 | 57 |
.thenApply( unused -> { |
58 |
// create the SSLTube wrapping the SocketTube, with the given engine |
|
59 |
flow = new SSLTube(engine, |
|
60 |
client().theExecutor(), |
|
49944 | 61 |
client().getSSLBufferSupplier()::recycle, |
48083 | 62 |
plainConnection.getConnectionFlow()); |
63 |
return null; } ); |
|
42460
7133f144981a
8170648: Move java.net.http package out of Java SE to incubator namespace
michaelm
parents:
diff
changeset
|
64 |
} |
7133f144981a
8170648: Move java.net.http package out of Java SE to incubator namespace
michaelm
parents:
diff
changeset
|
65 |
|
7133f144981a
8170648: Move java.net.http package out of Java SE to incubator namespace
michaelm
parents:
diff
changeset
|
66 |
@Override |
51364
31d9e82b2e64
8208391: Differentiate response and connect timeouts in HTTP Client API
chegar
parents:
49944
diff
changeset
|
67 |
public CompletableFuture<Void> finishConnect() { |
31d9e82b2e64
8208391: Differentiate response and connect timeouts in HTTP Client API
chegar
parents:
49944
diff
changeset
|
68 |
// The actual ALPN value, which may be the empty string, is not |
31d9e82b2e64
8208391: Differentiate response and connect timeouts in HTTP Client API
chegar
parents:
49944
diff
changeset
|
69 |
// interesting at this point, only that the handshake has completed. |
31d9e82b2e64
8208391: Differentiate response and connect timeouts in HTTP Client API
chegar
parents:
49944
diff
changeset
|
70 |
return getALPN() |
31d9e82b2e64
8208391: Differentiate response and connect timeouts in HTTP Client API
chegar
parents:
49944
diff
changeset
|
71 |
.handle((String unused, Throwable ex) -> { |
31d9e82b2e64
8208391: Differentiate response and connect timeouts in HTTP Client API
chegar
parents:
49944
diff
changeset
|
72 |
if (ex == null) { |
31d9e82b2e64
8208391: Differentiate response and connect timeouts in HTTP Client API
chegar
parents:
49944
diff
changeset
|
73 |
return plainConnection.finishConnect(); |
31d9e82b2e64
8208391: Differentiate response and connect timeouts in HTTP Client API
chegar
parents:
49944
diff
changeset
|
74 |
} else { |
31d9e82b2e64
8208391: Differentiate response and connect timeouts in HTTP Client API
chegar
parents:
49944
diff
changeset
|
75 |
plainConnection.close(); |
31d9e82b2e64
8208391: Differentiate response and connect timeouts in HTTP Client API
chegar
parents:
49944
diff
changeset
|
76 |
return MinimalFuture.<Void>failedFuture(ex); |
31d9e82b2e64
8208391: Differentiate response and connect timeouts in HTTP Client API
chegar
parents:
49944
diff
changeset
|
77 |
} }) |
31d9e82b2e64
8208391: Differentiate response and connect timeouts in HTTP Client API
chegar
parents:
49944
diff
changeset
|
78 |
.thenCompose(Function.identity()); |
31d9e82b2e64
8208391: Differentiate response and connect timeouts in HTTP Client API
chegar
parents:
49944
diff
changeset
|
79 |
} |
31d9e82b2e64
8208391: Differentiate response and connect timeouts in HTTP Client API
chegar
parents:
49944
diff
changeset
|
80 |
|
31d9e82b2e64
8208391: Differentiate response and connect timeouts in HTTP Client API
chegar
parents:
49944
diff
changeset
|
81 |
@Override |
42460
7133f144981a
8170648: Move java.net.http package out of Java SE to incubator namespace
michaelm
parents:
diff
changeset
|
82 |
boolean connected() { |
48083 | 83 |
return plainConnection.connected(); |
42460
7133f144981a
8170648: Move java.net.http package out of Java SE to incubator namespace
michaelm
parents:
diff
changeset
|
84 |
} |
7133f144981a
8170648: Move java.net.http package out of Java SE to incubator namespace
michaelm
parents:
diff
changeset
|
85 |
|
7133f144981a
8170648: Move java.net.http package out of Java SE to incubator namespace
michaelm
parents:
diff
changeset
|
86 |
@Override |
48083 | 87 |
HttpPublisher publisher() { return writePublisher; } |
88 |
||
89 |
@Override |
|
42460
7133f144981a
8170648: Move java.net.http package out of Java SE to incubator namespace
michaelm
parents:
diff
changeset
|
90 |
boolean isProxied() { |
7133f144981a
8170648: Move java.net.http package out of Java SE to incubator namespace
michaelm
parents:
diff
changeset
|
91 |
return false; |
7133f144981a
8170648: Move java.net.http package out of Java SE to incubator namespace
michaelm
parents:
diff
changeset
|
92 |
} |
7133f144981a
8170648: Move java.net.http package out of Java SE to incubator namespace
michaelm
parents:
diff
changeset
|
93 |
|
7133f144981a
8170648: Move java.net.http package out of Java SE to incubator namespace
michaelm
parents:
diff
changeset
|
94 |
@Override |
7133f144981a
8170648: Move java.net.http package out of Java SE to incubator namespace
michaelm
parents:
diff
changeset
|
95 |
SocketChannel channel() { |
44854
5a486e0acd29
8175814: Update default HttpClient protocol version and optional request version
michaelm
parents:
42460
diff
changeset
|
96 |
return plainConnection.channel(); |
5a486e0acd29
8175814: Update default HttpClient protocol version and optional request version
michaelm
parents:
42460
diff
changeset
|
97 |
} |
5a486e0acd29
8175814: Update default HttpClient protocol version and optional request version
michaelm
parents:
42460
diff
changeset
|
98 |
|
5a486e0acd29
8175814: Update default HttpClient protocol version and optional request version
michaelm
parents:
42460
diff
changeset
|
99 |
@Override |
42460
7133f144981a
8170648: Move java.net.http package out of Java SE to incubator namespace
michaelm
parents:
diff
changeset
|
100 |
ConnectionPool.CacheKey cacheKey() { |
7133f144981a
8170648: Move java.net.http package out of Java SE to incubator namespace
michaelm
parents:
diff
changeset
|
101 |
return ConnectionPool.cacheKey(address, null); |
7133f144981a
8170648: Move java.net.http package out of Java SE to incubator namespace
michaelm
parents:
diff
changeset
|
102 |
} |
7133f144981a
8170648: Move java.net.http package out of Java SE to incubator namespace
michaelm
parents:
diff
changeset
|
103 |
|
7133f144981a
8170648: Move java.net.http package out of Java SE to incubator namespace
michaelm
parents:
diff
changeset
|
104 |
@Override |
7133f144981a
8170648: Move java.net.http package out of Java SE to incubator namespace
michaelm
parents:
diff
changeset
|
105 |
public void close() { |
48083 | 106 |
plainConnection.close(); |
42460
7133f144981a
8170648: Move java.net.http package out of Java SE to incubator namespace
michaelm
parents:
diff
changeset
|
107 |
} |
7133f144981a
8170648: Move java.net.http package out of Java SE to incubator namespace
michaelm
parents:
diff
changeset
|
108 |
|
7133f144981a
8170648: Move java.net.http package out of Java SE to incubator namespace
michaelm
parents:
diff
changeset
|
109 |
@Override |
49765 | 110 |
SSLTube getConnectionFlow() { |
48083 | 111 |
return flow; |
112 |
} |
|
42460
7133f144981a
8170648: Move java.net.http package out of Java SE to incubator namespace
michaelm
parents:
diff
changeset
|
113 |
} |