Search in sources :

Example 46 with Axis2SynapseEnvironment

use of org.apache.synapse.core.axis2.Axis2SynapseEnvironment in project wso2-synapse by wso2.

the class TestMessageContextBuilder method build.

/**
 * Build the test message context.
 * This method returns a new (and independent) instance on every invocation.
 *
 * @return
 * @throws Exception
 */
public MessageContext build() throws Exception {
    SynapseConfiguration testConfig = new SynapseConfiguration();
    // TODO: check whether we need a SynapseEnvironment in all cases
    SynapseEnvironment synEnv = new Axis2SynapseEnvironment(new ConfigurationContext(new AxisConfiguration()), testConfig);
    MessageContext synCtx;
    if (requireAxis2MessageContext) {
        synCtx = new Axis2MessageContext(new org.apache.axis2.context.MessageContext(), testConfig, synEnv);
    } else {
        synCtx = new TestMessageContext();
        synCtx.setEnvironment(synEnv);
        synCtx.setConfiguration(testConfig);
    }
    for (Map.Entry<String, Entry> mapEntry : entries.entrySet()) {
        testConfig.addEntry(mapEntry.getKey(), mapEntry.getValue());
    }
    XMLStreamReader parser = null;
    if (contentString != null) {
        parser = StAXUtils.createXMLStreamReader(new StringReader(contentString));
    } else if (contentFile != null) {
        parser = StAXUtils.createXMLStreamReader(new FileInputStream(contentFile));
    } else if (contentStringJson != null) {
        // synCtx = new Axis2MessageContext(null, testConfig, synEnv);
        SOAPEnvelope envelope = OMAbstractFactory.getSOAP11Factory().getDefaultEnvelope();
        synCtx.setEnvelope(envelope);
        JsonUtil.getNewJsonPayload(((Axis2MessageContext) synCtx).getAxis2MessageContext(), contentStringJson, true, true);
        return synCtx;
    }
    SOAPEnvelope envelope;
    if (parser != null) {
        if (contentIsEnvelope) {
            envelope = new StAXSOAPModelBuilder(parser).getSOAPEnvelope();
        } else {
            envelope = OMAbstractFactory.getSOAP11Factory().getDefaultEnvelope();
            // TODO: don't know why this is here, but without it some unit tests fail...
            OMDocument omDoc = OMAbstractFactory.getSOAP11Factory().createOMDocument();
            omDoc.addChild(envelope);
            SOAPBody body = envelope.getBody();
            StAXOMBuilder builder = new StAXOMBuilder(parser);
            OMElement bodyElement = builder.getDocumentElement();
            if (addTextAroundBody) {
                OMFactory fac = OMAbstractFactory.getOMFactory();
                body.addChild(fac.createOMText("\n"));
                body.addChild(bodyElement);
                body.addChild(fac.createOMText("\n"));
            } else {
                body.addChild(bodyElement);
            }
        }
    } else {
        envelope = OMAbstractFactory.getSOAP11Factory().getDefaultEnvelope();
    }
    synCtx.setEnvelope(envelope);
    return synCtx;
}
Also used : ConfigurationContext(org.apache.axis2.context.ConfigurationContext) AxisConfiguration(org.apache.axis2.engine.AxisConfiguration) XMLStreamReader(javax.xml.stream.XMLStreamReader) Axis2SynapseEnvironment(org.apache.synapse.core.axis2.Axis2SynapseEnvironment) SynapseEnvironment(org.apache.synapse.core.SynapseEnvironment) OMElement(org.apache.axiom.om.OMElement) SOAPEnvelope(org.apache.axiom.soap.SOAPEnvelope) SynapseConfiguration(org.apache.synapse.config.SynapseConfiguration) FileInputStream(java.io.FileInputStream) OMDocument(org.apache.axiom.om.OMDocument) OMFactory(org.apache.axiom.om.OMFactory) Axis2SynapseEnvironment(org.apache.synapse.core.axis2.Axis2SynapseEnvironment) Entry(org.apache.synapse.config.Entry) SOAPBody(org.apache.axiom.soap.SOAPBody) StAXSOAPModelBuilder(org.apache.axiom.soap.impl.builder.StAXSOAPModelBuilder) StringReader(java.io.StringReader) StAXOMBuilder(org.apache.axiom.om.impl.builder.StAXOMBuilder) Axis2MessageContext(org.apache.synapse.core.axis2.Axis2MessageContext) HashMap(java.util.HashMap) Map(java.util.Map) Axis2MessageContext(org.apache.synapse.core.axis2.Axis2MessageContext)

Example 47 with Axis2SynapseEnvironment

use of org.apache.synapse.core.axis2.Axis2SynapseEnvironment 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)

Example 48 with Axis2SynapseEnvironment

use of org.apache.synapse.core.axis2.Axis2SynapseEnvironment in project wso2-synapse by wso2.

the class SynapseConfiguration method initXpathExtensions.

/**
 * This method initializes Xpath Extensions available through synapse.properties file
 * Xpath Extensions can be defined in Variable Context Extensions + Function Context Extensions
 * synapse.xpath.var.extensions --> Variable Extensions
 * synapse.xpath.func.extensions --> Function Extensions
 *
 * @param synapseEnvironment SynapseEnvironment
 */
