Search in sources :

Example 96 with SynapseConfiguration

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

the class SynapseXMLConfigurationSerializerTest method testSerializeConfiguration8.

/**
 * Test serializeConfigurationMethod with startUp added for SynapseConfiguration and assert OMElement returned
 */
@Test
public void testSerializeConfiguration8() {
    SynapseXMLConfigurationSerializer serializer = new SynapseXMLConfigurationSerializer();
    SynapseConfiguration synapseConfiguration = new SynapseConfiguration();
    StartUpController startup = new StartUpController();
    startup.setName("testStartup");
    TaskDescription taskDescription = new TaskDescription();
    taskDescription.setName("testTask");
    startup.setTaskDescription(taskDescription);
    synapseConfiguration.addStartup(startup);
    OMElement element = serializer.serializeConfiguration(synapseConfiguration);
    Assert.assertNotNull("OMElement is not returned", element);
    Assert.assertEquals("definitions", element.getLocalName());
    Assert.assertTrue("StartUp added is not serialized.", element.getChildren().next().toString().contains("name=\"testTask\""));
}
Also used : StartUpController(org.apache.synapse.startup.quartz.StartUpController) TaskDescription(org.apache.synapse.task.TaskDescription) OMElement(org.apache.axiom.om.OMElement) SynapseConfiguration(org.apache.synapse.config.SynapseConfiguration) Test(org.junit.Test)

Example 97 with SynapseConfiguration

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

the class SynapseXMLConfigurationSerializerTest method testSerializeConfiguration3.

/**
 * Test serializeConfigurationMethod with taskManager set for SynapseConfiguration and assert OMElement returned
 */
@Test
public void testSerializeConfiguration3() {
    SynapseXMLConfigurationSerializer serializer = new SynapseXMLConfigurationSerializer();
    SynapseConfiguration synapseConfiguration = new SynapseConfiguration();
    synapseConfiguration.setTaskManager(new QuartzTaskManager());
    OMElement element = serializer.serializeConfiguration(synapseConfiguration);
    Assert.assertNotNull("OMElement is not returned", element);
    Assert.assertEquals("definitions", element.getLocalName());
    Assert.assertTrue("TaskManager added is not serialized.", element.getChildren().next().toString().contains("taskManager"));
}
Also used : QuartzTaskManager(org.apache.synapse.startup.quartz.QuartzTaskManager) OMElement(org.apache.axiom.om.OMElement) SynapseConfiguration(org.apache.synapse.config.SynapseConfiguration) Test(org.junit.Test)

Example 98 with SynapseConfiguration

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

the class ResolvingEndpoint method loadAndInitEndpoint.

public Endpoint loadAndInitEndpoint(ConfigurationContext cc, String key) {
    Parameter parameter = cc.getAxisConfiguration().getParameter(SynapseConstants.SYNAPSE_CONFIG);
    Parameter synEnvParameter = cc.getAxisConfiguration().getParameter(SynapseConstants.SYNAPSE_ENV);
    if (parameter.getValue() instanceof SynapseConfiguration && synEnvParameter.getValue() instanceof SynapseEnvironment) {
        SynapseConfiguration synCfg = (SynapseConfiguration) parameter.getValue();
        SynapseEnvironment synapseEnvironment = (SynapseEnvironment) synEnvParameter.getValue();
        if (log.isDebugEnabled()) {
            log.debug("Loading real endpoint with key : " + key);
        }
        Endpoint ep = synCfg.getEndpoint(key);
        if (ep != null && !ep.isInitialized()) {
            synchronized (ep) {
                if (!ep.isInitialized()) {
                    ep.init(synapseEnvironment);
                }
            }
        }
        return ep;
    }
    return null;
}
Also used : SynapseEnvironment(org.apache.synapse.core.SynapseEnvironment) Parameter(org.apache.axis2.description.Parameter) SynapseConfiguration(org.apache.synapse.config.SynapseConfiguration)

Example 99 with SynapseConfiguration

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

the class ThrottleMediatorTest method testMediateWithXForwardedHeader.

/**
 * Test the XForwarded header based throttling.
 * @throws Exception
 */
public void testMediateWithXForwardedHeader() throws Exception {
    ByteArrayInputStream in = null;
    try {
        in = new ByteArrayInputStream(NEW_POLICY.getBytes());
        StAXOMBuilder build = new StAXOMBuilder(in);
        ThrottleTestMediator throttleMediator = new ThrottleTestMediator();
        throttleMediator.setInLinePolicy(build.getDocumentElement());
        MessageContext synCtx = createLightweightSynapseMessageContext("<empty/>");
        synCtx.setProperty(REMOTE_ADDR, "192.168.5.500");
        Map<String, String> headers = new TreeMap<String, String>(new Comparator<String>() {

            public int compare(String o1, String o2) {
                return o1.compareToIgnoreCase(o2);
            }
        });
        headers.put(NhttpConstants.HEADER_X_FORWARDED_FOR, "192.168..215");
        SynapseConfiguration synCfg = new SynapseConfiguration();
        synCtx.setConfiguration(synCfg);
        for (int i = 0; i < 6; i++) {
            try {
                throttleMediator.mediate(synCtx);
                Thread.sleep(1000);
            } catch (Exception e) {
                if (i == 3 || i == 4 || i == 5) {
                    assertTrue("X-forwarded header based throttling failed", e.getMessage().lastIndexOf("IP_BASE") > 0);
                }
            }
        }
    } finally {
        if (in != null) {
            in.close();
        }
    }
}
Also used : ByteArrayInputStream(java.io.ByteArrayInputStream) StAXOMBuilder(org.apache.axiom.om.impl.builder.StAXOMBuilder) MessageContext(org.apache.synapse.MessageContext) Axis2MessageContext(org.apache.synapse.core.axis2.Axis2MessageContext) TreeMap(java.util.TreeMap) SynapseConfiguration(org.apache.synapse.config.SynapseConfiguration) XMLStreamException(javax.xml.stream.XMLStreamException) SynapseException(org.apache.synapse.SynapseException)

Example 100 with SynapseConfiguration

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

the class ThrottleMediatorTest method createLightweightSynapseMessageContext.

public static MessageContext createLightweightSynapseMessageContext(String payload) throws Exception {
    org.apache.axis2.context.MessageContext mc = new org.apache.axis2.context.MessageContext();
    SynapseConfiguration config = new SynapseConfiguration();
    SynapseEnvironment env = new Axis2SynapseEnvironment(config);
    MessageContext synMc = new Axis2MessageContext(mc, config, env);
    SOAPEnvelope envelope = OMAbstractFactory.getSOAP11Factory().getDefaultEnvelope();
    OMDocument omDoc = OMAbstractFactory.getSOAP11Factory().createOMDocument();
    omDoc.addChild(envelope);
    envelope.getBody().addChild(createOMElement(payload));
    synMc.setEnvelope(envelope);
    return synMc;
}
Also used : Axis2SynapseEnvironment(org.apache.synapse.core.axis2.Axis2SynapseEnvironment) Axis2SynapseEnvironment(org.apache.synapse.core.axis2.Axis2SynapseEnvironment) SynapseEnvironment(org.apache.synapse.core.SynapseEnvironment) MessageContext(org.apache.synapse.MessageContext) Axis2MessageContext(org.apache.synapse.core.axis2.Axis2MessageContext) SOAPEnvelope(org.apache.axiom.soap.SOAPEnvelope) SynapseConfiguration(org.apache.synapse.config.SynapseConfiguration) Axis2MessageContext(org.apache.synapse.core.axis2.Axis2MessageContext) OMDocument(org.apache.axiom.om.OMDocument)

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