This is an automated email from the ASF dual-hosted git repository.

lburgazzoli pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/camel.git


The following commit(s) were added to refs/heads/main by this push:
     new c9d0b65  core: support for resolving resources from plain, base64 and 
base64+gzip strings
c9d0b65 is described below

commit c9d0b655868bf41453df71e7159b54b63e7cb5c4
Author: Luca Burgazzoli <[email protected]>
AuthorDate: Fri May 14 13:20:15 2021 +0200

    core: support for resolving resources from plain, base64 and base64+gzip 
strings
---
 .../camel/language/bean/BeanResourceResolver.java  |   8 +-
 .../org/apache/camel/resource-resolver/base64      |   2 +
 .../org/apache/camel/resource-resolver/gzip        |   2 +
 .../org/apache/camel/resource-resolver/mem         |   2 +
 .../impl/engine/DefaultResourceResolvers.java      | 226 ++++++++++++++-------
 .../apache/camel/urlhandler/custom/Handler.java    |   4 +-
 .../org/apache/camel/urlhandler/pd/Handler.java    |   2 +-
 .../org/apache/camel/util/ResourceLoaderTest.java  |  83 +++++++-
 .../camel/support/ResourceResolverSupport.java     |  33 ++-
 .../org/apache/camel/support/ResourceSupport.java} |  43 ++--
 10 files changed, 277 insertions(+), 128 deletions(-)

diff --git 
a/components/camel-bean/src/main/java/org/apache/camel/language/bean/BeanResourceResolver.java
 
b/components/camel-bean/src/main/java/org/apache/camel/language/bean/BeanResourceResolver.java
index 11c4955..cb72f23 100644
--- 
a/components/camel-bean/src/main/java/org/apache/camel/language/bean/BeanResourceResolver.java
+++ 
b/components/camel-bean/src/main/java/org/apache/camel/language/bean/BeanResourceResolver.java
@@ -39,10 +39,8 @@ public class BeanResourceResolver extends 
ResourceResolverSupport {
     }
 
     @Override
