Skip to content

Commit

Permalink
Merge pull request #130 from catenax-ng/release/1.12.19
Browse files Browse the repository at this point in the history
Release/1.12.19
  • Loading branch information
almadigabor authored May 24, 2024
2 parents 4f37ba8 + badfa70 commit aeb31ad
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 38 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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
*
Expand All @@ -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);
Expand Down Expand Up @@ -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)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down Expand Up @@ -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()) {
Expand Down

0 comments on commit aeb31ad

Please sign in to comment.