JDK-8146086 : Publishing two webservices on same port fails with "java.net.BindException: Address already in use"
  • Type: Bug
  • Component: xml
  • Sub-Component: jax-ws
  • Priority: P2
  • Status: Closed
  • Resolution: Fixed
  • OS: generic
  • Submitted: 2015-12-23
  • Updated: 2018-02-13
  • Resolved: 2016-01-18
The Version table provides details related to the release that this issue/RFE will be addressed.

Unresolved : Release in which this issue/RFE will be addressed.
Resolved: Release in which this issue/RFE has been resolved.
Fixed : Release in which this issue/RFE has been fixed. The release containing this fix may be available for download as an Early Access Release or a General Availability Release.

To download the current JDK release, click here.
JDK 8 JDK 9
8u152Fixed 9 b103Fixed
Description
Problem reported and fix provided by Kubota Yuji:

Publishing two services:


Endpoint endPoint1 = Endpoint.publish("http://0.0.0.0:8081/method1",
                                                                new Method1());
Endpoint endPoint2 = Endpoint.publish("http://0.0.0.0:8081/method2",
                                                                 new Method2());
 
ends with exception:
Exception in thread "main"
com.sun.xml.internal.ws.server.ServerRtException: Server Runtime
Error: java.net.BindException: Address already in use
        at com.sun.xml.internal.ws.transport.http.server.ServerMgr.createContext(ServerMgr.java:117)
        at com.sun.xml.internal.ws.transport.http.server.HttpEndpoint.publish(HttpEndpoint.java:64)
        at com.sun.xml.internal.ws.transport.http.server.EndpointImpl.publish(EndpointImpl.java:232)
        at com.sun.xml.internal.ws.spi.ProviderImpl.createAndPublishEndpoint(ProviderImpl.java:126)
        at javax.xml.ws.Endpoint.publish(Endpoint.java:240)
        at wstest.WSTest.main(WSTest.java:27)
Caused by: java.net.BindException: Address already in use
        at sun.nio.ch.Net.bind0(Native Method)
        at sun.nio.ch.Net.bind(Net.java:432)
        at sun.nio.ch.Net.bind(Net.java:424)
        at sun.nio.ch.ServerSocketChannelImpl.bind(ServerSocketChannelImpl.java:223)
        at sun.nio.ch.ServerSocketAdaptor.bind(ServerSocketAdaptor.java:74)
        at sun.net.httpserver.ServerImpl.<init>(ServerImpl.java:102)
        at sun.net.httpserver.HttpServerImpl.<init>(HttpServerImpl.java:50)
        at sun.net.httpserver.DefaultHttpServerProvider.createHttpServer(DefaultHttpServerProvider.java:35)
        at com.sun.net.httpserver.HttpServer.create(HttpServer.java:130)
        at com.sun.xml.internal.ws.transport.http.server.ServerMgr.createContext(ServerMgr.java:86)
        ... 5 more

see http://mail.openjdk.java.net/pipermail/core-libs-dev/2015-December/037067.html for more details.