Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
PojavLauncherTeam
GitHub Repository: PojavLauncherTeam/openjdk-multiarch-jdk8u
Path: blob/aarch64-shenandoah-jdk8u272-b10/jdk/test/javax/xml/ws/xsanymixed/Test.java
38853 views
1
/*
2
* Copyright (c) 2014, 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 8036981 8038966 8051441
27
* @summary the content of xs:any content:mixed should remain as is,
28
* no white space changes and no changes to namespace prefixes
29
* @run shell compile-wsdl.sh
30
* @run main/othervm Test
31
*/
32
33
import com.sun.net.httpserver.HttpServer;
34
35
import javax.xml.transform.Source;
36
import javax.xml.transform.Transformer;
37
import javax.xml.transform.TransformerException;
38
import javax.xml.transform.TransformerFactory;
39
import javax.xml.transform.stream.StreamResult;
40
import javax.xml.transform.stream.StreamSource;
41
import javax.xml.ws.Dispatch;
42
import javax.xml.ws.Endpoint;
43
import javax.xml.ws.Service;
44
import java.io.ByteArrayOutputStream;
45
import java.io.IOException;
46
import java.io.StringReader;
47
import java.net.InetSocketAddress;
48
import java.net.URL;
49
import java.nio.file.FileVisitResult;
50
import java.nio.file.Files;
51
import java.nio.file.Path;
52
import java.nio.file.Paths;
53
import java.nio.file.SimpleFileVisitor;
54
import java.nio.file.attribute.BasicFileAttributes;
55
56
import static java.nio.file.FileVisitResult.CONTINUE;
57
58
public class Test {
59
60
private static HttpServer httpServer;
61
private static Endpoint endpoint;
62
private static final String NL = System.getProperty("line.separator");
63
64
private static final String XS_ANY_MIXED_PART =
65
"<AppHdr xmlns=\"urn:head.001\">" + NL +
66
" <Fr>" + NL + NL +
67
"<FIId xmlns=\"urn:head.009\">" + NL + NL +
68
" any" + NL +
69
" white" + NL +
70
" space" + NL + NL +
71
" <FinInstnId>... and" + NL + NL +
72
" NO namespace prefixes!!!" + NL + NL +
73
" </FinInstnId>" + NL + NL +
74
" </FIId>" + NL +
75
"</Fr>" + NL +
76
"</AppHdr>";
77
78
private static final String XML_REQUEST = "<soap:Envelope " +
79
"xmlns:soap=\"http://schemas.xmlsoap.org/soap/envelope/\" " +
80
"xmlns:ws=\"http://ws.somewhere.org/\">" +
81
"<soap:Header/><soap:Body>" +
82
"<ws:echoRequest>" + NL +
83
XS_ANY_MIXED_PART + NL +
84
"</ws:echoRequest>" +
85
"</soap:Body></soap:Envelope>";
86
87
private static String deployWebservice() throws IOException {
88
// Manually create HttpServer here using ephemeral address for port
89
// so as to not end up with attempt to bind to an in-use port
90
httpServer = HttpServer.create(new InetSocketAddress(0), 0);
91
httpServer.start();
92
endpoint = Endpoint.create(new ServiceImpl());
93
endpoint.publish(httpServer.createContext("/wservice"));
94
95
String wsdlAddress = "http://localhost:" + httpServer.getAddress().getPort() + "/wservice?wsdl";
96
log("address = " + wsdlAddress);
97
return wsdlAddress;
98
}
99
100
private static void stopWebservice() {
101
if (endpoint != null && endpoint.isPublished()) {
102
endpoint.stop();
103
}
104
if (httpServer != null) {
105
httpServer.stop(0);
106
}
107
}
108
109
public static void main(String[] args) throws IOException, TransformerException {
110
111
try {
112
String address = deployWebservice();
113
Service service = Service.create(new URL(address), ServiceImpl.SERVICE_NAME);
114
115
Dispatch<Source> d = service.createDispatch(ServiceImpl.PORT_NAME, Source.class, Service.Mode.MESSAGE);
116
Source response = d.invoke(new StreamSource(new StringReader(XML_REQUEST)));
117
118
String resultXml = toString(response);
119
120
log("= request ======== \n");
121
log(XML_REQUEST);
122
log("= result ========= \n");
123
log(resultXml);
124
log("\n==================");
125
126
boolean xsAnyMixedPartSame = resultXml.contains(XS_ANY_MIXED_PART);
127
log("resultXml.contains(XS_ANY_PART) = " + xsAnyMixedPartSame);
128
if (!xsAnyMixedPartSame) {
129
fail("The xs:any content=mixed part is supposed to be same in request and response.");
130
throw new RuntimeException();
131
}
132
133
log("TEST PASSED");
134
} finally {
135
stopWebservice();
136
137
// if you need to debug or explore wsdl generation result
138
// comment this line out:
139
deleteGeneratedFiles();
140
}
141
}
142
143
private static String toString(Source response) throws TransformerException, IOException {
144
ByteArrayOutputStream bos = new ByteArrayOutputStream();
145
TransformerFactory transformerFactory = TransformerFactory.newInstance();
146
Transformer transformer = transformerFactory.newTransformer();
147
transformer.transform(response, new StreamResult(bos));
148
bos.close();
149
return new String(bos.toByteArray());
150
}
151
152
private static void fail(String message) {
153
log("TEST FAILED.");
154
throw new RuntimeException(message);
155
}
156
157
private static void log(String msg) {
158
System.out.println(msg);
159
}
160
161
private static void deleteGeneratedFiles() {
162
Path p = Paths.get("..", "classes", "javax", "xml", "ws", "xsanymixed", "org");
163
System.out.println("performing cleanup, deleting wsdl compilation result: " + p.toFile().getAbsolutePath());
164
if (Files.exists(p)) {
165
try {
166
Files.walkFileTree(p, new SimpleFileVisitor<Path>() {
167
@Override
168
public FileVisitResult visitFile(
169
Path file,
170
BasicFileAttributes attrs) throws IOException {
171
172
System.out.println("deleting file [" + file.toFile().getAbsoluteFile() + "]");
173
Files.delete(file);
174
return CONTINUE;
175
}
176
177
@Override
178
public FileVisitResult postVisitDirectory(
179
Path dir,
180
IOException exc) throws IOException {
181
182
System.out.println("deleting dir [" + dir.toFile().getAbsoluteFile() + "]");
183
if (exc == null) {
184
Files.delete(dir);
185
return CONTINUE;
186
} else {
187
throw exc;
188
}
189
}
190
});
191
} catch (IOException ioe) {
192
ioe.printStackTrace();
193
}
194
}
195
}
196
197
}
198
199