author | chegar |
Fri, 16 Feb 2018 16:09:14 +0000 | |
branch | http-client-branch |
changeset 56139 | b3d6203051df |
parent 56126 | 86e628130926 |
child 56451 | 9585061fdb04 |
permissions | -rw-r--r-- |
56023 | 1 |
/* |
2 |
* Copyright (c) 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. |
|
8 |
* |
|
9 |
* This code is distributed in the hope that it will be useful, but WITHOUT |
|
10 |
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or |
|
11 |
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License |
|
12 |
* version 2 for more details (a copy is included in the LICENSE file that |
|
13 |
* accompanied this code). |
|
14 |
* |
|
15 |
* You should have received a copy of the GNU General Public License version |
|
16 |
* 2 along with this work; if not, write to the Free Software Foundation, |
|
17 |
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. |
|
18 |
* |
|
19 |
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA |
|
20 |
* or visit www.oracle.com if you need additional information or have any |
|
21 |
* questions. |
|
22 |
*/ |
|
23 |
||
56126
86e628130926
http-client-branch: fixed TLS hostname checking issue, SSL session reuse, and changed HttpResponse to return SSLSession
michaelm
parents:
56089
diff
changeset
|
24 |
import javax.net.ssl.SSLSession; |
56023 | 25 |
import java.net.URI; |
26 |
import java.util.Optional; |
|
56089
42208b2f224e
http-client-branch: move to standard package and module name
chegar
parents:
56023
diff
changeset
|
27 |
import java.net.http.HttpClient; |
42208b2f224e
http-client-branch: move to standard package and module name
chegar
parents:
56023
diff
changeset
|
28 |
import java.net.http.HttpHeaders; |
42208b2f224e
http-client-branch: move to standard package and module name
chegar
parents:
56023
diff
changeset
|
29 |
import java.net.http.HttpRequest; |
42208b2f224e
http-client-branch: move to standard package and module name
chegar
parents:
56023
diff
changeset
|
30 |
import java.net.http.HttpResponse; |
56023 | 31 |
|
32 |
/** |
|
33 |
* An HttpResponse consisting of the given state. |
|
34 |
*/ |
|
56139 | 35 |
public class FixedHttpResponse<T> implements HttpResponse<T> { |
56023 | 36 |
|
37 |
private final int statusCode; |
|
38 |
private final HttpRequest request; |
|
39 |
private final HttpHeaders headers; |
|
40 |
private final T body; |
|
56126
86e628130926
http-client-branch: fixed TLS hostname checking issue, SSL session reuse, and changed HttpResponse to return SSLSession
michaelm
parents:
56089
diff
changeset
|
41 |
private final SSLSession sslSession; |
56023 | 42 |
private final URI uri; |
43 |
private final HttpClient.Version version; |
|
44 |
||
45 |
public FixedHttpResponse(int statusCode, |
|
46 |
HttpRequest request, |
|
47 |
HttpHeaders headers, |
|
48 |
T body, |
|
56126
86e628130926
http-client-branch: fixed TLS hostname checking issue, SSL session reuse, and changed HttpResponse to return SSLSession
michaelm
parents:
56089
diff
changeset
|
49 |
SSLSession sslSession, |
56023 | 50 |
URI uri, |
51 |
HttpClient.Version version) { |
|
52 |
this.statusCode = statusCode; |
|
53 |
this.request = request; |
|
54 |
this.headers = headers; |
|
55 |
this.body = body; |
|
56126
86e628130926
http-client-branch: fixed TLS hostname checking issue, SSL session reuse, and changed HttpResponse to return SSLSession
michaelm
parents:
56089
diff
changeset
|
56 |
this.sslSession = sslSession; |
56023 | 57 |
this.uri = uri; |
58 |
this.version = version; |
|
59 |
} |
|
60 |
||
61 |
@Override |
|
62 |
public int statusCode() { |
|
63 |
return statusCode; |
|
64 |
} |
|
65 |
||
66 |
@Override |
|
67 |
public HttpRequest request() { |
|
68 |
return request; |
|
69 |
} |
|
70 |
||
71 |
@Override |
|
72 |
public Optional<HttpResponse<T>> previousResponse() { |
|
73 |
return Optional.empty(); |
|
74 |
} |
|
75 |
||
76 |
@Override |
|
77 |
public HttpHeaders headers() { |
|
78 |
return headers; |
|
79 |
} |
|
80 |
||
81 |
@Override |
|
82 |
public T body() { |
|
83 |
return body; |
|
84 |
} |
|
85 |
||
86 |
@Override |
|
56126
86e628130926
http-client-branch: fixed TLS hostname checking issue, SSL session reuse, and changed HttpResponse to return SSLSession
michaelm
parents:
56089
diff
changeset
|
87 |
public Optional<SSLSession> sslSession() { |
86e628130926
http-client-branch: fixed TLS hostname checking issue, SSL session reuse, and changed HttpResponse to return SSLSession
michaelm
parents:
56089
diff
changeset
|
88 |
return Optional.ofNullable(sslSession); |
56023 | 89 |
} |
90 |
||
91 |
@Override |
|
92 |
public URI uri() { |
|
93 |
return uri; |
|
94 |
} |
|
95 |
||
96 |
@Override |
|
97 |
public HttpClient.Version version() { |
|
98 |
return version; |
|
99 |
} |
|
100 |
||
101 |
@Override |
|
102 |
public String toString() { |
|
103 |
StringBuilder sb = new StringBuilder(); |
|
104 |
return sb.append(super.toString()).append(" [ ") |
|
105 |
.append("status code: ").append(statusCode) |
|
106 |
.append(", request: ").append(request) |
|
107 |
.append(", headers: ").append(headers) |
|
108 |
.append(" ]") |
|
109 |
.toString(); |
|
110 |
} |
|
111 |
} |