Package org.apache.synapse.config

Examples of org.apache.synapse.config.SynapseConfiguration


    private static SynapseConfiguration getConfiguration(ConfigurationContext cfgCtx) {

        cfgCtx.setProperty("addressing.validateAction", Boolean.FALSE);
        AxisConfiguration axisConfiguration = cfgCtx.getAxisConfiguration();
        SynapseConfiguration synapseConfiguration;

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

        if (config != null) {
            if (log.isDebugEnabled()) {
                log.debug("System property '" + SynapseConstants.SYNAPSE_XML +
                        "' specifies Synapse configuration as " + config);
            }
            synapseConfiguration = SynapseConfigurationBuilder.getConfiguration(config);
        } else {
            log.warn("System property '" + SynapseConstants.SYNAPSE_XML +
                "' is not specified. 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(SynapseConstants.SYNAPSE_CONFIG, null);
        synapseCtxParam.setValue(synapseConfiguration);
        MessageContextCreatorForAxis2.setSynConfig(synapseConfiguration);

        Parameter synapseEnvParam = new Parameter(SynapseConstants.SYNAPSE_ENV, null);
        Axis2SynapseEnvironment synEnv = new Axis2SynapseEnvironment(cfgCtx, synapseConfiguration);
        synapseEnvParam.setValue(synEnv);
        MessageContextCreatorForAxis2.setSynEnv(synEnv);

        try {
            axisConfiguration.addParameter(synapseCtxParam);
            axisConfiguration.addParameter(synapseEnvParam);

        } catch (AxisFault e) {
            String msg =
                "Could not set parameters '" + SynapseConstants.SYNAPSE_CONFIG +
                    "' and/or '" + SynapseConstants.SYNAPSE_ENV +
                    "'to the Axis2 configuration : " + e.getMessage();
            log.fatal(msg, e);
            throw new SynapseException(msg, e);
        }
        synapseConfiguration.init(synEnv);
       
        return synapseConfiguration;
    }
View Full Code Here


        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) {
                    ep.init(synapseEnvironment);
                }
            }
