From 133951c4f5a029139a085a9a884f9a684a6e747c Mon Sep 17 00:00:00 2001 From: Christoph Deppisch Date: Fri, 8 Nov 2024 10:07:34 +0100 Subject: [PATCH] chore: URL encode query parameter part when creating dynamic endpoint components - Allows to use special characters in query parameters such as "#" for instance --- .../endpoint/AbstractEndpointComponent.java | 15 +++++++++++++-- 1 file changed, 13 insertions(+), 2 deletions(-) diff --git a/core/citrus-base/src/main/java/org/citrusframework/endpoint/AbstractEndpointComponent.java b/core/citrus-base/src/main/java/org/citrusframework/endpoint/AbstractEndpointComponent.java index 1fe8f46fe6..29c4f398d1 100644 --- a/core/citrus-base/src/main/java/org/citrusframework/endpoint/AbstractEndpointComponent.java +++ b/core/citrus-base/src/main/java/org/citrusframework/endpoint/AbstractEndpointComponent.java @@ -20,6 +20,8 @@ import java.lang.reflect.Method; import java.net.URI; import java.net.URISyntaxException; +import java.net.URLEncoder; +import java.nio.charset.StandardCharsets; import java.util.Arrays; import java.util.HashMap; import java.util.LinkedHashMap; @@ -30,8 +32,8 @@ import org.citrusframework.exceptions.CitrusRuntimeException; import org.citrusframework.spi.ReferenceResolverAware; import org.citrusframework.util.ReflectionHelper; -import org.citrusframework.util.TypeConversionUtils; import org.citrusframework.util.StringUtils; +import org.citrusframework.util.TypeConversionUtils; /** * Default endpoint component reads component name from endpoint uri and parses parameters from uri using @@ -59,7 +61,7 @@ public AbstractEndpointComponent(String name) { @Override public Endpoint createEndpoint(String endpointUri, TestContext context) { try { - URI uri = new URI(endpointUri); + URI uri = new URI(resolveEndpointUri(endpointUri)); String path = uri.getSchemeSpecificPart(); if (path.startsWith("//")) { @@ -202,6 +204,15 @@ protected String getParameterString(Map parameters, return paramString.toString(); } + private static String resolveEndpointUri(String endpointUri) { + if (endpointUri.contains("?")) { + String[] tokens = endpointUri.split("\\?", 2); + return tokens[0] + "?" + URLEncoder.encode(tokens[1], StandardCharsets.UTF_8); + } else { + return endpointUri; + } + } + /** * Create endpoint instance from uri resource and parameters. * @param resourcePath