Search in sources :

Example 1 with APITemplateBuilderImpl

use of org.wso2.carbon.apimgt.rest.api.publisher.v1.common.template.APITemplateBuilderImpl in project carbon-apimgt by wso2.

the class TemplateBuilderUtil method getAPITemplateBuilder.

public static APITemplateBuilderImpl getAPITemplateBuilder(APIProduct apiProduct, String tenantDomain, List<ClientCertificateDTO> clientCertificateDTOS, Map<String, APIDTO> associatedAPIMap) throws APIManagementException {
    int tenantId = APIUtil.getTenantIdFromTenantDomain(tenantDomain);
    APITemplateBuilderImpl vtb = new APITemplateBuilderImpl(apiProduct, associatedAPIMap);
    Map<String, String> latencyStatsProperties = new HashMap<String, String>();
    latencyStatsProperties.put(APIConstants.API_UUID, apiProduct.getUuid());
    if (!APIUtil.isStreamingApi(apiProduct)) {
        vtb.addHandler("org.wso2.carbon.apimgt.gateway.handlers.common.APIMgtLatencyStatsHandler", latencyStatsProperties);
    }
    Map<String, String> corsProperties = new HashMap<>();
    corsProperties.put(APIConstants.CORSHeaders.IMPLEMENTATION_TYPE_HANDLER_VALUE, APIConstants.IMPLEMENTATION_TYPE_ENDPOINT);
    // Get authorization header from the API object or from the tenant registry
    String authorizationHeader;
    if (!StringUtils.isBlank(apiProduct.getAuthorizationHeader())) {
        authorizationHeader = apiProduct.getAuthorizationHeader();
    } else {
        // Retrieves the auth configuration from tenant registry or api-manager.xml if not available
        // in tenant registry
        authorizationHeader = APIUtil.getOAuthConfiguration(tenantDomain, APIConstants.AUTHORIZATION_HEADER);
    }
    if (!StringUtils.isBlank(authorizationHeader)) {
        corsProperties.put(APIConstants.AUTHORIZATION_HEADER, authorizationHeader);
    }
    if (apiProduct.getCorsConfiguration() != null && apiProduct.getCorsConfiguration().isCorsConfigurationEnabled()) {
        CORSConfiguration corsConfiguration = apiProduct.getCorsConfiguration();
        if (corsConfiguration.getAccessControlAllowHeaders() != null) {
            StringBuilder allowHeaders = new StringBuilder();
            for (String header : corsConfiguration.getAccessControlAllowHeaders()) {
                allowHeaders.append(header).append(',');
            }
            if (allowHeaders.length() != 0) {
                allowHeaders.deleteCharAt(allowHeaders.length() - 1);
                corsProperties.put(APIConstants.CORSHeaders.ALLOW_HEADERS_HANDLER_VALUE, allowHeaders.toString());
            }
        }
        if (corsConfiguration.getAccessControlAllowOrigins() != null) {
            StringBuilder allowOrigins = new StringBuilder();
            for (String origin : corsConfiguration.getAccessControlAllowOrigins()) {
                allowOrigins.append(origin).append(',');
            }
            if (allowOrigins.length() != 0) {
                allowOrigins.deleteCharAt(allowOrigins.length() - 1);
                corsProperties.put(APIConstants.CORSHeaders.ALLOW_ORIGIN_HANDLER_VALUE, allowOrigins.toString());
            }
        }
        if (corsConfiguration.getAccessControlAllowMethods() != null) {
            StringBuilder allowedMethods = new StringBuilder();
            for (String methods : corsConfiguration.getAccessControlAllowMethods()) {
                allowedMethods.append(methods).append(',');
            }
            if (allowedMethods.length() != 0) {
                allowedMethods.deleteCharAt(allowedMethods.length() - 1);
                corsProperties.put(APIConstants.CORSHeaders.ALLOW_METHODS_HANDLER_VALUE, allowedMethods.toString());
            }
        }
        if (corsConfiguration.isAccessControlAllowCredentials()) {
            corsProperties.put(APIConstants.CORSHeaders.ALLOW_CREDENTIALS_HANDLER_VALUE, String.valueOf(corsConfiguration.isAccessControlAllowCredentials()));
        }
        vtb.addHandler("org.wso2.carbon.apimgt.gateway.handlers.security.CORSRequestHandler", corsProperties);
    } else if (APIUtil.isCORSEnabled()) {
        vtb.addHandler("org.wso2.carbon.apimgt.gateway.handlers.security.CORSRequestHandler", corsProperties);
    }
    vtb.addHandler("org.wso2.carbon.apimgt.gateway.handlers.common.APIStatusHandler", Collections.emptyMap());
    Map<String, String> clientCertificateObject = null;
    CertificateMgtUtils certificateMgtUtils = CertificateMgtUtils.getInstance();
    if (clientCertificateDTOS != null) {
        clientCertificateObject = new HashMap<>();
        for (ClientCertificateDTO clientCertificateDTO : clientCertificateDTOS) {
            clientCertificateObject.put(certificateMgtUtils.getUniqueIdentifierOfCertificate(clientCertificateDTO.getCertificate()), clientCertificateDTO.getTierName());
        }
    }
    Map<String, String> authProperties = new HashMap<String, String>();
    if (!StringUtils.isBlank(authorizationHeader)) {
        authProperties.put(APIConstants.AUTHORIZATION_HEADER, authorizationHeader);
    }
    String apiSecurity = apiProduct.getApiSecurity();
    String apiLevelPolicy = apiProduct.getProductLevelPolicy();
    authProperties.put(APIConstants.API_SECURITY, apiSecurity);
    authProperties.put(APIConstants.API_LEVEL_POLICY, apiLevelPolicy);
    if (clientCertificateObject != null) {
        authProperties.put(APIConstants.CERTIFICATE_INFORMATION, clientCertificateObject.toString());
    }
    // Get RemoveHeaderFromOutMessage from tenant registry or api-manager.xml
    String removeHeaderFromOutMessage = APIUtil.getOAuthConfiguration(tenantDomain, APIConstants.REMOVE_OAUTH_HEADER_FROM_OUT_MESSAGE);
    if (!StringUtils.isBlank(removeHeaderFromOutMessage)) {
        authProperties.put(APIConstants.REMOVE_OAUTH_HEADER_FROM_OUT_MESSAGE, removeHeaderFromOutMessage);
    } else {
        authProperties.put(APIConstants.REMOVE_OAUTH_HEADER_FROM_OUT_MESSAGE, APIConstants.REMOVE_OAUTH_HEADER_FROM_OUT_MESSAGE_DEFAULT);
    }
    authProperties.put("apiType", APIConstants.ApiTypes.PRODUCT_API.name());
    vtb.addHandler("org.wso2.carbon.apimgt.gateway.handlers.security.APIAuthenticationHandler", authProperties);
    Map<String, String> properties = new HashMap<String, String>();
    if (apiProduct.getProductionMaxTps() != null) {
        properties.put("productionMaxCount", apiProduct.getProductionMaxTps());
    }
    if (apiProduct.getSandboxMaxTps() != null) {
        properties.put("sandboxMaxCount", apiProduct.getSandboxMaxTps());
    }
    if (!APIUtil.isStreamingApi(apiProduct)) {
        vtb.addHandler("org.wso2.carbon.apimgt.gateway.handlers.throttling.ThrottleHandler", properties);
        properties = new HashMap<String, String>();
        properties.put("configKey", APIConstants.GA_CONF_KEY);
        vtb.addHandler("org.wso2.carbon.apimgt.gateway.handlers.analytics.APIMgtGoogleAnalyticsTrackingHandler", properties);
        String extensionHandlerPosition = getExtensionHandlerPosition(tenantDomain);
        if ("top".equalsIgnoreCase(extensionHandlerPosition)) {
            vtb.addHandlerPriority("org.wso2.carbon.apimgt.gateway.handlers.ext.APIManagerExtensionHandler", Collections.emptyMap(), 2);
        } else {
            vtb.addHandler("org.wso2.carbon.apimgt.gateway.handlers.ext.APIManagerExtensionHandler", Collections.emptyMap());
        }
    }
    return vtb;
}
Also used : CORSConfiguration(org.wso2.carbon.apimgt.api.model.CORSConfiguration) HashMap(java.util.HashMap) ClientCertificateDTO(org.wso2.carbon.apimgt.api.dto.ClientCertificateDTO) CertificateMgtUtils(org.wso2.carbon.apimgt.impl.utils.CertificateMgtUtils) APITemplateBuilderImpl(org.wso2.carbon.apimgt.rest.api.publisher.v1.common.template.APITemplateBuilderImpl)

