Skip to content

Commit 65dda0f

Browse files
committed
Shaphat wants url-encoded form empty bodies or it throws 405. Assuming SF was wanting empty JSON.
1 parent 10676c6 commit 65dda0f

File tree

1 file changed

+11
-9
lines changed
  • rest-client/src/main/java/com/compassion/commons/rest/client/auth

1 file changed

+11
-9
lines changed

rest-client/src/main/java/com/compassion/commons/rest/client/auth/AccessToken.java

Lines changed: 11 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -8,9 +8,10 @@
88

99
import jakarta.ws.rs.client.ClientBuilder;
1010
import jakarta.ws.rs.client.Entity;
11+
import jakarta.ws.rs.core.Form;
12+
import jakarta.ws.rs.core.Response.Status.Family;
1113
import lombok.AllArgsConstructor;
1214
import lombok.Getter;
13-
import lombok.NoArgsConstructor;
1415
import lombok.extern.log4j.Log4j2;
1516

1617
@Log4j2
@@ -20,12 +21,12 @@ public static IAccessToken acquire(OAuthMethod method, OAuthAwareConfig config)
2021

2122
try (var client = new RestClient(ClientBuilder.newBuilder())) {
2223
var ret = client.request(RecursiveTarget.newTarget(config.baseUrl()), config.authCreds())
23-
.post(Entity.json(null));
24+
.post(method.getRequestBody());
2425

25-
if (ret.getStatus() < 200 || ret.getStatus() >= 300) {
26-
throw new IOException(
27-
String.format("Retrieving access token failed with status code %d and details: %s", ret.getStatus(), ret.readEntity(String.class)));
28-
}
26+
if (ret.getStatusInfo().getFamily() != Family.SUCCESSFUL) {
27+
throw new IOException(
28+
String.format("Retrieving access token failed with status code %d and details: %s", ret.getStatus(), ret.readEntity(String.class)));
29+
}
2930
return ret.readEntity(method.getPojo());
3031
}
3132
}
@@ -35,12 +36,13 @@ public interface IAccessToken {
3536
WebParam providedSessionCreds();
3637
}
3738

38-
@NoArgsConstructor @AllArgsConstructor @Getter
39+
@AllArgsConstructor @Getter
3940
public enum OAuthMethod {
40-
SALESFORCE(SFSessionResponse.class),
41-
OATMEAL(OatmealSessionResponse.class);
41+
SALESFORCE(SFSessionResponse.class, Entity.json(null)),
42+
OATMEAL(OatmealSessionResponse.class, Entity.form(new Form()));
4243

4344
private Class<? extends IAccessToken> pojo;
45+
private Entity<?> requestBody;
4446
}
4547

4648
public interface OAuthAwareConfig {

0 commit comments

Comments
 (0)