use of org.apache.synapse.core.SynapseEnvironment in project wso2-synapse by wso2.
the class XpathExtensionUtil method getFunctionContext.
/**
* Returns a Function Context extension registered for given QName/namespaceURI+prefix+localName
* combination
*
* @param ctxt Synapse Message Context
* @param namespaceURI binding namespace in xpath expression
* @param prefix binding prefix string in xpath expression
* @param localName binding localname string in xpath expression
* @return jaxen Function object for corresponding extension
*/
public static Function getFunctionContext(MessageContext ctxt, String namespaceURI, String prefix, String localName) {
SynapseEnvironment environment = ctxt.getEnvironment();
if (environment != null) {
Map<QName, SynapseXpathFunctionContextProvider> extensions = environment.getXpathFunctionExtensions();
SynapseXpathFunctionContextProvider functionContextProvider = getMatchingExtensionProvider(extensions, namespaceURI, prefix, localName);
if (functionContextProvider != null) {
return initAndReturnXpathFunction(functionContextProvider, ctxt);
}
}
return null;
}
use of org.apache.synapse.core.SynapseEnvironment 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.SynapseEnvironment 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;
}
use of org.apache.synapse.core.SynapseEnvironment 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.SynapseEnvironment in project wso2-synapse by wso2.
the class SynapseConfiguration method updateEntry.
public synchronized void updateEntry(String key, Entry entry) {
if (entry.getType() == Entry.URL_SRC && entry.getValue() == null) {
try {
SynapseEnvironment synEnv = SynapseConfigUtils.getSynapseEnvironment(axisConfiguration);
entry.setValue(SynapseConfigUtils.getOMElementFromURL(entry.getSrc().toString(), synEnv != null ? synEnv.getServerContextInformation().getServerConfigurationInformation().getSynapseHome() : ""));
localRegistry.put(key, entry);
for (SynapseObserver o : observers) {
o.entryAdded(entry);
}
} catch (IOException e) {
handleException("Can not read from source URL : " + entry.getSrc());
}
} else {
localRegistry.put(key, entry);
for (SynapseObserver o : observers) {
o.entryAdded(entry);
}
}
}
Aggregations