Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
PojavLauncherTeam
GitHub Repository: PojavLauncherTeam/mobile
Path: blob/master/test/jdk/java/net/URLConnection/contentHandler/UserContentHandler.java
41153 views
1
/*
2
* Copyright (c) 1999, 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
/* @test
25
* @bug 4191147
26
* @summary 1.2beta4 does not load user defined content handlers
27
* @library /test/lib
28
* @build UserContentHandler
29
* @run main/othervm UserContentHandler
30
*/
31
32
/* Run in othervm mode since the test sets a system property, java.content.handler.pkgs,
33
* that prepends a specific package prefix defining a text/plain content
34
* handler. If other URLConnection tests run before this one they might trigger
35
* the Sun implementation text/plain content handler in sun.net.www.content
36
* to be loaded and cached, this will break this test.
37
*/
38
39
import java.net.*;
40
import java.io.*;
41
import java.util.*;
42
import jdk.test.lib.net.URIBuilder;
43
import static java.net.Proxy.NO_PROXY;
44
45
public class UserContentHandler implements Runnable {
46
47
ServerSocket ss;
48
49
public void run() {
50
try {
51
52
Socket s = ss.accept();
53
s.setTcpNoDelay(true);
54
55
PrintStream out = new PrintStream(
56
new BufferedOutputStream(
57
s.getOutputStream() ));
58
59
out.print("HTTP/1.1 200 OK\r\n");
60
out.print("Content-Length: 11\r\n");
61
out.print("Content-Type: text/plain\r\n");
62
out.print("\r\n");
63
out.print("l;ajfdjafd\n");
64
out.flush();
65
66
// don't close the connection immediately as otherwise
67
// the http headers may not have been received and the
68
// http client will re-connect.
69
Thread.sleep(2000);
70
71
s.close();
72
73
} catch (Exception e) {
74
e.printStackTrace();
75
}
76
}
77
78
UserContentHandler() throws Exception {
79
80
InetAddress loopback = InetAddress.getLoopbackAddress();
81
ss = new ServerSocket();
82
ss.bind(new InetSocketAddress(loopback, 0));
83
Thread thr = new Thread(this);
84
thr.start();
85
86
try {
87
Object o = new COM.foo.content.text.plain();
88
} catch (Exception ex) {
89
ex.printStackTrace();
90
}
91
Properties props = System.getProperties();
92
props.put("java.content.handler.pkgs", "COM.foo.content");
93
System.setProperties(props);
94
95
URL u = URIBuilder.newBuilder()
96
.scheme("http")
97
.loopback()
98
.port(ss.getLocalPort())
99
.path("/anything.txt")
100
.toURL();
101
102
if (!(u.openConnection(NO_PROXY).getContent() instanceof String)) {
103
throw new RuntimeException("Load user defined content handler failed.");
104
} else {
105
System.err.println("Load user defined content handler succeed!");
106
}
107
}
108
109
public static void main(String args[]) throws Exception {
110
new UserContentHandler();
111
}
112
}
113
114