From 3a492834aad3b9219394505e0ad5538dcd43dad6 Mon Sep 17 00:00:00 2001 From: Yuji Kubota Date: Mon, 18 Jan 2016 15:28:46 +0100 Subject: [PATCH 1/2] 8146086: Publishing two webservices on same port fails with "java.net.BindException: Address already in use" Reviewed-by: chegar --- .../ws/transport/http/server/ServerMgr.java | 50 ++++++++++++------- 1 file changed, 33 insertions(+), 17 deletions(-) diff --git a/jaxws/src/java.xml.ws/share/classes/com/sun/xml/internal/ws/transport/http/server/ServerMgr.java b/jaxws/src/java.xml.ws/share/classes/com/sun/xml/internal/ws/transport/http/server/ServerMgr.java index f7e34ec37f7..6455b83efa9 100644 --- a/jaxws/src/java.xml.ws/share/classes/com/sun/xml/internal/ws/transport/http/server/ServerMgr.java +++ b/jaxws/src/java.xml.ws/share/classes/com/sun/xml/internal/ws/transport/http/server/ServerMgr.java @@ -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,24 +83,38 @@ final class ServerMgr { synchronized(servers) { state = servers.get(inetAddress); if (state == null) { - 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(); + final int finalPortNum = port; + Optional stateOpt = + servers.values() + .stream() + .filter(s -> s.getServer() + .getAddress() + .getPort() == finalPortNum) + .findAny(); - // we have to get actual inetAddress from server, which can differ from the original in some cases. - // e.g. A port number of zero will let the system pick up an ephemeral port in a bind operation, - // or IP: 0.0.0.0 - which is used to monitor network traffic from any valid IP address - inetAddress = server.getAddress(); + 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); + 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); - state = new ServerState(server, path); - servers.put(inetAddress, state); - return context; + // we have to get actual inetAddress from server, which can differ from the original in some cases. + // e.g. A port number of zero will let the system pick up an ephemeral port in a bind operation, + // or IP: 0.0.0.0 - which is used to monitor network traffic from any valid IP address + inetAddress = server.getAddress(); + + logger.fine("HTTP server started = "+inetAddress); + state = new ServerState(server, path); + servers.put(inetAddress, state); + return context; + } } } server = state.getServer(); From 6d7faffbd6f8b7ce24a24eff1d28284eca754dfd Mon Sep 17 00:00:00 2001 From: Iris Clark Date: Tue, 19 Jan 2016 20:30:02 -0800 Subject: [PATCH 2/2] 8136494: Update "@since 1.9" to "@since 9" to match java.version.specification Reviewed-by: alanb, chegar, lancea --- .../share/classes/javax/xml/bind/JAXBContextFactory.java | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/jaxws/src/java.xml.bind/share/classes/javax/xml/bind/JAXBContextFactory.java b/jaxws/src/java.xml.bind/share/classes/javax/xml/bind/JAXBContextFactory.java index 1835f77eb3f..09630484dc9 100644 --- a/jaxws/src/java.xml.bind/share/classes/javax/xml/bind/JAXBContextFactory.java +++ b/jaxws/src/java.xml.bind/share/classes/javax/xml/bind/JAXBContextFactory.java @@ -32,7 +32,7 @@ import java.util.Map; * * JAXBContextFactory can be located using {@link java.util.ServiceLoader#load(Class)} * - * @since 1.9, JAXB 2.3 + * @since 9, JAXB 2.3 */ public interface JAXBContextFactory { @@ -68,7 +68,7 @@ public interface JAXBContextFactory { * @throws IllegalArgumentException * if the parameter contains {@code null} (i.e., {@code newInstance(null,someMap);}) * - * @since 1.9, JAXB 2.3 + * @since 9, JAXB 2.3 */ JAXBContext createContext(Class[] classesToBeBound, Map properties ) throws JAXBException; @@ -100,7 +100,7 @@ public interface JAXBContextFactory { *
  • failure to locate a value for the context factory provider property
  • *
  • mixing schema derived packages from different providers on the same contextPath
  • * - * @since 1.9, JAXB 2.3 + * @since 9, JAXB 2.3 */ JAXBContext createContext(String contextPath, ClassLoader classLoader,