Search in sources :

Example 61 with SynapseConfiguration

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

the class HessianMessageBuilderTest method testProcessDocumentFaultWithSynEnv.

public void testProcessDocumentFaultWithSynEnv() throws IOException {
    SynapseEnvironment synEnv = new Axis2SynapseEnvironment(new ConfigurationContext(new AxisConfiguration()), new SynapseConfiguration());
    testProcessDocumentFault(synEnv);
}
Also used : Axis2SynapseEnvironment(org.apache.synapse.core.axis2.Axis2SynapseEnvironment) ConfigurationContext(org.apache.axis2.context.ConfigurationContext) AxisConfiguration(org.apache.axis2.engine.AxisConfiguration) Axis2SynapseEnvironment(org.apache.synapse.core.axis2.Axis2SynapseEnvironment) SynapseEnvironment(org.apache.synapse.core.SynapseEnvironment) SynapseConfiguration(org.apache.synapse.config.SynapseConfiguration)

Example 62 with SynapseConfiguration

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

the class MultiXMLConfigurationBuilder method createConfigurationFromSynapseXML.

private static SynapseConfiguration createConfigurationFromSynapseXML(String rootDirPath, Properties properties) {
    File synapseXML = new File(rootDirPath, SynapseConstants.SYNAPSE_XML);
    if (!synapseXML.exists() || !synapseXML.isFile()) {
        return null;
    }
    FileInputStream is;
    SynapseConfiguration config = null;
    try {
        is = FileUtils.openInputStream(synapseXML);
    } catch (IOException e) {
        handleException("Error while opening the file: " + synapseXML.getName(), e);
        return null;
    }
    try {
        config = XMLConfigurationBuilder.getConfiguration(is, properties);
        is.close();
    } catch (XMLStreamException e) {
        handleException("Error while loading the Synapse configuration from the " + synapseXML.getName() + " file", e);
    } catch (IOException e) {
        log.warn("Error while closing the input stream from file: " + synapseXML.getName(), e);
    }
    return config;
}
Also used : XMLStreamException(javax.xml.stream.XMLStreamException) SynapseConfiguration(org.apache.synapse.config.SynapseConfiguration)

Example 63 with SynapseConfiguration

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

the class SynapseXMLConfigurationFactory method getConfiguration.

