8146086: Publishing two webservices on same port fails with "java.net.BindException: Address already in use"
Reviewed-by: chegar
This commit is contained in:
parent
07b44796c2
commit
3a492834aa
@ -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.
|
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
|
||||||
*
|
*
|
||||||
* This code is free software; you can redistribute it and/or modify it
|
* 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.ExecutorService;
|
||||||
import java.util.concurrent.Executors;
|
import java.util.concurrent.Executors;
|
||||||
import java.util.logging.Logger;
|
import java.util.logging.Logger;
|
||||||
|
import java.util.Optional;
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Manages all the WebService HTTP servers created by JAXWS runtime.
|
* Manages all the WebService HTTP servers created by JAXWS runtime.
|
||||||
@ -81,24 +83,38 @@ final class ServerMgr {
|
|||||||
synchronized(servers) {
|
synchronized(servers) {
|
||||||
state = servers.get(inetAddress);
|
state = servers.get(inetAddress);
|
||||||
if (state == null) {
|
if (state == null) {
|
||||||
logger.fine("Creating new HTTP Server at "+inetAddress);
|
final int finalPortNum = port;
|
||||||
// Creates server with default socket backlog
|
Optional<ServerState> stateOpt =
|
||||||
server = HttpServer.create(inetAddress, 0);
|
servers.values()
|
||||||
server.setExecutor(Executors.newCachedThreadPool());
|
.stream()
|
||||||
String path = url.toURI().getPath();
|
.filter(s -> s.getServer()
|
||||||
logger.fine("Creating HTTP Context at = "+path);
|
.getAddress()
|
||||||
HttpContext context = server.createContext(path);
|
.getPort() == finalPortNum)
|
||||||
server.start();
|
.findAny();
|
||||||
|
|
||||||
// we have to get actual inetAddress from server, which can differ from the original in some cases.
|
if (inetAddress.getAddress().isAnyLocalAddress() &&
|
||||||
// e.g. A port number of zero will let the system pick up an ephemeral port in a bind operation,
|
stateOpt.isPresent()) {
|
||||||
// or IP: 0.0.0.0 - which is used to monitor network traffic from any valid IP address
|
state = stateOpt.get();
|
||||||
inetAddress = server.getAddress();
|
} else {
|
||||||
|
logger.fine("Creating new HTTP Server at "+inetAddress);
|
||||||
|
// Creates server with default socket backlog
|
||||||
|
server = HttpServer.create(inetAddress, 0);
|
||||||
|
server.setExecutor(Executors.newCachedThreadPool());
|
||||||
|
String path = url.toURI().getPath();
|
||||||
|
logger.fine("Creating HTTP Context at = "+path);
|
||||||
|
HttpContext context = server.createContext(path);
|
||||||
|
server.start();
|
||||||
|
|
||||||
logger.fine("HTTP server started = "+inetAddress);
|
// we have to get actual inetAddress from server, which can differ from the original in some cases.
|
||||||
state = new ServerState(server, path);
|
// e.g. A port number of zero will let the system pick up an ephemeral port in a bind operation,
|
||||||
servers.put(inetAddress, state);
|
// or IP: 0.0.0.0 - which is used to monitor network traffic from any valid IP address
|
||||||
return context;
|
inetAddress = server.getAddress();
|
||||||
|
|
||||||
|
logger.fine("HTTP server started = "+inetAddress);
|
||||||
|
state = new ServerState(server, path);
|
||||||
|
servers.put(inetAddress, state);
|
||||||
|
return context;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
server = state.getServer();
|
server = state.getServer();
|
||||||
|
Loading…
Reference in New Issue
Block a user