Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
PojavLauncherTeam
GitHub Repository: PojavLauncherTeam/mobile
Path: blob/master/test/jdk/com/sun/net/httpserver/bugs/8199849/TestHttpUnicode.java
41161 views
1
/*
2
* Copyright (c) 2019, 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
24
/**
25
* @test
26
* @bug 8199849
27
* @library /test/lib
28
* @summary Checks that unicode bytes are being handled correctly
29
* @run main/othervm -Dfile.encoding=UTF_8 TestHttpUnicode
30
*/
31
32
import com.sun.net.httpserver.*;
33
import jdk.test.lib.net.URIBuilder;
34
35
import java.io.IOException;
36
import java.io.InputStream;
37
import java.net.*;
38
39
public class TestHttpUnicode {
40
41
private static final String TEST_USER = "Selam D\u00fcnya. Ho\u015f\u00e7akal D\u00fcnya";
42
private static final String TEST_PW = "Selam D\u00fcnya. Ho\u015f\u00e7akal D\u00fcnya";
43
44
static class ClientAuthenticator extends java.net.Authenticator {
45
public PasswordAuthentication getPasswordAuthentication() {
46
return new PasswordAuthentication(TEST_USER, TEST_PW.toCharArray());
47
}
48
}
49
50
static class Handler implements HttpHandler {
51
public void handle(HttpExchange t) throws IOException {
52
InputStream is = t.getRequestBody();
53
while (is.read() != -1) ;
54
is.close();
55
56
HttpPrincipal p = t.getPrincipal();
57
if (p.getUsername().equals(TEST_USER)) {
58
t.sendResponseHeaders(200, -1);
59
}
60
t.close();
61
}
62
}
63
64
public static void main(String[] args) throws Exception {
65
HttpServer testHttpServer = null;
66
try {
67
InetSocketAddress loopbackAddress = new InetSocketAddress(InetAddress.getLoopbackAddress(), 0);
68
testHttpServer = HttpServer.create(loopbackAddress, 0);
69
HttpContext context = testHttpServer.createContext("/test", new Handler());
70
System.setProperty("http.maxRedirects", "3");
71
72
BasicAuthenticator serverAuthenticator = new BasicAuthenticator("[email protected]") {
73
public boolean checkCredentials(String username, String pw) {
74
return username.equals(TEST_USER) && pw.equals(TEST_PW);
75
}
76
};
77
context.setAuthenticator(serverAuthenticator);
78
java.net.Authenticator.setDefault(new ClientAuthenticator());
79
80
testHttpServer.start();
81
URL url = URIBuilder.newBuilder()
82
.scheme("http")
83
.loopback()
84
.port(testHttpServer.getAddress().getPort())
85
.path("/test/authCharacterSet.html")
86
.toURL();
87
HttpURLConnection testConnection = (HttpURLConnection) url.openConnection(Proxy.NO_PROXY);
88
89
// Authenication CHECK
90
if (testConnection.getResponseCode() == 401) {
91
throw new RuntimeException("Test Authentication failed with HTTP Status 401.");
92
}
93
94
InputStream is = testConnection.getInputStream();
95
while (is.read() != -1) ;
96
} finally {
97
testHttpServer.stop(2);
98
}
99
}
100
}
101
102