Search in sources :

Example 41 with SynapseEnvironment

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;
}
Also used : SynapseEnvironment(org.apache.synapse.core.SynapseEnvironment) QName(javax.xml.namespace.QName)

Example 42 with SynapseEnvironment

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;
}
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 43 with SynapseEnvironment

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;
}
Also used : SynapseEnvironment(org.apache.synapse.core.SynapseEnvironment) Parameter(org.apache.axis2.description.Parameter) SynapseConfiguration(org.apache.synapse.config.SynapseConfiguration)

Example 44 with SynapseEnvironment

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;
}
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 45 with SynapseEnvironment

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);
        }
    }
}
Also used : Axis2SynapseEnvironment(org.apache.synapse.core.axis2.Axis2SynapseEnvironment) SynapseEnvironment(org.apache.synapse.core.SynapseEnvironment) IOException(java.io.IOException)

Aggregations

SynapseEnvironment (org.apache.synapse.core.SynapseEnvironment)67 Axis2SynapseEnvironment (org.apache.synapse.core.axis2.Axis2SynapseEnvironment)50 SynapseConfiguration (org.apache.synapse.config.SynapseConfiguration)49 AxisConfiguration (org.apache.axis2.engine.AxisConfiguration)44 ConfigurationContext (org.apache.axis2.context.ConfigurationContext)43 Test (org.junit.Test)40 OMElement (org.apache.axiom.om.OMElement)35 Parameter (org.apache.axis2.description.Parameter)29 MessageContext (org.apache.synapse.MessageContext)18 Axis2MessageContext (org.apache.synapse.core.axis2.Axis2MessageContext)18 ArrayList (java.util.ArrayList)8 AddressEndpoint (org.apache.synapse.endpoints.AddressEndpoint)8 Endpoint (org.apache.synapse.endpoints.Endpoint)8 SOAPEnvelope (org.apache.axiom.soap.SOAPEnvelope)6 HashMap (java.util.HashMap)5 OMDocument (org.apache.axiom.om.OMDocument)4 SynapseException (org.apache.synapse.SynapseException)4 TestMessageContext (org.apache.synapse.TestMessageContext)4 IOException (java.io.IOException)3 ManagedLifecycle (org.apache.synapse.ManagedLifecycle)3