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