View Full Code Here

    /**
     * Reload as needed , either from registry , local entries or predefined endpoints
     * @param se synapse environment
     */
    private synchronized void reLoadAndInitEndpoint(SynapseEnvironment se) {
        SynapseConfiguration synCfg = se.getSynapseConfiguration();

        //always do reloading at init
        boolean reLoad = (realEndpoint == null);
        if (!reLoad) {
            Entry entry = synCfg.getEntryDefinition(template);
            if (entry != null && entry.isDynamic()) {
                if (!entry.isCached() || entry.isExpired()) {
                    reLoad = true;
                }
            } else {
                // this endpoint is static -->
                // since template-endpoint is static, should ONLY be loaded at initialization to prevent
                // reloading every single time this endpoint is executed..
                // incase tempalate config has changed this endpoint should be redeployed
                reLoad = false;
            }
        }

        if (reLoad) {
            if (log.isDebugEnabled()) {
                log.debug("Loading template endpoint with key : " + template);
            }

            Template eprTemplate = synCfg.getEndpointTemplate(template);

            if (eprTemplate != null) {
                realEndpoint = eprTemplate.create(this, synCfg.getProperties());
            } else {
                log.warn("Couldn't retrieve the endpoint template with the key:" + template);
            }

            if (realEndpoint != null && !realEndpoint.isInitialized()) {
View Full Code Here

        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();

            boolean reLoad = (realEndpoint == null);
            if (!reLoad) {

                Entry entry = synCfg.getEntryDefinition(key);
                if (entry != null && entry.isDynamic()) {

                    if (!entry.isCached() || entry.isExpired()) {
                        reLoad = true;
                    }
                } else {
                    // If the endpoint is static we should reload it from the Synapse config
                    reLoad = true;
                }
            }

            if (reLoad) {

                if (log.isDebugEnabled()) {
                    log.debug("Loading real endpoint with key : " + key);
                }

                realEndpoint = synCfg.getEndpoint(key);
                if (realEndpoint != null && !realEndpoint.isInitialized()) {
                    realEndpoint.init(synapseEnvironment);
                }
            } else {
                Endpoint epr = synCfg.getEndpoint(key);
                if (epr != realEndpoint) {
                    realEndpoint = epr;
                    if (realEndpoint != null && !realEndpoint.isInitialized()) {
                        realEndpoint.init(synapseEnvironment);
                    }
View Full Code Here

     * @param mc message context
     * @throws AxisFault
     */
    public void receive(MessageContext mc) throws AxisFault {
        // Create synapse message context from the axis2 message context
        SynapseConfiguration synCfg = (SynapseConfiguration) mc.getConfigurationContext()
                .getAxisConfiguration().getParameter(SynapseConstants.SYNAPSE_CONFIG).getValue();
        SynapseEnvironment synEnv = (SynapseEnvironment) mc.getConfigurationContext()
                .getAxisConfiguration().getParameter(SynapseConstants.SYNAPSE_ENV).getValue();
        org.apache.synapse.MessageContext smc = new Axis2MessageContext(mc, synCfg, synEnv);
        // initialize the response message builder using the message context
View Full Code Here

                    String propName = schemaKey.evaluateValue(synCtx);
                    sources[i++] = SynapseConfigUtils.getStreamSource(synCtx.getEntry(propName));
                }
                // load the UserDefined SchemaURIResolver implementations
                try {
                  SynapseConfiguration synCfg = synCtx.getConfiguration();
                  if(synCfg.getProperty(SynapseConstants.SYNAPSE_SCHEMA_RESOLVER) !=null){
                    setUserDefinedSchemaResourceResolver(synCtx);
                  }
                  else{
                    factory.setResourceResolver(
                                                new SchemaResourceResolver(synCtx.getConfiguration(), resourceMap));
View Full Code Here

     * UserDefined schema resource resolver

     * @param synCtx message context
     */
    private void setUserDefinedSchemaResourceResolver(MessageContext synCtx) {
        SynapseConfiguration synCfg = synCtx.getConfiguration();
        String schemaResolverName = synCfg.getProperty(SynapseConstants.SYNAPSE_SCHEMA_RESOLVER);
        Class schemaClazz;
        Object schemaClazzObject;
        try {
            schemaClazz = Class.forName(schemaResolverName);
        } catch (ClassNotFoundException e) {
View Full Code Here

    private static final String TEST_API = "TestAPI";

    public void testGeneralAPIDispatch() throws Exception {
        API api = new API(TEST_API, "/");
        SynapseConfiguration synapseConfig = new SynapseConfiguration();
        synapseConfig.addAPI(TEST_API, api);

        RESTRequestHandler handler = new RESTRequestHandler();

        MessageContext synCtx = getMessageContext(synapseConfig, false, "/test", "GET");
        handler.process(synCtx);
View Full Code Here

        assertEquals(TEST_API, synCtx.getProperty(RESTConstants.SYNAPSE_REST_API));
    }

    public void testBasicAPIDispatch() throws Exception {
        API api = new API(TEST_API, "/test");
        SynapseConfiguration synapseConfig = new SynapseConfiguration();
        synapseConfig.addAPI(TEST_API, api);

        RESTRequestHandler handler = new RESTRequestHandler();

        // Messages with '/test' context should ne dispatched
        MessageContext synCtx = getMessageContext(synapseConfig, false, "/test", "GET");
View Full Code Here

        assertNull(synCtx.getProperty(RESTConstants.SYNAPSE_REST_API));
    }

    public void testResponseDispatch() throws Exception {
        API api = new API(TEST_API, "/test");
        SynapseConfiguration synapseConfig = new SynapseConfiguration();
        synapseConfig.addAPI(TEST_API, api);

        RESTRequestHandler handler = new RESTRequestHandler();

        // Messages with '/test' context should ne dispatched
        MessageContext synCtx = getMessageContext(synapseConfig, false, "/test", "GET");
View Full Code Here

TOP

Related Classes of org.apache.synapse.config.SynapseConfiguration

Copyright © 2018 www.massapicom. 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.