Search in sources :

Example 61 with Types

use of org.wso2.ballerinalang.compiler.semantics.analyzer.Types in project carbon-apimgt by wso2.

the class WSDLSOAPOperationExtractorImplTestCase method testGetSwaggerModelForCompositeComplexType.

@Test
public void testGetSwaggerModelForCompositeComplexType() throws Exception {
    APIMWSDLReader wsdlReader = new APIMWSDLReader(Thread.currentThread().getContextClassLoader().getResource("wsdls/sample-service.wsdl").toExternalForm());
    byte[] wsdlContent = wsdlReader.getWSDL();
    WSDL11SOAPOperationExtractor processor = SOAPOperationBindingUtils.getWSDL11SOAPOperationExtractor(wsdlContent, wsdlReader);
    Map<String, ModelImpl> parameterModelMap = processor.getWsdlInfo().getParameterModelMap();
    Assert.assertNotNull(parameterModelMap);
    Assert.assertTrue("wsdl complex types has not been properly parsed", parameterModelMap.size() == 12);
    // composite complex type
    Assert.assertNotNull(parameterModelMap.get("ItemSearchRequest"));
    Assert.assertEquals(7, parameterModelMap.get("ItemSearchRequest").getProperties().size());
    Assert.assertNotNull(parameterModelMap.get("ItemSearchRequest").getProperties().get("Tracks"));
    Assert.assertNotNull(parameterModelMap.get("ItemSearchRequest").getProperties().get("Tracks"));
    Assert.assertEquals(ArrayProperty.TYPE, parameterModelMap.get("ItemSearchRequest").getProperties().get("Tracks").getType());
    Assert.assertNotNull(((ArrayProperty) parameterModelMap.get("ItemSearchRequest").getProperties().get("Tracks")).getItems());
}
Also used : APIMWSDLReader(org.wso2.carbon.apimgt.impl.utils.APIMWSDLReader) ModelImpl(io.swagger.models.ModelImpl) Test(org.junit.Test) PrepareForTest(org.powermock.core.classloader.annotations.PrepareForTest)

Example 62 with Types

use of org.wso2.ballerinalang.compiler.semantics.analyzer.Types in project carbon-apimgt by wso2.

the class FaultyRequestDataCollector method collectData.

public void collectData() throws AnalyticsException {
    log.debug("Handling faulty analytics types");
    Event faultyEvent = getFaultyEvent();
    switch(provider.getFaultType()) {
        case AUTH:
            authDataCollector.collectFaultData(faultyEvent);
            break;
        case THROTTLED:
            throttledDataCollector.collectFaultData(faultyEvent);
            break;
        case TARGET_CONNECTIVITY:
            targetDataCollector.collectFaultData(faultyEvent);
            break;
        case OTHER:
            unclassifiedFaultDataCollector.collectFaultData(faultyEvent);
            break;
    }
}
Also used : Event(org.wso2.carbon.apimgt.common.analytics.publishers.dto.Event)

Example 63 with Types

use of org.wso2.ballerinalang.compiler.semantics.analyzer.Types in project carbon-apimgt by wso2.

the class SuccessRequestDataCollector method collectData.

public void collectData() throws AnalyticsException {
    log.debug("Handling success analytics types");
    long requestInTime = provider.getRequestTime();
    String offsetDateTime = getTimeInISO(requestInTime);
    Event event = new Event();
    API api = provider.getApi();
    Operation operation = provider.getOperation();
    Target target = provider.getTarget();
    Application application;
    if (provider.isAnonymous()) {
        application = getAnonymousApp();
    } else {
        application = provider.getApplication();
    }
    Latencies latencies = provider.getLatencies();
    MetaInfo metaInfo = provider.getMetaInfo();
    String userAgent = provider.getUserAgentHeader();
    String userIp = provider.getEndUserIP();
    if (userIp == null) {
        userIp = Constants.UNKNOWN_VALUE;
    }
    event.setApi(api);
    event.setOperation(operation);
    event.setTarget(target);
    event.setApplication(application);
    event.setLatencies(latencies);
    event.setProxyResponseCode(provider.getProxyResponseCode());
    event.setRequestTimestamp(offsetDateTime);
    event.setMetaInfo(metaInfo);
    event.setUserAgentHeader(userAgent);
    event.setUserIp(userIp);
    this.processor.publish(event);
}
Also used : Target(org.wso2.carbon.apimgt.common.analytics.publishers.dto.Target) Latencies(org.wso2.carbon.apimgt.common.analytics.publishers.dto.Latencies) MetaInfo(org.wso2.carbon.apimgt.common.analytics.publishers.dto.MetaInfo) Event(org.wso2.carbon.apimgt.common.analytics.publishers.dto.Event) API(org.wso2.carbon.apimgt.common.analytics.publishers.dto.API) Operation(org.wso2.carbon.apimgt.common.analytics.publishers.dto.Operation) Application(org.wso2.carbon.apimgt.common.analytics.publishers.dto.Application)

