Search in sources :

Example 46 with org.wso2.carbon.humantask.client.api.types

use of org.wso2.carbon.humantask.client.api.types in project carbon-apimgt by wso2.

the class ServiceDiscoveryInPublisherTestCase method testDiscoverServiceEndpoints.

@Test
public void testDiscoverServiceEndpoints() throws Exception {
    /* Create a impl config without any namespace or criteria */
    ServiceDiscoveryImplConfig sdImplConfig = new ServiceDiscoveryImplConfig();
    sdImplConfig.setImplClass("org.wso2.carbon.apimgt.core.impl.ServiceDiscovererTestClass");
    sdImplConfig.setImplParameters(new HashMap<>());
    /* Create a impl config with a namespace set */
    Map<String, String> implParamWithNamespace = new HashMap<>();
    implParamWithNamespace.put(APIMgtConstants.ServiceDiscoveryConstants.NAMESPACE, "dev");
    ServiceDiscoveryImplConfig sdImplConfigWithNamespace = new ServiceDiscoveryImplConfig();
    sdImplConfigWithNamespace.setImplClass("org.wso2.carbon.apimgt.core.impl.ServiceDiscovererTestClass");
    sdImplConfigWithNamespace.setImplParameters(implParamWithNamespace);
    /* Create a impl config with a criteria set */
    Map<String, String> implParamWithCriteria = new HashMap<>();
    implParamWithCriteria.put(APIMgtConstants.ServiceDiscoveryConstants.CRITERIA, "app=web");
    ServiceDiscoveryImplConfig sdImplConfigWitCriteria = new ServiceDiscoveryImplConfig();
    sdImplConfigWitCriteria.setImplClass("org.wso2.carbon.apimgt.core.impl.ServiceDiscovererTestClass");
    sdImplConfigWitCriteria.setImplParameters(implParamWithCriteria);
    /* Create a impl config with both a namespace and a criteria is set */
    Map<String, String> implParamWithNamespaceAndCriteria = new HashMap<>();
    implParamWithNamespaceAndCriteria.put(APIMgtConstants.ServiceDiscoveryConstants.NAMESPACE, "dev");
    implParamWithNamespaceAndCriteria.put(APIMgtConstants.ServiceDiscoveryConstants.CRITERIA, "app=web");
    ServiceDiscoveryImplConfig sdImplConfigWithNamespaceNCriteria = new ServiceDiscoveryImplConfig();
    sdImplConfigWithNamespaceNCriteria.setImplClass("org.wso2.carbon.apimgt.core.impl.ServiceDiscovererTestClass");
    sdImplConfigWithNamespaceNCriteria.setImplParameters(implParamWithNamespaceAndCriteria);
    /* Create the implementationsList adding all four impl configs */
    List<ServiceDiscoveryImplConfig> implementationsList = new ArrayList<>();
    implementationsList.add(sdImplConfig);
    implementationsList.add(sdImplConfigWithNamespace);
    implementationsList.add(sdImplConfigWitCriteria);
    implementationsList.add(sdImplConfigWithNamespaceNCriteria);
    /* Create the final configuration */
    ServiceDiscoveryConfigurations sdConfig = new ServiceDiscoveryConfigurations();
    sdConfig.setEnabled(true);
    sdConfig.setImplementationsList(implementationsList);
    PowerMockito.mockStatic(ServiceDiscoveryConfigBuilder.class);
    PowerMockito.when(ServiceDiscoveryConfigBuilder.getServiceDiscoveryConfiguration()).thenReturn(sdConfig);
    /* Check whether all four types of #listServices methods have been called */
    APIPublisherImpl apiPublisher = getApiPublisherImpl();
    List<Endpoint> endpoints = apiPublisher.discoverServiceEndpoints();
    Assert.assertEquals(endpoints.size(), 4);
}
Also used : ServiceDiscoveryImplConfig(org.wso2.carbon.apimgt.core.configuration.models.ServiceDiscoveryImplConfig) Endpoint(org.wso2.carbon.apimgt.core.models.Endpoint) HashMap(java.util.HashMap) ArrayList(java.util.ArrayList) ServiceDiscoveryConfigurations(org.wso2.carbon.apimgt.core.configuration.models.ServiceDiscoveryConfigurations) Test(org.junit.Test) PrepareForTest(org.powermock.core.classloader.annotations.PrepareForTest)

Example 47 with org.wso2.carbon.humantask.client.api.types

use of org.wso2.carbon.humantask.client.api.types 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 48 with org.wso2.carbon.humantask.client.api.types