Example 2 with APITemplateBuilderImpl

use of org.wso2.carbon.apimgt.rest.api.publisher.v1.common.template.APITemplateBuilderImpl in project carbon-apimgt by wso2.

the class TemplateBuilderUtil method createAPIGatewayDTOtoPublishAPI.

private static GatewayAPIDTO createAPIGatewayDTOtoPublishAPI(Environment environment, APIProduct apiProduct, APITemplateBuilder builder, String tenantDomain, Map<String, APIDTO> associatedAPIsMap, List<ClientCertificateDTO> clientCertificatesDTOList) throws APITemplateException, XMLStreamException, APIManagementException {
    APIProductIdentifier id = apiProduct.getId();
    GatewayAPIDTO productAPIDto = new GatewayAPIDTO();
    productAPIDto.setProvider(id.getProviderName());
    productAPIDto.setApiId(apiProduct.getUuid());
    productAPIDto.setName(id.getName());
    productAPIDto.setVersion(id.getVersion());
    productAPIDto.setTenantDomain(tenantDomain);
    productAPIDto.setKeyManagers(Collections.singletonList(APIConstants.KeyManager.API_LEVEL_ALL_KEY_MANAGERS));
    String definition = apiProduct.getDefinition();
    productAPIDto.setLocalEntriesToBeRemove(GatewayUtils.addStringToList(apiProduct.getUuid(), productAPIDto.getLocalEntriesToBeRemove()));
    GatewayContentDTO productLocalEntry = new GatewayContentDTO();
    productLocalEntry.setName(apiProduct.getUuid());
    productLocalEntry.setContent("<localEntry key=\"" + apiProduct.getUuid() + "\">" + definition.replaceAll("&(?!amp;)", "&amp;").replaceAll("<", "&lt;").replaceAll(">", "&gt;") + "</localEntry>");
    productAPIDto.setLocalEntriesToBeAdd(addGatewayContentToList(productLocalEntry, productAPIDto.getLocalEntriesToBeAdd()));
    setClientCertificatesToBeAdded(tenantDomain, productAPIDto, clientCertificatesDTOList);
    for (Map.Entry<String, APIDTO> apidtoEntry : associatedAPIsMap.entrySet()) {
        String apiExtractedPath = apidtoEntry.getKey();
        APIDTO apidto = apidtoEntry.getValue();
        API api = APIMappingUtil.fromDTOtoAPI(apidto, apidto.getProvider());
        api.setUuid(apidto.getId());
        GatewayUtils.setCustomSequencesToBeRemoved(apiProduct.getId(), api.getUuid(), productAPIDto);
        APITemplateBuilder apiTemplateBuilder = new APITemplateBuilderImpl(api, apiProduct);
        addEndpoints(api, apiTemplateBuilder, productAPIDto);
        setCustomSequencesToBeAdded(apiProduct, api, productAPIDto, apiExtractedPath, apidto);
        setAPIFaultSequencesToBeAdded(api, productAPIDto, apiExtractedPath, apidto);
        String prefix = id.getName() + "--v" + id.getVersion();
        setSecureVaultPropertyToBeAdded(prefix, api, productAPIDto);
    }
    productAPIDto.setApiDefinition(builder.getConfigStringForTemplate(environment));
    return productAPIDto;
}
Also used : GatewayAPIDTO(org.wso2.carbon.apimgt.api.gateway.GatewayAPIDTO) APIProductIdentifier(org.wso2.carbon.apimgt.api.model.APIProductIdentifier) GatewayAPIDTO(org.wso2.carbon.apimgt.api.gateway.GatewayAPIDTO) APIDTO(org.wso2.carbon.apimgt.rest.api.publisher.v1.dto.APIDTO) APITemplateBuilder(org.wso2.carbon.apimgt.impl.template.APITemplateBuilder) API(org.wso2.carbon.apimgt.api.model.API) Map(java.util.Map) HashMap(java.util.HashMap) APITemplateBuilderImpl(org.wso2.carbon.apimgt.rest.api.publisher.v1.common.template.APITemplateBuilderImpl) GatewayContentDTO(org.wso2.carbon.apimgt.api.gateway.GatewayContentDTO)

