Path: blob/aarch64-shenandoah-jdk8u272-b10/jdk/test/javax/xml/ws/8033113/WsImportTest.java
38853 views
/*1* Copyright (c) 2014, Oracle and/or its affiliates. All rights reserved.2* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.3*4* This code is free software; you can redistribute it and/or modify it5* under the terms of the GNU General Public License version 2 only, as6* published by the Free Software Foundation.7*8* This code is distributed in the hope that it will be useful, but WITHOUT9* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or10* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License11* version 2 for more details (a copy is included in the LICENSE file that12* accompanied this code).13*14* You should have received a copy of the GNU General Public License version15* 2 along with this work; if not, write to the Free Software Foundation,16* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.17*18* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA19* or visit www.oracle.com if you need additional information or have any20* questions.21*/2223/*24* @test25* @bug 803311326* @summary wsimport fails on WSDL:header parameter name customization27* @run main/othervm WsImportTest28*/2930import java.io.InputStreamReader;31import java.io.IOException;32import java.io.BufferedReader;33import java.io.File;34import java.nio.file.Files;35import java.nio.file.FileVisitResult;36import java.nio.file.Path;37import java.nio.file.Paths;38import java.nio.file.SimpleFileVisitor;39import java.nio.file.attribute.BasicFileAttributes;4041import static java.nio.file.FileVisitResult.*;4243public class WsImportTest {4445public static void main(String[] args) throws IOException {4647String wsimport = getWsImport();48String customization = getWSDLFilePath("customization.xml");49String wsdl = getWSDLFilePath("Organization_List.wsdl");5051try {52log("Importing wsdl: " + wsdl);53String[] wsargs = {54wsimport,55"-keep",56"-verbose",57"-extension",58"-XadditionalHeaders",59"-Xdebug",60"-b",61customization,62wsdl63};6465ProcessBuilder pb = new ProcessBuilder(wsargs);66pb.redirectErrorStream(true);67Process p = pb.start();68logOutput(p);69int result = p.waitFor();70p.destroy();7172if (result != 0) {73fail("WsImport failed. TEST FAILED.");74} else {75log("Test PASSED.");76}7778} catch (Exception e) {79e.printStackTrace();80fail(e.getMessage());81} finally {82deleteGeneratedFiles();83}84}8586private static void fail(String message) {87throw new RuntimeException(message);88}8990private static void log(String msg) {91System.out.println(msg);92}9394private static void logOutput(Process p) throws IOException {95BufferedReader r = new BufferedReader(new InputStreamReader(p.getInputStream()));96String s = r.readLine();97while (s != null) {98log(s.trim());99s = r.readLine();100}101}102103private static void deleteGeneratedFiles() {104Path p = Paths.get("generated");105if (Files.exists(p)) {106try {107Files.walkFileTree(p, new SimpleFileVisitor<Path>() {108@Override109public FileVisitResult visitFile(Path file,110BasicFileAttributes attrs) throws IOException {111112Files.delete(file);113return CONTINUE;114}115116@Override117public FileVisitResult postVisitDirectory(Path dir,118IOException exc) throws IOException {119120if (exc == null) {121Files.delete(dir);122return CONTINUE;123} else {124throw exc;125}126}127});128} catch (IOException ioe) {129ioe.printStackTrace();130}131}132}133134private static String getWSDLFilePath(String filename) {135String testSrc = System.getProperty("test.src");136if (testSrc == null) testSrc = ".";137return Paths.get(testSrc).resolve(filename).toString();138}139140private static String getWsImport() {141String javaHome = System.getProperty("java.home");142if (javaHome.endsWith("jre")) {143javaHome = new File(javaHome).getParent();144}145String wsimport = javaHome + File.separator + "bin" + File.separator + "wsimport";146if (System.getProperty("os.name").startsWith("Windows")) {147wsimport = wsimport.concat(".exe");148}149return wsimport;150}151}152153154