Search in sources :

Example 66 with SynapseConfiguration

use of org.apache.synapse.config.SynapseConfiguration in project wso2-synapse by wso2.

the class MultiXMLConfigurationBuilder method getConfiguration.

public static SynapseConfiguration getConfiguration(String root, Properties properties) {
    log.info("Building synapse configuration from the synapse artifact repository at : " + root);
    // First try to load the configuration from synapse.xml
    SynapseConfiguration synapseConfig = createConfigurationFromSynapseXML(root, properties);
    if (synapseConfig == null) {
        synapseConfig = SynapseConfigUtils.newConfiguration();
        synapseConfig.setDefaultQName(XMLConfigConstants.DEFINITIONS_ELT);
    } else if (log.isDebugEnabled()) {
        log.debug("Found a synapse configuration in the " + SynapseConstants.SYNAPSE_XML + " file at the artifact repository root, which gets precedence " + "over other definitions");
    }
    if (synapseConfig.getRegistry() == null) {
        // If the synapse.xml does not define a registry look for a registry.xml
        createRegistry(synapseConfig, root, properties);
    } else if (log.isDebugEnabled()) {
        log.debug("Using the registry defined in the " + SynapseConstants.SYNAPSE_XML + " as the registry, any definitions in the " + REGISTRY_FILE + " will be neglected");
    }
    if (synapseConfig.getTaskManager() == null) {
        // If the synapse.xml does not define a taskManager look for a task-manager.xml
        createTaskManager(synapseConfig, root, properties);
    } else if (log.isDebugEnabled()) {
        log.debug("Using the task manager defined in the " + SynapseConstants.SYNAPSE_XML + " as the task manager, any definitions in the " + TASK_MANAGER_FILE + " will be neglected");
    }
    createSynapseImports(synapseConfig, root, properties);
    createLocalEntries(synapseConfig, root, properties);
    createEndpoints(synapseConfig, root, properties);
    createSequences(synapseConfig, root, properties);
    createTemplates(synapseConfig, root, properties);
    createProxyServices(synapseConfig, root, properties);
    createTasks(synapseConfig, root, properties);
    createEventSources(synapseConfig, root, properties);
    createExecutors(synapseConfig, root, properties);
    createMessageStores(synapseConfig, root, properties);
    createMessageProcessors(synapseConfig, root, properties);
    createAPIs(synapseConfig, root, properties);
    createInboundEndpoint(synapseConfig, root, properties);
    return synapseConfig;
}
Also used : SynapseConfiguration(org.apache.synapse.config.SynapseConfiguration)

Example 67 with SynapseConfiguration

use of org.apache.synapse.config.SynapseConfiguration in project wso2-synapse by wso2.

the class DynamicResourceTest method setUp.

public void setUp() {
    System.out.println("Initializing in-memory registry for dynamic resource tests...");
    Map<String, OMNode> data = new HashMap<String, OMNode>();
    data.put(KEY_DYNAMIC_ENDPOINT_1, TestUtils.createOMElement(DYNAMIC_ENDPOINT_1));
    data.put(KEY_DYNAMIC_SEQUENCE_1, TestUtils.createOMElement(DYNAMIC_SEQUENCE_1));
    registry = new SimpleInMemoryRegistry(data, 8000L);
    config = new SynapseConfiguration();
    config.setRegistry(registry);
}
Also used : OMNode(org.apache.axiom.om.OMNode) HashMap(java.util.HashMap) SynapseConfiguration(org.apache.synapse.config.SynapseConfiguration)

Example 68 with SynapseConfiguration

use of org.apache.synapse.config.SynapseConfiguration in project wso2-synapse by wso2.

the class APIDispatcherTest method testAPIContextVersionBasedDispatchVersionInMiddle.

