Skip to content

Commit

Permalink
Today, all GET URL parameters are URL encoded in DIL. (#77)
Browse files Browse the repository at this point in the history
https://github.com/linkedin/data-integration-library/blob/master/docs/parameters/ms.http.request.method.md

This change adds a new GET_XE ms.http.request method which will not encode URL parameters.
This is a hidden feature. That's why no update to documentation.
  • Loading branch information
booddu authored Nov 2, 2022
1 parent 6177daf commit 270600d
Show file tree
Hide file tree
Showing 2 changed files with 71 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,27 @@
*/

public enum HttpRequestMethod {
/**
* Note: This works when the URI template has all the variable parameters.
* If there are any additional parameters, then URIBuilder encodes all parameters while building.
*/
GET_XE("GET_XE") {
@Override
protected HttpUriRequest getHttpRequestContentJson(String uriTemplate,
JsonObject parameters, JsonObject payloads)
throws UnsupportedEncodingException {
Pair<String, JsonObject> replaced = VariableUtils.replaceWithTracking(uriTemplate, parameters, false);
//ignore payloads
return new HttpGet(appendParameters(replaced.getKey(), replaced.getValue()));
}

@Override
protected HttpUriRequest getHttpRequestContentUrlEncoded(String uriTemplate, JsonObject parameters)
throws UnsupportedEncodingException {
return getHttpRequestContentJson(uriTemplate, parameters, new JsonObject());
}
},

GET("GET") {
@Override
protected HttpUriRequest getHttpRequestContentJson(String uriTemplate,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,8 @@ public class HttpRequestMethodTest extends PowerMockTestCase {
final static String CONTENT_TYPE = "Content-Type";
final static String CONTENT_TYPE_VALUE = "application/x-www-form-urlencoded";
final static String BASE_URI = "https://domain/%s/calls";
final static String BASE_URI_WITH_ONLYFROM_PARAMS = "https://domain/%s/calls?fdt=%s";
final static String BASE_URI_WITH_TOANDFROM_PARAMS = "https://domain/%s/calls?fdt=%s&tdt=%s";
private static Gson gson = new Gson();
private Map<String, String> headers;
private String expected;
Expand All @@ -67,6 +69,54 @@ public void setUp() {
headers = new HashMap<>();
}

/**
* Test HttpGet_xe method with parameters
* Note: This works when the URI template has all the variable parameters.
* If there are any additional parameters, then URIBuilder encodes all parameters while building.
*
* @throws UnsupportedEncodingException
*/
/*
@Test
public void testGetXeHttpGetRequest1() throws UnsupportedEncodingException {
expected = String.format(
"%s %s %s",
"GET",
String.format(BASE_URI_WITH_TOANDFROM_PARAMS, VERSION_2, FROM_DATETIME, URLEncoder.encode(TO_DATETIME, StandardCharsets.UTF_8.toString())),
HTTP_POST_FIX);
parameters = generateParameterString(FROM_DATETIME, TO_DATETIME, VERSION_2);
String uriTemplate = String.format(BASE_URI_WITH_ONLYFROM_PARAMS, "{{version}}", "{{fromDateTime}}");
HttpUriRequest getRequest =
HttpRequestMethod.GET_XE.getHttpRequest(
uriTemplate, parameters, headers);
Assert.assertEquals(getRequest.toString(), expected);
addContentType();
getRequest = HttpRequestMethod.GET_XE.getHttpRequest(uriTemplate, parameters, headers);
Assert.assertEquals(getRequest.toString(), expected);
}
*/
@Test
public void testGetXeHttpGetRequest() throws UnsupportedEncodingException {
expected = String.format(
"%s %s %s",
"GET",
String.format(BASE_URI_WITH_TOANDFROM_PARAMS, VERSION_2, FROM_DATETIME, TO_DATETIME),
HTTP_POST_FIX);
parameters = generateParameterString(FROM_DATETIME, TO_DATETIME, VERSION_2);
String uriTemplate = String.format(BASE_URI_WITH_TOANDFROM_PARAMS, "{{version}}", "{{fromDateTime}}", "{{toDateTime}}");

HttpUriRequest getRequest =
HttpRequestMethod.GET_XE.getHttpRequest(
uriTemplate, parameters, headers);
Assert.assertEquals(getRequest.toString(), expected);

addContentType();
getRequest = HttpRequestMethod.GET_XE.getHttpRequest(uriTemplate, parameters, headers);
Assert.assertEquals(getRequest.toString(), expected);
}

/**
* Test HttpGet method with parameters
* @throws UnsupportedEncodingException
Expand Down

0 comments on commit 270600d

Please sign in to comment.