Add the missing factory methods that the latest API code sometimes requires
diff --git a/jaxrs-api-2.1/src/main/java/javax/ws/rs/client/FactoryFinder.java b/jaxrs-api-2.1/src/main/java/javax/ws/rs/client/FactoryFinder.java
index 400592b..fd597f5 100644
--- a/jaxrs-api-2.1/src/main/java/javax/ws/rs/client/FactoryFinder.java
+++ b/jaxrs-api-2.1/src/main/java/javax/ws/rs/client/FactoryFinder.java
@@ -120,7 +120,7 @@
throw new ClassNotFoundException("Provider " + className + " could not be instantiated: " + x, x);
}
}
-
+
/**
* Finds the implementation <code>Class</code> object for the given
* factory name, or if that fails, finds the <code>Class</code> object
@@ -142,10 +142,43 @@
* or could not be instantiated
*/
static Object find(final String factoryId, final String fallbackClassName) throws ClassNotFoundException {
+ return find(factoryId, fallbackClassName, null);
+ }
+ /**
+ * Finds the implementation <code>Class</code> object for the given
+ * factory name, or if that fails, finds the <code>Class</code> 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.
+ * <P>
+ * This method is package private so that this code can be shared.
+ *
+ * @param factoryId 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</code> to indicate that
+ * there is no fallback class name
+ * @param service The interface class of the service
+ * @return the <code>Class</code> object of the specified message factory;
+ * may not be <code>null</code>
+ * @throws ClassNotFoundException if the given class could not be found
+ * or could not be instantiated
+ */
+ static <T> Object find(final String factoryId, final String fallbackClassName, Class<T> service) throws ClassNotFoundException {
try {
// If we are deployed into an OSGi environment, leverage it
- Class factoryClass = FactoryFinder.class.getClassLoader().loadClass(factoryId);
+ Class factoryClass = null;
+ try {
+ factoryClass = FactoryFinder.class.getClassLoader().loadClass(factoryId);
+ } catch (Throwable t) {
+ if (service != null) {
+ factoryClass = service;
+ } else {
+ throw t;
+ }
+ }
Class spiClass = org.apache.servicemix.specs.locator.OsgiLocator.locate(factoryClass, factoryId);
if (spiClass != null) {
return spiClass.newInstance();
diff --git a/jaxrs-api-2.1/src/main/java/javax/ws/rs/ext/FactoryFinder.java b/jaxrs-api-2.1/src/main/java/javax/ws/rs/ext/FactoryFinder.java
index c82a1aa..ffa4965 100644
--- a/jaxrs-api-2.1/src/main/java/javax/ws/rs/ext/FactoryFinder.java
+++ b/jaxrs-api-2.1/src/main/java/javax/ws/rs/ext/FactoryFinder.java
@@ -65,17 +65,52 @@
* may not be <code>null</code>
* @throws WebServiceException if there is an error
*/
- static Object find(String factoryId, String fallbackClassName) throws ClassNotFoundException {
+ static Object find(final String factoryId, final String fallbackClassName) throws ClassNotFoundException {
+ return find(factoryId, fallbackClassName, null);
+ }
+
+ /**
+ * Finds the implementation <code>Class</code> object for the given
+ * factory name, or if that fails, finds the <code>Class</code> 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.
+ * <P>
+ * This method is package private so that this code can be shared.
+ *
+ * @param factoryId 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</code> to indicate that
+ * there is no fallback class name
+ * @param service The interface class of the service
+ * @return the <code>Class</code> object of the specified message factory;
+ * may not be <code>null</code>
+ * @throws ClassNotFoundException if the given class could not be found
+ * or could not be instantiated
+ */
+ static <T> Object find(final String factoryId, final String fallbackClassName, Class<T> service) throws ClassNotFoundException {
+
try {
// If we are deployed into an OSGi environment, leverage it
- Class factoryClass = FactoryFinder.class.getClassLoader().loadClass(factoryId);
+ Class factoryClass = null;
+ try {
+ factoryClass = FactoryFinder.class.getClassLoader().loadClass(factoryId);
+ } catch (Throwable t) {
+ if (service != null) {
+ factoryClass = service;
+ } else {
+ throw t;
+ }
+ }
Class spiClass = org.apache.servicemix.specs.locator.OsgiLocator.locate(factoryClass, factoryId);
if (spiClass != null) {
return spiClass.newInstance();
}
} catch (Throwable e) {
}
-
+
ClassLoader classLoader;
try {
classLoader = Thread.currentThread().getContextClassLoader();