Skip to content

Commit d9e0216

Browse files
revert: remove URL encoding and raw body from InvokeConnection
URL encoding path/query params is a breaking change for users who pre-encode values (double-encoding), and Go SDK v1/v2 does raw substitution with no encoding — keep consistent. Raw string body support is not confirmed by the Connections API docs; the gateway needs structured (JSON/form) bodies for token replacement, so raw strings would forward tokens unreplaced. Remove to avoid misleading users. Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
1 parent e42aa8d commit d9e0216

6 files changed

Lines changed: 14 additions & 110 deletions

File tree

src/main/java/com/skyflow/utils/Constants.java

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,6 @@ public final class Constants {
4040
public static final String QUOTE = "\"";
4141

4242
public static final class HttpUtilityExtra {
43-
public static final String RAW_BODY_KEY = "__raw_body__";
4443
public static final String SDK_GENERATED_PREFIX = "SDK-Generated-";
4544
private HttpUtilityExtra() {}
4645
}

src/main/java/com/skyflow/utils/HttpUtility.java

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -57,9 +57,7 @@ public static String sendRequest(String method, URL url, JsonObject params, Map<
5757
byte[] input = null;
5858
String requestContentType = connection.getRequestProperty("content-type");
5959

60-
if (params.has(Constants.HttpUtilityExtra.RAW_BODY_KEY) && params.size() == 1) {
61-
input = params.get(Constants.HttpUtilityExtra.RAW_BODY_KEY).getAsString().getBytes(StandardCharsets.UTF_8);
62-
} else if (requestContentType != null && requestContentType.contains("application/x-www-form-urlencoded")) {
60+
if (requestContentType != null && requestContentType.contains("application/x-www-form-urlencoded")) {
6361
input = formatJsonToFormEncodedString(params).getBytes(StandardCharsets.UTF_8);
6462
} else if (requestContentType != null && requestContentType.contains("multipart/form-data")) {
6563
input = formatJsonToMultiPartFormDataString(params, boundary).getBytes(StandardCharsets.UTF_8);

src/main/java/com/skyflow/utils/Utils.java

Lines changed: 2 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -17,8 +17,6 @@
1717
import java.io.File;
1818
import java.net.MalformedURLException;
1919
import java.net.URL;
20-
import java.net.URLEncoder;
21-
import java.nio.charset.StandardCharsets;
2220
import java.security.KeyFactory;
2321
import java.security.NoSuchAlgorithmException;
2422
import java.security.PrivateKey;
@@ -121,12 +119,7 @@ public static String constructConnectionURL(ConnectionConfig config, InvokeConne
121119
for (Map.Entry<String, String> entry : invokeConnectionRequest.getPathParams().entrySet()) {
122120
String key = entry.getKey();
123121
String value = entry.getValue();
124-
try {
125-
String encodedValue = URLEncoder.encode(value, StandardCharsets.UTF_8.name());
126-
filledURL = new StringBuilder(filledURL.toString().replace(String.format(Constants.CURLY_PLACEHOLDER, key), encodedValue));
127-
} catch (Exception e) {
128-
filledURL = new StringBuilder(filledURL.toString().replace(String.format(Constants.CURLY_PLACEHOLDER, key), value));
129-
}
122+
filledURL = new StringBuilder(filledURL.toString().replace(String.format(Constants.CURLY_PLACEHOLDER, key), value));
130123
}
131124
}
132125

@@ -135,13 +128,7 @@ public static String constructConnectionURL(ConnectionConfig config, InvokeConne
135128
for (Map.Entry<String, String> entry : invokeConnectionRequest.getQueryParams().entrySet()) {
136129
String key = entry.getKey();
137130
String value = entry.getValue();
138-
try {
139-
String encodedKey = URLEncoder.encode(key, StandardCharsets.UTF_8.name());
140-
String encodedValue = URLEncoder.encode(value, StandardCharsets.UTF_8.name());
141-
filledURL.append(encodedKey).append("=").append(encodedValue).append("&");
142-
} catch (Exception e) {
143-
filledURL.append(key).append("=").append(value).append("&");
144-
}
131+
filledURL.append(key).append("=").append(value).append("&");
145132
}
146133
filledURL = new StringBuilder(filledURL.substring(0, filledURL.length() - 1));
147134
}

src/main/java/com/skyflow/utils/validations/Validations.java

Lines changed: 6 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,6 @@
1010
import java.util.regex.Pattern;
1111

1212
import com.google.gson.Gson;
13-
import com.google.gson.JsonElement;
1413
import com.google.gson.JsonObject;
1514
import com.skyflow.config.ConnectionConfig;
1615
import com.skyflow.config.Credentials;
@@ -150,24 +149,12 @@ public static void validateInvokeConnectionRequest(InvokeConnectionRequest invok
150149
if (requestBody.getClass().equals(Object.class)) {
151150
return;
152151
}
153-
if (requestBody instanceof String) {
154-
String bodyStr = (String) requestBody;
155-
if (bodyStr.trim().isEmpty()) {
156-
LogUtil.printErrorLog(Utils.parameterizedString(
157-
ErrorLogs.EMPTY_REQUEST_BODY.getLog(), InterfaceName.INVOKE_CONNECTION.getName()));
158-
throw new SkyflowException(ErrorCode.INVALID_INPUT.getCode(), ErrorMessage.EmptyRequestBody.getMessage());
159-
}
160-
} else {
161-
Gson gson = new Gson();
162-
JsonElement bodyElement = gson.toJsonTree(requestBody);
163-
if (bodyElement.isJsonObject()) {
164-
JsonObject bodyObject = bodyElement.getAsJsonObject();
165-
if (bodyObject.isEmpty()) {
166-
LogUtil.printErrorLog(Utils.parameterizedString(
167-
ErrorLogs.EMPTY_REQUEST_BODY.getLog(), InterfaceName.INVOKE_CONNECTION.getName()));
168-
throw new SkyflowException(ErrorCode.INVALID_INPUT.getCode(), ErrorMessage.EmptyRequestBody.getMessage());
169-
}
170-
}
152+
Gson gson = new Gson();
153+
JsonObject bodyObject = gson.toJsonTree(requestBody).getAsJsonObject();
154+
if (bodyObject.isEmpty()) {
155+
LogUtil.printErrorLog(Utils.parameterizedString(
156+
ErrorLogs.EMPTY_REQUEST_BODY.getLog(), InterfaceName.INVOKE_CONNECTION.getName()));
157+
throw new SkyflowException(ErrorCode.INVALID_INPUT.getCode(), ErrorMessage.EmptyRequestBody.getMessage());
171158
}
172159
}
173160
}

src/main/java/com/skyflow/vault/controller/ConnectionController.java

Lines changed: 5 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -55,26 +55,11 @@ public InvokeConnectionResponse invoke(InvokeConnectionRequest invokeConnectionR
5555
Object requestBodyObject = invokeConnectionRequest.getRequestBody();
5656

5757
if (requestBodyObject != null) {
58-
if (requestBodyObject instanceof String) {
59-
String contentType = headers.getOrDefault("content-type", "");
60-
if (!contentType.isEmpty() && !contentType.toLowerCase().contains("application/json")) {
61-
requestBody = new JsonObject();
62-
requestBody.addProperty(Constants.HttpUtilityExtra.RAW_BODY_KEY, (String) requestBodyObject);
63-
} else {
64-
try {
65-
requestBody = convertObjectToJson(requestBodyObject);
66-
} catch (Exception e) {
67-
LogUtil.printErrorLog(ErrorLogs.INVALID_REQUEST_HEADERS.getLog());
68-
throw new SkyflowException(ErrorCode.INVALID_INPUT.getCode(), ErrorMessage.InvalidRequestBody.getMessage());
69-
}
70-
}
71-
} else {
72-
try {
73-
requestBody = convertObjectToJson(requestBodyObject);
74-
} catch (Exception e) {
75-
LogUtil.printErrorLog(ErrorLogs.INVALID_REQUEST_HEADERS.getLog());
76-
throw new SkyflowException(ErrorCode.INVALID_INPUT.getCode(), ErrorMessage.InvalidRequestBody.getMessage());
77-
}
58+
try {
59+
requestBody = convertObjectToJson(requestBodyObject);
60+
} catch (Exception e) {
61+
LogUtil.printErrorLog(ErrorLogs.INVALID_REQUEST_HEADERS.getLog());
62+
throw new SkyflowException(ErrorCode.INVALID_INPUT.getCode(), ErrorMessage.InvalidRequestBody.getMessage());
7863
}
7964
}
8065

src/test/java/com/skyflow/vault/controller/ConnectionControllerTests.java

Lines changed: 0 additions & 52 deletions
Original file line numberDiff line numberDiff line change
@@ -137,44 +137,6 @@ public void testInvoke_successWithPutMethod() throws Exception {
137137
Assert.assertNotNull(response);
138138
}
139139

140-
@Test
141-
public void testInvoke_successWithStringBodyAndJsonContentType() throws Exception {
142-
when(HttpUtility.sendRequest(anyString(), any(URL.class), any(), any()))
143-
.thenReturn("{\"parsed\":true}");
144-
when(HttpUtility.getRequestID()).thenReturn(REQUEST_ID);
145-
146-
Map<String, String> headers = new HashMap<>();
147-
headers.put("content-type", "application/json");
148-
149-
InvokeConnectionRequest request = InvokeConnectionRequest.builder()
150-
.method(RequestMethod.POST)
151-
.requestHeaders(headers)
152-
.requestBody("{\"key\":\"value\"}")
153-
.build();
154-
InvokeConnectionResponse response = controller.invoke(request);
155-
156-
Assert.assertNotNull(response);
157-
}
158-
159-
@Test
160-
public void testInvoke_successWithStringBodyAndNonJsonContentType() throws Exception {
161-
when(HttpUtility.sendRequest(anyString(), any(URL.class), any(), any()))
162-
.thenReturn("ok");
163-
when(HttpUtility.getRequestID()).thenReturn(REQUEST_ID);
164-
165-
Map<String, String> headers = new HashMap<>();
166-
headers.put("content-type", "text/plain");
167-
168-
InvokeConnectionRequest request = InvokeConnectionRequest.builder()
169-
.method(RequestMethod.POST)
170-
.requestHeaders(headers)
171-
.requestBody("raw body content")
172-
.build();
173-
InvokeConnectionResponse response = controller.invoke(request);
174-
175-
Assert.assertNotNull(response);
176-
}
177-
178140
@Test
179141
public void testInvoke_successWithObjectBody() throws Exception {
180142
when(HttpUtility.sendRequest(anyString(), any(URL.class), any(), any()))
@@ -364,20 +326,6 @@ public void testInvoke_emptyQueryParamsThrowsSkyflowException() {
364326
}
365327
}
366328

367-
@Test
368-
public void testInvoke_emptyStringBodyThrowsSkyflowException() {
369-
try {
370-
InvokeConnectionRequest request = InvokeConnectionRequest.builder()
371-
.requestBody(" ")
372-
.build();
373-
controller.invoke(request);
374-
Assert.fail(EXCEPTION_NOT_THROWN);
375-
} catch (SkyflowException e) {
376-
Assert.assertEquals(ErrorCode.INVALID_INPUT.getCode(), e.getHttpCode());
377-
Assert.assertEquals(ErrorMessage.EmptyRequestBody.getMessage(), e.getMessage());
378-
}
379-
}
380-
381329
@Test
382330
public void testInvoke_emptyHashMapBodyThrowsSkyflowException() {
383331
try {

0 commit comments

Comments
 (0)