Improve get all api method to accept header params

pull/142/head
Pasindu Rupasinghe 1 year ago
parent a8d45ee41a
commit 45d98d5e49

@ -49,7 +49,7 @@ public interface ConsumerRESTAPIServices {
throws APIServicesException, BadRequestException, UnexpectedResponseException; throws APIServicesException, BadRequestException, UnexpectedResponseException;
APIInfo[] getAllApis(APIApplicationKey apiApplicationKey, AccessTokenInfo accessTokenInfo, APIInfo[] getAllApis(APIApplicationKey apiApplicationKey, AccessTokenInfo accessTokenInfo,
Map<String, String> queryParam) Map<String, String> queryParam, Map<String, String> headerParams)
throws APIServicesException, BadRequestException, UnexpectedResponseException; throws APIServicesException, BadRequestException, UnexpectedResponseException;
Subscription createSubscription(APIApplicationKey apiApplicationKey, AccessTokenInfo accessTokenInfo, Subscription createSubscription(APIApplicationKey apiApplicationKey, AccessTokenInfo accessTokenInfo,

@ -224,7 +224,7 @@ public class ConsumerRESTAPIServicesImpl implements ConsumerRESTAPIServices {
@Override @Override
public APIInfo[] getAllApis(APIApplicationKey apiApplicationKey, AccessTokenInfo accessTokenInfo, public APIInfo[] getAllApis(APIApplicationKey apiApplicationKey, AccessTokenInfo accessTokenInfo,
Map<String, String> queryParams) Map<String, String> queryParams, Map<String, String> headerParams)
throws APIServicesException, BadRequestException, UnexpectedResponseException { throws APIServicesException, BadRequestException, UnexpectedResponseException {
String getAPIsURL = endPointPrefix + Constants.DEV_PORTAL_API; String getAPIsURL = endPointPrefix + Constants.DEV_PORTAL_API;
@ -233,12 +233,15 @@ public class ConsumerRESTAPIServicesImpl implements ConsumerRESTAPIServices {
getAPIsURL = getAPIsURL + Constants.AMPERSAND + query.getKey() + Constants.EQUAL + query.getValue(); getAPIsURL = getAPIsURL + Constants.AMPERSAND + query.getKey() + Constants.EQUAL + query.getValue();
} }
Request request = new Request.Builder() Request.Builder builder = new Request.Builder();
.url(getAPIsURL) builder.url(getAPIsURL);
.addHeader(Constants.AUTHORIZATION_HEADER_NAME, Constants.AUTHORIZATION_HEADER_PREFIX_BEARER builder.addHeader(Constants.AUTHORIZATION_HEADER_NAME, Constants.AUTHORIZATION_HEADER_PREFIX_BEARER
+ accessTokenInfo.getAccess_token()) + accessTokenInfo.getAccess_token());
.get() for (Map.Entry<String, String> header : headerParams.entrySet()) {
.build(); builder.addHeader(header.getKey(), header.getValue());
}
builder.get();
Request request = builder.build();
try { try {
Response response = client.newCall(request).execute(); Response response = client.newCall(request).execute();
@ -251,7 +254,7 @@ public class ConsumerRESTAPIServicesImpl implements ConsumerRESTAPIServices {
generateAccessTokenFromRefreshToken(accessTokenInfo.getRefresh_token(), generateAccessTokenFromRefreshToken(accessTokenInfo.getRefresh_token(),
apiApplicationKey.getClientId(), apiApplicationKey.getClientSecret()); apiApplicationKey.getClientId(), apiApplicationKey.getClientSecret());
//TODO: max attempt count //TODO: max attempt count
return getAllApis(apiApplicationKey, refreshedAccessToken, queryParams); return getAllApis(apiApplicationKey, refreshedAccessToken, queryParams, headerParams);
} else if (HttpStatus.SC_BAD_REQUEST == response.code()) { } else if (HttpStatus.SC_BAD_REQUEST == response.code()) {
String msg = "Bad Request, Invalid request"; String msg = "Bad Request, Invalid request";
log.error(msg); log.error(msg);

Loading…
Cancel
Save