use of org.wso2.carbon.apimgt.api.APIMgtResourceNotFoundException in project carbon-apimgt by wso2.
the class CertificateRestApiUtils method preValidateClientCertificate.
/**
* To pre validate client certificate given for an alias
*
* @param alias Alias of the certificate.
* @param apiIdentifier Identifier of the API.
* @param organization Identifier of the organization.
* @return Client certificate
* @throws APIManagementException API Management Exception.
*/
public static ClientCertificateDTO preValidateClientCertificate(String alias, APIIdentifier apiIdentifier, String organization) throws APIManagementException {
int tenantId = APIUtil.getInternalOrganizationId(organization);
if (StringUtils.isEmpty(alias)) {
throw new APIManagementException("The alias cannot be empty", ExceptionCodes.ALIAS_CANNOT_BE_EMPTY);
}
APIProvider apiProvider = RestApiCommonUtil.getLoggedInUserProvider();
ClientCertificateDTO clientCertificate = apiProvider.getClientCertificate(tenantId, alias, apiIdentifier, organization);
if (clientCertificate == null) {
if (log.isDebugEnabled()) {
log.debug(String.format("Could not find a client certificate in truststore which belongs to " + "tenant : %d and with alias : %s. Hence the operation is terminated.", tenantId, alias));
}
String message = "Certificate for alias '" + alias + "' is not found.";
throw new APIMgtResourceNotFoundException(message);
}
return clientCertificate;
}
use of org.wso2.carbon.apimgt.api.APIMgtResourceNotFoundException in project carbon-apimgt by wso2.
the class ApiProductsApiServiceImpl method updateAPIProductDeployment.
@Override
public Response updateAPIProductDeployment(String apiProductId, String deploymentId, APIRevisionDeploymentDTO apIRevisionDeploymentDTO, MessageContext messageContext) throws APIManagementException {
APIProvider apiProvider = RestApiCommonUtil.getLoggedInUserProvider();
String revisionId = apIRevisionDeploymentDTO.getRevisionUuid();
String decodedDeploymentName;
if (deploymentId != null) {
try {
decodedDeploymentName = new String(Base64.getUrlDecoder().decode(deploymentId), StandardCharsets.UTF_8);
} catch (IllegalArgumentException e) {
throw new APIMgtResourceNotFoundException("deployment with " + deploymentId + " not found", ExceptionCodes.from(ExceptionCodes.EXISTING_DEPLOYMENT_NOT_FOUND, deploymentId));
}
} else {
throw new APIMgtResourceNotFoundException("deployment id not found", ExceptionCodes.from(ExceptionCodes.DEPLOYMENT_ID_NOT_FOUND));
}
APIRevisionDeployment apiRevisionDeployment = new APIRevisionDeployment();
apiRevisionDeployment.setRevisionUUID(revisionId);
apiRevisionDeployment.setDeployment(decodedDeploymentName);
apiRevisionDeployment.setVhost(apIRevisionDeploymentDTO.getVhost());
apiRevisionDeployment.setDisplayOnDevportal(apIRevisionDeploymentDTO.isDisplayOnDevportal());
apiProvider.updateAPIProductDisplayOnDevportal(apiProductId, revisionId, apiRevisionDeployment);
APIRevisionDeployment apiRevisionDeploymentsResponse = apiProvider.getAPIRevisionDeployment(decodedDeploymentName, revisionId);
APIRevisionDeploymentDTO apiRevisionDeploymentDTO = APIMappingUtil.fromAPIRevisionDeploymenttoDTO(apiRevisionDeploymentsResponse);
Response.Status status = Response.Status.OK;
return Response.status(status).entity(apiRevisionDeploymentDTO).build();
}
use of org.wso2.carbon.apimgt.api.APIMgtResourceNotFoundException in project carbon-apimgt by wso2.
the class ApisApiServiceImpl method createNewAPIVersion.
@Override
public Response createNewAPIVersion(String newVersion, String apiId, Boolean defaultVersion, String serviceVersion, MessageContext messageContext) throws APIManagementException {
URI newVersionedApiUri;
APIDTO newVersionedApi = new APIDTO();
ServiceEntry service = new ServiceEntry();
try {
APIIdentifier apiIdentifierFromTable = APIMappingUtil.getAPIIdentifierFromUUID(apiId);
if (apiIdentifierFromTable == null) {
throw new APIMgtResourceNotFoundException("Couldn't retrieve existing API with API UUID: " + apiId, ExceptionCodes.from(ExceptionCodes.API_NOT_FOUND, apiId));
}
APIProvider apiProvider = RestApiCommonUtil.getLoggedInUserProvider();
String organization = RestApiUtil.getValidatedOrganization(messageContext);
int tenantId = APIUtil.getInternalOrganizationId(organization);
API existingAPI = apiProvider.getAPIbyUUID(apiId, organization);
if (existingAPI == null) {
throw new APIMgtResourceNotFoundException("API not found for id " + apiId, ExceptionCodes.from(ExceptionCodes.API_NOT_FOUND, apiId));
}
if (newVersion.equals(existingAPI.getId().getVersion())) {
throw new APIMgtResourceAlreadyExistsException("Version " + newVersion + " exists for api " + existingAPI.getId().getApiName(), ExceptionCodes.from(API_VERSION_ALREADY_EXISTS, newVersion, existingAPI.getId().getApiName()));
}
if (StringUtils.isNotEmpty(serviceVersion)) {
String serviceName = existingAPI.getServiceInfo("name");
ServiceCatalogImpl serviceCatalog = new ServiceCatalogImpl();
service = serviceCatalog.getServiceByNameAndVersion(serviceName, serviceVersion, tenantId);
if (service == null) {
throw new APIManagementException("No matching service version found", ExceptionCodes.SERVICE_VERSION_NOT_FOUND);
}
}
if (StringUtils.isNotEmpty(serviceVersion) && !serviceVersion.equals(existingAPI.getServiceInfo("version"))) {
APIDTO apidto = createAPIDTO(existingAPI, newVersion);
if (ServiceEntry.DefinitionType.OAS2.equals(service.getDefinitionType()) || ServiceEntry.DefinitionType.OAS3.equals(service.getDefinitionType())) {
newVersionedApi = importOpenAPIDefinition(service.getEndpointDef(), null, null, apidto, null, service, organization);
} else if (ServiceEntry.DefinitionType.ASYNC_API.equals(service.getDefinitionType())) {
newVersionedApi = importAsyncAPISpecification(service.getEndpointDef(), null, apidto, null, service, organization);
}
} else {
API versionedAPI = apiProvider.createNewAPIVersion(apiId, newVersion, defaultVersion, organization);
newVersionedApi = APIMappingUtil.fromAPItoDTO(versionedAPI);
}
// This URI used to set the location header of the POST response
newVersionedApiUri = new URI(RestApiConstants.RESOURCE_PATH_APIS + "/" + newVersionedApi.getId());
return Response.created(newVersionedApiUri).entity(newVersionedApi).build();
} catch (APIManagementException e) {
if (isAuthorizationFailure(e)) {
RestApiUtil.handleAuthorizationFailure("Authorization failure while copying API : " + apiId, e, log);
} else {
throw e;
}
} catch (URISyntaxException e) {
String errorMessage = "Error while retrieving API location of " + apiId;
RestApiUtil.handleInternalServerError(errorMessage, e, log);
}
return null;
}
use of org.wso2.carbon.apimgt.api.APIMgtResourceNotFoundException in project carbon-apimgt by wso2.
the class ApisApiServiceImpl method getOperationPolicyForAPIByPolicyId.
/**
* Get the API specific operation policy specification by providing the policy ID
*
* @param apiId API UUID
* @param operationPolicyId UUID of the operation policy
* @param messageContext message context
* @return Operation policy DTO as response
*/
@Override
public Response getOperationPolicyForAPIByPolicyId(String apiId, String operationPolicyId, MessageContext messageContext) {
try {
APIProvider apiProvider = RestApiCommonUtil.getLoggedInUserProvider();
String organization = RestApiUtil.getValidatedOrganization(messageContext);
// validate whether api exists or not
validateAPIExistence(apiId);
OperationPolicyData existingPolicy = apiProvider.getAPISpecificOperationPolicyByPolicyId(operationPolicyId, apiId, organization, false);
if (existingPolicy != null) {
OperationPolicyDataDTO policyDataDTO = OperationPolicyMappingUtil.fromOperationPolicyDataToDTO(existingPolicy);
return Response.ok().entity(policyDataDTO).build();
} else {
throw new APIMgtResourceNotFoundException("Couldn't retrieve an existing operation policy with ID: " + operationPolicyId + " for API " + apiId, ExceptionCodes.from(ExceptionCodes.OPERATION_POLICY_NOT_FOUND, operationPolicyId));
}
} catch (APIManagementException e) {
if (RestApiUtil.isDueToResourceNotFound(e) || RestApiUtil.isDueToAuthorizationFailure(e)) {
RestApiUtil.handleResourceNotFoundError(RestApiConstants.RESOURCE_PATH_OPERATION_POLICIES, operationPolicyId, e, log);
} else {
String errorMessage = "Error while getting an API specific operation policy with ID :" + operationPolicyId + " for API " + apiId + " " + e.getMessage();
RestApiUtil.handleInternalServerError(errorMessage, e, log);
}
} catch (Exception e) {
RestApiUtil.handleInternalServerError("An Error has occurred while getting the operation policy with ID " + operationPolicyId + "operation policy for API " + apiId, e, log);
}
return null;
}
use of org.wso2.carbon.apimgt.api.APIMgtResourceNotFoundException in project carbon-apimgt by wso2.
the class ApisApiServiceImpl method validateDocument.
@Override
public Response validateDocument(String apiId, String name, String ifMatch, MessageContext messageContext) {
if (StringUtils.isEmpty(name) || StringUtils.isEmpty(apiId)) {
RestApiUtil.handleBadRequest("API Id and/ or document name should not be empty", log);
}
try {
String organization = RestApiUtil.getValidatedOrganization(messageContext);
APIProvider apiProvider = RestApiCommonUtil.getLoggedInUserProvider();
APIIdentifier apiIdentifier = APIMappingUtil.getAPIIdentifierFromUUID(apiId);
if (apiIdentifier == null) {
throw new APIMgtResourceNotFoundException("Couldn't retrieve existing API with API UUID: " + apiId, ExceptionCodes.from(ExceptionCodes.API_NOT_FOUND, apiId));
}
return apiProvider.isDocumentationExist(apiId, name, organization) ? Response.status(Response.Status.OK).build() : Response.status(Response.Status.NOT_FOUND).build();
} catch (APIManagementException e) {
RestApiUtil.handleInternalServerError("Error while checking the api existence", e, log);
}
return Response.status(Response.Status.NOT_FOUND).build();
}
Aggregations