use of org.wso2.carbon.apimgt.rest.api.gateway.dto.ErrorDTO in project carbon-apimgt by wso2.
the class ApiProductsApiServiceImpl method getAPIProductRevision.
@Override
public Response getAPIProductRevision(String apiProductId, String revisionId, MessageContext messageContext) throws APIManagementException {
// remove errorObject and add implementation code!
org.wso2.carbon.apimgt.rest.api.common.dto.ErrorDTO errorObject = new ErrorDTO();
Response.Status status = Response.Status.NOT_IMPLEMENTED;
errorObject.setCode((long) status.getStatusCode());
errorObject.setMessage(status.toString());
errorObject.setDescription("The requested resource has not been implemented");
return Response.status(status).entity(errorObject).build();
}
use of org.wso2.carbon.apimgt.rest.api.gateway.dto.ErrorDTO in project carbon-apimgt by wso2.
the class ApisApiServiceImpl method apisGet.
public Response apisGet(String context, String version, String tenantDomain, MessageContext messageContext) {
tenantDomain = GatewayUtils.validateTenantDomain(tenantDomain, messageContext);
SubscriptionDataStore subscriptionDataStore = SubscriptionDataHolder.getInstance().getTenantSubscriptionStore(tenantDomain);
if (subscriptionDataStore == null) {
log.warn("Subscription data store is not initialized for " + tenantDomain);
return Response.status(Response.Status.NOT_FOUND).build();
}
if (StringUtils.isNotEmpty(context) && StringUtils.isNotEmpty(version)) {
API api = subscriptionDataStore.getApiByContextAndVersion(context, version);
if (api == null) {
return Response.status(Response.Status.NOT_FOUND).build();
}
APIListDTO apiListDTO = GatewayUtils.generateAPIListDTO(Collections.singletonList(api));
return Response.ok().entity(apiListDTO).build();
} else if ((StringUtils.isEmpty(context) && StringUtils.isNotEmpty(version)) || (StringUtils.isNotEmpty(context) && StringUtils.isEmpty(version))) {
return Response.status(Response.Status.BAD_REQUEST).entity(new ErrorDTO().moreInfo("required parameters " + "are missing")).build();
} else {
List<API> apiList = subscriptionDataStore.getAPIs();
APIListDTO apiListDTO = GatewayUtils.generateAPIListDTO(apiList);
return Response.status(Response.Status.OK).entity(apiListDTO).build();
}
}
use of org.wso2.carbon.apimgt.rest.api.gateway.dto.ErrorDTO in project carbon-apimgt by wso2.
the class ApisApiServiceImpl method importAsyncAPISpecification.
private APIDTO importAsyncAPISpecification(InputStream definition, String definitionUrl, APIDTO apiDTOFromProperties, Attachment fileDetail, ServiceEntry service, String organization) {
// validate and retrieve the AsyncAPI specification
Map validationResponseMap = null;
boolean isServiceAPI = false;
try {
if (service != null) {
isServiceAPI = true;
}
validationResponseMap = validateAsyncAPISpecification(definitionUrl, definition, fileDetail, true, isServiceAPI);
} catch (APIManagementException e) {
RestApiUtil.handleInternalServerError("Error occurred while validating API Definition", e, log);
}
AsyncAPISpecificationValidationResponseDTO validationResponseDTO = (AsyncAPISpecificationValidationResponseDTO) validationResponseMap.get(RestApiConstants.RETURN_DTO);
APIDefinitionValidationResponse validationResponse = (APIDefinitionValidationResponse) validationResponseMap.get(RestApiConstants.RETURN_MODEL);
if (!validationResponseDTO.isIsValid()) {
ErrorDTO errorDTO = APIMappingUtil.getErrorDTOFromErrorListItems(validationResponseDTO.getErrors());
throw RestApiUtil.buildBadRequestException(errorDTO);
}
// Import the API and Definition
try {
APIProvider apiProvider = RestApiCommonUtil.getLoggedInUserProvider();
String definitionToAdd = validationResponse.getJsonContent();
String protocol = validationResponse.getProtocol();
if (isServiceAPI) {
apiDTOFromProperties.setType(PublisherCommonUtils.getAPIType(service.getDefinitionType(), protocol));
}
if (!APIConstants.WSO2_GATEWAY_ENVIRONMENT.equals(apiDTOFromProperties.getGatewayVendor())) {
apiDTOFromProperties.getPolicies().add(APIConstants.DEFAULT_SUB_POLICY_ASYNC_UNLIMITED);
apiDTOFromProperties.setAsyncTransportProtocols(AsyncApiParser.getTransportProtocolsForAsyncAPI(definitionToAdd));
}
API apiToAdd = PublisherCommonUtils.prepareToCreateAPIByDTO(apiDTOFromProperties, apiProvider, RestApiCommonUtil.getLoggedInUsername(), organization);
if (isServiceAPI) {
apiToAdd.setServiceInfo("key", service.getKey());
apiToAdd.setServiceInfo("md5", service.getMd5());
if (!APIConstants.API_TYPE_WEBSUB.equals(protocol.toUpperCase())) {
apiToAdd.setEndpointConfig(PublisherCommonUtils.constructEndpointConfigForService(service.getServiceUrl(), protocol));
}
}
apiToAdd.setAsyncApiDefinition(definitionToAdd);
// load topics from AsyncAPI
apiToAdd.setUriTemplates(new AsyncApiParser().getURITemplates(definitionToAdd, APIConstants.API_TYPE_WS.equals(apiToAdd.getType()) || !APIConstants.WSO2_GATEWAY_ENVIRONMENT.equals(apiToAdd.getGatewayVendor())));
apiToAdd.setOrganization(organization);
apiToAdd.setAsyncApiDefinition(definitionToAdd);
apiProvider.addAPI(apiToAdd);
return APIMappingUtil.fromAPItoDTO(apiProvider.getAPIbyUUID(apiToAdd.getUuid(), organization));
} catch (APIManagementException e) {
String errorMessage = "Error while adding new API : " + apiDTOFromProperties.getProvider() + "-" + apiDTOFromProperties.getName() + "-" + apiDTOFromProperties.getVersion() + " - " + e.getMessage();
RestApiUtil.handleInternalServerError(errorMessage, e, log);
}
return null;
}
use of org.wso2.carbon.apimgt.rest.api.gateway.dto.ErrorDTO in project carbon-apimgt by wso2.
the class ApisApiServiceImpl method getAPIRevision.
/**
* Retrieve a revision of an API
*
* @param apiId UUID of the API
* @param revisionId Revision ID of the API
* @param messageContext message context object
* @return response containing APIRevision object
*/
@Override
public Response getAPIRevision(String apiId, String revisionId, MessageContext messageContext) {
// remove errorObject and add implementation code!
ErrorDTO errorObject = new ErrorDTO();
Response.Status status = Response.Status.NOT_IMPLEMENTED;
errorObject.setCode((long) status.getStatusCode());
errorObject.setMessage(status.toString());
errorObject.setDescription("The requested resource has not been implemented");
return Response.status(status).entity(errorObject).build();
}
use of org.wso2.carbon.apimgt.rest.api.gateway.dto.ErrorDTO in project carbon-apimgt by wso2.
the class BlacklistApiServiceImpl method blacklistGet.
@Override
public Response blacklistGet(String accept, Request request) throws NotFoundException {
try {
APIMgtAdminService apiMgtAdminService = APIManagerFactory.getInstance().getAPIMgtAdminService();
List<BlockConditions> blockConditionsList = apiMgtAdminService.getBlockConditions();
BlockingConditionListDTO blockingConditionListDTO = MappingUtil.fromBlockConditionListToListDTO(blockConditionsList);
return Response.ok(blockingConditionListDTO).build();
} catch (APIManagementException e) {
String errorMessage = "Error while retrieving block conditions";
ErrorDTO errorDTO = RestApiUtil.getErrorDTO(e.getErrorHandler());
log.error(errorMessage, e);
return Response.status(e.getErrorHandler().getHttpStatusCode()).header(HttpHeaders.CONTENT_TYPE, MediaType.APPLICATION_JSON).entity(errorDTO).build();
}
}
Aggregations