Get hardcoded values as constats and fix exception error handling

factory-management
Pasindu Rupasinghe 2 years ago
parent ba5effbf65
commit 2ca425819e

@ -179,6 +179,7 @@ public class APIApplicationServicesImpl implements APIApplicationServices {
sc.init(null, trustAllCerts, new java.security.SecureRandom());
return sc.getSocketFactory();
} catch (KeyManagementException | NoSuchAlgorithmException e) {
log.error("Error while creating the SSL socket factory due to " + e.getMessage(), e);
return null;
}

@ -50,7 +50,8 @@ public class PublisherRESTAPIServices {
public JSONObject getScopes(APIApplicationKey apiApplicationKey, AccessTokenInfo accessTokenInfo)
throws APIServicesException, BadRequestException {
String getAllScopesUrl = "https://" + host + ":" + port + Constants.GET_ALL_SCOPES;
String getAllScopesUrl = Constants.HTTPS_PROTOCOL + Constants.SCHEME_SEPARATOR + host + Constants.COLON
+ port + Constants.GET_ALL_SCOPES;
Request request = new Request.Builder()
.url(getAllScopesUrl)
.addHeader(Constants.AUTHORIZATION_HEADER_NAME, Constants.AUTHORIZATION_HEADER_PREFIX_BEARER
@ -87,8 +88,10 @@ public class PublisherRESTAPIServices {
public boolean isSharedScopeNameExists(APIApplicationKey apiApplicationKey, AccessTokenInfo accessTokenInfo, String key)
throws APIServicesException, BadRequestException {
String keyValue = new String(Base64.encodeBase64((key).getBytes())).replace("=", "");
String getScopeUrl = "https://" + host + ":" + port + Constants.GET_SCOPE + keyValue;
String keyValue = new String(Base64.encodeBase64((key).getBytes())).replace(Constants.QUERY_KEY_VALUE_SEPARATOR,
Constants.EMPTY_STRING);
String getScopeUrl = Constants.HTTPS_PROTOCOL + Constants.SCHEME_SEPARATOR + host + Constants.COLON
+ port + Constants.GET_SCOPE + keyValue;
Request request = new Request.Builder()
.url(getScopeUrl)
@ -124,7 +127,8 @@ public class PublisherRESTAPIServices {
public boolean updateSharedScope(APIApplicationKey apiApplicationKey, AccessTokenInfo accessTokenInfo, Scope scope)
throws APIServicesException, BadRequestException {
String updateScopeUrl = "https://" + host + ":" + port + Constants.GET_SCOPE + scope.getId();
String updateScopeUrl = Constants.HTTPS_PROTOCOL + Constants.SCHEME_SEPARATOR + host
+ Constants.COLON + port + Constants.GET_SCOPE + scope.getId();
ScopeUtils scopeUtil = new ScopeUtils();
scopeUtil.setKey(scope.getKey());

@ -53,6 +53,11 @@ public final class Constants {
public static final String PASSWORD_GRANT_TYPE_SCOPES = "scopes";
public static final String ACCESS_TOKEN_GRANT_TYPE_PARAM_NAME = "access_token";
public static final String GRANT_TYPE_PARAM_NAME = "grant_type";
public static final String HTTPS_PROTOCOL = "https";
public static final String HTTP_PROTOCOL = "http";
public static final String SCHEME_SEPARATOR = "://";
public static final String COLON = ":";
public static final String QUERY_KEY_VALUE_SEPARATOR = "=";
public static final String IOT_CORE_HOST = "iot.core.host";
public static final String IOT_CORE_HTTPS_PORT = "iot.core.https.port";
public static final String GET_ALL_SCOPES = "/api/am/publisher/v2/scopes?limit=1000";

@ -433,8 +433,7 @@ public class APIPublisherServiceImpl implements APIPublisherService {
//Set scope id which related to the scope key
JSONArray scopeList = (JSONArray) scopeObject.get("list");
for (int i = 0; i < scopeList.length(); i++) {
JSONObject scopeObj = null;
scopeObj = scopeList.getJSONObject(i);
JSONObject scopeObj = scopeList.getJSONObject(i);
if (scopeObj.getString("name").equals(scopeMapping[2] != null ?
StringUtils.trim(scopeMapping[2]) : StringUtils.EMPTY)) {
scope.setId(scopeObj.getString("id"));

Loading…
Cancel
Save