Skip to content

Commit 2c6099e

Browse files
authored
Merge pull request #48 from camporter/fix_createobjects_calls
Make sure calls to createObjects explicitly include the method name in the URL
2 parents 9d19560 + c71832b commit 2c6099e

File tree

2 files changed

+26
-5
lines changed

2 files changed

+26
-5
lines changed

src/main/java/com/softlayer/api/RestApiClient.java

Lines changed: 25 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,18 @@ public class RestApiClient implements ApiClient {
4141
static {
4242
HEADERS = Collections.singletonMap("SoftLayer-Include-Types", Collections.singletonList("true"));
4343
}
44+
45+
/**
46+
* A list of service methods that do not have to be added to the REST URL.
47+
* createObjects is supposed to work, but does not.
48+
*/
49+
private static final List<String> IMPLICIT_SERVICE_METHODS = Arrays.asList(
50+
"getObject",
51+
"deleteObject",
52+
"createObject",
53+
"editObject",
54+
"editObjects"
55+
);
4456

4557
private final String baseUrl;
4658
private HttpClientFactory httpClientFactory;
@@ -135,7 +147,18 @@ protected String getHttpMethodFromMethodName(String methodName) {
135147
return "GET";
136148
}
137149
}
138-
150+
151+
/**
152+
* Get the full REST URL required to make a request.
153+
*
154+
* @param serviceName The name of the API service.
155+
* @param methodName The name of the method on the service to call.
156+
* @param id The identifier of the object to make a call to,
157+
* otherwise null if not making a request to a specific object.
158+
* @param resultLimit The number of results to limit the request to.
159+
* @param maskString The mask, in string form, to use on the request.
160+
* @return String
161+
*/
139162
protected String getFullUrl(String serviceName, String methodName, String id,
140163
ResultLimit resultLimit, String maskString) {
141164
StringBuilder url = new StringBuilder(baseUrl + serviceName);
@@ -146,9 +169,7 @@ protected String getFullUrl(String serviceName, String methodName, String id,
146169
// Some method names are not included, others can have the "get" stripped
147170
if (methodName.startsWith("get") && !"getObject".equals(methodName)) {
148171
url.append('/').append(methodName.substring(3));
149-
} else if (!"getObject".equals(methodName) && !"deleteObject".equals(methodName) &&
150-
!"createObject".equals(methodName) && !"createObjects".equals(methodName) &&
151-
!"editObject".equals(methodName) && !"editObjects".equals(methodName)) {
172+
} else if (!IMPLICIT_SERVICE_METHODS.contains(methodName)) {
152173
url.append('/').append(methodName);
153174
}
154175
url.append(".json");

src/test/java/com/softlayer/api/RestApiClientTest.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,7 @@ public void testGetFullUrl() {
6363
client.getFullUrl("SomeService", "deleteObject", null, null, null));
6464
assertEquals("http://example.com/SomeService.json",
6565
client.getFullUrl("SomeService", "createObject", null, null, null));
66-
assertEquals("http://example.com/SomeService.json",
66+
assertEquals("http://example.com/SomeService/createObjects.json",
6767
client.getFullUrl("SomeService", "createObjects", null, null, null));
6868
assertEquals("http://example.com/SomeService.json",
6969
client.getFullUrl("SomeService", "editObject", null, null, null));

0 commit comments

Comments
 (0)