Search in sources :

Example 76 with ErrorDTO

use of org.wso2.carbon.apimgt.rest.api.authenticator.dto.ErrorDTO in project carbon-apimgt by wso2.

the class EndpointsApiServiceImpl method endpointsGet.

@Override
public Response endpointsGet(Integer limit, String accept, Request request) throws NotFoundException {
    EndpointListDTO endpointListDTO = new EndpointListDTO();
    try {
        APIMgtAdminService adminService = RestApiUtil.getAPIMgtAdminService();
        List<Endpoint> endpointList = adminService.getAllEndpoints();
        endpointListDTO.setList(MappingUtil.toEndpointListDto(endpointList));
        endpointListDTO.setCount(endpointList.size());
        return Response.ok().entity(endpointListDTO).build();
    } catch (APIManagementException e) {
        String errorMessage = "Error while retrieving APIs";
        ErrorDTO errorDTO = RestApiUtil.getErrorDTO(e.getErrorHandler());
        log.error(errorMessage, e);
        return Response.status(e.getErrorHandler().getHttpStatusCode()).entity(errorDTO).build();
    }
}
Also used : APIMgtAdminService(org.wso2.carbon.apimgt.core.api.APIMgtAdminService) Endpoint(org.wso2.carbon.apimgt.core.models.Endpoint) APIManagementException(org.wso2.carbon.apimgt.core.exception.APIManagementException) ErrorDTO(org.wso2.carbon.apimgt.rest.api.common.dto.ErrorDTO) EndpointListDTO(org.wso2.carbon.apimgt.rest.api.core.dto.EndpointListDTO)

Example 77 with ErrorDTO

use of org.wso2.carbon.apimgt.rest.api.authenticator.dto.ErrorDTO in project carbon-apimgt by wso2.

the class EndpointsApiServiceImpl method endpointsEndpointIdGatewayConfigGet.

@Override
public Response endpointsEndpointIdGatewayConfigGet(String endpointId, String accept, Request request) throws NotFoundException {
    try {
        APIMgtAdminService apiMgtAdminService = APIManagerFactory.getInstance().getAPIMgtAdminService();
        String endpointGatewayConfig = apiMgtAdminService.getEndpointGatewayConfig(endpointId);
        if (endpointGatewayConfig != null) {
            return Response.ok().entity(endpointGatewayConfig).build();
        } else {
            String msg = "Endpoint is not found with apiId : " + endpointId;
            ErrorDTO errorDTO = RestApiUtil.getErrorDTO(msg, 900314L, msg);
            log.error(msg);
            return Response.status(Response.Status.NOT_FOUND).header(HttpHeaders.CONTENT_TYPE, MediaType.APPLICATION_JSON).entity(errorDTO).build();
        }
    } catch (APIManagementException e) {
        String errorMessage = "Error while retrieving gateway config of Endpoint : " + endpointId;
        Map<String, String> paramList = new HashMap<>();
        paramList.put(APIMgtConstants.ExceptionsConstants.ENDPOINT_ID, endpointId);
        ErrorDTO errorDTO = RestApiUtil.getErrorDTO(e.getErrorHandler(), paramList);
        log.error(errorMessage, e);
        return Response.status(e.getErrorHandler().getHttpStatusCode()).header(HttpHeaders.CONTENT_TYPE, MediaType.APPLICATION_JSON).entity(errorDTO).build();
    }
}
Also used : APIMgtAdminService(org.wso2.carbon.apimgt.core.api.APIMgtAdminService) APIManagementException(org.wso2.carbon.apimgt.core.exception.APIManagementException) ErrorDTO(org.wso2.carbon.apimgt.rest.api.common.dto.ErrorDTO) HashMap(java.util.HashMap) Map(java.util.Map)

Example 78 with ErrorDTO

use of org.wso2.carbon.apimgt.rest.api.authenticator.dto.ErrorDTO in project carbon-apimgt by wso2.

the class ExportApiServiceImpl method exportPoliciesThrottleGet.

/**
 * Export throttle policies containing zip.
 *
 * @param accept  Accept header value
 * @param request msf4j request object
 * @return Response object
 * @throws NotFoundException if an error occurred when particular resource does not exits in the system.
 */