Example 3 with APITemplateBuilderImpl

use of org.wso2.carbon.apimgt.rest.api.publisher.v1.common.template.APITemplateBuilderImpl in project carbon-apimgt by wso2.

the class WebSubConfigContextTest method testWithSecretConfigContextForAPI.

@Test
public void testWithSecretConfigContextForAPI() throws Exception {
    API api = new API(new APIIdentifier("admin", "websubAPI", "1.0.0"));
    api.setStatus(APIConstants.CREATED);
    api.setContextTemplate("/websub");
    api.setTransports(Constants.TRANSPORT_HTTP);
    api.setEndpointSecured(false);
    api.setUriTemplates(setAPIUriTemplates());
    api.setType(APIConstants.APITransportType.WEBSUB.toString());
    WebsubSubscriptionConfiguration webSubConfig = new WebsubSubscriptionConfiguration(true, "9207975e1fef9c41fab41645f81dbf0f", "SHA1", "x-hub-signature");
    api.setWebsubSubscriptionConfiguration(webSubConfig);
    Environment environment = new Environment();
    environment.setType("production");
    config = Mockito.mock(APIManagerConfiguration.class);
    APIManagerConfigurationService apiManagerConfigurationService = new APIManagerConfigurationServiceImpl(config);
    ServiceReferenceHolder.getInstance().setAPIManagerConfigurationService(apiManagerConfigurationService);
    String templatePath = System.getProperty("user.dir") + File.separator + "src" + File.separator + "test" + File.separator + "resources" + File.separator;
    System.setProperty("carbon.home", templatePath);
    APITemplateBuilderImpl apiTemplateBuilder = new APITemplateBuilderImpl(api, null, null);
    String updatedTemplate = apiTemplateBuilder.getConfigStringForTemplate(environment);
    Assert.assertTrue("The websub velocity template is not updated correctly", updatedTemplate.contains("generated_signature"));
}
Also used : APIManagerConfiguration(org.wso2.carbon.apimgt.impl.APIManagerConfiguration) APIManagerConfigurationService(org.wso2.carbon.apimgt.impl.APIManagerConfigurationService) APIManagerConfigurationServiceImpl(org.wso2.carbon.apimgt.impl.APIManagerConfigurationServiceImpl) Environment(org.wso2.carbon.apimgt.api.model.Environment) API(org.wso2.carbon.apimgt.api.model.API) APIIdentifier(org.wso2.carbon.apimgt.api.model.APIIdentifier) WebsubSubscriptionConfiguration(org.wso2.carbon.apimgt.api.model.WebsubSubscriptionConfiguration) APITemplateBuilderImpl(org.wso2.carbon.apimgt.rest.api.publisher.v1.common.template.APITemplateBuilderImpl) Test(org.junit.Test)

