Skip to content
New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

Remove DEFAULT_JAXWSPROVIDER fallback class name #132

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
78 changes: 14 additions & 64 deletions api/src/main/java/jakarta/xml/ws/spi/FactoryFinder.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand All @@ -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.
* <P>
* This method is package private so that this code can be shared.
*
Expand All @@ -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> T find(Class<T> factoryClass, String fallbackClassName) {
static <T> T find(Class<T> 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() {
Expand Down
15 changes: 1 addition & 14 deletions api/src/main/java/jakarta/xml/ws/spi/Provider.java
Original file line number Diff line number Diff line change
Expand Up @@ -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.internal.ws.spi.ProviderImpl";

/**
* Creates a new instance of Provider
*/
Expand All @@ -50,20 +42,15 @@ protected Provider() {
* <li> 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}.
* <li>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}.
* <li> 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.
* <li> Finally, a platform default implementation is used.
* </ul>
*
* @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) {
Expand Down