Examples of SynapseConfiguration


Examples of org.apache.synapse.config.SynapseConfiguration

        synapseService.addOperation(mediateOperation);
        axisCfg.addService(synapseService);

        // Initializing the SynapseEnvironment and SynapseConfiguration
        log.info("Initializing the Synapse configuration ...");
        SynapseConfiguration synCfg = initializeSynapse(configurationContext);

        log.info("Deploying Proxy services...");
        Iterator iter = synCfg.getProxyServices().iterator();
        while (iter.hasNext()) {
            ProxyService proxy = (ProxyService) iter.next();
            proxy.buildAxisService(synCfg, axisCfg);
            if (!proxy.isStartOnLoad()) {
                proxy.stop(synCfg);
View Full Code Here

Examples of org.apache.synapse.config.SynapseConfiguration

        /*
        First check, if synapse.xml URL is provided as a system property, if so use it..
        else check if synapse.xml location is available from the axis2.xml
        "SynapseConfiguration" else use the default config
        */
        SynapseConfiguration synapseConfiguration;
        Parameter configParam = axisConfiguration.getParameter(Constants.SYNAPSE_CONFIGURATION);

        String config = System.getProperty(Constants.SYNAPSE_XML);

        if (config != null) {
            log.info("System property '" + Constants.SYNAPSE_XML +
                "' specifies synapse configuration as " + config);
            synapseConfiguration =
                SynapseConfigurationBuilder.getConfiguration(config);
        } else if (configParam != null) {
            log.info(
                "Synapse configuration is available via the " +
                    "'SynapseConfiguration' parameter in axis2.xml");
            synapseConfiguration = SynapseConfigurationBuilder
                .getConfiguration(configParam.getValue().toString().trim());
        } else {
            log.warn("System property '" + Constants.SYNAPSE_XML +
                "' is not specified or 'SynapseConfiguration' Parameter " +
                "is not available via axis2.xml.  Using default configuration..");
            synapseConfiguration =
                SynapseConfigurationBuilder.getDefaultConfiguration();
        }

        // Set the Axis2 ConfigurationContext to the SynapseConfiguration
        synapseConfiguration.setAxisConfiguration(cfgCtx.getAxisConfiguration());

        // set the Synapse configuration and environment into the Axis2 configuration
        Parameter synapseCtxParam = new Parameter(Constants.SYNAPSE_CONFIG, null);
        synapseCtxParam.setValue(synapseConfiguration);

View Full Code Here

Examples of org.apache.synapse.config.SynapseConfiguration

    public static TestMessageContext getTestContext(String bodyText, Map props) throws Exception {

        // create a test synapse context
        TestMessageContext synCtx = new TestMessageContext();
        SynapseConfiguration testConfig = new SynapseConfiguration();
        testConfig.addRegistry(null, new SimpleURLRegistry());

        if (props != null) {
            Iterator iter = props.keySet().iterator();
            while (iter.hasNext()) {
                String key = (String) iter.next();
                testConfig.addProperty(key, (Property)props.get(key));
            }
        }
        synCtx.setConfiguration(testConfig);

        SOAPEnvelope envelope = OMAbstractFactory.getSOAP11Factory().getDefaultEnvelope();
View Full Code Here

Examples of org.apache.synapse.config.SynapseConfiguration

    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();
        MessageContext synMc = new Axis2MessageContext(mc,config,env);
        SOAPEnvelope envelope =
                OMAbstractFactory.getSOAP11Factory().getDefaultEnvelope();
        OMDocument omDoc =
View Full Code Here

Examples of org.apache.synapse.config.SynapseConfiguration

     */
    public void testSetAndReadGlobalProperty() throws Exception {

        MessageContext synCtx = TestUtils.getTestContext("<empty/>");

        SynapseConfiguration synCfg = new SynapseConfiguration();
        Property prop = new Property();
        prop.setName("name");
        prop.setType(Property.VALUE_TYPE);
        prop.setValue("value");
        synCfg.addProperty("name", prop);
        synCtx.setConfiguration(synCfg);

        assertTrue(
            "value".equals(Axis2MessageContext.getStringValue(
                new AXIOMXPath("synapse:get-property('name')"), synCtx)));
View Full Code Here

Examples of org.apache.synapse.config.SynapseConfiguration

            throws AxisFault {

        // we get the configuration on each message from the Axis2 configuration since the Synapse configuration
        // may be updated externally and thus should not be cached.

        SynapseConfiguration synCfg = getSynapseConfigFromAxisConfig(axisMsgCtx);
        SynapseEnvironment synEnv = getSynapseEnvironment(axisMsgCtx);

        if (synCfg == null || synEnv == null) {
            String msg = "Synapse environment has not initialized properly..";
            log.fatal(msg);
View Full Code Here

Examples of org.apache.synapse.config.SynapseConfiguration

        synapseService.addOperation(mediateOperation);
        axisCfg.addService(synapseService);

        // Initializing the SynapseEnvironment and SynapseConfiguration
        log.info("Initializing the Synapse configuration ...");
        SynapseConfiguration synCfg = initializeSynapse(configurationContext);

        log.info("Deploying Proxy services...");
        Iterator iter = synCfg.getProxyServices().iterator();
        while (iter.hasNext()) {
            ProxyService proxy = (ProxyService) iter.next();
            proxy.buildAxisService(synCfg, axisCfg);
            if(!proxy.isStartOnLoad()) {
                proxy.stop(synCfg);
View Full Code Here

Examples of org.apache.synapse.config.SynapseConfiguration

        /*
        First check, if synapse.xml URL is provided as a system property, if so use it..
        else check if synapse.xml location is available from the axis2.xml
        "SynapseConfiguration" else use the default config
        */
        SynapseConfiguration synapseConfiguration;
        Parameter configParam = axisConfiguration.getParameter(Constants.SYNAPSE_CONFIGURATION);

        String config = System.getProperty(Constants.SYNAPSE_XML);

        if (config != null) {
            log.info("System property '" + Constants.SYNAPSE_XML +
                     "' specifies synapse configuration as " + config);
            synapseConfiguration =
                    SynapseConfigurationBuilder.getConfiguration(config);
        } else if (configParam != null) {
            log.info(
                    "Synapse configuration is available via the " +
                    "'SynapseConfiguration' parameter in axis2.xml");
            synapseConfiguration = SynapseConfigurationBuilder
                    .getConfiguration(configParam.getValue().toString().trim());
        } else {
            log.warn("System property '" + Constants.SYNAPSE_XML +
                     "' is not specified or 'SynapseConfiguration' Parameter " +
                     "is not available via axis2.xml.  Using default configuration..");
            synapseConfiguration =
                    SynapseConfigurationBuilder.getDefaultConfiguration();
        }

        // Set the Axis2 ConfigurationContext to the SynapseConfiguration
        synapseConfiguration.setAxisConfiguration(cfgCtx.getAxisConfiguration());

        // set the Synapse configuration and environment into the Axis2 configuration
        Parameter synapseCtxParam = new Parameter(Constants.SYNAPSE_CONFIG, null);
        synapseCtxParam.setValue(synapseConfiguration);

View Full Code Here

Examples of org.apache.synapse.config.SynapseConfiguration

    private static Log log = LogFactory.getLog(XMLConfigurationBuilder.class);

    public static SynapseConfiguration getConfiguration(InputStream is) {

        log.info("Generating the Synapse configuration model by parsing the XML configuration");
        SynapseConfiguration config = new SynapseConfiguration();

        OMElement root = null;
        try {
            root = new StAXOMBuilder(is).getDocumentElement();
        } catch (XMLStreamException e) {
            handleException("Error parsing Synapse configuration : " + e.getMessage(), e);
        }
        root.build();

        Iterator regs = root.getChildrenWithName(Constants.REGISTRY_ELT);
        if (regs != null) {
            while (regs.hasNext()) {
                Object o = regs.next();
                if (o instanceof OMElement) {
                    Registry reg = RegistryFactory.createRegistry((OMElement) o);
                    config.addRegistry(reg.getRegistryName(), reg);
                } else {
                    handleException("Invalid registry declaration in configuration");
                }
            }
        }

        OMContainer definitions = root.getFirstChildWithName(Constants.DEFINITIONS_ELT);
        if (definitions != null) {

            Iterator iter = definitions.getChildren();
            while (iter.hasNext()) {
                Object o = iter.next();
                if (o instanceof OMElement) {
                    OMElement elt = (OMElement) o;
                    if (Constants.SEQUENCE_ELT.equals(elt.getQName())) {
                        defineSequence(config, elt);
                    } else if (Constants.ENDPOINT_ELT.equals(elt.getQName())) {
                        defineEndpoint(config, elt);
                    } else if (Constants.PROPERTY_ELT.equals(elt.getQName())) {
                        defineProperty(config, elt);
                    } else {
                        handleException("Unexpected element : " + elt);
                    }
                }
            }
        }

        OMElement proxies = root.getFirstChildWithName(Constants.PROXIES_ELT);
        if (proxies != null) {
            Iterator iter = proxies.getChildren();
            while (iter.hasNext()) {
                Object o = iter.next();
                if (o instanceof OMElement) {
                    OMElement elt = (OMElement) o;
                    if (Constants.PROXY_ELT.equals(elt.getQName())) {
                        ProxyService proxy = ProxyServiceFactory.createProxy(elt);
                        config.addProxyService(proxy.getName(), proxy);
                    }
                }
            }
        }

        OMElement rules = root.getFirstChildWithName(Constants.RULES_ELT);

        if (rules == null) {
            if (regs == null) {
                handleException("A valid Synapse configuration MUST specify the main mediator using the <rules> element");
            } else {
                // this is a fully dynamic configuration. look for synapse.xml at thr registry root
                OMNode cfg = config.getRegistry(null).lookup("synapse.xml");
                return getConfiguration(Util.getStreamSource(cfg).getInputStream());
            }

        } else {
            OMAttribute key = rules.getAttribute(new QName(Constants.NULL_NAMESPACE, "key"));
            if (key != null) {
                Property dp = new Property();
                dp.setName("namespace");
                dp.setType(Property.DYNAMIC_TYPE);
                dp.setKey(key.getAttributeValue());
                dp.setMapper(MediatorFactoryFinder.getInstance());
                config.setMainMediator(dp);
            } else {
                SynapseMediator sm = (SynapseMediator)
                        MediatorFactoryFinder.getInstance().getMediator(rules);
                if (sm.getList().isEmpty()) {
                    handleException("Invalid configuration, the main mediator specified by the <rules> element is empty");
                } else {
                    config.setMainMediator(sm);
                }
            }
        }

        if (is != null) {
View Full Code Here

Examples of org.apache.synapse.config.SynapseConfiguration

        if (!definitions.getQName().equals(XMLConfigConstants.DEFINITIONS_ELT)) {
            throw new SynapseException(
                    "Wrong QName for this config factory " + definitions.getQName());
        }

        SynapseConfiguration config = new SynapseConfiguration();
        config.setDefaultQName(definitions.getQName());

        SequenceMediator rootSequence = new SequenceMediator();
        rootSequence.setName(org.apache.synapse.SynapseConstants.MAIN_SEQUENCE_KEY);

        Iterator iter = definitions.getChildren();
       
        while (iter.hasNext()) {
            Object o = iter.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 mediator of the main sequence
                    if (key != null) {
                        Mediator m = MediatorFactoryFinder.getInstance().getMediator(elt);
                        rootSequence.addChild(m);
                    } else {
                        defineSequence(config, elt);
                    }
                } else if (XMLConfigConstants.ENDPOINT_ELT.equals(elt.getQName())) {
                    defineEndpoint(config, elt);
                } else if (XMLConfigConstants.ENTRY_ELT.equals(elt.getQName())) {
                    defineEntry(config, elt);
                } else if (XMLConfigConstants.PROXY_ELT.equals(elt.getQName())) {
                    defineProxy(config, elt);
                } else if (XMLConfigConstants.REGISTRY_ELT.equals(elt.getQName())) {
                    defineRegistry(config, elt);
                } else if (XMLConfigConstants.TASK_ELT.equals(elt.getQName())) {
                    defineStartup(config, elt);
                } else {
                    Mediator m = MediatorFactoryFinder.getInstance().getMediator(elt);
                    rootSequence.addChild(m);
                }
            }
        }

        if (config.getLocalRegistry().isEmpty() && config.getProxyServices().isEmpty() &&
                rootSequence.getList().isEmpty() && config.getRegistry() != null) {
            OMNode remoteConfigNode = config.getRegistry().lookup("synapse.xml");
            try {
                config = XMLConfigurationBuilder.getConfiguration(SynapseConfigUtils
                    .getStreamSource(remoteConfigNode).getInputStream());
            } catch (XMLStreamException xse) {
                throw new SynapseException("Problem loading remote synapse.xml ", xse);
            }

        }

        // if there is no sequence named main defined locally look for the set of mediators in
        // the root level before trying to look in the registry (hence config.getMainSequence
        // can not be used here)
        if (!config.getLocalRegistry().containsKey(SynapseConstants.MAIN_SEQUENCE_KEY)) {
            // if the root tag does not contain any mediators & registry does not have a
            // entry with key main then use the defualt main sequence
            if (rootSequence.getList().isEmpty() && config.getMainSequence() == null) {
                setDefaultMainSequence(config);
            } else {
                config.addSequence(rootSequence.getName(), rootSequence);
            }
        } else if (!rootSequence.getList().isEmpty()) {
            handleException("Invalid Synapse Configuration : Conflict in resolving the \"main\" " +
                    "mediator\n\tSynapse Configuration cannot have sequence named \"main\" and " +
                    "toplevel mediators simultaniously");
        }

        if (config.getFaultSequence() == null) {
            setDefaultFaultSequence(config);
        }

        return config;
    }
View Full Code Here
TOP
Copyright © 2018 www.massapi.com. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.