Example 4 with APITemplateBuilderImpl

use of org.wso2.carbon.apimgt.rest.api.publisher.v1.common.template.APITemplateBuilderImpl in project carbon-apimgt by wso2.

the class WebSubConfigContextTest method testWithoutSecretConfigContextForAPI.

@Test
public void testWithoutSecretConfigContextForAPI() throws Exception {
    API api = new API(new APIIdentifier("admin", "websubAPI", "1.0.0"));
    api.setStatus(APIConstants.CREATED);
    api.setContextTemplate("/websub");
    api.setTransports(Constants.TRANSPORT_HTTP);
    api.setEndpointSecured(false);
    api.setUriTemplates(setAPIUriTemplates());
    api.setType(APIConstants.APITransportType.WEBSUB.toString());
    WebsubSubscriptionConfiguration webSubConfig = new WebsubSubscriptionConfiguration(false, "", "", "");
    api.setWebsubSubscriptionConfiguration(webSubConfig);
    Environment environment = new Environment();
    environment.setType("production");
    config = Mockito.mock(APIManagerConfiguration.class);
    APIManagerConfigurationService apiManagerConfigurationService = new APIManagerConfigurationServiceImpl(config);
    ServiceReferenceHolder.getInstance().setAPIManagerConfigurationService(apiManagerConfigurationService);
    String templatePath = System.getProperty("user.dir") + File.separator + "src" + File.separator + "test" + File.separator + "resources" + File.separator;
    System.setProperty("carbon.home", templatePath);
    APITemplateBuilderImpl apiTemplateBuilder = new APITemplateBuilderImpl(api, null, null);
    String updatedTemplate = apiTemplateBuilder.getConfigStringForTemplate(environment);
    Assert.assertFalse("The websub velocity template is not updated correctly", updatedTemplate.contains("generated_signature"));
}
Also used : APIManagerConfiguration(org.wso2.carbon.apimgt.impl.APIManagerConfiguration) APIManagerConfigurationService(org.wso2.carbon.apimgt.impl.APIManagerConfigurationService) APIManagerConfigurationServiceImpl(org.wso2.carbon.apimgt.impl.APIManagerConfigurationServiceImpl) Environment(org.wso2.carbon.apimgt.api.model.Environment) API(org.wso2.carbon.apimgt.api.model.API) APIIdentifier(org.wso2.carbon.apimgt.api.model.APIIdentifier) WebsubSubscriptionConfiguration(org.wso2.carbon.apimgt.api.model.WebsubSubscriptionConfiguration) APITemplateBuilderImpl(org.wso2.carbon.apimgt.rest.api.publisher.v1.common.template.APITemplateBuilderImpl) Test(org.junit.Test)