private void initXpathExtensions(SynapseEnvironment synapseEnvironment) {
    Axis2SynapseEnvironment axis2SynapseEnvironment = (Axis2SynapseEnvironment) synapseEnvironment;
    /*Initialize Function Context extensions for xpath
        */
    List<SynapseXpathFunctionContextProvider> functionExtensions = XpathExtensionUtil.getRegisteredFunctionExtensions();
    for (SynapseXpathFunctionContextProvider functionExtension : functionExtensions) {
        axis2SynapseEnvironment.setXpathFunctionExtensions(functionExtension);
    }
    /*Initialize Variable Context extensions for xpath
        */
    List<SynapseXpathVariableResolver> variableExtensions = XpathExtensionUtil.getRegisteredVariableExtensions();
    for (SynapseXpathVariableResolver variableExtension : variableExtensions) {
        axis2SynapseEnvironment.setXpathVariableExtensions(variableExtension);
    }
}
Also used : Axis2SynapseEnvironment(org.apache.synapse.core.axis2.Axis2SynapseEnvironment) SynapseXpathFunctionContextProvider(org.apache.synapse.util.xpath.ext.SynapseXpathFunctionContextProvider) SynapseXpathVariableResolver(org.apache.synapse.util.xpath.ext.SynapseXpathVariableResolver)

Example 49 with Axis2SynapseEnvironment

use of org.apache.synapse.core.axis2.Axis2SynapseEnvironment in project wso2-synapse by wso2.

the class DebugManagerTest method setupTestEnvironment.

public static void setupTestEnvironment() {
    synConfig = new SynapseConfiguration();
    synEnv = new Axis2SynapseEnvironment(synConfig);
    synEnv.setDebugEnabled(true);
    dm = SynapseDebugManager.getInstance();
    dm.init(synConfig, null, synEnv, false);
    synEnv.setDebugEnabled(false);
    synEnv.setSynapseDebugManager(dm);
}
Also used : Axis2SynapseEnvironment(org.apache.synapse.core.axis2.Axis2SynapseEnvironment) SynapseConfiguration(org.apache.synapse.config.SynapseConfiguration)

Example 50 with Axis2SynapseEnvironment

use of org.apache.synapse.core.axis2.Axis2SynapseEnvironment in project wso2-synapse by wso2.

the class APIDeployerTest method testDeploy.

/**
 * Testing the deployment of an API
 *
 * @throws Exception
 */
@Test
public void testDeploy() throws Exception {
    String inputXML = "<api name=\"TestAPI\" context=\"/order\" xmlns=\"http://ws.apache.org/ns/synapse\">" + "<resource url-mapping=\"/list\" inSequence=\"seq1\" outSequence=\"seq2\" xmlns=\"http://ws.apache.org/ns/synapse\"/>" + "</api>";
    OMElement inputElement = AXIOMUtil.stringToOM(inputXML);
    APIDeployer apiDeployer = new APIDeployer();
    SynapseConfiguration synapseConfiguration = new SynapseConfiguration();
    AxisConfiguration axisConfiguration = synapseConfiguration.getAxisConfiguration();
    ConfigurationContext cfgCtx = new ConfigurationContext(axisConfiguration);
    SynapseEnvironment synapseEnvironment = new Axis2SynapseEnvironment(cfgCtx, synapseConfiguration);
    axisConfiguration.addParameter(new Parameter(SynapseConstants.SYNAPSE_ENV, synapseEnvironment));
    axisConfiguration.addParameter(new Parameter(SynapseConstants.SYNAPSE_CONFIG, synapseConfiguration));
    cfgCtx.setAxisConfiguration(axisConfiguration);
    apiDeployer.init(cfgCtx);
    String response = apiDeployer.deploySynapseArtifact(inputElement, "sampleFile", null);
    Assert.assertEquals("API not deployed!", "TestAPI", response);
}
Also used : AxisConfiguration(org.apache.axis2.engine.AxisConfiguration) ConfigurationContext(org.apache.axis2.context.ConfigurationContext) Axis2SynapseEnvironment(org.apache.synapse.core.axis2.Axis2SynapseEnvironment) SynapseEnvironment(org.apache.synapse.core.SynapseEnvironment) Axis2SynapseEnvironment(org.apache.synapse.core.axis2.Axis2SynapseEnvironment) Parameter(org.apache.axis2.description.Parameter) OMElement(org.apache.axiom.om.OMElement) SynapseConfiguration(org.apache.synapse.config.SynapseConfiguration) Test(org.junit.Test)

Aggregations

Axis2SynapseEnvironment (org.apache.synapse.core.axis2.Axis2SynapseEnvironment)81 SynapseConfiguration (org.apache.synapse.config.SynapseConfiguration)64 ConfigurationContext (org.apache.axis2.context.ConfigurationContext)57 AxisConfiguration (org.apache.axis2.engine.AxisConfiguration)49 SynapseEnvironment (org.apache.synapse.core.SynapseEnvironment)43 Test (org.junit.Test)38 OMElement (org.apache.axiom.om.OMElement)30 Parameter (org.apache.axis2.description.Parameter)26 MessageContext (org.apache.synapse.MessageContext)23 Axis2MessageContext (org.apache.synapse.core.axis2.Axis2MessageContext)21 Properties (java.util.Properties)14 TestMessageContext (org.apache.synapse.TestMessageContext)13 Mediator (org.apache.synapse.Mediator)12 SOAPEnvelope (org.apache.axiom.soap.SOAPEnvelope)10 ArrayList (java.util.ArrayList)8 AddressEndpoint (org.apache.synapse.endpoints.AddressEndpoint)7 Endpoint (org.apache.synapse.endpoints.Endpoint)7 HashMap (java.util.HashMap)5 OMDocument (org.apache.axiom.om.OMDocument)4 EndpointReference (org.apache.axis2.addressing.EndpointReference)4