Skip to content

Commit

Permalink
fix: remove content-type in header from /retrieve GET request #6096
Browse files Browse the repository at this point in the history
Signed-off-by: Arnab Dutta <arnab.bdutta@gmail.com>
  • Loading branch information
duttarnab committed Sep 21, 2023
1 parent 34a5f8f commit 6a6718d
Showing 1 changed file with 25 additions and 30 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -148,13 +148,9 @@ public GenericResponse checkLicense() {
return CommonUtils.createGenericResponse(false, 404, ErrorResponse.LICENSE_NOT_PRESENT.getDescription());

} catch (Exception e) {
if (response.getStatus() == 404) {
log.error("{}", LICENSE_APIS_404);
return CommonUtils.createGenericResponse(false, response.getStatus(), LICENSE_APIS_404);
}
if (response.getStatus() == 503) {
log.error("{}", LICENSE_APIS_503);
return CommonUtils.createGenericResponse(false, response.getStatus(), LICENSE_APIS_503);
GenericResponse genericResponse = handleLicenseApiNotAccessible(response);
if (genericResponse == null) {
return genericResponse;
}
log.error(ErrorResponse.CHECK_LICENSE_ERROR.getDescription(), e);
return CommonUtils.createGenericResponse(false, 500, ErrorResponse.CHECK_LICENSE_ERROR.getDescription());
Expand Down Expand Up @@ -194,7 +190,6 @@ public GenericResponse retrieveLicense() {

Invocation.Builder request = ClientFactory.instance().getClientBuilder(retriveLicenseUrl);
request.header(AUTHORIZATION, BEARER + tokenResponse.getAccessToken());
request.header(CONTENT_TYPE, APPLICATION_JSON);
response = request.get();

log.info("license request status code: {}", response.getStatus());
Expand All @@ -215,7 +210,7 @@ public GenericResponse retrieveLicense() {

if (response.getStatus() == 402) {
log.error("Payment Required: 402");
return CommonUtils.createGenericResponse(false, 402, "Payment Required.");
return CommonUtils.createGenericResponse(false, 402, "Payment Required. Subscribe Admin UI license on Agama Lab.");
}
if (!Strings.isNullOrEmpty(jsonNode.get(MESSAGE).textValue())) {
log.error("{}: {}", LICENSE_RETRIEVE_ERROR_RESPONSE, jsonData);
Expand All @@ -225,13 +220,9 @@ public GenericResponse retrieveLicense() {
return CommonUtils.createGenericResponse(false, 500, ErrorResponse.RETRIEVE_LICENSE_ERROR.getDescription());

} catch (Exception e) {
if (response.getStatus() == 404) {
log.error("{}", LICENSE_APIS_404);
return CommonUtils.createGenericResponse(false, response.getStatus(), LICENSE_APIS_404);
}
if (response.getStatus() == 503) {
log.error("{}", LICENSE_APIS_503);
return CommonUtils.createGenericResponse(false, response.getStatus(), LICENSE_APIS_503);
GenericResponse genericResponse = handleLicenseApiNotAccessible(response);
if (genericResponse == null) {
return genericResponse;
}
log.error(ErrorResponse.CHECK_LICENSE_ERROR.getDescription(), e);
return CommonUtils.createGenericResponse(false, 500, ErrorResponse.RETRIEVE_LICENSE_ERROR.getDescription());
Expand Down Expand Up @@ -306,13 +297,9 @@ public GenericResponse activateLicense(LicenseRequest licenseRequest) {
log.error("{}: {}", LICENSE_ACTIVATE_ERROR_RESPONSE, jsonData);
return CommonUtils.createGenericResponse(false, response.getStatus(), "License is not activated.");
} catch (Exception e) {
if (response.getStatus() == 404) {
log.error("{}", LICENSE_APIS_404);
return CommonUtils.createGenericResponse(false, response.getStatus(), LICENSE_APIS_404);
}
if (response.getStatus() == 503) {
log.error("{}", LICENSE_APIS_503);
return CommonUtils.createGenericResponse(false, response.getStatus(), LICENSE_APIS_503);
GenericResponse genericResponse = handleLicenseApiNotAccessible(response);
if (genericResponse == null) {
return genericResponse;
}
log.error(ErrorResponse.ACTIVATE_LICENSE_ERROR.getDescription(), e);
return CommonUtils.createGenericResponse(false, 500, ErrorResponse.ACTIVATE_LICENSE_ERROR.getDescription());
Expand Down Expand Up @@ -382,13 +369,9 @@ public GenericResponse generateTrialLicense() {
log.error("{}: {}", TRIAL_GENERATE_ERROR_RESPONSE, jsonData);
return CommonUtils.createGenericResponse(false, response.getStatus(), "Error in generating trial license.");
} catch (Exception e) {
if (response.getStatus() == 404) {
log.error("{}", LICENSE_APIS_404);
return CommonUtils.createGenericResponse(false, response.getStatus(), LICENSE_APIS_404);
}
if (response.getStatus() == 503) {
log.error("{}", LICENSE_APIS_503);
return CommonUtils.createGenericResponse(false, response.getStatus(), LICENSE_APIS_503);
GenericResponse genericResponse = handleLicenseApiNotAccessible(response);
if (genericResponse == null) {
return genericResponse;
}
log.error(ErrorResponse.ERROR_IN_TRIAL_LICENSE.getDescription(), e);
return CommonUtils.createGenericResponse(false, 500, ErrorResponse.ERROR_IN_TRIAL_LICENSE.getDescription());
Expand Down Expand Up @@ -508,4 +491,16 @@ private io.jans.as.client.TokenResponse generateToken(String opHost, String clie
return null;
}
}

private GenericResponse handleLicenseApiNotAccessible(Response response) {
if (response.getStatus() == 404) {
log.error("{}", LICENSE_APIS_404);
return CommonUtils.createGenericResponse(false, response.getStatus(), LICENSE_APIS_404);
}
if (response.getStatus() == 503) {
log.error("{}", LICENSE_APIS_503);
return CommonUtils.createGenericResponse(false, response.getStatus(), LICENSE_APIS_503);
}
return null;
}
}

0 comments on commit 6a6718d

Please sign in to comment.