Example 64 with Types

use of org.wso2.ballerinalang.compiler.semantics.analyzer.Types in project carbon-apimgt by wso2.

the class APIUtil method getTokenEndpointsByType.

public static String getTokenEndpointsByType(String type, String organization) throws APIManagementException {
    Map<String, Environment> environments = getEnvironments(organization);
    Map<String, String> map = new HashMap<>();
    String productionUrl = "";
    String sandboxUrl = "";
    String hybridUrl = "";
    // Set URL for a given default env
    for (Environment environment : environments.values()) {
        String environmentUrl = getHttpsEnvironmentUrl(environment);
        String environmentType = environment.getType();
        boolean isDefault = environment.isDefault();
        if (APIConstants.GATEWAY_ENV_TYPE_HYBRID.equals(environmentType)) {
            if (isDefault) {
                map.put(APIConstants.GATEWAY_ENV_TYPE_HYBRID, environmentUrl);
            } else {
                hybridUrl = environmentUrl;
            }
        } else if (APIConstants.GATEWAY_ENV_TYPE_PRODUCTION.equals(environmentType)) {
            if (isDefault) {
                map.put(APIConstants.GATEWAY_ENV_TYPE_PRODUCTION, environmentUrl);
            } else {
                productionUrl = environmentUrl;
            }
        } else if (APIConstants.GATEWAY_ENV_TYPE_SANDBOX.equals(environmentType)) {
            if (isDefault) {
                map.put(APIConstants.GATEWAY_ENV_TYPE_SANDBOX, environmentUrl);
            } else {
                sandboxUrl = environmentUrl;
            }
        } else {
            log.warn("Invalid gateway environment type : " + environmentType + " has been configured in api-manager.xml");
        }
    }
    // If no default envs are specified, set URL from each of the configured env types at random
    if (map.isEmpty()) {
        if (StringUtils.isNotEmpty(productionUrl)) {
            map.put(APIConstants.GATEWAY_ENV_TYPE_PRODUCTION, productionUrl);
        }
        if (StringUtils.isNotEmpty(sandboxUrl)) {
            map.put(APIConstants.GATEWAY_ENV_TYPE_SANDBOX, sandboxUrl);
        }
        if (StringUtils.isNotEmpty(hybridUrl)) {
            map.put(APIConstants.GATEWAY_ENV_TYPE_HYBRID, hybridUrl);
        }
    }
    if (map.containsKey(APIConstants.GATEWAY_ENV_TYPE_HYBRID)) {
        return map.get(APIConstants.GATEWAY_ENV_TYPE_HYBRID);
    }
    if (map.containsKey(APIConstants.GATEWAY_ENV_TYPE_PRODUCTION)) {
        return map.get(APIConstants.GATEWAY_ENV_TYPE_PRODUCTION);
    }
    if (map.containsKey(APIConstants.GATEWAY_ENV_TYPE_SANDBOX)) {
        return map.get(APIConstants.GATEWAY_ENV_TYPE_SANDBOX);
    }
    return map.get(type);
}
Also used : LinkedHashMap(java.util.LinkedHashMap) HashMap(java.util.HashMap) RecommendationEnvironment(org.wso2.carbon.apimgt.impl.recommendationmgt.RecommendationEnvironment) Environment(org.wso2.carbon.apimgt.api.model.Environment) ExternalEnvironment(org.wso2.carbon.apimgt.impl.ExternalEnvironment)

Example 65 with Types

use of org.wso2.ballerinalang.compiler.semantics.analyzer.Types in project carbon-apimgt by wso2.

the class ExtendedHTTPEventAdaptorTestCase method testHttpPublisherFactory.