public SynapseConfiguration getConfiguration(OMElement definitions, Properties properties) {
    if (!definitions.getQName().equals(XMLConfigConstants.DEFINITIONS_ELT)) {
        throw new SynapseException("Wrong QName for this configuration factory " + definitions.getQName());
    }
    SynapseConfiguration config = SynapseConfigUtils.newConfiguration();
    config.setDefaultQName(definitions.getQName());
    Iterator itr = definitions.getChildren();
    while (itr.hasNext()) {
        Object o = itr.next();
        if (o instanceof OMElement) {
            OMElement elt = (OMElement) o;
            if (XMLConfigConstants.SEQUENCE_ELT.equals(elt.getQName())) {
                String key = elt.getAttributeValue(new QName(XMLConfigConstants.NULL_NAMESPACE, "key"));
                // this could be a sequence def or a referred sequence
                if (key != null) {
                    handleException("Referred sequences are not allowed at the top level");
                } else {
                    defineSequence(config, elt, properties);
                }
            } else if (XMLConfigConstants.TEMPLATE_ELT.equals(elt.getQName())) {
                defineTemplate(config, elt, properties);
            } else if (XMLConfigConstants.IMPORT_ELT.equals(elt.getQName())) {
                defineImport(config, elt, properties);
            } else if (XMLConfigConstants.ENDPOINT_ELT.equals(elt.getQName())) {
                defineEndpoint(config, elt, properties);
            } else if (XMLConfigConstants.ENTRY_ELT.equals(elt.getQName())) {
                defineEntry(config, elt, properties);
            } else if (XMLConfigConstants.PROXY_ELT.equals(elt.getQName())) {
                defineProxy(config, elt, properties);
            } else if (XMLConfigConstants.REGISTRY_ELT.equals(elt.getQName())) {
                defineRegistry(config, elt, properties);
            } else if (XMLConfigConstants.EVENT_SOURCE_ELT.equals(elt.getQName())) {
                defineEventSource(config, elt, properties);
            } else if (XMLConfigConstants.EXECUTOR_ELT.equals(elt.getQName())) {
                defineExecutor(config, elt, properties);
            } else if (XMLConfigConstants.MESSAGE_STORE_ELT.equals(elt.getQName())) {
                defineMessageStore(config, elt, properties);
            } else if (XMLConfigConstants.TASK_MANAGER_ELT.equals(elt.getQName())) {
                defineTaskManager(config, elt, properties);
            } else if (XMLConfigConstants.MESSAGE_PROCESSOR_ELT.equals(elt.getQName())) {
                defineMessageProcessor(config, elt, properties);
            } else if (StartupFinder.getInstance().isStartup(elt.getQName())) {
                defineStartup(config, elt, properties);
            } else if (XMLConfigConstants.API_ELT.equals(elt.getQName())) {
                defineAPI(config, elt, properties);
            } else if (XMLConfigConstants.DESCRIPTION_ELT.equals(elt.getQName())) {
                config.setDescription(elt.getText());
            } else if (XMLConfigConstants.INBOUND_ENDPOINT_ELT.equals(elt.getQName())) {
                defineInboundEndpoint(config, elt, properties);
            } else {
                handleException("Invalid configuration element at the top level, one of \'sequence\', " + "\'endpoint\', \'proxy\', \'eventSource\', \'localEntry\', \'priorityExecutor\'" + ", \'registry\' or \'inboundEndpoint\' is expected");
            }
        } else if (o instanceof OMComment) {
            OMComment commentNode = (OMComment) o;
            defineComments(config, commentNode);
        }
    }
    return config;
}
Also used : SynapseException(org.apache.synapse.SynapseException) QName(javax.xml.namespace.QName) OMComment(org.apache.axiom.om.OMComment) Iterator(java.util.Iterator) OMElement(org.apache.axiom.om.OMElement) SynapseConfiguration(org.apache.synapse.config.SynapseConfiguration)

Example 64 with SynapseConfiguration

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

the class MessageContextCreatorForAxis2 method getSynapseConfiguration.

private static SynapseConfiguration getSynapseConfiguration(org.apache.axis2.context.MessageContext axisMsgCtx) {
    AxisConfiguration axisCfg = axisMsgCtx.getConfigurationContext().getAxisConfiguration();
    Parameter param = axisCfg.getParameter(SynapseConstants.SYNAPSE_CONFIG);
    if (param != null) {
        return (SynapseConfiguration) param.getValue();
    }
    return null;
}
Also used : AxisConfiguration(org.apache.axis2.engine.AxisConfiguration) Parameter(org.apache.axis2.description.Parameter) SynapseConfiguration(org.apache.synapse.config.SynapseConfiguration)

Example 65 with SynapseConfiguration

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

the class MessageContextCreatorForAxis2 method getSynapseMessageContext.

public static MessageContext getSynapseMessageContext(org.apache.axis2.context.MessageContext axisMsgCtx) throws AxisFault {
    if (synCfg == null || synEnv == null) {
        String msg = "Synapse environment has not initialized properly..";
        log.fatal(msg);
        throw new SynapseException(msg);
    }
    // we should try to get the synapse configuration and environment from
    // the axis2 configuration.
    SynapseEnvironment synapseEnvironment = getSynapseEnvironment(axisMsgCtx);
    SynapseConfiguration synapseConfiguration = getSynapseConfiguration(axisMsgCtx);
    if (synapseConfiguration != null && synapseEnvironment != null) {
        return new Axis2MessageContext(axisMsgCtx, synapseConfiguration, synapseEnvironment);
    } else {
        return new Axis2MessageContext(axisMsgCtx, synCfg, synEnv);
    }
}
Also used : SynapseException(org.apache.synapse.SynapseException) SynapseEnvironment(org.apache.synapse.core.SynapseEnvironment) SynapseConfiguration(org.apache.synapse.config.SynapseConfiguration)

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