88
99import jakarta .ws .rs .client .ClientBuilder ;
1010import jakarta .ws .rs .client .Entity ;
11+ import jakarta .ws .rs .core .Form ;
12+ import jakarta .ws .rs .core .Response .Status .Family ;
1113import lombok .AllArgsConstructor ;
1214import lombok .Getter ;
13- import lombok .NoArgsConstructor ;
1415import 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