8146086: Publishing two webservices on same port fails with "java.net.BindException: Address already in use"

Reviewed-by: chegar
This commit is contained in:
Yuji Kubota 2016-01-18 15:28:46 +01:00 committed by Miroslav Kos
parent 07b44796c2
commit 3a492834aa

View File

@ -1,5 +1,5 @@
/*
* Copyright (c) 1997, 2013, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 1997, 2016, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
@ -38,6 +38,8 @@ import java.util.Set;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;
import java.util.logging.Logger;
import java.util.Optional;
/**
* Manages all the WebService HTTP servers created by JAXWS runtime.
@ -81,6 +83,19 @@ final class ServerMgr {
synchronized(servers) {
state = servers.get(inetAddress);
if (state == null) {
final int finalPortNum = port;
Optional<ServerState> stateOpt =
servers.values()
.stream()
.filter(s -> s.getServer()
.getAddress()
.getPort() == finalPortNum)
.findAny();
if (inetAddress.getAddress().isAnyLocalAddress() &&
stateOpt.isPresent()) {
state = stateOpt.get();
} else {
logger.fine("Creating new HTTP Server at "+inetAddress);
// Creates server with default socket backlog
server = HttpServer.create(inetAddress, 0);
@ -101,6 +116,7 @@ final class ServerMgr {
return context;
}
}
}
server = state.getServer();
if (state.getPaths().contains(url.getPath())) {