|
|
@ -45,15 +45,13 @@ public class PublisherRESTAPIServices {
|
|
|
|
private static final Log log = LogFactory.getLog(PublisherRESTAPIServices.class);
|
|
|
|
private static final Log log = LogFactory.getLog(PublisherRESTAPIServices.class);
|
|
|
|
private static final OkHttpClient client = getOkHttpClient();
|
|
|
|
private static final OkHttpClient client = getOkHttpClient();
|
|
|
|
private static final MediaType JSON = MediaType.parse("application/json; charset=utf-8");
|
|
|
|
private static final MediaType JSON = MediaType.parse("application/json; charset=utf-8");
|
|
|
|
|
|
|
|
|
|
|
|
private static final String host = System.getProperty(Constants.IOT_CORE_HOST);
|
|
|
|
private static final String host = System.getProperty(Constants.IOT_CORE_HOST);
|
|
|
|
private static final String port = System.getProperty(Constants.IOT_CORE_HTTPS_PORT);
|
|
|
|
private static final String port = System.getProperty(Constants.IOT_CORE_HTTPS_PORT);
|
|
|
|
|
|
|
|
|
|
|
|
public JSONObject getScopes(APIApplicationKey apiApplicationKey, AccessTokenInfo accessTokenInfo)
|
|
|
|
public JSONObject getScopes(APIApplicationKey apiApplicationKey, AccessTokenInfo accessTokenInfo)
|
|
|
|
throws APIServicesException, BadRequestException {
|
|
|
|
throws APIServicesException, BadRequestException {
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
String getAllScopesUrl = "https://" + host + ":" + port + Constants.GET_ALL_SCOPES;
|
|
|
|
String getAllScopesUrl = "https://" + "://" + host + ":" + port + Constants.GET_ALL_SCOPES;
|
|
|
|
|
|
|
|
Request request = new Request.Builder()
|
|
|
|
Request request = new Request.Builder()
|
|
|
|
.url(getAllScopesUrl)
|
|
|
|
.url(getAllScopesUrl)
|
|
|
|
.addHeader(Constants.AUTHORIZATION_HEADER_NAME, Constants.AUTHORIZATION_HEADER_PREFIX_BEARER
|
|
|
|
.addHeader(Constants.AUTHORIZATION_HEADER_NAME, Constants.AUTHORIZATION_HEADER_PREFIX_BEARER
|
|
|
@ -90,16 +88,17 @@ public class PublisherRESTAPIServices {
|
|
|
|
throws APIServicesException, BadRequestException {
|
|
|
|
throws APIServicesException, BadRequestException {
|
|
|
|
|
|
|
|
|
|
|
|
String keyValue = new String(Base64.encodeBase64((key).getBytes())).replace("=", "");
|
|
|
|
String keyValue = new String(Base64.encodeBase64((key).getBytes())).replace("=", "");
|
|
|
|
String getScopeUrl = "https://" + "://" + host + ":" + port + Constants.GET_SCOPE + keyValue;
|
|
|
|
String getScopeUrl = "https://" + host + ":" + port + Constants.GET_SCOPE + keyValue;
|
|
|
|
|
|
|
|
|
|
|
|
Request request = new Request.Builder()
|
|
|
|
Request request = new Request.Builder()
|
|
|
|
.url(getScopeUrl)
|
|
|
|
.url(getScopeUrl)
|
|
|
|
.addHeader(Constants.AUTHORIZATION_HEADER_NAME, "Bearer " + accessTokenInfo.getAccess_token())
|
|
|
|
.addHeader(Constants.AUTHORIZATION_HEADER_NAME, Constants.AUTHORIZATION_HEADER_PREFIX_BEARER
|
|
|
|
|
|
|
|
+ accessTokenInfo.getAccess_token())
|
|
|
|
.head()
|
|
|
|
.head()
|
|
|
|
.build();
|
|
|
|
.build();
|
|
|
|
try {
|
|
|
|
try {
|
|
|
|
Response response = client.newCall(request).execute();
|
|
|
|
Response response = client.newCall(request).execute();
|
|
|
|
if (response.code() == HttpStatus.SC_OK) {
|
|
|
|
if (HttpStatus.SC_OK == response.code()) {
|
|
|
|
return true;
|
|
|
|
return true;
|
|
|
|
} else if (HttpStatus.SC_UNAUTHORIZED == response.code()) {
|
|
|
|
} else if (HttpStatus.SC_UNAUTHORIZED == response.code()) {
|
|
|
|
APIApplicationServices apiApplicationServices = new APIApplicationServicesImpl();
|
|
|
|
APIApplicationServices apiApplicationServices = new APIApplicationServicesImpl();
|
|
|
@ -124,7 +123,7 @@ public class PublisherRESTAPIServices {
|
|
|
|
public boolean updateSharedScope(APIApplicationKey apiApplicationKey, AccessTokenInfo accessTokenInfo, Scope scope)
|
|
|
|
public boolean updateSharedScope(APIApplicationKey apiApplicationKey, AccessTokenInfo accessTokenInfo, Scope scope)
|
|
|
|
throws APIServicesException, BadRequestException {
|
|
|
|
throws APIServicesException, BadRequestException {
|
|
|
|
|
|
|
|
|
|
|
|
String updateScopeUrl = "https://" + "://" + host + ":" + port + Constants.GET_SCOPE + scope.getId();
|
|
|
|
String updateScopeUrl = "https://" + host + ":" + port + Constants.GET_SCOPE + scope.getId();
|
|
|
|
|
|
|
|
|
|
|
|
ScopeUtils scopeUtil = new ScopeUtils();
|
|
|
|
ScopeUtils scopeUtil = new ScopeUtils();
|
|
|
|
scopeUtil.setKey(scope.getKey());
|
|
|
|
scopeUtil.setKey(scope.getKey());
|
|
|
@ -136,13 +135,14 @@ public class PublisherRESTAPIServices {
|
|
|
|
RequestBody requestBody = RequestBody.create(JSON, scopeString);
|
|
|
|
RequestBody requestBody = RequestBody.create(JSON, scopeString);
|
|
|
|
Request request = new Request.Builder()
|
|
|
|
Request request = new Request.Builder()
|
|
|
|
.url(updateScopeUrl)
|
|
|
|
.url(updateScopeUrl)
|
|
|
|
.addHeader(Constants.AUTHORIZATION_HEADER_NAME, "Bearer " + accessTokenInfo.getAccess_token())
|
|
|
|
.addHeader(Constants.AUTHORIZATION_HEADER_NAME, Constants.AUTHORIZATION_HEADER_PREFIX_BEARER
|
|
|
|
|
|
|
|
+ accessTokenInfo.getAccess_token())
|
|
|
|
.put(requestBody)
|
|
|
|
.put(requestBody)
|
|
|
|
.build();
|
|
|
|
.build();
|
|
|
|
|
|
|
|
|
|
|
|
try {
|
|
|
|
try {
|
|
|
|
Response response = client.newCall(request).execute();
|
|
|
|
Response response = client.newCall(request).execute();
|
|
|
|
if (response.code() == HttpStatus.SC_OK) {
|
|
|
|
if (HttpStatus.SC_OK == response.code()) {
|
|
|
|
return true;
|
|
|
|
return true;
|
|
|
|
} else if (HttpStatus.SC_UNAUTHORIZED == response.code()) {
|
|
|
|
} else if (HttpStatus.SC_UNAUTHORIZED == response.code()) {
|
|
|
|
APIApplicationServices apiApplicationServices = new APIApplicationServicesImpl();
|
|
|
|
APIApplicationServices apiApplicationServices = new APIApplicationServicesImpl();
|
|
|
|