Example 5 with APITemplateBuilderImpl

use of org.wso2.carbon.apimgt.rest.api.publisher.v1.common.template.APITemplateBuilderImpl in project carbon-apimgt by wso2.

the class TemplateBuilderUtil method getAPITemplateBuilder.

public static APITemplateBuilderImpl getAPITemplateBuilder(API api, String tenantDomain, List<ClientCertificateDTO> clientCertificateDTOS, List<SoapToRestMediationDto> soapToRestInMediationDtos, List<SoapToRestMediationDto> soapToRestMediationDtos) throws APIManagementException {
    int tenantId = APIUtil.getTenantIdFromTenantDomain(tenantDomain);
    APITemplateBuilderImpl vtb = new APITemplateBuilderImpl(api, soapToRestInMediationDtos, soapToRestMediationDtos);
    Map<String, String> latencyStatsProperties = new HashMap<String, String>();
    latencyStatsProperties.put(APIConstants.API_UUID, api.getUUID());
    if (!APIUtil.isStreamingApi(api)) {
        vtb.addHandler("org.wso2.carbon.apimgt.gateway.handlers.common.APIMgtLatencyStatsHandler", latencyStatsProperties);
    }
    Map<String, String> corsProperties = new HashMap<String, String>();
    corsProperties.put(APIConstants.CORSHeaders.IMPLEMENTATION_TYPE_HANDLER_VALUE, api.getImplementation());
    // Get authorization header from the API object or from the tenant registry
    String authorizationHeader;
    if (!StringUtils.isBlank(api.getAuthorizationHeader())) {
        authorizationHeader = api.getAuthorizationHeader();
    } else {
        // Retrieves the auth configuration from tenant registry or api-manager.xml if not available
        // in tenant registry
        authorizationHeader = APIUtil.getOAuthConfiguration(tenantDomain, APIConstants.AUTHORIZATION_HEADER);
    }
    if (!StringUtils.isBlank(authorizationHeader)) {
        corsProperties.put(APIConstants.AUTHORIZATION_HEADER, authorizationHeader);
    }
    if (!(APIConstants.APITransportType.WS.toString().equals(api.getType()))) {
        if (api.getCorsConfiguration() != null && api.getCorsConfiguration().isCorsConfigurationEnabled()) {
            CORSConfiguration corsConfiguration = api.getCorsConfiguration();
            if (corsConfiguration.getAccessControlAllowHeaders() != null) {
                StringBuilder allowHeaders = new StringBuilder();
                for (String header : corsConfiguration.getAccessControlAllowHeaders()) {
                    allowHeaders.append(header).append(',');
                }
                if (allowHeaders.length() != 0) {
                    allowHeaders.deleteCharAt(allowHeaders.length() - 1);
                    corsProperties.put(APIConstants.CORSHeaders.ALLOW_HEADERS_HANDLER_VALUE, allowHeaders.toString());
                }
            }
            if (corsConfiguration.getAccessControlAllowOrigins() != null) {
                StringBuilder allowOrigins = new StringBuilder();
                for (String origin : corsConfiguration.getAccessControlAllowOrigins()) {
                    allowOrigins.append(origin).append(',');
                }
                if (allowOrigins.length() != 0) {
                    allowOrigins.deleteCharAt(allowOrigins.length() - 1);
                    corsProperties.put(APIConstants.CORSHeaders.ALLOW_ORIGIN_HANDLER_VALUE, allowOrigins.toString());
                }
            }
            if (corsConfiguration.getAccessControlAllowMethods() != null) {
                StringBuilder allowedMethods = new StringBuilder();
                for (String methods : corsConfiguration.getAccessControlAllowMethods()) {
                    allowedMethods.append(methods).append(',');
                }
                if (allowedMethods.length() != 0) {
                    allowedMethods.deleteCharAt(allowedMethods.length() - 1);
                    corsProperties.put(APIConstants.CORSHeaders.ALLOW_METHODS_HANDLER_VALUE, allowedMethods.toString());
                }
            }
            if (corsConfiguration.isAccessControlAllowCredentials()) {
                corsProperties.put(APIConstants.CORSHeaders.ALLOW_CREDENTIALS_HANDLER_VALUE, String.valueOf(corsConfiguration.isAccessControlAllowCredentials()));
            }
            vtb.addHandler("org.wso2.carbon.apimgt.gateway.handlers.security.CORSRequestHandler", corsProperties);
        } else if (APIUtil.isCORSEnabled()) {
            vtb.addHandler("org.wso2.carbon.apimgt.gateway.handlers.security.CORSRequestHandler", corsProperties);
        }
        vtb.addHandler("org.wso2.carbon.apimgt.gateway.handlers.common.APIStatusHandler", Collections.emptyMap());
    }
    Map<String, String> clientCertificateObject = null;
    CertificateMgtUtils certificateMgtUtils = CertificateMgtUtils.getInstance();
    if (clientCertificateDTOS != null) {
        clientCertificateObject = new HashMap<>();
        for (ClientCertificateDTO clientCertificateDTO : clientCertificateDTOS) {
            clientCertificateObject.put(certificateMgtUtils.getUniqueIdentifierOfCertificate(clientCertificateDTO.getCertificate()), clientCertificateDTO.getTierName());
        }
    }
    Map<String, String> authProperties = new HashMap<>();
    if (!StringUtils.isBlank(authorizationHeader)) {
        authProperties.put(APIConstants.AUTHORIZATION_HEADER, authorizationHeader);
    }
    String apiSecurity = api.getApiSecurity();
    String apiLevelPolicy = api.getApiLevelPolicy();
    authProperties.put(APIConstants.API_SECURITY, apiSecurity);
    authProperties.put(APIConstants.API_LEVEL_POLICY, apiLevelPolicy);
    if (clientCertificateObject != null) {
        authProperties.put(APIConstants.CERTIFICATE_INFORMATION, clientCertificateObject.toString());
    }
    // Get RemoveHeaderFromOutMessage from tenant registry or api-manager.xml
    String removeHeaderFromOutMessage = APIUtil.getOAuthConfiguration(tenantDomain, APIConstants.REMOVE_OAUTH_HEADER_FROM_OUT_MESSAGE);
    if (!StringUtils.isBlank(removeHeaderFromOutMessage)) {
        authProperties.put(APIConstants.REMOVE_OAUTH_HEADER_FROM_OUT_MESSAGE, removeHeaderFromOutMessage);
    } else {
        authProperties.put(APIConstants.REMOVE_OAUTH_HEADER_FROM_OUT_MESSAGE, APIConstants.REMOVE_OAUTH_HEADER_FROM_OUT_MESSAGE_DEFAULT);
    }
    authProperties.put(APIConstants.API_UUID, api.getUUID());
    authProperties.put("keyManagers", String.join(",", api.getKeyManagers()));
    if (APIConstants.GRAPHQL_API.equals(api.getType())) {
        Map<String, String> apiUUIDProperty = new HashMap<String, String>();
        apiUUIDProperty.put(APIConstants.API_UUID, api.getUUID());
        vtb.addHandler("org.wso2.carbon.apimgt.gateway.handlers.graphQL.GraphQLAPIHandler", apiUUIDProperty);
    }
    if (APIConstants.APITransportType.WEBSUB.toString().equals(api.getType())) {
        authProperties.put(APIConstants.WebHookProperties.EVENT_RECEIVING_RESOURCE_PATH, APIConstants.WebHookProperties.DEFAULT_SUBSCRIPTION_RESOURCE_PATH);
        authProperties.put(APIConstants.WebHookProperties.TOPIC_QUERY_PARAM_NAME, APIConstants.WebHookProperties.DEFAULT_TOPIC_QUERY_PARAM_NAME);
        vtb.addHandler("org.wso2.carbon.apimgt.gateway.handlers.streaming.webhook.WebhookApiHandler", authProperties);
        vtb.addHandler("org.wso2.carbon.apimgt.gateway.handlers.streaming.webhook." + "WebhooksExtensionHandler", Collections.emptyMap());
    } else if (APIConstants.APITransportType.SSE.toString().equals(api.getType())) {
        vtb.addHandler("org.wso2.carbon.apimgt.gateway.handlers.streaming.sse.SseApiHandler", authProperties);
    } else if (!(APIConstants.APITransportType.WS.toString().equals(api.getType()))) {
        vtb.addHandler("org.wso2.carbon.apimgt.gateway.handlers.security.APIAuthenticationHandler", authProperties);
    }
    if (APIConstants.GRAPHQL_API.equals(api.getType())) {
        vtb.addHandler("org.wso2.carbon.apimgt.gateway.handlers.graphQL.GraphQLQueryAnalysisHandler", Collections.emptyMap());
    }
    if (!APIUtil.isStreamingApi(api)) {
        Map<String, String> properties = new HashMap<String, String>();
        if (api.getProductionMaxTps() != null) {
            properties.put("productionMaxCount", api.getProductionMaxTps());
        }
        if (api.getSandboxMaxTps() != null) {
            properties.put("sandboxMaxCount", api.getSandboxMaxTps());
        }
        vtb.addHandler("org.wso2.carbon.apimgt.gateway.handlers.throttling.ThrottleHandler", properties);
        properties = new HashMap<String, String>();
        properties.put("configKey", APIConstants.GA_CONF_KEY);
        vtb.addHandler("org.wso2.carbon.apimgt.gateway.handlers.analytics.APIMgtGoogleAnalyticsTrackingHandler", properties);
        String extensionHandlerPosition = getExtensionHandlerPosition(tenantDomain);
        if ("top".equalsIgnoreCase(extensionHandlerPosition)) {
            vtb.addHandlerPriority("org.wso2.carbon.apimgt.gateway.handlers.ext.APIManagerExtensionHandler", Collections.emptyMap(), 2);
        } else {
            vtb.addHandler("org.wso2.carbon.apimgt.gateway.handlers.ext.APIManagerExtensionHandler", Collections.emptyMap());
        }
    }
    return vtb;
}
Also used : CORSConfiguration(org.wso2.carbon.apimgt.api.model.CORSConfiguration) HashMap(java.util.HashMap) ClientCertificateDTO(org.wso2.carbon.apimgt.api.dto.ClientCertificateDTO) CertificateMgtUtils(org.wso2.carbon.apimgt.impl.utils.CertificateMgtUtils) APITemplateBuilderImpl(org.wso2.carbon.apimgt.rest.api.publisher.v1.common.template.APITemplateBuilderImpl)

