Search in sources :

Example 16 with API

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

the class SynapseXMLConfigurationFactory method defineAPI.

public static API defineAPI(SynapseConfiguration config, OMElement elem, Properties properties) {
    API api = null;
    try {
        api = APIFactory.createAPI(elem, properties);
        config.addAPI(api.getName(), api);
    } catch (Exception e) {
        String msg = "API configuration cannot be built";
        handleConfigurationError(SynapseConstants.FAIL_SAFE_MODE_API, msg, e);
    }
    return api;
}
Also used : API(org.apache.synapse.rest.API) SynapseException(org.apache.synapse.SynapseException)

Example 17 with API

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

the class SynapseXMLConfigurationFactory method defineAPI.

/**
 * Add api with the option of re-ordering the api collection based on the context
 *
 * @param config SynapseConfiguration
 * @param elem OMElement element
 * @param properties Properties
 * @param reOrder reorder the deployment order based on the context
 * @return API api object
 */
public static API defineAPI(SynapseConfiguration config, OMElement elem, Properties properties, boolean reOrder) {
    API api = null;
    try {
        api = APIFactory.createAPI(elem, properties);
        config.addAPI(api.getName(), api, reOrder);
    } catch (Exception e) {
        String msg = "API configuration cannot be built";
        handleConfigurationError(SynapseConstants.FAIL_SAFE_MODE_API, msg, e);
    }
    return api;
}
Also used : API(org.apache.synapse.rest.API) SynapseException(org.apache.synapse.SynapseException)

Example 18 with API

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

the class SynapseXMLConfigurationSerializer method serializeAPIs.

private static void serializeAPIs(OMElement definitions, Collection<API> apiSet) {
    for (API api : apiSet) {
        OMElement apiElt = APISerializer.serializeAPI(api);
        definitions.addChild(apiElt);
    }
}
Also used : API(org.apache.synapse.rest.API)

Example 19 with API

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

the class SynapseConfigurationTest method testAPITableOrderWithAddAPI.

public void testAPITableOrderWithAddAPI() {
    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);
    config.addAPI("API2", api2);
    config.addAPI("API3", api3);
    // this should get the api table in descending order with longest at the first
    Collection<API> apis = config.getAPIs();
    API[] apisArray = apis.toArray(new API[apis.size()]);
    // api3 with context /context/test/ctx should be first in the list
    assertEquals("Order is not correct", api3, apisArray[0]);
}
Also used : API(org.apache.synapse.rest.API)

Example 20 with API

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

the class APIDeployer method deploySynapseArtifact.

@Override
public String deploySynapseArtifact(OMElement artifactConfig, String fileName, Properties properties) {
    CustomLogSetter.getInstance().setLogAppender(customLogContent);
    if (log.isDebugEnabled()) {
        log.debug("API deployment from file : " + fileName + " : Started");
    }
    try {
        API api = APIFactory.createAPI(artifactConfig, properties);
        api.setArtifactContainerName(customLogContent);
        if (api != null) {
            api.setFileName((new File(fileName)).getName());
            if (log.isDebugEnabled()) {
                log.debug("API named '" + api.getName() + "' has been built from the file " + fileName);
            }
            api.init(getSynapseEnvironment());
            if (log.isDebugEnabled()) {
                log.debug("Initialized the API: " + api.getName());
            }
            getSynapseConfiguration().addAPI(api.getName(), api);
            if (log.isDebugEnabled()) {
                log.debug("API deployment from file : " + fileName + " : Completed");
            }
            log.info("API named '" + api.getName() + "' has been deployed from file : " + fileName);
            return api.getName();
        } else {
            handleSynapseArtifactDeploymentError("API deployment Failed. The artifact " + "described in the file " + fileName + " is not a valid API");
        }
    } catch (Exception e) {
        handleSynapseArtifactDeploymentError("API deployment from the file : " + fileName + " : Failed.", e);
    }
    return null;
}
Also used : API(org.apache.synapse.rest.API) File(java.io.File) DeploymentException(org.apache.axis2.deployment.DeploymentException)

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