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

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


The following commit(s) were added to refs/heads/main by this push:
     new 6bd6b4fd923 Add vfs to URIResolver (#3113)
6bd6b4fd923 is described below

commit 6bd6b4fd923140c9cebdd83fb4294f8fb00e7c1f
Author: Colm O hEigeartaigh <[email protected]>
AuthorDate: Thu May 14 15:05:15 2026 +0100

    Add vfs to URIResolver (#3113)
---
 .../java/org/apache/cxf/resource/URIResolver.java  |  2 +-
 .../org/apache/cxf/resource/URIResolverTest.java   | 27 +++++++++++++
 .../apache/cxf/resource/protocol/vfs/Handler.java  | 47 ++++++++++++++++++++++
 3 files changed, 75 insertions(+), 1 deletion(-)

diff --git a/core/src/main/java/org/apache/cxf/resource/URIResolver.java 
b/core/src/main/java/org/apache/cxf/resource/URIResolver.java
index f2c5e7a180c..a694fb1fe61 100644
--- a/core/src/main/java/org/apache/cxf/resource/URIResolver.java
+++ b/core/src/main/java/org/apache/cxf/resource/URIResolver.java
@@ -65,7 +65,7 @@ public class URIResolver implements AutoCloseable {
         "org.apache.cxf.resource.uriresolver.allowedSchemes";
     private static final Set<String> DEFAULT_ALLOWED_URL_SCHEMES =
         Collections.unmodifiableSet(
-            new HashSet<>(Arrays.asList("file", "http", "https", "jar", "zip", 
"wsjar", "local", "classpath")));
+            new HashSet<>(Arrays.asList("file", "http", "https", "jar", "zip", 
"wsjar", "local", "classpath", "vfs")));
 
     private Map<String, LoadingByteArrayOutputStream> cache = new HashMap<>();
     private File file;
diff --git a/core/src/test/java/org/apache/cxf/resource/URIResolverTest.java 
b/core/src/test/java/org/apache/cxf/resource/URIResolverTest.java
index adc21742a45..99e2b0c3d03 100644
--- a/core/src/test/java/org/apache/cxf/resource/URIResolverTest.java
+++ b/core/src/test/java/org/apache/cxf/resource/URIResolverTest.java
@@ -39,6 +39,8 @@ import static org.junit.Assert.fail;
 
 public class URIResolverTest {
 
+    private static final String TEST_PROTOCOL_HANDLER_PACKAGE = 
"org.apache.cxf.resource.protocol";
+
     private URIResolver uriResolver;
 
     private URL resourceURL = 
getClass().getResource("resources/helloworld.bpr");
@@ -231,6 +233,31 @@ public class URIResolverTest {
         }
     }
 
+    @Test
+    public void testVfsProtocolAllowedAndResolved() throws Exception {
+        String oldHandlers = System.getProperty("java.protocol.handler.pkgs");
+        try {
+            if (oldHandlers == null || oldHandlers.isEmpty()) {
+                System.setProperty("java.protocol.handler.pkgs", 
TEST_PROTOCOL_HANDLER_PACKAGE);
+            } else if (!oldHandlers.contains(TEST_PROTOCOL_HANDLER_PACKAGE)) {
+                System.setProperty("java.protocol.handler.pkgs", oldHandlers + 
"|" + TEST_PROTOCOL_HANDLER_PACKAGE);
+            }
+
+            URIResolver resolver = new 
URIResolver("vfs://test/path/schema.xsd");
+            assertTrue(resolver.isResolved());
+            assertNotNull(resolver.getInputStream());
+            String content = IOUtils.toString(resolver.getInputStream());
+            assertEquals("vfs-test-content", content);
+            resolver.close();
+        } finally {
+            if (oldHandlers == null) {
+                System.clearProperty("java.protocol.handler.pkgs");
+            } else {
+                System.setProperty("java.protocol.handler.pkgs", oldHandlers);
+            }
+        }
+    }
+
     private void resolveWithCheckingClassloader(URIResolver resolver, String 
baseUriStr, String uriStr,
             Class<?> callingCls) throws InterruptedException {
         checkingThreadThrowable = null;
diff --git 
a/core/src/test/java/org/apache/cxf/resource/protocol/vfs/Handler.java 
b/core/src/test/java/org/apache/cxf/resource/protocol/vfs/Handler.java
new file mode 100644
index 00000000000..9728f9e475f
--- /dev/null
+++ b/core/src/test/java/org/apache/cxf/resource/protocol/vfs/Handler.java
@@ -0,0 +1,47 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.cxf.resource.protocol.vfs;
+
+import java.io.ByteArrayInputStream;
+import java.io.IOException;
+import java.io.InputStream;
+import java.net.URL;
+import java.net.URLConnection;
+import java.net.URLStreamHandler;
+import java.nio.charset.StandardCharsets;
+
+public class Handler extends URLStreamHandler {
+    private static final byte[] CONTENT = 
"vfs-test-content".getBytes(StandardCharsets.UTF_8);
+
+    @Override
+    protected URLConnection openConnection(URL url) {
+        return new URLConnection(url) {
+            @Override
+            public void connect() {
+                // No-op: test URL handler has no external endpoint.
+            }
+
+            @Override
+            public InputStream getInputStream() throws IOException {
+                connect();
+                return new ByteArrayInputStream(CONTENT);
+            }
+        };
+    }
+}

Reply via email to