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;
}
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;
}
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);
}
}
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);
}
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);
}
Aggregations