From 0ead7a33c3827b4bac3a718552e5aec4c83f1928 Mon Sep 17 00:00:00 2001 From: Francisco Javier Tirado Sarti Date: Tue, 20 Oct 2026 12:31:35 +0200 Subject: [PATCH] [Fix #1776] Make DefaultResourceLoader easier to customize fileResource and httpResource are now protected. Signed-off-by: Francisco Javier Tirado Sarti --- .../impl/resources/DefaultResourceLoader.java | 20 ++++++++---- .../sdk/impl/resources/GitHubHelper.java | 31 ++++++++++++------- .../sdk/impl/resources/HttpResource.java | 2 +- 3 files changed, 34 insertions(+), 19 deletions(-) diff --git a/impl/core/src/main/java/org/openworkflow/sdk/impl/resources/DefaultResourceLoader.java b/impl/core/src/main/java/org/openworkflow/sdk/impl/resources/DefaultResourceLoader.java index 00857854c..21f43ed46 100644 --- a/impl/core/src/main/java/org/openworkflow/sdk/impl/resources/DefaultResourceLoader.java +++ b/impl/core/src/main/java/org/openworkflow/sdk/impl/resources/DefaultResourceLoader.java @@ -51,7 +51,7 @@ public T loadURI( .content(); } - private ExternalResourceHandler fileResource(String pathStr) { + protected ExternalResourceHandler fileResource(String pathStr) { Path path = Path.of(pathStr); if (path.isAbsolute()) { return new FileResource(path); @@ -62,16 +62,24 @@ private ExternalResourceHandler fileResource(String pathStr) { } } + protected ExternalResourceHandler httpResource(URI uri, Optional auth) { + try { + return new HttpResource(uri.toURL(), auth); + } catch (MalformedURLException e) { + throw new IllegalArgumentException(e); + } + } + + protected URI handleURI(URI uri) { + return GitHubHelper.handleURL(uri); + } + private ExternalResourceHandler buildFromURI(URI uri, Optional auth) { String scheme = uri.getScheme(); if (scheme == null || scheme.equalsIgnoreCase("file")) { return fileResource(uri.getPath()); } else if (scheme.equalsIgnoreCase("http") || scheme.equalsIgnoreCase("https")) { - try { - return new HttpResource(uri.toURL(), auth); - } catch (MalformedURLException e) { - throw new IllegalArgumentException(e); - } + return httpResource(handleURI(uri), auth); } else { throw new UnsupportedOperationException("Unsupported scheme " + scheme); } diff --git a/impl/core/src/main/java/org/openworkflow/sdk/impl/resources/GitHubHelper.java b/impl/core/src/main/java/org/openworkflow/sdk/impl/resources/GitHubHelper.java index d57f17892..54ce1773f 100644 --- a/impl/core/src/main/java/org/openworkflow/sdk/impl/resources/GitHubHelper.java +++ b/impl/core/src/main/java/org/openworkflow/sdk/impl/resources/GitHubHelper.java @@ -15,9 +15,8 @@ */ package org.openworkflow.sdk.impl.resources; -import java.io.UncheckedIOException; -import java.net.MalformedURLException; -import java.net.URL; +import java.net.URI; +import java.net.URISyntaxException; public class GitHubHelper { @@ -25,17 +24,25 @@ private GitHubHelper() {} private static final String BLOB = "blob/"; - public static URL handleURL(URL url) { - if (url.getHost().equals("github.com")) { + public static URI handleURL(URI url) { + if ("github.com".equals(url.getHost())) { + String path = url.getPath(); + if (path.startsWith(BLOB)) { + path = path.substring(BLOB.length()); + } try { - String path = url.getPath(); - if (path.startsWith(BLOB)) { - path = path.substring(BLOB.length()); - } - return new URL(url.getProtocol(), "raw.githubusercontent.com", url.getPort(), path); - } catch (MalformedURLException e) { - throw new UncheckedIOException(e); + return new URI( + url.getScheme(), + url.getUserInfo(), + "raw.githubusercontent.com", + url.getPort(), + path, + url.getQuery(), + url.getFragment()); + } catch (URISyntaxException e) { + return url; } + } else { return url; } diff --git a/impl/core/src/main/java/org/openworkflow/sdk/impl/resources/HttpResource.java b/impl/core/src/main/java/org/openworkflow/sdk/impl/resources/HttpResource.java index 4a80859d0..968c336f9 100644 --- a/impl/core/src/main/java/org/openworkflow/sdk/impl/resources/HttpResource.java +++ b/impl/core/src/main/java/org/openworkflow/sdk/impl/resources/HttpResource.java @@ -32,7 +32,7 @@ public class HttpResource implements ExternalResourceHandler { private final Optional auth; public HttpResource(URL url, Optional auth) { - this.url = GitHubHelper.handleURL(url); + this.url = url; this.auth = auth; }