From a5500dc3fb08dbad6ae1037c8ce6ba5da1a0c577 Mon Sep 17 00:00:00 2001 From: Gaurav Gupta Date: Wed, 3 Jun 2020 17:32:54 +0530 Subject: [PATCH 1/2] Fix jakarta.xml.ws.spi.Provider implementation package Signed-off-by: Gaurav Gupta --- api/src/main/java/jakarta/xml/ws/spi/Provider.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/api/src/main/java/jakarta/xml/ws/spi/Provider.java b/api/src/main/java/jakarta/xml/ws/spi/Provider.java index db7108e..7d6f253 100644 --- a/api/src/main/java/jakarta/xml/ws/spi/Provider.java +++ b/api/src/main/java/jakarta/xml/ws/spi/Provider.java @@ -32,7 +32,7 @@ public abstract class Provider { **/ // Using two strings so that package renaming doesn't change it private static final String DEFAULT_JAXWSPROVIDER = - "com.sun"+".xml.internal.ws.spi.ProviderImpl"; + "com.sun"+".xml.ws.spi.ProviderImpl"; /** * Creates a new instance of Provider From 015a3b1d6cb5fd94ab1b4151f16625a844339a14 Mon Sep 17 00:00:00 2001 From: Gaurav Gupta Date: Thu, 4 Jun 2020 11:44:20 +0530 Subject: [PATCH 2/2] Remove DEFAULT_JAXWSPROVIDER fallback class name Signed-off-by: Gaurav Gupta --- .../jakarta/xml/ws/spi/FactoryFinder.java | 78 ++++--------------- .../java/jakarta/xml/ws/spi/Provider.java | 15 +--- 2 files changed, 15 insertions(+), 78 deletions(-) diff --git a/api/src/main/java/jakarta/xml/ws/spi/FactoryFinder.java b/api/src/main/java/jakarta/xml/ws/spi/FactoryFinder.java index cb78d82..0f1fb28 100644 --- a/api/src/main/java/jakarta/xml/ws/spi/FactoryFinder.java +++ b/api/src/main/java/jakarta/xml/ws/spi/FactoryFinder.java @@ -10,13 +10,6 @@ package jakarta.xml.ws.spi; -import java.io.*; - -import java.nio.file.Files; -import java.nio.file.Path; -import java.nio.file.Paths; -import java.util.Properties; -import java.util.logging.Level; import java.util.logging.Logger; import jakarta.xml.ws.WebServiceException; @@ -34,10 +27,7 @@ public WebServiceException createException(Throwable throwable, String message) /** * Finds the implementation {@code Class} object for the given - * factory name, or if that fails, finds the {@code Class} object - * for the given fallback class name. The arguments supplied MUST be - * used in order. If using the first argument is successful, the second - * one will not be used. + * factory name. *

* This method is package private so that this code can be shared. * @@ -46,86 +36,46 @@ public WebServiceException createException(Throwable throwable, String message) * * @param factoryClass the name of the factory to find, which is * a system property - * @param fallbackClassName the implementation class name, which is - * to be used only if nothing else - * is found; {@code null} to indicate that - * there is no fallback class name - * @exception WebServiceException if there is an error + * @exception WebServiceException if provider not found + * */ @SuppressWarnings("unchecked") - static T find(Class factoryClass, String fallbackClassName) { + static T find(Class factoryClass) { + String factoryId = factoryClass.getName(); ClassLoader classLoader = ServiceLoaderUtil.contextClassLoader(EXCEPTION_HANDLER); - T provider = ServiceLoaderUtil.firstByServiceLoader(factoryClass, logger, EXCEPTION_HANDLER); - if (provider != null) return provider; - - String factoryId = factoryClass.getName(); - - // try to read from $java.home/lib/jaxws.properties - provider = (T) fromJDKProperties(factoryId, fallbackClassName, classLoader); - if (provider != null) return provider; // Use the system property - provider = (T) fromSystemProperty(factoryId, fallbackClassName, classLoader); - if (provider != null) return provider; + if (provider == null) { + provider = (T) fromSystemProperty(factoryId, classLoader); + } // handling Glassfish (platform specific default) - if (isOsgi()) { - return (T) lookupUsingOSGiServiceLoader(factoryId); + if (provider == null && isOsgi()) { + provider = (T) lookupUsingOSGiServiceLoader(factoryId); } - if (fallbackClassName == null) { + if (provider == null) { throw new WebServiceException( - "Provider for " + factoryId + " cannot be found", null); + "Provider for " + factoryId + " cannot be found", null); } - return (T) ServiceLoaderUtil.newInstance(fallbackClassName, - fallbackClassName, classLoader, EXCEPTION_HANDLER); + return provider; } private static Object fromSystemProperty(String factoryId, - String fallbackClassName, ClassLoader classLoader) { try { String systemProp = System.getProperty(factoryId); if (systemProp != null) { return ServiceLoaderUtil.newInstance(systemProp, - fallbackClassName, classLoader, EXCEPTION_HANDLER); + null, classLoader, EXCEPTION_HANDLER); } } catch (SecurityException ignored) { } return null; } - private static Object fromJDKProperties(String factoryId, - String fallbackClassName, - ClassLoader classLoader) { - Path path = null; - try { - String JAVA_HOME = System.getProperty("java.home"); - path = Paths.get(JAVA_HOME, "conf", "jaxws.properties"); - - // to ensure backwards compatibility - if (!Files.exists(path)) { - path = Paths.get(JAVA_HOME, "lib", "jaxws.properties"); - } - - if (Files.exists(path)) { - Properties props = new Properties(); - try (InputStream inStream = Files.newInputStream(path)) { - props.load(inStream); - } - String factoryClassName = props.getProperty(factoryId); - return ServiceLoaderUtil.newInstance(factoryClassName, - fallbackClassName, classLoader, EXCEPTION_HANDLER); - } - } catch (Exception ignored) { - logger.log(Level.SEVERE, "Error reading JAX-WS configuration from [" + path + - "] file. Check it is accessible and has correct format.", ignored); - } - return null; - } - private static final String OSGI_SERVICE_LOADER_CLASS_NAME = "org.glassfish.hk2.osgiresourcelocator.ServiceLoader"; private static boolean isOsgi() { diff --git a/api/src/main/java/jakarta/xml/ws/spi/Provider.java b/api/src/main/java/jakarta/xml/ws/spi/Provider.java index 7d6f253..94120f5 100644 --- a/api/src/main/java/jakarta/xml/ws/spi/Provider.java +++ b/api/src/main/java/jakarta/xml/ws/spi/Provider.java @@ -26,14 +26,6 @@ */ public abstract class Provider { - /** - * A constant representing the name of the default - * {@code Provider} implementation class. - **/ - // Using two strings so that package renaming doesn't change it - private static final String DEFAULT_JAXWSPROVIDER = - "com.sun"+".xml.ws.spi.ProviderImpl"; - /** * Creates a new instance of Provider */ @@ -50,20 +42,15 @@ protected Provider() { *

  • Use the service-provider loading facilities, defined by the {@link java.util.ServiceLoader} class, * to attempt to locate and load an implementation of {@link jakarta.xml.ws.spi.Provider} service using * the {@linkplain java.util.ServiceLoader#load(java.lang.Class) default loading mechanism}. - *
  • Use the configuration file "jaxws.properties". The file is in standard - * {@link java.util.Properties} format and typically located in the - * {@code conf} directory of the Java installation. It contains the fully qualified - * name of the implementation class with the key {@code jakarta.xml.ws.spi.Provider}. *
  • If a system property with the name {@code jakarta.xml.ws.spi.Provider} * is defined, then its value is used as the name of the implementation class. - *
  • Finally, a platform default implementation is used. * * * @return provider object */ public static Provider provider() { try { - return FactoryFinder.find(Provider.class, DEFAULT_JAXWSPROVIDER); + return FactoryFinder.find(Provider.class); } catch (WebServiceException ex) { throw ex; } catch (Exception ex) {