public void testAPIContextVersionBasedDispatchVersionInMiddle() throws Exception {
    API api = new API(TEST_API, "/test/{version}/bar");
    api.setVersionStrategy(new ContextVersionStrategy(api, TEST_API_VERSION, null));
    SynapseConfiguration synapseConfig = new SynapseConfiguration();
    synapseConfig.addAPI(api.getName(), api);
    RESTRequestHandler handler = new RESTRequestHandler();
    // Messages with '/test' context should NOT be dispatched
    MessageContext synCtx = getMessageContext(synapseConfig, false, "/test/", "GET");
    handler.process(synCtx);
    assertNull(synCtx.getProperty(RESTConstants.SYNAPSE_REST_API));
    assertNull(synCtx.getProperty(RESTConstants.SYNAPSE_REST_API_VERSION));
    synCtx = getMessageContext(synapseConfig, false, "/test/1.0.0/bar", "GET");
    handler.process(synCtx);
    assertEquals(api.getName(), synCtx.getProperty(RESTConstants.SYNAPSE_REST_API));
    assertEquals(TEST_API_VERSION, synCtx.getProperty(RESTConstants.SYNAPSE_REST_API_VERSION));
    synCtx = getMessageContext(synapseConfig, false, "/test/1.0.0/bar/", "GET");
    handler.process(synCtx);
    assertEquals(api.getName(), synCtx.getProperty(RESTConstants.SYNAPSE_REST_API));
    assertEquals(TEST_API_VERSION, synCtx.getProperty(RESTConstants.SYNAPSE_REST_API_VERSION));
    synCtx = getMessageContext(synapseConfig, false, "/test/1.0.0/bar/foo/bar?a=5", "GET");
    handler.process(synCtx);
    assertEquals(api.getName(), synCtx.getProperty(RESTConstants.SYNAPSE_REST_API));
    assertEquals(TEST_API_VERSION, synCtx.getProperty(RESTConstants.SYNAPSE_REST_API_VERSION));
    synCtx = getMessageContext(synapseConfig, false, "/test/1.0.0/bar?a=5", "GET");
    handler.process(synCtx);
    assertEquals(api.getName(), synCtx.getProperty(RESTConstants.SYNAPSE_REST_API));
    assertEquals(TEST_API_VERSION, synCtx.getProperty(RESTConstants.SYNAPSE_REST_API_VERSION));
    // Message with '/test' context & URL as a Query Parameter should be dispatched
    synCtx = getMessageContext(synapseConfig, false, "/test/1.0.0/bar?a=http://localhost.com", "GET");
    handler.process(synCtx);
    assertEquals(api.getName(), synCtx.getProperty(RESTConstants.SYNAPSE_REST_API));
    assertEquals(TEST_API_VERSION, synCtx.getProperty(RESTConstants.SYNAPSE_REST_API_VERSION));
    // Messages WITHOUT the '/test' context should NOT be dispatched
    synCtx = getMessageContext(synapseConfig, false, "/foo/test/1.0.0/bar?a=5", "GET");
    handler.process(synCtx);
    assertNull(synCtx.getProperty(RESTConstants.SYNAPSE_REST_API));
    assertNull(synCtx.getProperty(RESTConstants.SYNAPSE_REST_API_VERSION));
    // Messages WITHOUT the '/test' context and proper version should NOT be dispatched
    synCtx = getMessageContext(synapseConfig, false, "/test/1.0.1/bar/foo/bar?a=5", "GET");
    handler.process(synCtx);
    assertNull(synCtx.getProperty(RESTConstants.SYNAPSE_REST_API));
    assertNull(synCtx.getProperty(RESTConstants.SYNAPSE_REST_API_VERSION));
    synCtx = getMessageContext(synapseConfig, false, "/test/2.0/bar/foo/bar?a=5", "GET");
    handler.process(synCtx);
    assertNull(synCtx.getProperty(RESTConstants.SYNAPSE_REST_API));
    assertNull(synCtx.getProperty(RESTConstants.SYNAPSE_REST_API_VERSION));
    synCtx = getMessageContext(synapseConfig, false, "/test/2.0.0.0/bar/foo/bar?a=5", "GET");
    handler.process(synCtx);
    assertNull(synCtx.getProperty(RESTConstants.SYNAPSE_REST_API));
    assertNull(synCtx.getProperty(RESTConstants.SYNAPSE_REST_API_VERSION));
}
Also used : ContextVersionStrategy(org.apache.synapse.rest.version.ContextVersionStrategy) MessageContext(org.apache.synapse.MessageContext) SynapseConfiguration(org.apache.synapse.config.SynapseConfiguration)

