Path: blob/aarch64-shenandoah-jdk8u272-b10/jdk/test/javax/xml/ws/publish/WSTest.java
38853 views
/*1* Copyright (c) 2016, 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 814608626* @summary Publishing two webservices on same port fails with "java.net.BindException: Address already in use"27* @run main/othervm WSTest28*/29import javax.jws.WebMethod;30import javax.jws.WebService;31import javax.xml.ws.Endpoint;32import java.net.ServerSocket;3334public class WSTest {3536@WebService(targetNamespace = "test")37public static class Method1 {38@WebMethod39public String getMethod1Value() {40return "from Method1";41}42}4344@WebService(targetNamespace = "test")45public static class Method2 {46@WebMethod47public String getMethod2Value() {48return "from Method2";49}50}5152public static void main(String[] args) throws Exception {5354// find a free port55ServerSocket ss = new ServerSocket(0);56int port = ss.getLocalPort();57ss.close();5859Endpoint endPoint1 = null;60Endpoint endPoint2 = null;61try {62endPoint1 = Endpoint.publish("http://0.0.0.0:" + port + "/method1",63new Method1());64endPoint2 = Endpoint.publish("http://0.0.0.0:" + port + "/method2",65new Method2());6667System.out.println("Sleep 3 secs...");6869Thread.sleep(3000);70} finally {71stop(endPoint2);72stop(endPoint1);73}74}7576private static void stop(Endpoint endPoint) {77if (endPoint == null) return;7879try {80endPoint.stop();81} catch (Throwable ignored) {82}83}8485}868788