Aggregations

APITemplateBuilderImpl (org.wso2.carbon.apimgt.rest.api.publisher.v1.common.template.APITemplateBuilderImpl)5 HashMap (java.util.HashMap)3 API (org.wso2.carbon.apimgt.api.model.API)3 Test (org.junit.Test)2 ClientCertificateDTO (org.wso2.carbon.apimgt.api.dto.ClientCertificateDTO)2 APIIdentifier (org.wso2.carbon.apimgt.api.model.APIIdentifier)2 CORSConfiguration (org.wso2.carbon.apimgt.api.model.CORSConfiguration)2 Environment (org.wso2.carbon.apimgt.api.model.Environment)2 WebsubSubscriptionConfiguration (org.wso2.carbon.apimgt.api.model.WebsubSubscriptionConfiguration)2 APIManagerConfiguration (org.wso2.carbon.apimgt.impl.APIManagerConfiguration)2 APIManagerConfigurationService (org.wso2.carbon.apimgt.impl.APIManagerConfigurationService)2 APIManagerConfigurationServiceImpl (org.wso2.carbon.apimgt.impl.APIManagerConfigurationServiceImpl)2 CertificateMgtUtils (org.wso2.carbon.apimgt.impl.utils.CertificateMgtUtils)2 Map (java.util.Map)1 GatewayAPIDTO (org.wso2.carbon.apimgt.api.gateway.GatewayAPIDTO)1 GatewayContentDTO (org.wso2.carbon.apimgt.api.gateway.GatewayContentDTO)1 APIProductIdentifier (org.wso2.carbon.apimgt.api.model.APIProductIdentifier)1 APITemplateBuilder (org.wso2.carbon.apimgt.impl.template.APITemplateBuilder)1 APIDTO (org.wso2.carbon.apimgt.rest.api.publisher.v1.dto.APIDTO)1