Search in sources :

Example 6 with API

use of org.apache.synapse.rest.API in project wso2-synapse by wso2.

the class SynapseXMLConfigurationSerializerTest method testSerializeConfiguration11.

/**
 * Test serializeConfigurationMethod with API added for SynapseConfiguration and assert OMElement returned
 */
@Test
public void testSerializeConfiguration11() {
    SynapseXMLConfigurationSerializer serializer = new SynapseXMLConfigurationSerializer();
    SynapseConfiguration synapseConfiguration = new SynapseConfiguration();
    API api = new API("testAPI", "/");
    synapseConfiguration.addAPI(api.getName(), api);
    OMElement element = serializer.serializeConfiguration(synapseConfiguration);
    Assert.assertNotNull("OMElement is not returned", element);
    Assert.assertEquals("definitions", element.getLocalName());
    Assert.assertTrue("testAPI added is not serialized.", element.getChildren().next().toString().contains("name=\"testAPI\""));
}
Also used : API(org.apache.synapse.rest.API) OMElement(org.apache.axiom.om.OMElement) SynapseConfiguration(org.apache.synapse.config.SynapseConfiguration) Test(org.junit.Test)

Example 7 with API

use of org.apache.synapse.rest.API in project wso2-synapse by wso2.

the class SynapseConfigurationTest method testAPITableOrderWithAddAPIwithoutReOrder.

public void testAPITableOrderWithAddAPIwithoutReOrder() {
    SynapseConfiguration config = new SynapseConfiguration();
    API api1 = new API("API1", "/context/test");
    API api2 = new API("API2", "/context");
    API api3 = new API("API3", "/context/test/ctx");
    config.addAPI("API1", api1, false);
    config.addAPI("API2", api2, false);
    config.addAPI("API3", api3, false);
    // this should get the api table as it is.
    Collection<API> apis = config.getAPIs();
    API[] apisArray = apis.toArray(new API[apis.size()]);
    // api1 with context /context/test/ctx should be first in the list
    assertEquals("Order is not correct before sorting", api1, apisArray[0]);
    // calling explicitly to order the apitable
    config.reconstructAPITable();
    apis = config.getAPIs();
    API[] apisArray2 = apis.toArray(new API[apis.size()]);
    // api3 with context /context/test/ctx should be first in the list
    assertEquals("Order is not correct", api3, apisArray2[0]);
}
Also used : API(org.apache.synapse.rest.API)

Example 8 with API

use of org.apache.synapse.rest.API in project wso2-synapse by wso2.

the class StatisticSynapseConfigurationObserverTest method testApiUpdated.

/**
 * Test apiUpdated method by hash generation.
 */
@Test
public void testApiUpdated() {
    final String apiName = "testName";
    final String apiContext = "/testContext";
    API api = new API(apiName, apiContext);
    observer.apiUpdated(api);
    Assert.assertNotNull("New hash must be set by the method", api.getAspectConfiguration().getHashCode());
}
Also used : API(org.apache.synapse.rest.API) Test(org.junit.Test)

Example 9 with API

use of org.apache.synapse.rest.API in project wso2-synapse by wso2.

the class SynapseConfiguration method updateAPI.

public synchronized void updateAPI(String name, API api) {
    if (!apiTable.containsKey(name)) {
        handleException("No API exists by the name: " + name);
    } else {
        for (API existingAPI : apiTable.values()) {
            if (!api.getName().equals(existingAPI.getName()) && api.getVersion().equals(existingAPI.getVersion()) && existingAPI.getContext().equals(api.getContext())) {
                handleException("URL context: " + api.getContext() + " is already registered" + " with the API: " + existingAPI.getName());
            }
        }
        apiTable.put(name, api);
        reconstructAPITable();
        for (SynapseObserver o : observers) {
            o.apiUpdated(api);
        }
    }
}
Also used : API(org.apache.synapse.rest.API)

Example 10 with API

use of org.apache.synapse.rest.API in project wso2-synapse by wso2.

the class SynapseConfiguration method reconstructAPITable.

/**
 * This method reconstructs the apiTable in descending order of context
 */
public synchronized void reconstructAPITable() {
    if (log.isDebugEnabled()) {
        log.debug("Start re-constructing the API Table...");
    }
    Map<String, API> duplicateAPITable = new LinkedHashMap<String, API>();
    String[] contextValues = new String[apiTable.size()];
    int i = 0;
    for (API api : apiTable.values()) {
        contextValues[i] = api.getContext();
        i++;
    }
    Arrays.sort(contextValues, new java.util.Comparator<String>() {

        public int compare(String context1, String context2) {
            return context1.length() - context2.length();
        }
    });
    ArrayUtils.reverse(contextValues);
    for (String context : contextValues) {
        for (String mapKeys : apiTable.keySet()) {
            if (context.equals(apiTable.get(mapKeys).getContext())) {
                duplicateAPITable.put(mapKeys, apiTable.get(mapKeys));
                break;
            }
        }
    }
    apiTable = duplicateAPITable;
}
Also used : API(org.apache.synapse.rest.API) InboundEndpoint(org.apache.synapse.inbound.InboundEndpoint) Endpoint(org.apache.synapse.endpoints.Endpoint) LinkedHashMap(java.util.LinkedHashMap)

Aggregations

API (org.apache.synapse.rest.API)26 OMElement (org.apache.axiom.om.OMElement)10 DeploymentException (org.apache.axis2.deployment.DeploymentException)4 SynapseException (org.apache.synapse.SynapseException)4 ProxyService (org.apache.synapse.core.axis2.ProxyService)4 InboundEndpoint (org.apache.synapse.inbound.InboundEndpoint)4 PriorityExecutor (org.apache.synapse.commons.executors.PriorityExecutor)3 Endpoint (org.apache.synapse.endpoints.Endpoint)3 TemplateMediator (org.apache.synapse.mediators.template.TemplateMediator)3 MessageProcessor (org.apache.synapse.message.processor.MessageProcessor)3 MessageStore (org.apache.synapse.message.store.MessageStore)3 Resource (org.apache.synapse.rest.Resource)3 File (java.io.File)2 Iterator (java.util.Iterator)2 ManagedLifecycle (org.apache.synapse.ManagedLifecycle)2 Mediator (org.apache.synapse.Mediator)2 APIMediationFlowPoint (org.apache.synapse.debug.constructs.APIMediationFlowPoint)2 SynapseMediationFlowPoint (org.apache.synapse.debug.constructs.SynapseMediationFlowPoint)2 SynapseSequenceType (org.apache.synapse.debug.constructs.SynapseSequenceType)2 AbstractMediator (org.apache.synapse.mediators.AbstractMediator)2