use of org.wso2.carbon.humantask.client.api.types 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 49 with org.wso2.carbon.humantask.client.api.types

use of org.wso2.carbon.humantask.client.api.types in project carbon-apimgt by wso2.

the class ResourcesApiServiceImpl method resourcesGet.

@Override
public Response resourcesGet(String apiContext, String apiVersion, String accept, Request request) throws NotFoundException {
    try {
        APIMgtAdminService apiMgtAdminService = APIManagerFactory.getInstance().getAPIMgtAdminService();
        List<UriTemplate> resourcesOfApi = new ArrayList<>();
        if (!StringUtils.isEmpty(apiContext) && !StringUtils.isEmpty(apiVersion)) {
            resourcesOfApi = apiMgtAdminService.getAllResourcesForApi(apiContext, apiVersion);
        }
        ResourcesListDTO resourcesListDTO = new ResourcesListDTO();
        resourcesListDTO.setList(MappingUtil.convertToResourceListDto(resourcesOfApi));
        return Response.ok(resourcesListDTO).build();
    } catch (APIManagementException e) {
        String errorMessage = "Error while retrieving resources.";
        Map<String, String> paramList = new HashMap<String, String>();
        if (!StringUtils.isEmpty(apiContext)) {
            paramList.put(APIMgtConstants.ExceptionsConstants.API_CONTEXT, apiContext);
        }
        if (!StringUtils.isEmpty(apiVersion)) {
            paramList.put(APIMgtConstants.ExceptionsConstants.API_VERSION, apiVersion);
        }
        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 : ArrayList(java.util.ArrayList) UriTemplate(org.wso2.carbon.apimgt.core.models.UriTemplate) APIMgtAdminService(org.wso2.carbon.apimgt.core.api.APIMgtAdminService) APIManagementException(org.wso2.carbon.apimgt.core.exception.APIManagementException) HashMap(java.util.HashMap) Map(java.util.Map) ResourcesListDTO(org.wso2.carbon.apimgt.rest.api.core.dto.ResourcesListDTO)

Example 50 with org.wso2.carbon.humantask.client.api.types

use of org.wso2.carbon.humantask.client.api.types in project carbon-apimgt by wso2.

the class ServiceReferenceHolder method getApimUIConfigurations.

public APIMUIConfigurations getApimUIConfigurations() {
    try {
        if (configProvider != null) {
            apimUIConfigurations = configProvider.getConfigurationObject(APIMUIConfigurations.class);
        } else {
            log.error("Configuration provider is null");
        }
    } catch (ConfigurationException e) {
        log.error("Error getting config : org.wso2.carbon.apimgt.rest.api.configurations.models." + "EnvironmentConfigurations", e);
    }
    if (apimUIConfigurations == null) {
        apimUIConfigurations = new APIMUIConfigurations();
        log.info("Setting default configurations...");
    }
    return apimUIConfigurations;
}
Also used : ConfigurationException(org.wso2.carbon.config.ConfigurationException) APIMUIConfigurations(org.wso2.carbon.apimgt.rest.api.configurations.models.APIMUIConfigurations)

Aggregations

APIManagementException (org.wso2.carbon.apimgt.core.exception.APIManagementException)18 APIMgtAdminService (org.wso2.carbon.apimgt.core.api.APIMgtAdminService)13 HashMap (java.util.HashMap)12 Query (javax.persistence.Query)9 ErrorDTO (org.wso2.carbon.apimgt.rest.api.common.dto.ErrorDTO)9 ArrayList (java.util.ArrayList)8 Map (java.util.Map)8 APIMgtDAOException (org.wso2.carbon.apimgt.core.exception.APIMgtDAOException)5 TAttachment (org.wso2.carbon.attachment.mgt.skeleton.types.TAttachment)5 APIPolicy (org.wso2.carbon.apimgt.core.models.policy.APIPolicy)4 AttachmentDAO (org.wso2.carbon.attachment.mgt.core.dao.AttachmentDAO)4 AttachmentMgtException (org.wso2.carbon.attachment.mgt.core.exceptions.AttachmentMgtException)4 AttachmentMgtException (org.wso2.carbon.attachment.mgt.skeleton.AttachmentMgtException)4 Test (org.testng.annotations.Test)3 ConfigurationException (org.wso2.carbon.config.ConfigurationException)3 ByteArrayOutputStream (java.io.ByteArrayOutputStream)2 File (java.io.File)2 PrintStream (java.io.PrintStream)2 Connection (java.sql.Connection)2 List (java.util.List)2