Skip to content

Commit

Permalink
fix: add skip decoding field for rest outbound connector
Browse files Browse the repository at this point in the history
  • Loading branch information
ztefanie committed Jan 10, 2025
1 parent 2fcec35 commit 9d46417
Show file tree
Hide file tree
Showing 8 changed files with 71 additions and 5 deletions.
16 changes: 13 additions & 3 deletions connectors/gitlab/element-templates/gitlab-connector.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
"$schema": "https://unpkg.com/@camunda/zeebe-element-templates-json-schema/resources/schema.json",
"name": "GitLab Outbound Connector",
"id": "io.camunda.connectors.GitLab.v1",
"version": 5,
"version": 6,
"description": "Manage GitLab issues, branches, releases, and more",
"metadata": {
"keywords": [
Expand Down Expand Up @@ -653,8 +653,18 @@
"createAnIssue"
]
}
},
{
}, {
"id" : "skipEncoding",
"label" : "Skip encoding",
"optional" : true,
"group" : "endpoint",
"binding" : {
"name" : "skipEncoding",
"type" : "zeebe:input"
},
"value": "true",
"type" : "Hidden"
}, {
"label": "Issue ID",
"description": "The internal ID of a project’s issue",
"group": "operation",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,6 @@ public class ApacheRequestUriBuilder implements ApacheRequestPartBuilder {

@Override
public void build(ClassicRequestBuilder builder, HttpCommonRequest request) {
builder.setUri(UrlEncoder.toEncodedUri(request.getUrl()));
builder.setUri(UrlEncoder.toEncodedUri(request.getUrl(), request.getSkipEncoding()));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -28,11 +28,14 @@
public class UrlEncoder {
private static final Logger LOG = LoggerFactory.getLogger(ApacheRequestUriBuilder.class);

public static URI toEncodedUri(String requestUrl) {
public static URI toEncodedUri(String requestUrl, Boolean skipEncoding) {
try {
// We try to decode the URL first, because it might be encoded already
// which would lead to double encoding. Decoding is safe here, because it does nothing if
// the URL is not encoded.
if (skipEncoding) {
return URI.create(requestUrl);
}
var decodedUrl = URLDecoder.decode(requestUrl, StandardCharsets.UTF_8);
var url = new URL(decodedUrl);
// Only this URI constructor escapes the URL properly
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -111,6 +111,13 @@ public class HttpCommonRequest {
description = "Store the response as a document in the document store")
private boolean storeResponse;

@TemplateProperty(
type = TemplateProperty.PropertyType.Hidden,
feel = Property.FeelMode.disabled,
group = "endpoint",
optional = true)
private String skipEncoding;

public Object getBody() {
return body;
}
Expand Down Expand Up @@ -139,6 +146,14 @@ public void setQueryParameters(Map<String, String> queryParameters) {
this.queryParameters = queryParameters;
}

public boolean getSkipEncoding() {
return Objects.equals(skipEncoding, "true");
}

public void setSkipEncoding(final String skipEncoding) {
this.skipEncoding = skipEncoding;
}

public boolean hasAuthentication() {
return authentication != null;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -321,6 +321,23 @@ public void shouldReturn200_whenEscapedSpaceInPathAndQueryParametersInPath(
assertThat(result).isNotNull();
assertThat(result.status()).isEqualTo(200);
}

@ParameterizedTest
@EnumSource(HttpMethod.class)
public void shouldKeepOriginalEscaping_whenSkipEscapingIsSet(
HttpMethod method, WireMockRuntimeInfo wmRuntimeInfo) {
stubFor(any(urlEqualTo("/path%2Fwith%2Fencoding")).willReturn(ok()));
stubFor(any(urlEqualTo("/path/with/encoding")).willReturn(badRequest()));
HttpCommonRequest request = new HttpCommonRequest();
request.setMethod(method);
request.setUrl(wmRuntimeInfo.getHttpBaseUrl() + "/path%2Fwith%2Fencoding");
request.setSkipEncoding("true");

HttpCommonResult result = customApacheHttpClient.execute(request);

assertThat(result).isNotNull();
assertThat(result.status()).isEqualTo(200);
}
}

@Nested
Expand Down
10 changes: 10 additions & 0 deletions connectors/http/rest/element-templates/http-json-connector.json
Original file line number Diff line number Diff line change
Expand Up @@ -402,6 +402,16 @@
"type" : "zeebe:input"
},
"type" : "Boolean"
}, {
"id" : "skipEncoding",
"label" : "Skip encoding",
"optional" : true,
"group" : "endpoint",
"binding" : {
"name" : "skipEncoding",
"type" : "zeebe:input"
},
"type" : "Hidden"
}, {
"id" : "connectionTimeoutInSeconds",
"label" : "Connection timeout in seconds",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -407,6 +407,16 @@
"type" : "zeebe:input"
},
"type" : "Boolean"
}, {
"id" : "skipEncoding",
"label" : "Skip encoding",
"optional" : true,
"group" : "endpoint",
"binding" : {
"name" : "skipEncoding",
"type" : "zeebe:input"
},
"type" : "Hidden"
}, {
"id" : "connectionTimeoutInSeconds",
"label" : "Connection timeout in seconds",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@
"authentication",
"headers",
"queryParameters",
"skipEncoding",
"connectionTimeoutInSeconds",
"readTimeoutInSeconds",
"writeTimeoutInSeconds",
Expand Down

0 comments on commit 9d46417

Please sign in to comment.