Example 69 with SynapseConfiguration

use of org.apache.synapse.config.SynapseConfiguration in project wso2-synapse by wso2.

the class APIDispatcherTest method testAPIURLVersionBasedDispatch.

public void testAPIURLVersionBasedDispatch() throws Exception {
    API api = new API(TEST_API, "/test");
    api.setVersionStrategy(new URLBasedVersionStrategy(api, TEST_API_VERSION, null));
    SynapseConfiguration synapseConfig = new SynapseConfiguration();
    synapseConfig.addAPI(api.getName(), api);
    RESTRequestHandler handler = new RESTRequestHandler();
    // Messages with '/test' context should NOT be dispatched
    MessageContext synCtx = getMessageContext(synapseConfig, false, "/test/", "GET");
    handler.process(synCtx);
    assertNull(synCtx.getProperty(RESTConstants.SYNAPSE_REST_API));
    assertNull(synCtx.getProperty(RESTConstants.SYNAPSE_REST_API_VERSION));
    synCtx = getMessageContext(synapseConfig, false, "/test/1.0.0", "GET");
    handler.process(synCtx);
    assertEquals(api.getName(), synCtx.getProperty(RESTConstants.SYNAPSE_REST_API));
    assertEquals(TEST_API_VERSION, synCtx.getProperty(RESTConstants.SYNAPSE_REST_API_VERSION));
    synCtx = getMessageContext(synapseConfig, false, "/test/1.0.0/", "GET");
    handler.process(synCtx);
    assertEquals(api.getName(), synCtx.getProperty(RESTConstants.SYNAPSE_REST_API));
    assertEquals(TEST_API_VERSION, synCtx.getProperty(RESTConstants.SYNAPSE_REST_API_VERSION));
    synCtx = getMessageContext(synapseConfig, false, "/test/1.0.0/foo/bar?a=5", "GET");
    handler.process(synCtx);
    assertEquals(api.getName(), synCtx.getProperty(RESTConstants.SYNAPSE_REST_API));
    assertEquals(TEST_API_VERSION, synCtx.getProperty(RESTConstants.SYNAPSE_REST_API_VERSION));
    synCtx = getMessageContext(synapseConfig, false, "/test/1.0.0?a=5", "GET");
    handler.process(synCtx);
    assertEquals(api.getName(), synCtx.getProperty(RESTConstants.SYNAPSE_REST_API));
    assertEquals(TEST_API_VERSION, synCtx.getProperty(RESTConstants.SYNAPSE_REST_API_VERSION));
    // Message with '/test' context & URL as a Query Parameter should be dispatched
    synCtx = getMessageContext(synapseConfig, false, "/test/1.0.0?a=http://localhost.com", "GET");
    handler.process(synCtx);
    assertEquals(api.getName(), synCtx.getProperty(RESTConstants.SYNAPSE_REST_API));
    assertEquals(TEST_API_VERSION, synCtx.getProperty(RESTConstants.SYNAPSE_REST_API_VERSION));
    // Messages WITHOUT the '/test' context should NOT be dispatched
    synCtx = getMessageContext(synapseConfig, false, "/foo/test/bar?a=5", "GET");
    handler.process(synCtx);
    assertNull(synCtx.getProperty(RESTConstants.SYNAPSE_REST_API));
    assertNull(synCtx.getProperty(RESTConstants.SYNAPSE_REST_API_VERSION));
    // Messages WITHOUT the '/test' context and proper version should NOT be dispatched
    synCtx = getMessageContext(synapseConfig, false, "/test/1.0.1/foo/bar?a=5", "GET");
    handler.process(synCtx);
    assertNull(synCtx.getProperty(RESTConstants.SYNAPSE_REST_API));
    assertNull(synCtx.getProperty(RESTConstants.SYNAPSE_REST_API_VERSION));
    synCtx = getMessageContext(synapseConfig, false, "/test/2.0/foo/bar?a=5", "GET");
    handler.process(synCtx);
    assertNull(synCtx.getProperty(RESTConstants.SYNAPSE_REST_API));
    assertNull(synCtx.getProperty(RESTConstants.SYNAPSE_REST_API_VERSION));
    synCtx = getMessageContext(synapseConfig, false, "/test/2.0.0.0/foo/bar?a=5", "GET");
    handler.process(synCtx);
    assertNull(synCtx.getProperty(RESTConstants.SYNAPSE_REST_API));
    assertNull(synCtx.getProperty(RESTConstants.SYNAPSE_REST_API_VERSION));
}
Also used : MessageContext(org.apache.synapse.MessageContext) SynapseConfiguration(org.apache.synapse.config.SynapseConfiguration) URLBasedVersionStrategy(org.apache.synapse.rest.version.URLBasedVersionStrategy)

