1 /*
   2  * Copyright (c) 2015, 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 8146086
  27  * @summary Publishing two webservices on same port fails with "java.net.BindException: Address already in use"
  28  * @run main/othervm WSTest
  29  */
  30 import javax.jws.WebMethod;
  31 import javax.jws.WebService;
  32 import javax.xml.ws.Endpoint;
  33 
  34 public class WSTest {
  35 
  36     @WebService(targetNamespace = "test")
  37     public static class Method1 {
  38         @WebMethod
  39         public String getMethod1Value() {
  40             return "from Method1";
  41         }
  42     }
  43 
  44     @WebService(targetNamespace = "test")
  45     public static class Method2 {
  46         @WebMethod
  47         public String getMethod2Value() {
  48             return "from Method2";
  49         }
  50     }
  51 
  52     public static void main(String[] args) throws Exception {
  53         Endpoint endPoint1 = null;
  54         Endpoint endPoint2 = null;
  55         try {
  56             endPoint1 = Endpoint.publish("http://0.0.0.0:8081/method1",
  57                     new Method1());
  58             endPoint2 = Endpoint.publish("http://0.0.0.0:8081/method2",
  59                     new Method2());
  60 
  61             System.out.println("Sleep 3 secs...");
  62 
  63             Thread.sleep(3000);
  64         } finally {
  65             stop(endPoint2);
  66             stop(endPoint1);
  67         }
  68     }
  69 
  70     private static void stop(Endpoint endPoint) {
  71         if (endPoint == null) return;
  72 
  73         try {
  74             endPoint.stop();
  75         } catch (Throwable ignored) {
  76         }
  77     }
  78 
  79 }