@Test
public void testHttpPublisherFactory() {
    logger.info("Test case for factory properties of Extended HTTP output adaptor.");
    ExtendedHTTPEventAdapterFactory adapterFactory = new ExtendedHTTPEventAdapterFactory();
    List<Property> dyPropertyList = adapterFactory.getDynamicPropertyList();
    List<Property> propertyList = new ArrayList<>();
    Property property = new Property("http.url");
    property.setRequired(true);
    property.setSecured(false);
    property.setEncrypted(false);
    property.setDisplayName("URL");
    property.setDefaultValue(null);
    property.setOptions(null);
    property.setHint("The target HTTP/HTTPS URL, e.g. \"http://yourhost:8080/service\"");
    propertyList.add(property);
    property = new Property("http.username");
    property.setRequired(false);
    property.setSecured(false);
    property.setEncrypted(false);
    property.setDisplayName("Username");
    property.setDefaultValue(null);
    property.setOptions(null);
    property.setHint("HTTP BasicAuth username");
    propertyList.add(property);
    property = new Property("http.password");
    property.setRequired(false);
    property.setSecured(true);
    property.setEncrypted(true);
    property.setDisplayName("Password");
    property.setDefaultValue(null);
    property.setOptions(null);
    property.setHint("HTTP BasicAuth password");
    propertyList.add(property);
    property = new Property("http.headers");
    property.setRequired(false);
    property.setSecured(false);
    property.setEncrypted(false);
    property.setDisplayName("Headers");
    property.setDefaultValue(null);
    property.setOptions(null);
    property.setHint("Custom HTTP headers, e.g. \"header1: value1, header2: value2\"");
    propertyList.add(property);
    Assert.assertEquals(4, dyPropertyList.size());
    int i = 0;
    for (Property prop : propertyList) {
        Assert.assertEquals(prop.getPropertyName(), dyPropertyList.get(i).getPropertyName());
        Assert.assertEquals(prop.getDefaultValue(), dyPropertyList.get(i).getDefaultValue());
        Assert.assertEquals(prop.getDisplayName(), dyPropertyList.get(i).getDisplayName());
        Assert.assertEquals(prop.getHint(), dyPropertyList.get(i).getHint());
        i++;
    }
    List<String> types = new ArrayList<>();
    types.add("text");
    types.add("xml");
    types.add("json");
    List<String> supportedTypes = adapterFactory.getSupportedMessageFormats();
    Assert.assertEquals(supportedTypes.toString(), types.toString());
    Assert.assertEquals("http-extended", adapterFactory.getType());
    setupCarbonConfig();
    PrivilegedCarbonContext privilegedCarbonContext = PrivilegedCarbonContext.getThreadLocalCarbonContext();
    privilegedCarbonContext.setTenantId(-1234);
    OutputEventAdapterConfiguration eventAdapterConfiguration = new OutputEventAdapterConfiguration();
    eventAdapterConfiguration.setName("TestHttpAdaptor");
    eventAdapterConfiguration.setType("http-extended");
    eventAdapterConfiguration.setMessageFormat("text");
    Map<String, String> staticPropertes = new HashMap<>();
    staticPropertes.put("http.client.method", "HttpPost");
    staticPropertes.put("http.proxy.port", "9090");
    staticPropertes.put("http.proxy.host", "localhost");
    staticPropertes.put("oauth.url", "localhost:9090/token");
    staticPropertes.put("oauth.consumer.key", "key");
    staticPropertes.put("oauth.consumer.secret", "secret");
    eventAdapterConfiguration.setStaticProperties(staticPropertes);
    Map<String, String> globalProperties = new HashMap<>();
    globalProperties.put("jobQueueSize", "10000");
    globalProperties.put("keepAliveTimeInMillis", "20000");
    globalProperties.put("maxThread", "100");
    globalProperties.put("minThread", "8");
    globalProperties.put("defaultMaxConnectionsPerHost", "50");
    globalProperties.put("maxTotalConnections", "1000");
    adapterFactory.createEventAdapter(eventAdapterConfiguration, globalProperties);
}
Also used : HashMap(java.util.HashMap) ArrayList(java.util.ArrayList) PrivilegedCarbonContext(org.wso2.carbon.context.PrivilegedCarbonContext) Property(org.wso2.carbon.event.output.adapter.core.Property) OutputEventAdapterConfiguration(org.wso2.carbon.event.output.adapter.core.OutputEventAdapterConfiguration) Test(org.junit.Test)

Aggregations

ArrayList (java.util.ArrayList)20 Test (org.testng.annotations.Test)15 BType (org.wso2.ballerinalang.compiler.semantics.model.types.BType)13 SiddhiManager (org.wso2.siddhi.core.SiddhiManager)12 HashMap (java.util.HashMap)11 Map (java.util.Map)11 APIManagementException (org.wso2.carbon.apimgt.api.APIManagementException)10 List (java.util.List)8 JsonObject (com.google.gson.JsonObject)5 Test (org.junit.Test)5 SiddhiAppRuntime (org.wso2.siddhi.core.SiddhiAppRuntime)5 Arrays (java.util.Arrays)4 Collectors (java.util.stream.Collectors)4 JSONObject (org.json.simple.JSONObject)4 BSymbol (org.wso2.ballerinalang.compiler.semantics.model.symbols.BSymbol)4 BLangPackage (org.wso2.ballerinalang.compiler.tree.BLangPackage)4 JsonElement (com.google.gson.JsonElement)3 Paths (java.nio.file.Paths)3 TokenStream (org.antlr.v4.runtime.TokenStream)3 StringUtils (org.apache.commons.lang3.StringUtils)3