diff --git a/matchmaking/src/main/java/org/eclipse/tractusx/agents/http/DelegationServiceImpl.java b/matchmaking/src/main/java/org/eclipse/tractusx/agents/http/DelegationServiceImpl.java index b977598..e38f71f 100644 --- a/matchmaking/src/main/java/org/eclipse/tractusx/agents/http/DelegationServiceImpl.java +++ b/matchmaking/src/main/java/org/eclipse/tractusx/agents/http/DelegationServiceImpl.java @@ -41,7 +41,6 @@ import java.io.IOException; import java.io.InputStream; import java.io.InputStreamReader; -import java.net.URI; import java.nio.charset.Charset; import java.util.List; import java.util.Map; @@ -131,22 +130,6 @@ public DelegationResponse executeQueryRemote(String remoteUrl, String skill, Str } - /** - * URL Validation - * - * @param url URL string for validation - * @return Returns true if the URL is valid, false otherwise. - */ - public static boolean isValid(String url) { - // Try creating a valid URL - try { - new URI(url).toURL(); - return true; - } catch (Exception e) { // If there was an Exception while creating URL object - return false; - } - } - /** * route a get request * @@ -160,7 +143,7 @@ public DelegationResponse sendGetRequest(EndpointDataReference dataReference, St monitor.debug(String.format("About to delegate GET %s", url)); - if (isValid(url.toString())) { + if (Pattern.matches("(http|edc)s?://.*", url.toString())) { var requestBuilder = new okhttp3.Request.Builder() .url(url); @@ -193,7 +176,7 @@ public DelegationResponse sendPostRequest(EndpointDataReference dataReference, S monitor.debug(String.format("About to delegate POST %s with content type %s", url, contentType)); - if (isValid(url.toString())) { + if (Pattern.matches("(http|edc)s?://.*", url.toString())) { var requestBuilder = new okhttp3.Request.Builder() .url(url) diff --git a/matchmaking/src/main/java/org/eclipse/tractusx/agents/service/DataManagement.java b/matchmaking/src/main/java/org/eclipse/tractusx/agents/service/DataManagement.java index 546ef7a..9efb115 100644 --- a/matchmaking/src/main/java/org/eclipse/tractusx/agents/service/DataManagement.java +++ b/matchmaking/src/main/java/org/eclipse/tractusx/agents/service/DataManagement.java @@ -41,11 +41,11 @@ import org.eclipse.tractusx.agents.utils.TypeManager; import java.io.IOException; -import java.net.URI; import java.net.URLEncoder; import java.nio.charset.StandardCharsets; import java.util.List; import java.util.UUID; +import java.util.regex.Pattern; import static java.lang.String.format; @@ -426,34 +426,17 @@ public IdResponse createOrUpdateGraph(String assetId, String name, String descri return createOrUpdateAsset(assetId, assetSpec); } - /** - * URL Validation - * - * @param url URL string for validation - * @return Returns true if the URL is valid, false otherwise. - */ - public static boolean isValid(String url) { - // Try creating a valid URL - try { - new URI(url).toURL(); - return true; - } catch (Exception e) { // If there was an Exception while creating URL object - return false; - } - } - /** * deletes an existing aseet * * @param assetId key of the asset * @return idresponse */ - public IdResponse deleteAsset(String assetId) throws IOException { String version = "/v3"; var url = String.format(ASSET_UPDATE_CALL, config.getControlPlaneManagementProviderUrl(), version, assetId); - if (isValid(url)) { + if (Pattern.matches("(http|edc)s?://.*", url)) { var request = new Request.Builder().url(url).delete(); config.getControlPlaneManagementHeaders().forEach(request::addHeader); try (var response = httpClient.newCall(request.build()).execute()) {