@Override
public Response exportPoliciesThrottleGet(String accept, Request request) throws NotFoundException {
    String archiveName = "exported-policies";
    // files will be written to following directory
    String exportedPoliciesDirName = "exported-policies";
    // archive will be here at following location tmp directory
    String archiveDir = System.getProperty("java.io.tmpdir");
    if (log.isDebugEnabled()) {
        log.debug("Received export policies GET request ");
    }
    try {
        APIMgtAdminService apiMgtAdminService = APIManagerFactory.getInstance().getAPIMgtAdminService();
        PolicyExportManager policyExportManager = new PolicyExportManager(apiMgtAdminService);
        // create archive and get the archive location
        String zippedFilePath = policyExportManager.createArchiveFromExecutionPlans(exportedPoliciesDirName, archiveDir, archiveName);
        APIFileUtils.deleteDirectory(exportedPoliciesDirName);
        File exportedApiArchiveFile = new File(zippedFilePath);
        Response.ResponseBuilder responseBuilder = Response.status(Response.Status.OK).entity(exportedApiArchiveFile);
        responseBuilder.header(HttpHeaders.CONTENT_TYPE, MediaType.APPLICATION_OCTET_STREAM).header("Content-Disposition", "attachment; filename=\"" + exportedApiArchiveFile.getName() + "\"");
        Response response = responseBuilder.build();
        return response;
    } catch (APIManagementException e) {
        String errorMessage = "Error while exporting policies";
        log.error(errorMessage, e);
        org.wso2.carbon.apimgt.rest.api.common.dto.ErrorDTO errorDTO = RestApiUtil.getErrorDTO(e.getErrorHandler());
        return Response.status(e.getErrorHandler().getHttpStatusCode()).entity(errorDTO).build();
    }
}
Also used : Response(javax.ws.rs.core.Response) APIMgtAdminService(org.wso2.carbon.apimgt.core.api.APIMgtAdminService) APIManagementException(org.wso2.carbon.apimgt.core.exception.APIManagementException) PolicyExportManager(org.wso2.carbon.apimgt.rest.api.core.utils.PolicyExportManager) File(java.io.File)

Example 79 with ErrorDTO

use of org.wso2.carbon.apimgt.rest.api.authenticator.dto.ErrorDTO in project carbon-apimgt by wso2.

the class GatewaysApiServiceImpl method gatewaysRegisterPost.

/**
 * Register gateway
 *
 * @param body        RegistrationDTO
 * @param contentType Content-Type header value
 * @return Registration summary details
 * @throws NotFoundException If failed to register gateway
 */
@Override
public Response gatewaysRegisterPost(RegistrationDTO body, String contentType, Request request) throws NotFoundException {
    try {
        LabelInfoDTO labelInfoDTO = body.getLabelInfo();
        if (labelInfoDTO != null) {
            APIMgtAdminService adminService = RestApiUtil.getAPIMgtAdminService();
            String overwriteLabels = labelInfoDTO.getOverwriteLabels();
            List<Label> labels = MappingUtil.convertToLabels(labelInfoDTO.getLabelList());
            adminService.registerGatewayLabels(labels, overwriteLabels);
            RegistrationSummary registrationSummary = adminService.getRegistrationSummary();
            return Response.ok().entity(MappingUtil.toRegistrationSummaryDTO(registrationSummary)).build();
        } else {
            String errorMessage = "Label information cannot be null";
            APIMgtResourceNotFoundException e = new APIMgtResourceNotFoundException(errorMessage, ExceptionCodes.LABEL_INFORMATION_CANNOT_BE_NULL);
            HashMap<String, String> paramList = new HashMap<String, String>();
            org.wso2.carbon.apimgt.rest.api.common.dto.ErrorDTO errorDTO = RestApiUtil.getErrorDTO(e.getErrorHandler(), paramList);
            log.error(errorMessage, e);
            return Response.status(e.getErrorHandler().getHttpStatusCode()).entity(errorDTO).build();
        }
    } catch (APIManagementException e) {
        String errorMessage = "Error while registering the gateway";
        HashMap<String, String> paramList = new HashMap<String, String>();
        org.wso2.carbon.apimgt.rest.api.common.dto.ErrorDTO errorDTO = RestApiUtil.getErrorDTO(e.getErrorHandler(), paramList);
        log.error(errorMessage, e);
        return Response.status(e.getErrorHandler().getHttpStatusCode()).entity(errorDTO).build();
    }
}
Also used : HashMap(java.util.HashMap) Label(org.wso2.carbon.apimgt.core.models.Label) APIMgtResourceNotFoundException(org.wso2.carbon.apimgt.core.exception.APIMgtResourceNotFoundException) LabelInfoDTO(org.wso2.carbon.apimgt.rest.api.core.dto.LabelInfoDTO) APIMgtAdminService(org.wso2.carbon.apimgt.core.api.APIMgtAdminService) APIManagementException(org.wso2.carbon.apimgt.core.exception.APIManagementException) RegistrationSummary(org.wso2.carbon.apimgt.core.models.RegistrationSummary)