-    public Resource createResource(String location) {
-        final String expression = getRemaining(location);
-
-        LOGGER.trace("Creating resource from expression {}", expression);
+    public Resource createResource(String location, String remaining) {
+        LOGGER.trace("Creating resource from expression {}", remaining);
 
         return new Resource() {
             @Override
@@ -61,7 +59,7 @@ public class BeanResourceResolver extends 
ResourceResolverSupport {
                 final Exchange dummy = new DefaultExchange(context);
 
                 InputStream answer = null;
-                Object out = evaluate(dummy, expression);
+                Object out = evaluate(dummy, remaining);
 
                 if (dummy.getException() != null) {
                     throw new IOException(
diff --git 
a/core/camel-base-engine/src/generated/resources/META-INF/services/org/apache/camel/resource-resolver/base64
 
b/core/camel-base-engine/src/generated/resources/META-INF/services/org/apache/camel/resource-resolver/base64
new file mode 100644
index 0000000..de3964a
--- /dev/null
+++ 
b/core/camel-base-engine/src/generated/resources/META-INF/services/org/apache/camel/resource-resolver/base64
@@ -0,0 +1,2 @@
+# Generated by camel build tools - do NOT edit this file!
+class=org.apache.camel.impl.engine.DefaultResourceResolvers$Base64Resolver
diff --git 
a/core/camel-base-engine/src/generated/resources/META-INF/services/org/apache/camel/resource-resolver/gzip
 
b/core/camel-base-engine/src/generated/resources/META-INF/services/org/apache/camel/resource-resolver/gzip
new file mode 100644
index 0000000..4882a76
--- /dev/null
+++ 
b/core/camel-base-engine/src/generated/resources/META-INF/services/org/apache/camel/resource-resolver/gzip
@@ -0,0 +1,2 @@
+# Generated by camel build tools - do NOT edit this file!
+class=org.apache.camel.impl.engine.DefaultResourceResolvers$GzipResolver
diff --git 
a/core/camel-base-engine/src/generated/resources/META-INF/services/org/apache/camel/resource-resolver/mem
 
b/core/camel-base-engine/src/generated/resources/META-INF/services/org/apache/camel/resource-resolver/mem
new file mode 100644
index 0000000..08aff77
--- /dev/null
+++ 
b/core/camel-base-engine/src/generated/resources/META-INF/services/org/apache/camel/resource-resolver/mem
@@ -0,0 +1,2 @@
+# Generated by camel build tools - do NOT edit this file!
+class=org.apache.camel.impl.engine.DefaultResourceResolvers$MemResolver
diff --git 
a/core/camel-base-engine/src/main/java/org/apache/camel/impl/engine/DefaultResourceResolvers.java
 
b/core/camel-base-engine/src/main/java/org/apache/camel/impl/engine/DefaultResourceResolvers.java
index ea9db30..2a6aa30 100644
--- 
a/core/camel-base-engine/src/main/java/org/apache/camel/impl/engine/DefaultResourceResolvers.java
+++ 
b/core/camel-base-engine/src/main/java/org/apache/camel/impl/engine/DefaultResourceResolvers.java
@@ -25,46 +25,42 @@ import java.net.URI;
 import java.net.URISyntaxException;
 import java.net.URL;
 import java.net.URLConnection;
+import java.net.URLDecoder;
+import java.nio.charset.StandardCharsets;
 import java.nio.file.Files;
 import java.nio.file.Path;
 import java.nio.file.Paths;
+import java.util.Base64;
+import java.util.zip.GZIPInputStream;
 
 import org.apache.camel.ExtendedCamelContext;
 import org.apache.camel.spi.Resource;
 import org.apache.camel.spi.annotations.ResourceResolver;
 import org.apache.camel.support.CamelContextHelper;
 import org.apache.camel.support.ResourceResolverSupport;
+import org.apache.camel.support.ResourceSupport;
 import org.apache.camel.util.FileUtil;
-import org.apache.camel.util.StringHelper;
-import org.slf4j.Logger;
-import org.slf4j.LoggerFactory;
 
 public final class DefaultResourceResolvers {
     private DefaultResourceResolvers() {
     }
 
+    /**
+     * An implementation of the {@link ResourceResolver} that resolves a 
{@link Resource} from a file.
+     */
     @ResourceResolver(FileResolver.SCHEME)
     public static class FileResolver extends ResourceResolverSupport {
         public static final String SCHEME = "file";
-        private static final Logger LOGGER = 
LoggerFactory.getLogger(FileResolver.class);
 
         public FileResolver() {
             super(SCHEME);
         }
 
         @Override
-        public Resource createResource(String location) {
-            final String remaining = getRemaining(location);
+        public Resource createResource(String location, String remaining) {
             final Path path = Paths.get(tryDecodeUri(remaining));
 
-            LOGGER.trace("Creating resource: {} from file system", path);
-
-            return new Resource() {
-                @Override
-                public String getLocation() {
-                    return location;
-                }
-
+            return new ResourceSupport(location) {
                 @Override
                 public boolean exists() {
                     return Files.exists(path);
@@ -78,44 +74,44 @@ public final class DefaultResourceResolvers {
                 @Override
                 public InputStream getInputStream() throws IOException {
                     if (!exists()) {
-                        throw new FileNotFoundException(path.toString() + " 
does not exists");
+                        throw new FileNotFoundException(path + " does not 
exists");
                     }
                     if (Files.isDirectory(path)) {
-                        throw new FileNotFoundException(path.toString() + " is 
a directory");
+                        throw new FileNotFoundException(path + " is a 
directory");
                     }
 
                     return Files.newInputStream(path);
                 }
-
-                @Override
-                public String toString() {
-                    return "Resource{" +
-                           "location=" + getLocation() +
-                           '}';
-                }
             };
         }
+
+        protected String tryDecodeUri(String uri) {
+            try {
+                // try to decode as the uri may contain %20 for spaces etc
+                uri = URLDecoder.decode(uri, StandardCharsets.UTF_8.name());
+            } catch (Exception e) {
+                getLogger().trace("Error URL decoding uri using UTF-8 
encoding: {}. This exception is ignored.", uri);
+                // ignore
+            }
+
+            return uri;
+        }
     }
 
+    /**
+     * An implementation of the {@link ResourceResolver} that resolves a 
{@link Resource} from http.
+     */
     @ResourceResolver(HttpResolver.SCHEME)
     public static class HttpResolver extends ResourceResolverSupport {
         public static final String SCHEME = "http";
-        private static final Logger LOGGER = 
LoggerFactory.getLogger(HttpResolver.class);
 
         public HttpResolver() {
             super(SCHEME);
         }
 
         @Override
-        public Resource createResource(String location) {
-            LOGGER.trace("Creating resource: {} from HTTP", location);
-
-            return new Resource() {
-                @Override
-                public String getLocation() {
-                    return location;
-                }
-
+        public Resource createResource(String location, String remaining) {
+            return new ResourceSupport(location) {
                 @Override
                 public boolean exists() {
                     URLConnection connection = null;
@@ -155,38 +151,26 @@ public final class DefaultResourceResolvers {
                         throw e;
                     }
                 }
-
-                @Override
-                public String toString() {
-                    return "Resource{" +
-                           "location=" + getLocation() +
-                           '}';
-                }
             };
         }
     }
 
+    /**
+     * An implementation of the {@link ResourceResolver} that resolves a 
{@link Resource} from the classpath.
+     */
     @ResourceResolver(ClasspathResolver.SCHEME)
     public static class ClasspathResolver extends ResourceResolverSupport {
         public static final String SCHEME = "classpath";
-        private static final Logger LOGGER = 
LoggerFactory.getLogger(ClasspathResolver.class);
 
         public ClasspathResolver() {
             super(SCHEME);
         }
 
         @Override
-        public Resource createResource(String location) {
-            final String path = getPath(location);
-
-            LOGGER.trace("Creating resource: {} from classpath", path);
-
-            return new Resource() {
-                @Override
-                public String getLocation() {
-                    return location;
-                }
+        public Resource createResource(String location, String remaining) {
+            final String path = getPath(remaining);
 
+            return new ResourceSupport(location) {
                 @Override
                 public boolean exists() {
                     return getURI() != null;
@@ -214,66 +198,156 @@ public final class DefaultResourceResolvers {
                             .getClassResolver()
                             .loadResourceAsStream(path);
                 }
-
-                @Override
-                public String toString() {
-                    return "Resource{" +
-                           "location=" + getLocation() +
-                           '}';
-                }
             };
         }
 
         private String getPath(String location) {
-            String uri = StringHelper.after(location, "classpath:");
-            uri = tryDecodeUri(uri);
-            uri = FileUtil.compactPath(uri, '/');
+            String uri = tryDecodeUri(location);
+            return FileUtil.compactPath(uri, '/');
+        }
+
+        protected String tryDecodeUri(String uri) {
+            try {
+                // try to decode as the uri may contain %20 for spaces etc
+                uri = URLDecoder.decode(uri, StandardCharsets.UTF_8.name());
+            } catch (Exception e) {
+                getLogger().trace("Error URL decoding uri using UTF-8 
encoding: {}. This exception is ignored.", uri);
+                // ignore
+            }
 
             return uri;
         }
     }
 
+    /**
+     * An implementation of the {@link ResourceResolver} that resolves a 
{@link Resource} from a bean in the registry of
+     * type String.
+     */
     @ResourceResolver(RefResolver.SCHEME)
     public static class RefResolver extends ResourceResolverSupport {
         public static final String SCHEME = "ref";
-        private static final Logger LOGGER = 
LoggerFactory.getLogger(RefResolver.class);
 
         public RefResolver() {
             super(SCHEME);
         }
 
         @Override
-        public Resource createResource(String location) {
-            final String key = getRemaining(location);
-            final String val = CamelContextHelper.lookup(getCamelContext(), 
key, String.class);
+        public Resource createResource(String location, String remaining) {
+            final String val = CamelContextHelper.lookup(getCamelContext(), 
remaining, String.class);
 
-            LOGGER.trace("Creating resource: {} from registry", key);
+            return new ResourceSupport(location) {
+                @Override
+                public boolean exists() {
+                    return val != null;
+                }
 
-            return new Resource() {
                 @Override
-                public String getLocation() {
-                    return location;
+                public InputStream getInputStream() throws IOException {
+                    if (!exists()) {
+                        throw new IOException("There is no bean in the 
registry with name " + remaining + "and type String");
+                    }
+
+                    return new ByteArrayInputStream(val.getBytes());
                 }
+            };
+        }
+    }
+
+    /**
+     * An implementation of the {@link ResourceResolver} that resolves a 
{@link Resource} from a base64 encoded string.
+     */
+    @ResourceResolver(Base64Resolver.SCHEME)
+    public static class Base64Resolver extends ResourceResolverSupport {
+        public static final String SCHEME = "base64";
 
+        public Base64Resolver() {
+            super(SCHEME);
+        }
+
+        @Override
+        public Resource createResource(String location, String remaining) {
+            return new ResourceSupport(location) {
                 @Override
                 public boolean exists() {
-                    return val != null;
+                    return remaining != null;
                 }
 
                 @Override
                 public InputStream getInputStream() throws IOException {
                     if (!exists()) {
-                        throw new IOException("There is no bean in the 
registry with name " + key + "and type String");
+                        throw new IOException("No base64 content defined");
                     }
 
-                    return new ByteArrayInputStream(val.getBytes());
+                    final byte[] decoded = 
Base64.getDecoder().decode(remaining);
+                    final InputStream is = new ByteArrayInputStream(decoded);
+
+                    return is;
+                }
+            };
+        }
+    }
+
+    /**
+     * An implementation of the {@link ResourceResolver} that resolves a 
{@link Resource} from a gzip+base64 encoded
+     * string.
+     */
+    @ResourceResolver(GzipResolver.SCHEME)
+    public static class GzipResolver extends ResourceResolverSupport {
+        public static final String SCHEME = "gzip";
+
+        public GzipResolver() {
+            super(SCHEME);
+        }
+
+        @Override
+        public Resource createResource(String location, String remaining) {
+            return new ResourceSupport(location) {
+                @Override
+                public boolean exists() {
+                    return remaining != null;
                 }
 
                 @Override
-                public String toString() {
-                    return "Resource{" +
-                           "location=" + getLocation() +
-                           '}';
+                public InputStream getInputStream() throws IOException {
+                    if (!exists()) {
+                        throw new IOException("No gzip content defined");
+                    }
+
+                    final byte[] decoded = 
Base64.getDecoder().decode(remaining);
+                    final InputStream is = new ByteArrayInputStream(decoded);
+
+                    return new GZIPInputStream(is);
+                }
+            };
+        }
+    }
+
+    /**
+     * An implementation of the {@link ResourceResolver} that resolves a 
{@link Resource} from a string.
+     */
+    @ResourceResolver(MemResolver.SCHEME)
+    public static class MemResolver extends ResourceResolverSupport {
+        public static final String SCHEME = "mem";
+
+        public MemResolver() {
+            super(SCHEME);
+        }
+
+        @Override
+        public Resource createResource(String location, String remaining) {
+            return new ResourceSupport(location) {
+                @Override
+                public boolean exists() {
+                    return remaining != null;
+                }
+
+                @Override
+                public InputStream getInputStream() throws IOException {
+                    if (!exists()) {
+                        throw new IOException("No memory content defined");
+                    }
+
+                    return new ByteArrayInputStream(remaining.getBytes());
                 }
             };
         }
diff --git 
a/core/camel-core/src/test/java/org/apache/camel/urlhandler/custom/Handler.java 
b/core/camel-core/src/test/java/org/apache/camel/urlhandler/custom/Handler.java
index 4d9469f..c0f5295 100644
--- 
a/core/camel-core/src/test/java/org/apache/camel/urlhandler/custom/Handler.java
+++ 
b/core/camel-core/src/test/java/org/apache/camel/urlhandler/custom/Handler.java
@@ -30,7 +30,7 @@ public class Handler extends ResourceResolverSupport {
     }
 
     @Override
-    protected Resource createResource(String location) {
+    protected Resource createResource(String location, String remaining) {
         return new Resource() {
             @Override
             public String getLocation() {
@@ -44,7 +44,7 @@ public class Handler extends ResourceResolverSupport {
 
             @Override
             public InputStream getInputStream() throws IOException {
-                return new 
ByteArrayInputStream(getRemaining(location).getBytes(StandardCharsets.UTF_8));
+                return new 
ByteArrayInputStream(remaining.getBytes(StandardCharsets.UTF_8));
             }
         };
     }
diff --git 
a/core/camel-core/src/test/java/org/apache/camel/urlhandler/pd/Handler.java 
b/core/camel-core/src/test/java/org/apache/camel/urlhandler/pd/Handler.java
index f753c92..92a43b5 100644
--- a/core/camel-core/src/test/java/org/apache/camel/urlhandler/pd/Handler.java
+++ b/core/camel-core/src/test/java/org/apache/camel/urlhandler/pd/Handler.java
@@ -61,7 +61,7 @@ public class Handler extends ResourceResolverSupport {
     }
 
     @Override
-    protected Resource createResource(String location) {
+    protected Resource createResource(String location, String remaining) {
         return new Resource() {
             @Override
             public String getLocation() {
diff --git 
a/core/camel-core/src/test/java/org/apache/camel/util/ResourceLoaderTest.java 
b/core/camel-core/src/test/java/org/apache/camel/util/ResourceLoaderTest.java
index 1df8c89..a3d64f8 100644
--- 
a/core/camel-core/src/test/java/org/apache/camel/util/ResourceLoaderTest.java
+++ 
b/core/camel-core/src/test/java/org/apache/camel/util/ResourceLoaderTest.java
@@ -17,10 +17,14 @@
 package org.apache.camel.util;
 
 import java.io.ByteArrayInputStream;
+import java.io.ByteArrayOutputStream;
 import java.io.File;
 import java.io.InputStream;
 import java.net.URL;
+import java.nio.charset.StandardCharsets;
+import java.util.Base64;
 import java.util.concurrent.atomic.AtomicReference;
+import java.util.zip.GZIPOutputStream;
 
 import org.apache.camel.TestSupport;
 import org.apache.camel.impl.DefaultCamelContext;
@@ -30,6 +34,7 @@ import org.apache.camel.support.ResourceHelper;
 import org.apache.camel.support.ResourceResolverSupport;
 import org.junit.jupiter.api.Test;
 
+import static org.apache.camel.util.CollectionHelper.propertiesOf;
 import static org.apache.camel.util.FileUtil.copyFile;
 import static org.junit.jupiter.api.Assertions.assertEquals;
 import static org.junit.jupiter.api.Assertions.assertFalse;
@@ -113,7 +118,7 @@ public class ResourceLoaderTest extends TestSupport {
                 }
 
                 @Override
-                protected Resource createResource(String location) {
+                protected Resource createResource(String location, String 
remaining) {
                     throw new UnsupportedOperationException();
                 }
             });
@@ -246,4 +251,80 @@ public class ResourceLoaderTest extends TestSupport {
 
         context.stop();
     }
+
+    @Test
+    public void testLoadMem() throws Exception {
+        final String raw = "to-be-encoded";
+
+        DefaultCamelContext context = new DefaultCamelContext();
+        Resource resource = context.getResourceLoader().resolveResource("mem:" 
+ raw);
+
+        try (InputStream is = resource.getInputStream()) {
+            assertNotNull(is);
+
+            String content = 
context.getTypeConverter().convertTo(String.class, is);
+            assertNotNull(content);
+            assertEquals(raw, content);
+        }
+    }
+
+    @Test
+    public void testLoadBase64() throws Exception {
+        final String raw = "to-be-encoded";
+        final String encoded = 
Base64.getEncoder().encodeToString(raw.getBytes(StandardCharsets.UTF_8));
+
+        DefaultCamelContext context = new DefaultCamelContext();
+        Resource resource = 
context.getResourceLoader().resolveResource("base64:" + encoded);
+
+        try (InputStream is = resource.getInputStream()) {
+            assertNotNull(is);
+
+            String content = 
context.getTypeConverter().convertTo(String.class, is);
+            assertNotNull(content);
+            assertEquals(raw, content);
+        }
+    }
+
+    @Test
+    public void testLoadBase64WithPlaceholders() throws Exception {
+        final String raw = "to-be-encoded";
+        final String encoded = 
Base64.getEncoder().encodeToString(raw.getBytes(StandardCharsets.UTF_8));
+
+        DefaultCamelContext context = new DefaultCamelContext();
+        
context.getPropertiesComponent().setInitialProperties(propertiesOf("my.encoded",
 encoded));
+        Resource resource = 
context.getResourceLoader().resolveResource("base64:{{my.encoded}}");
+
+        try (InputStream is = resource.getInputStream()) {
+            assertNotNull(is);
+
+            String content = 
context.getTypeConverter().convertTo(String.class, is);
+            assertNotNull(content);
+            assertEquals(raw, content);
+        }
+    }
+
+    @Test
+    public void testLoadGzip() throws Exception {
+        final String raw = "to-be-encoded";
+        final String encoded;
+
+        try (ByteArrayOutputStream out = new ByteArrayOutputStream()) {
+            try (GZIPOutputStream gzip = new GZIPOutputStream(out)) {
+                gzip.write(raw.getBytes(StandardCharsets.UTF_8));
+            }
+
+            encoded = Base64.getEncoder().encodeToString(out.toByteArray());
+        }
+
+        DefaultCamelContext context = new DefaultCamelContext();
+        Resource resource = 
context.getResourceLoader().resolveResource("gzip:" + encoded);
+
+        try (InputStream is = resource.getInputStream()) {
+            assertNotNull(is);
+
+            String content = 
context.getTypeConverter().convertTo(String.class, is);
+            assertNotNull(content);
+            assertEquals(raw, content);
+        }
+    }
 }
diff --git 
a/core/camel-support/src/main/java/org/apache/camel/support/ResourceResolverSupport.java
 
b/core/camel-support/src/main/java/org/apache/camel/support/ResourceResolverSupport.java
index 9968641..c3d0819 100644
--- 
a/core/camel-support/src/main/java/org/apache/camel/support/ResourceResolverSupport.java
+++ 
b/core/camel-support/src/main/java/org/apache/camel/support/ResourceResolverSupport.java
@@ -16,10 +16,8 @@
  */
 package org.apache.camel.support;
 
-import java.net.URLDecoder;
-import java.nio.charset.StandardCharsets;
-
 import org.apache.camel.CamelContext;
+import org.apache.camel.spi.PropertiesComponent;
 import org.apache.camel.spi.Resource;
 import org.apache.camel.spi.ResourceResolver;
 import org.apache.camel.support.service.ServiceSupport;
@@ -31,13 +29,13 @@ import org.slf4j.LoggerFactory;
  * Base class for {@link ResourceResolver} implementations.
  */
 public abstract class ResourceResolverSupport extends ServiceSupport 
implements ResourceResolver {
-    private static final Logger LOGGER = 
LoggerFactory.getLogger(ResourceResolverSupport.class);
-
     private final String scheme;
+    private final Logger logger;
     private CamelContext camelContext;
 
     protected ResourceResolverSupport(String scheme) {
         this.scheme = scheme;
+        this.logger = LoggerFactory.getLogger(getClass());
     }
 
     public String getSupportedScheme() {
@@ -60,24 +58,25 @@ public abstract class ResourceResolverSupport extends 
ServiceSupport implements
             throw new IllegalArgumentException("Unsupported scheme: " + 
location);
         }
 
-        return createResource(location);
-    }
-
-    protected abstract Resource createResource(String location);
+        String context = StringHelper.after(location, ":");
+        if (context == null) {
+            throw new IllegalArgumentException("No context path provided: " + 
location);
+        }
 
-    protected String tryDecodeUri(String uri) {
-        try {
-            // try to decode as the uri may contain %20 for spaces etc
-            uri = URLDecoder.decode(uri, StandardCharsets.UTF_8.name());
-        } catch (Exception e) {
-            LOGGER.trace("Error URL decoding uri using UTF-8 encoding: {}. 
This exception is ignored.", uri);
-            // ignore
+        if (context.contains(PropertiesComponent.PREFIX_TOKEN) && 
context.contains(PropertiesComponent.SUFFIX_TOKEN)) {
+            context = camelContext.getPropertiesComponent().parseUri(context);
         }
 
-        return uri;
+        return createResource(location, context);
     }
 
+    protected abstract Resource createResource(String location, String 
remaining);
+
     protected String getRemaining(String location) {
         return StringHelper.after(location, getSupportedScheme() + ":");
     }
+
+    protected Logger getLogger() {
+        return this.logger;
+    }
 }
diff --git 
a/core/camel-core/src/test/java/org/apache/camel/urlhandler/custom/Handler.java 
b/core/camel-support/src/main/java/org/apache/camel/support/ResourceSupport.java
similarity index 50%
copy from 
core/camel-core/src/test/java/org/apache/camel/urlhandler/custom/Handler.java
copy to 
core/camel-support/src/main/java/org/apache/camel/support/ResourceSupport.java
index 4d9469f..d277f8a 100644
--- 
a/core/camel-core/src/test/java/org/apache/camel/urlhandler/custom/Handler.java
+++ 
b/core/camel-support/src/main/java/org/apache/camel/support/ResourceSupport.java
@@ -14,38 +14,29 @@
  * See the License for the specific language governing permissions and
  * limitations under the License.
  */
-package org.apache.camel.urlhandler.custom;
-
-import java.io.ByteArrayInputStream;
-import java.io.IOException;
-import java.io.InputStream;
-import java.nio.charset.StandardCharsets;
+package org.apache.camel.support;
 
 import org.apache.camel.spi.Resource;
-import org.apache.camel.support.ResourceResolverSupport;
 
-public class Handler extends ResourceResolverSupport {
-    public Handler() {
-        super("custom");
+/**
+ * Base class for {@link Resource} implementations.
+ */
+public abstract class ResourceSupport implements Resource {
+    private final String location;
+
+    protected ResourceSupport(String location) {
+        this.location = location;
     }
 
     @Override
-    protected Resource createResource(String location) {
-        return new Resource() {
-            @Override
-            public String getLocation() {
-                return location;
-            }
-
-            @Override
-            public boolean exists() {
-                return true;
-            }
+    public String getLocation() {
+        return location;
+    }
 
-            @Override
-            public InputStream getInputStream() throws IOException {
-                return new 
ByteArrayInputStream(getRemaining(location).getBytes(StandardCharsets.UTF_8));
-            }
-        };
+    @Override
+    public String toString() {
+        return getClass().getSimpleName() + "{" +
+               "location=" + getLocation() +
+               '}';
     }
 }

Reply via email to