Example 70 with SynapseConfiguration

use of org.apache.synapse.config.SynapseConfiguration in project wso2-synapse by wso2.

the class APIDispatcherTest method testMultipleAPIDispatch.

public void testMultipleAPIDispatch() throws Exception {
    String apiName1 = "TestAPI1";
    String apiName2 = "TestAPI2";
    String apiName3 = "TestAPI3";
    API api1 = new API(apiName1, "/test");
    API api2 = new API(apiName2, "/dictionary");
    api2.setHost("synapse.apache.org");
    API api3 = new API(apiName3, "/foo/bar");
    SynapseConfiguration synapseConfig = new SynapseConfiguration();
    synapseConfig.addAPI(apiName1, api1);
    synapseConfig.addAPI(apiName2, api2);
    synapseConfig.addAPI(apiName3, api3);
    RESTRequestHandler handler = new RESTRequestHandler();
    MessageContext synCtx = getMessageContext(synapseConfig, false, "/test", "GET");
    handler.process(synCtx);
    assertEquals(apiName1, synCtx.getProperty(RESTConstants.SYNAPSE_REST_API));
    synCtx = getMessageContext(synapseConfig, false, "/dictionary/c/cat", "GET");
    addHttpHeader(HTTP.TARGET_HOST, "synapse.apache.org", synCtx);
    handler.process(synCtx);
    assertEquals(apiName2, synCtx.getProperty(RESTConstants.SYNAPSE_REST_API));
    synCtx = getMessageContext(synapseConfig, false, "/foo/bar/index.jsp?user=test", "GET");
    handler.process(synCtx);
    assertEquals(apiName3, synCtx.getProperty(RESTConstants.SYNAPSE_REST_API));
    synCtx = getMessageContext(synapseConfig, false, "/foo/index.jsp?user=test", "GET");
    handler.process(synCtx);
    assertNull(synCtx.getProperty(RESTConstants.SYNAPSE_REST_API));
}
Also used : MessageContext(org.apache.synapse.MessageContext) SynapseConfiguration(org.apache.synapse.config.SynapseConfiguration)

Aggregations

SynapseConfiguration (org.apache.synapse.config.SynapseConfiguration)145 Axis2SynapseEnvironment (org.apache.synapse.core.axis2.Axis2SynapseEnvironment)64 AxisConfiguration (org.apache.axis2.engine.AxisConfiguration)59 MessageContext (org.apache.synapse.MessageContext)56 Test (org.junit.Test)56 ConfigurationContext (org.apache.axis2.context.ConfigurationContext)50 SynapseEnvironment (org.apache.synapse.core.SynapseEnvironment)49 OMElement (org.apache.axiom.om.OMElement)41 Parameter (org.apache.axis2.description.Parameter)29 Axis2MessageContext (org.apache.synapse.core.axis2.Axis2MessageContext)27 TestMessageContext (org.apache.synapse.TestMessageContext)16 Properties (java.util.Properties)15 SynapseException (org.apache.synapse.SynapseException)13 Mediator (org.apache.synapse.Mediator)12 AddressEndpoint (org.apache.synapse.endpoints.AddressEndpoint)11 File (java.io.File)10 ArrayList (java.util.ArrayList)10 HashMap (java.util.HashMap)9 SOAPEnvelope (org.apache.axiom.soap.SOAPEnvelope)7 Endpoint (org.apache.synapse.endpoints.Endpoint)7