Example 80 with ErrorDTO

use of org.wso2.carbon.apimgt.rest.api.authenticator.dto.ErrorDTO in project carbon-apimgt by wso2.

the class PoliciesApiServiceImpl method policiesGet.

@Override
public Response policiesGet(String accept, Request request) throws NotFoundException {
    PolicyListDTO policyListDTO = new PolicyListDTO();
    try {
        APIMgtAdminService adminService = RestApiUtil.getAPIMgtAdminService();
        List<PolicyDTO> policyDTOList = MappingUtil.convertToPolicyDtoList(adminService.getAllPolicies());
        policyListDTO.setList(policyDTOList);
        policyListDTO.setCount(policyDTOList.size());
        return Response.ok().entity(policyListDTO).build();
    } catch (APIManagementException e) {
        String errorMessage = "Error while retrieving Policies";
        ErrorDTO errorDTO = RestApiUtil.getErrorDTO(e.getErrorHandler());
        log.error(errorMessage, e);
        return Response.status(e.getErrorHandler().getHttpStatusCode()).entity(errorDTO).build();
    }
}
Also used : APIMgtAdminService(org.wso2.carbon.apimgt.core.api.APIMgtAdminService) PolicyDTO(org.wso2.carbon.apimgt.rest.api.core.dto.PolicyDTO) APIManagementException(org.wso2.carbon.apimgt.core.exception.APIManagementException) PolicyListDTO(org.wso2.carbon.apimgt.rest.api.core.dto.PolicyListDTO) ErrorDTO(org.wso2.carbon.apimgt.rest.api.common.dto.ErrorDTO)

Aggregations

ErrorDTO (org.wso2.carbon.apimgt.rest.api.common.dto.ErrorDTO)155 APIManagementException (org.wso2.carbon.apimgt.core.exception.APIManagementException)154 HashMap (java.util.HashMap)106 APIStore (org.wso2.carbon.apimgt.core.api.APIStore)48 APIPublisher (org.wso2.carbon.apimgt.core.api.APIPublisher)45 APIMgtAdminService (org.wso2.carbon.apimgt.core.api.APIMgtAdminService)40 Map (java.util.Map)25 APIMgtResourceNotFoundException (org.wso2.carbon.apimgt.core.exception.APIMgtResourceNotFoundException)15 ErrorHandler (org.wso2.carbon.apimgt.core.exception.ErrorHandler)15 IOException (java.io.IOException)11 Application (org.wso2.carbon.apimgt.core.models.Application)11 URI (java.net.URI)10 URISyntaxException (java.net.URISyntaxException)10 DocumentInfo (org.wso2.carbon.apimgt.core.models.DocumentInfo)9 Subscription (org.wso2.carbon.apimgt.core.models.Subscription)7 ArrayList (java.util.ArrayList)6 API (org.wso2.carbon.apimgt.core.models.API)6 Endpoint (org.wso2.carbon.apimgt.core.models.Endpoint)6 Label (org.wso2.carbon.apimgt.core.models.Label)6 ErrorDTO (org.wso2.carbon.apimgt.rest.api.authenticator.dto.ErrorDTO)6