Skip to content

Commit

Permalink
#122: Drop search through JDK installation from the provider lookup
Browse files Browse the repository at this point in the history
Signed-off-by: Lukas Jungmann <lukas.jungmann@oracle.com>
  • Loading branch information
lukasj committed Feb 10, 2022
1 parent c22d73a commit e4ba4a6
Show file tree
Hide file tree
Showing 7 changed files with 15 additions and 118 deletions.
44 changes: 0 additions & 44 deletions api/src/main/java/jakarta/xml/soap/FactoryFinder.java
Original file line number Diff line number Diff line change
Expand Up @@ -101,15 +101,6 @@ static <T> T find(Class<T> factoryClass,
}
}

// try to read from $java.home/lib/jaxm.properties
className = fromJDKProperties(factoryId);
if (className != null) {
Object result = newInstance(className, defaultClassName, tccl);
if (result != null) {
return (T) result;
}
}

// standard services: java.util.ServiceLoader
T factory = ServiceLoaderUtil.firstByServiceLoader(
factoryClass,
Expand Down Expand Up @@ -159,41 +150,6 @@ private static Object newInstance(String className, String defaultClassName, Cla
return newInstance;
}

private static String fromJDKProperties(String factoryId) {
Path path = null;
try {
String JAVA_HOME = getSystemProperty("java.home");
path = Paths.get(JAVA_HOME, "conf", "jaxm.properties");
logger.log(Level.FINE, "Checking configuration in {0}", path);

// to ensure backwards compatibility
if (!Files.exists(path)) {
path = Paths.get(JAVA_HOME, "lib", "jaxm.properties");
}

logger.log(Level.FINE, "Checking configuration in {0}", path);
if (Files.exists(path)) {
Properties props = new Properties();
try (InputStream inputStream = Files.newInputStream(path)) {
props.load(inputStream);
}

// standard property
logger.log(Level.FINE, "Checking property {0}", factoryId);
String factoryClassName = props.getProperty(factoryId);
logFound(factoryClassName);
if (factoryClassName != null) {
return factoryClassName;
}

}
} catch (Exception ignored) {
logger.log(Level.SEVERE, "Error reading SAAJ configuration from [" + path +
"] file. Check it is accessible and has correct format.", ignored);
}
return null;
}

private static String fromSystemProperty(String factoryId) {
String systemProp = getSystemProperty(factoryId);
if (systemProp != null) {
Expand Down
5 changes: 0 additions & 5 deletions api/src/main/java/jakarta/xml/soap/SAAJMetaFactory.java
Original file line number Diff line number Diff line change
Expand Up @@ -30,11 +30,6 @@
* to be the fully qualified name of the implementation class. This property, defined by previous specifications
* (up to 1.3), is still supported, but it is strongly recommended to migrate to new property
* {@code jakarta.xml.soap.SAAJMetaFactory}.
* <li>Use the configuration file "jaxm.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 key {@code jakarta.xml.soap.SAAJMetaFactory}. If no such property is defined,
* again, property with key {@code jakarta.xml.soap.MetaFactory} is used. It is strongly recommended to migrate to
* new property {@code jakarta.xml.soap.SAAJMetaFactory}.
* <li> Use the service-provider loading facilities, defined by the {@link java.util.ServiceLoader} class,
* to attempt to locate and load an implementation of the service using the {@linkplain
* java.util.ServiceLoader#load(java.lang.Class) default loading mechanism}.
Expand Down
7 changes: 1 addition & 6 deletions api/src/main/java/jakarta/xml/soap/package-info.java
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2005, 2021 Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2005, 2022 Oracle and/or its affiliates. All rights reserved.
*
* This program and the accompanying materials are made available under the
* terms of the Eclipse Distribution License v. 1.0, which is available at
Expand Down Expand Up @@ -78,11 +78,6 @@
* <li>Checks if a system property with the same name as the factory class is set (e.g.
* {@code jakarta.xml.soap.SOAPFactory}). If such property exists then its value is assumed to be the fully qualified
* name of the implementation class. This phase of the look up enables per-JVM override of the SAAJ implementation.
* <li>Use the configuration file "jaxm.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 being the system property
* defined above.
* <li> Use the service-provider loading facilities, defined by the {@link java.util.ServiceLoader} class,
* to attempt to locate and load an implementation of the service using the {@linkplain
* java.util.ServiceLoader#load(java.lang.Class) default loading mechanism}.
Expand Down
65 changes: 12 additions & 53 deletions api/src/test/java/jakarta/xml/soap/test/SAAJFactoryTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -30,19 +30,12 @@

/*
* test for JDK-8131334: SAAJ Plugability Layer: using java.util.ServiceLoader
*
* There are unsafe scenarios not to be run within the build (modifying jdk files).
* To run those, following needs to be done:
* 1. allow java to write into $JAVA_HOME/conf: mkdir $JAVA_HOME/conf; chmod a+rw $JAVA_HOME/conf
* 2. use "runUnsafe" property: mvn clean test -DrunUnsafe=true
*/
@RunWith(Parameterized.class)
public class SAAJFactoryTest {

static final Logger logger = Logger.getLogger(SAAJFactoryTest.class.getName());

static final Boolean skipUnsafe = !Boolean.getBoolean("runUnsafe");

// test configuration ------------------------------------------

// test-classes directory (required for setup and for security settings)
Expand All @@ -56,10 +49,6 @@ public class SAAJFactoryTest {
static Path providersDir = Paths.get(classesDir, "META-INF", "services");
static Path providersFile = providersDir.resolve("jakarta.xml.soap.MessageFactory");

// configuration to be created by the test
static Path jdkDir = Paths.get(System.getProperty("java.home"), "conf");
static Path jdkFile = jdkDir.resolve("jaxm.properties");

// test instance -----------------------------------------------

// scenario name - just for logging
Expand All @@ -74,30 +63,23 @@ public class SAAJFactoryTest {
public static Collection<?> configurations() {
return Arrays.asList(new Object[][]{
// see SAAJFactoryTest constructor signature for paremeters meaning ...
{null, "com.sun.xml.internal.messaging.saaj.soap.ver1_1.SOAPMessageFactory1_1Impl", jakarta.xml.soap.SOAPException.class, "scenario2", null, null},
{"saaj.factory.Valid", "saaj.factory.Valid", null, "scenario5", null, null},
{"saaj.factory.NonExisting SAAJFactoryTest", null, jakarta.xml.soap.SOAPException.class, "scenario6", null, null},
{"saaj.factory.Invalid SAAJFactoryTest", null, jakarta.xml.soap.SOAPException.class, "scenario7", null, null},
{null, "saaj.factory.Valid", null, "scenario8", null, "saaj.factory.Valid"},
{null, "saaj.factory.Valid", null, "scenario9", null, "saaj.factory.Valid"},
{null, null, jakarta.xml.soap.SOAPException.class, "scenario10", null, "saaj.factory.NonExisting"},
{null, null, jakarta.xml.soap.SOAPException.class, "scenario11", null, "saaj.factory.Invalid"},
{null, "com.sun.xml.internal.messaging.saaj.soap.ver1_1.SOAPMessageFactory1_1Impl", jakarta.xml.soap.SOAPException.class, "scenario12", null, null},
{null, "saaj.factory.Valid", null, "scenario15", null, "saaj.factory.Valid"},

{null, "saaj.factory.Valid", null, "unsafe-scenario1", "saaj.factory.Valid", null},
{null, null, jakarta.xml.soap.SOAPException.class, "unsafe-scenario3", "non.existing.FactoryClass", null},
{null, null, jakarta.xml.soap.SOAPException.class, "unsafe-scenario4", "saaj.factory.Invalid", null},
{"saaj.factory.Valid3", "saaj.factory.Valid3", null, "unsafe-scenario13", "saaj.factory.Valid", "saaj.factory.Valid2"},
{null, "saaj.factory.Valid", null, "unsafe-scenario14", "saaj.factory.Valid", "saaj.factory.Valid2"}
{null, "com.sun.xml.internal.messaging.saaj.soap.ver1_1.SOAPMessageFactory1_1Impl", jakarta.xml.soap.SOAPException.class, "scenario2", null},
{"saaj.factory.Valid", "saaj.factory.Valid", null, "scenario5", null},
{"saaj.factory.NonExisting SAAJFactoryTest", null, jakarta.xml.soap.SOAPException.class, "scenario6", null},
{"saaj.factory.Invalid SAAJFactoryTest", null, jakarta.xml.soap.SOAPException.class, "scenario7", null},
{null, "saaj.factory.Valid", null, "scenario8", "saaj.factory.Valid"},
{null, "saaj.factory.Valid", null, "scenario9", "saaj.factory.Valid"},
{null, null, jakarta.xml.soap.SOAPException.class, "scenario10", "saaj.factory.NonExisting"},
{null, null, jakarta.xml.soap.SOAPException.class, "scenario11", "saaj.factory.Invalid"},
{null, "com.sun.xml.internal.messaging.saaj.soap.ver1_1.SOAPMessageFactory1_1Impl", jakarta.xml.soap.SOAPException.class, "scenario12", null},
{null, "saaj.factory.Valid", null, "scenario15", "saaj.factory.Valid"},
});
}

public SAAJFactoryTest(String systemProperty,
String expectedFactory,
Class<?> expectedException,
String scenario,
String jdkConfClass,
String spiClass) {

// ensure setup may be done ...
Expand All @@ -113,22 +95,11 @@ public SAAJFactoryTest(String systemProperty,
this.expectedFactory = expectedFactory;
this.expectedException = expectedException;

if (skipUnsafe && scenario.startsWith("unsafe")) {
log("Skipping unsafe scenario:" + scenario);
return;
}

prepare(jdkConfClass, spiClass);
prepare(spiClass);
}

@Test
public void testFactoryDiscovery() throws IOException {

if (skipUnsafe && scenario.startsWith("unsafe")) {
log("Skipping unsafe scenario:" + scenario);
return;
}

logConfigurations();
try {
MessageFactory factory = factory();
Expand All @@ -152,8 +123,6 @@ public void testFactoryDiscovery() throws IOException {
cleanResource(providersFile);
cleanResource(providersDir);

// unsafe; not running:
cleanResource(jdkFile);
System.setSecurityManager(null);
}
}
Expand Down Expand Up @@ -192,22 +161,13 @@ private void cleanResource(Path resource) {
}
}

private void prepare(String propertiesClassName, String providerClassName) {

private void prepare(String providerClassName) {
try {
log("providerClassName = " + providerClassName);
log("propertiesClassName = " + propertiesClassName);

setupFile(providersFile, providersDir, providerClassName);


// unsafe; not running:
if (propertiesClassName != null) {
setupFile(jdkFile, jdkDir, "jakarta.xml.soap.MessageFactory=" + propertiesClassName);
} else {
cleanResource(jdkFile);
}

log(" SETUP OK.");

} catch (IOException e) {
Expand All @@ -218,7 +178,6 @@ private void prepare(String propertiesClassName, String providerClassName) {

private void logConfigurations() throws IOException {
logFile(providersFile);
logFile(jdkFile);
}

private void logFile(Path path) throws IOException {
Expand Down
3 changes: 0 additions & 3 deletions api/src/test/resources/jakarta/xml/soap/test.policy
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,6 @@ grant {
// reading java.home to find jdk-wide property file
permission java.util.PropertyPermission "java.home", "read";

// reading / modifying jdk/conf/jaxm.properties
permission java.io.FilePermission "${java.home}${/}-", "read, write, delete";

// reading defined system properties
permission java.util.PropertyPermission "jakarta.xml.soap.MessageFactory", "read";
permission java.util.PropertyPermission "jakarta.xml.soap.MetaFactory", "read";
Expand Down
6 changes: 0 additions & 6 deletions spec/src/main/asciidoc/SOAPAttachments.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -473,12 +473,6 @@ such property exists then its value is assumed to be the fully qualified
name of the implementation class. This phase of the look up enables
per-JVM override of the Jakarta SOAP Attachments implementation.

* Use the configuration file "jaxm.properties".
The file is in standard `Properties` format and typically located in the
`conf` directory of the Java installation. It contains the fully qualified
name of the implementation class with the key being the system property
defined above.

* Use the service-provider loading facilities,
defined by the `ServiceLoader` class, to attempt to locate and load an
implementation of the service using the default loading mechanism.
Expand Down
3 changes: 2 additions & 1 deletion spec/src/main/asciidoc/appendix.adoc
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
//
// Copyright (c) 2020, 2021 Contributors to the Eclipse Foundation
// Copyright (c) 2020, 2022 Contributors to the Eclipse Foundation
//

== Appendix A: References
Expand Down Expand Up @@ -36,6 +36,7 @@ http://www.ws-i.org/Profiles/AttachmentsProfile-1.0.html

* `SOAPElementFactory` has been removed
* `SOAPConnection.call` is no longer required to support `javax.xml.messaging.URLEndpoint`
* Provider lookup through `jaxm.properties` is removed

=== Changes in Version 2.0

Expand Down

0 comments on commit e4ba4a6

Please sign in to comment.