This is an automated email from the ASF dual-hosted git repository. davsclaus pushed a commit to branch CAMEL-18665 in repository https://gitbox.apache.org/repos/asf/camel.git
commit cbb613f3a55f86cb9d7658b33438502d0f200208 Author: Claus Ibsen <[email protected]> AuthorDate: Mon Oct 31 21:56:49 2022 +0100 CAMEL-18665: camel-core: JsseParameters should use the camel provided resource loader instead of its own --- .../java/org/apache/camel/spi/ResourceLoader.java | 1 + .../apache/camel/support/jsse/JsseParameters.java | 82 +++------------------- 2 files changed, 9 insertions(+), 74 deletions(-) diff --git a/core/camel-api/src/main/java/org/apache/camel/spi/ResourceLoader.java b/core/camel-api/src/main/java/org/apache/camel/spi/ResourceLoader.java index 5f96beb161e..103ec2c4462 100644 --- a/core/camel-api/src/main/java/org/apache/camel/spi/ResourceLoader.java +++ b/core/camel-api/src/main/java/org/apache/camel/spi/ResourceLoader.java @@ -22,6 +22,7 @@ import org.apache.camel.CamelContextAware; * SPI for loading resources. */ public interface ResourceLoader extends CamelContextAware { + /** * Service factory key. */ diff --git a/core/camel-api/src/main/java/org/apache/camel/support/jsse/JsseParameters.java b/core/camel-api/src/main/java/org/apache/camel/support/jsse/JsseParameters.java index 6d7ba7724f7..4e3bce57ec4 100644 --- a/core/camel-api/src/main/java/org/apache/camel/support/jsse/JsseParameters.java +++ b/core/camel-api/src/main/java/org/apache/camel/support/jsse/JsseParameters.java @@ -26,8 +26,11 @@ import java.util.List; import org.apache.camel.CamelContext; import org.apache.camel.CamelContextAware; +import org.apache.camel.ExtendedCamelContext; import org.apache.camel.RuntimeCamelException; import org.apache.camel.spi.ClassResolver; +import org.apache.camel.spi.Resource; +import org.apache.camel.spi.ResourceLoader; import org.slf4j.Logger; import org.slf4j.LoggerFactory; @@ -106,90 +109,21 @@ public class JsseParameters implements CamelContextAware { } /** - * Attempts to loads a resource using a number of different approaches. The loading of the resource, is attempted by + * Attempts to load a resource using a number of different approaches. The loading of the resource, is attempted by * treating the resource as a file path, a class path resource, a URL, and using the Camel Context's - * {@link ClassResolver} if a context is available in that order. An exception is thrown if the resource cannot be + * {@link ResourceLoader} if a context is available in that order. An exception is thrown if the resource cannot be * resolved to readable input stream using any of the above methods. * * @param resource the resource location * @return the input stream for the resource - * * @throws IOException if the resource cannot be resolved using any of the above methods - * - * @see #setCamelContext(CamelContext) */ protected InputStream resolveResource(String resource) throws IOException { - InputStream is = null; - - // attempt as plain file first - try { - LOG.trace("Trying to open resource [{}] as a file.", resource); - is = new FileInputStream(resource); - LOG.debug("Opened resource [{}] as a file.", resource); - } catch (FileNotFoundException e) { - LOG.trace("Could not open resource [{}] as a file.", resource, e); - } - - // then prefer to use ClassResolver from CamelContext if possible - if (is == null && this.context != null) { - LOG.trace("Trying to open resource using the CamelContext ClassResolver [{}].", context.getClassResolver()); - try { - is = context.getClassResolver().loadResourceAsStream(resource); - if (is == null) { - LOG.trace("Could not to open resource [{}] using the CamelContext ClassResolver [{}].", - resource, context.getClassResolver()); - } else { - LOG.debug("Opened resource [{}] using the CamelContext ClassResolver [{}].", - resource, this.getClass().getClassLoader()); - } - } catch (Throwable e) { - LOG.trace("Could not open resource [{}] using the CamelContext ClassResolver.", resource, e); - } - } - - if (is == null && Thread.currentThread().getContextClassLoader() != null) { - LOG.trace("Trying to open resource [{}] as a class path resource with the TCCL [{}].", - resource, Thread.currentThread().getContextClassLoader()); - is = Thread.currentThread().getContextClassLoader().getResourceAsStream(resource); - - if (is == null) { - LOG.trace("Could not open resource [{}] as a class path resource using the TCCL [{}].", - resource, Thread.currentThread().getContextClassLoader()); - } else { - LOG.debug("Opened resource [{}] as a class path resource with the TCCL [{}].", - resource, Thread.currentThread().getContextClassLoader()); - } - } - - if (is == null) { - LOG.trace("Trying to open resource [{}] as a class path resource using the classloader [{}].", - resource, this.getClass().getClassLoader()); - is = this.getClass().getResourceAsStream(resource); - - if (is == null) { - LOG.trace("Could not open resource [{}] as a class path resource using the classloader [{}].", - resource, this.getClass().getClassLoader()); - } else { - LOG.debug("Opened resource [{}] as a class path resource with the classloader [{}].", - resource, this.getClass().getClassLoader()); - } - } - - if (is == null) { - try { - LOG.trace("Trying to open resource [{}] as a URL.", resource); - is = new URL(resource).openStream(); - LOG.debug("Opened resource [{}] as a URL.", resource); - } catch (IOException e) { - LOG.trace("Could not open resource [{}] as a URL.", resource, e); - } - } - - if (is == null) { + Resource res = getCamelContext().adapt(ExtendedCamelContext.class).getResourceLoader().resolveResource(resource); + if (res == null) { throw new IOException("Could not open " + resource + " as a file, class path resource, or URL."); } - - return is; + return res.getInputStream(); } }
