synapse-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Ruwan Linton <ruwan.lin...@gmail.com>
Subject Re: svn commit: r749210 [1/2] - in /synapse/trunk/java/modules: core/src/main/java/org/apache/synapse/ core/src/main/java/org/apache/synapse/config/ core/src/main/java/org/apache/synapse/config/xml/ core/src/main/java/org/apache/synapse/config/xml/en
Date Thu, 05 Mar 2009 02:59:01 GMT
Indika, please try to not to commit in bulk rather make these commits
modular (one concern per commit).

It seems this particular commit has introduced a lot of regressions.

Thanks,
Ruwan

On Mon, Mar 2, 2009 at 11:50 AM, <indika@apache.org> wrote:

> Author: indika
> Date: Mon Mar  2 06:20:35 2009
> New Revision: 749210
>
> URL: http://svn.apache.org/viewvc?rev=749210&view=rev
> Log:
> changes for remove two init methods
> some changes for fixing SYNAPSE-376
>
> patch was at dev list
>
> Added:
>
>  synapse/trunk/java/modules/core/src/main/java/org/apache/synapse/Axis2SynapseController.java
>
>  synapse/trunk/java/modules/core/src/main/java/org/apache/synapse/ServerConfigurationInformation.java
>
>  synapse/trunk/java/modules/core/src/main/java/org/apache/synapse/ServerConfigurationInformationFactory.java
>
>  synapse/trunk/java/modules/core/src/main/java/org/apache/synapse/ServerContextInformation.java
>
>  synapse/trunk/java/modules/core/src/main/java/org/apache/synapse/ServerState.java
>
>  synapse/trunk/java/modules/core/src/main/java/org/apache/synapse/ServerStateDetectionStrategy.java
>
>  synapse/trunk/java/modules/core/src/main/java/org/apache/synapse/SynapseController.java
>
>  synapse/trunk/java/modules/core/src/main/java/org/apache/synapse/SynapseControllerFactory.java
> Modified:
>
>  synapse/trunk/java/modules/core/src/main/java/org/apache/synapse/ServerManager.java
>
>  synapse/trunk/java/modules/core/src/main/java/org/apache/synapse/SynapseConstants.java
>
>  synapse/trunk/java/modules/core/src/main/java/org/apache/synapse/SynapseServer.java
>
>  synapse/trunk/java/modules/core/src/main/java/org/apache/synapse/config/SynapseConfigUtils.java
>
>  synapse/trunk/java/modules/core/src/main/java/org/apache/synapse/config/SynapseConfiguration.java
>
>  synapse/trunk/java/modules/core/src/main/java/org/apache/synapse/config/SynapsePropertiesLoader.java
>
>  synapse/trunk/java/modules/core/src/main/java/org/apache/synapse/config/xml/SwitchCase.java
>
>  synapse/trunk/java/modules/core/src/main/java/org/apache/synapse/config/xml/endpoints/WSDLEndpointFactory.java
>
>  synapse/trunk/java/modules/core/src/main/java/org/apache/synapse/core/axis2/ProxyService.java
>
>  synapse/trunk/java/modules/core/src/main/java/org/apache/synapse/core/axis2/SynapseAxisServlet.java
>
>  synapse/trunk/java/modules/core/src/main/java/org/apache/synapse/core/axis2/SynapseCallbackReceiver.java
>
>  synapse/trunk/java/modules/core/src/main/java/org/apache/synapse/core/axis2/SynapseInitializationModule.java
>
>  synapse/trunk/java/modules/core/src/main/java/org/apache/synapse/core/axis2/SynapseStartUpServlet.java
>
>  synapse/trunk/java/modules/core/src/main/java/org/apache/synapse/core/axis2/TimeoutHandler.java
>
>  synapse/trunk/java/modules/core/src/main/java/org/apache/synapse/endpoints/AbstractEndpoint.java
>
>  synapse/trunk/java/modules/core/src/main/java/org/apache/synapse/endpoints/DynamicLoadbalanceEndpoint.java
>
>  synapse/trunk/java/modules/core/src/main/java/org/apache/synapse/endpoints/Endpoint.java
>
>  synapse/trunk/java/modules/core/src/main/java/org/apache/synapse/endpoints/IndirectEndpoint.java
>
>  synapse/trunk/java/modules/core/src/main/java/org/apache/synapse/endpoints/LoadbalanceEndpoint.java
>
>  synapse/trunk/java/modules/core/src/main/java/org/apache/synapse/endpoints/SALoadbalanceEndpoint.java
>
>  synapse/trunk/java/modules/core/src/main/java/org/apache/synapse/mediators/AbstractListMediator.java
>
>  synapse/trunk/java/modules/core/src/main/java/org/apache/synapse/mediators/AbstractMediator.java
>
>  synapse/trunk/java/modules/core/src/main/java/org/apache/synapse/mediators/builtin/CacheMediator.java
>
>  synapse/trunk/java/modules/core/src/main/java/org/apache/synapse/mediators/builtin/SendMediator.java
>
>  synapse/trunk/java/modules/core/src/main/java/org/apache/synapse/mediators/eip/aggregator/AggregateMediator.java
>
>  synapse/trunk/java/modules/core/src/main/java/org/apache/synapse/mediators/eip/splitter/CloneMediator.java
>
>  synapse/trunk/java/modules/core/src/main/java/org/apache/synapse/mediators/eip/splitter/IterateMediator.java
>
>  synapse/trunk/java/modules/core/src/main/java/org/apache/synapse/mediators/filters/SwitchMediator.java
>
>  synapse/trunk/java/modules/core/src/main/java/org/apache/synapse/startup/quartz/SimpleQuartz.java
>
>  synapse/trunk/java/modules/core/src/test/java/org/apache/synapse/n2n/SynapseCommodityServiceTest.java
>
>  synapse/trunk/java/modules/experimental/src/main/java/org/apache/synapse/experimental/ProxyDeployer.java
>
>  synapse/trunk/java/modules/handler/src/main/java/org/apache/synapse/handler/SynapseModule.java
>
>  synapse/trunk/java/modules/samples/src/test/java/org/apache/synapse/samples/n2n/AbstractAutomationTestCase.java
>
> Added:
> synapse/trunk/java/modules/core/src/main/java/org/apache/synapse/Axis2SynapseController.java
> URL:
> http://svn.apache.org/viewvc/synapse/trunk/java/modules/core/src/main/java/org/apache/synapse/Axis2SynapseController.java?rev=749210&view=auto
>
> ==============================================================================
> ---
> synapse/trunk/java/modules/core/src/main/java/org/apache/synapse/Axis2SynapseController.java
> (added)
> +++
> synapse/trunk/java/modules/core/src/main/java/org/apache/synapse/Axis2SynapseController.java
> Mon Mar  2 06:20:35 2009
> @@ -0,0 +1,406 @@
> +/*
> + *  Licensed to the Apache Software Foundation (ASF) under one
> + *  or more contributor license agreements.  See the NOTICE file
> + *  distributed with this work for additional information
> + *  regarding copyright ownership.  The ASF licenses this file
> + *  to you under the Apache License, Version 2.0 (the
> + *  "License"); you may not use this file except in compliance
> + *  with the License.  You may obtain a copy of the License at
> + *
> + *   http://www.apache.org/licenses/LICENSE-2.0
> + *
> + *  Unless required by applicable law or agreed to in writing,
> + *  software distributed under the License is distributed on an
> + *   * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
> + *  KIND, either express or implied.  See the License for the
> + *  specific language governing permissions and limitations
> + *  under the License.
> + */
> +package org.apache.synapse;
> +
> +import org.apache.axis2.AxisFault;
> +import org.apache.axis2.Constants;
> +import org.apache.axis2.context.ConfigurationContext;
> +import org.apache.axis2.context.ConfigurationContextFactory;
> +import org.apache.axis2.description.*;
> +import org.apache.axis2.engine.AxisConfiguration;
> +import org.apache.axis2.engine.ListenerManager;
> +import org.apache.axis2.format.BinaryBuilder;
> +import org.apache.axis2.format.PlainTextBuilder;
> +import org.apache.commons.logging.Log;
> +import org.apache.commons.logging.LogFactory;
> +import
> org.apache.synapse.commons.util.datasource.DataSourceInformationRepositoryHelper;
> +import org.apache.synapse.config.SynapseConfiguration;
> +import org.apache.synapse.config.SynapseConfigurationBuilder;
> +import org.apache.synapse.config.SynapsePropertiesLoader;
> +import org.apache.synapse.config.Entry;
> +import org.apache.synapse.core.SynapseEnvironment;
> +import org.apache.synapse.core.axis2.Axis2SynapseEnvironment;
> +import org.apache.synapse.core.axis2.MessageContextCreatorForAxis2;
> +import org.apache.synapse.core.axis2.ProxyService;
> +import org.apache.synapse.core.axis2.SynapseMessageReceiver;
> +import org.apache.synapse.eventing.SynapseEventSource;
> +
> +import java.util.ArrayList;
> +import java.util.List;
> +import java.util.Map;
> +import java.util.Date;
> +
> +/**
> + * Axis2 Based Synapse Controller
> + *
> + * @see org.apache.synapse.SynapseController
> + */
> +public class Axis2SynapseController implements SynapseController {
> +
> +    private static final Log log =
> LogFactory.getLog(Axis2SynapseController.class);
> +
> +    /*The Axis2 listener Manager */
> +    private ListenerManager listenerManager;
> +    /*The Axis2 configuration context used by Synapse */
> +    private ConfigurationContext configurationContext;
> +    /*Reference to the Synapse configuration */
> +    private SynapseConfiguration synapseConfiguration;
> +    /*Reference to the Synapse configuration */
> +    private SynapseEnvironment synapseEnvironment;
> +    /*Indicate initialization state */
> +    private boolean initialize;
> +    /* ServerConfiguration Information */
> +    private ServerConfigurationInformation information;
> +
> +    /**
> +     * Initiates the  Axis2 Based Server Environment
> +     *
> +     * @param configurationInformation ServerConfigurationInformation
> Instance
> +     * @param contextInformation       Server Context if the Axis2 Based
> Server
> +     *                                 Environment has been already set
> up.
> +     */
> +    public void init(ServerConfigurationInformation
> configurationInformation,
> +                     ServerContextInformation contextInformation) {
> +
> +        log.info("Initializing Synapse at : " + new Date());
> +
> +        this.information = configurationInformation;
> +
> +        if (contextInformation == null) {
> +            if (log.isDebugEnabled()) {
> +                log.debug("Initializing Synapse in a new axis2 server
> environment instance ");
> +            }
> +            createNewInstance(configurationInformation);
> +        } else {
> +            Object context = contextInformation.getServerContext();
> +            if (context instanceof ConfigurationContext) {
> +                if (log.isDebugEnabled()) {
> +                    log.debug("Initializing Synapse in a already created "
> +
> +                            "axis2 server environment instance");
> +                }
> +                configurationContext = (ConfigurationContext) context;
> +            } else {
> +                handleFatal("Synapse startup initialization failed :
> Provided server context is" +
> +                        " invalid,expected a Axis2 ConfigurationContext
> instance");
> +            }
> +        }
> +        initDefault();
> +        initialize = true;
> +    }
> +
> +    /**
> +     * Destroy the  Axis2 Based Server Environment
> +     */
> +    public void destroy() {
> +
> +        try {
> +            // stop all services
> +            if (information.isCreateNewInstance()) {  // only if we have
> created the server
> +
> +                if (configurationContext != null &&
> +                        configurationContext.getAxisConfiguration() !=
> null) {
> +
> +                    Map<String, AxisService> serviceMap =
> +
>  configurationContext.getAxisConfiguration().getServices();
> +                    for (AxisService svc : serviceMap.values()) {
> +                        svc.setActive(false);
> +                    }
> +
> +                    // stop all modules
> +                    Map<String, AxisModule> moduleMap =
> +
>  configurationContext.getAxisConfiguration().getModules();
> +                    for (AxisModule mod : moduleMap.values()) {
> +                        if (mod.getModule() != null &&
> !"synapse".equals(mod.getName())) {
> +
>  mod.getModule().shutdown(configurationContext);
> +                        }
> +                    }
> +                }
> +
> +                // stop all transports
> +                if (listenerManager != null) {
> +                    listenerManager.stop();
> +                    listenerManager.destroy();
> +                }
> +
> +                // we need to call this method to clean the temp files we
> created.
> +                if (configurationContext != null) {
> +                    configurationContext.terminate();
> +                }
> +            }
> +            initialize = false;
> +        } catch (Exception e) {
> +            log.error("Error stopping the Axis2 Based Server Environment",
> e);
> +        }
> +    }
> +
> +    public boolean isInitialized() {
> +        return initialize;
> +    }
> +
> +    /**
> +     * Setup synapse in axis2 environment and then , creates and returns
> +     * a SynapseEnvironment instance
> +     *
> +     * @return SynapseEnvironment instance
> +     */
> +    public SynapseEnvironment createSynapseEnvironment() {
> +
> +        try {
> +            setupSynapse();
> +        } catch (AxisFault axisFault) {
> +            log.fatal("Synapse startup failed...", axisFault);
> +            throw new SynapseException("Synapse startup failed",
> axisFault);
> +        }
> +
> +        Parameter synapseEnvironmentParameter = new
> Parameter(SynapseConstants.SYNAPSE_ENV, null);
> +        synapseEnvironment = new Axis2SynapseEnvironment(
> +                configurationContext, synapseConfiguration);
> +        synapseEnvironmentParameter.setValue(synapseEnvironment);
> +
> +        MessageContextCreatorForAxis2.setSynEnv(synapseEnvironment);
> +
> +        try {
> +
>  configurationContext.getAxisConfiguration().addParameter(synapseEnvironmentParameter);
> +        } catch (AxisFault e) {
> +            handleFatal("Could not set parameters '" +
> SynapseConstants.SYNAPSE_CONFIG +
> +                    "' and/or '" + SynapseConstants.SYNAPSE_ENV +
> +                    "'to the Axis2 configuration : " + e.getMessage(), e);
> +
> +        }
> +        synapseEnvironment.setInitialized(true);
> +        synapseConfiguration.init(synapseEnvironment);
> +        return synapseEnvironment;
> +    }
> +
> +    public void destroySynapseEnvironment() {
> +        if (synapseEnvironment != null) {
> +            synapseEnvironment.setInitialized(false);
> +        }
> +    }
> +
> +    public SynapseConfiguration createSynapseConfiguration() {
> +
> +        String synapseXMLLocation = information.getSynapseXMLLocation();
> +
> +        if (synapseXMLLocation != null) {
> +            synapseConfiguration =
> SynapseConfigurationBuilder.getConfiguration(synapseXMLLocation);
> +        } else {
> +            log.warn("System property or init-parameter '" +
> SynapseConstants.SYNAPSE_XML +
> +                    "' is not specified. Using default configuration..");
> +            synapseConfiguration =
> SynapseConfigurationBuilder.getDefaultConfiguration();
> +        }
> +
> +
>  synapseConfiguration.setProperties(SynapsePropertiesLoader.loadSynapseProperties());
> +
> +        // Set the Axis2 ConfigurationContext to the SynapseConfiguration
> +
>  synapseConfiguration.setAxisConfiguration(configurationContext.getAxisConfiguration());
> +
> +        // set the Synapse configuration and environment into the Axis2
> configuration
> +        Parameter synapseConfigurationParameter = new Parameter(
> +                SynapseConstants.SYNAPSE_CONFIG, null);
> +        synapseConfigurationParameter.setValue(synapseConfiguration);
> +        MessageContextCreatorForAxis2.setSynConfig(synapseConfiguration);
> +
> +        try {
> +
>  configurationContext.getAxisConfiguration().addParameter(synapseConfigurationParameter);
> +
> +        } catch (AxisFault e) {
> +            handleFatal("Could not set parameters '" +
> SynapseConstants.SYNAPSE_CONFIG +
> +                    "' and/or '" + SynapseConstants.SYNAPSE_ENV +
> +                    "'to the Axis2 configuration : " + e.getMessage(), e);
> +        }
> +        return synapseConfiguration;
> +    }
> +
> +    public void destroySynapseConfiguration() {
> +        if (synapseConfiguration != null) {
> +            synapseConfiguration.destroy();
> +        }
> +    }
> +
> +    public Object getContext() {
> +        return configurationContext;
> +    }
> +
> +    /**
> +     * Create a Axis2 Based Server Environment
> +     *
> +     * @param information (ServerConfigurationInformation instance
> +     */
> +    private void createNewInstance(ServerConfigurationInformation
> information) {
> +
> +        try {
> +            configurationContext = ConfigurationContextFactory.
> +
>  createConfigurationContextFromFileSystem(information.getAxis2RepoLocation(),
> +                            information.getAxis2Xml());
> +
> +            listenerManager = configurationContext.getListenerManager();
> +            if (listenerManager == null) {
> +                listenerManager = new ListenerManager();
> +                listenerManager.init(configurationContext);
> +            }
> +
> +            for (String trp : configurationContext.getAxisConfiguration()
> +                    .getTransportsIn().keySet()) {
> +
> +                TransportInDescription trsIn =
> +
>  configurationContext.getAxisConfiguration().getTransportsIn().get(trp);
> +
> +                String msg = "Starting transport " + trsIn.getName();
> +                if (trsIn.getParameter("port") != null) {
> +                    msg += " on port " +
> trsIn.getParameter("port").getValue();
> +                }
> +                log.info(msg);
> +
> +                listenerManager.addListener(trsIn, false);
> +            }
> +            information.setCreateNewInstance(true);
> +            initialize = true;
> +
> +        } catch (Throwable t) {
> +            handleFatal("Synapse startup failed...", t);
> +        }
> +    }
> +
> +    /**
> +     * Setup required setting for enable main message mediation
> +     *
> +     * @throws AxisFault For any in setup
> +     */
> +    private void setupMainMediation() throws AxisFault {
> +
> +        log.info("Deploying the Synapse service..");
> +        // Dynamically initialize the Synapse Service and deploy it into
> Axis2
> +        AxisConfiguration axisCfg =
> configurationContext.getAxisConfiguration();
> +        AxisService synapseService = new
> AxisService(SynapseConstants.SYNAPSE_SERVICE_NAME);
> +        AxisOperation mediateOperation = new InOutAxisOperation(
> +                SynapseConstants.SYNAPSE_OPERATION_NAME);
> +        mediateOperation.setMessageReceiver(new SynapseMessageReceiver());
> +        synapseService.addOperation(mediateOperation);
> +        List<String> transports = new ArrayList<String>();
> +        transports.add(Constants.TRANSPORT_HTTP);
> +        transports.add(Constants.TRANSPORT_HTTPS);
> +        synapseService.setExposedTransports(transports);
> +        axisCfg.addService(synapseService);
> +    }
> +
> +    /**
> +     * Setup required setting for enable proxy message mediation
> +     */
> +    private void setupProxyServiceMediation() {
> +
> +        log.info("Deploying Proxy services...");
> +        String thisServerName = information.getServerName();
> +        if (thisServerName == null || "".equals(thisServerName)) {
> +            thisServerName = information.getHostName();
> +            if (thisServerName == null || "".equals(thisServerName)) {
> +                thisServerName = "localhost";
> +            }
> +        }
> +        for (ProxyService proxy : synapseConfiguration.getProxyServices())
> {
> +
> +            // start proxy service if either,
> +            // pinned server name list is empty
> +            // or pinned server list has this server name
> +            List pinnedServers = proxy.getPinnedServers();
> +            if (pinnedServers != null && !pinnedServers.isEmpty()) {
> +                if (!pinnedServers.contains(thisServerName)) {
> +                    log.info("Server name not in pinned servers list." +
> +                            " Not deploying Proxy service : " +
> proxy.getName());
> +                    continue;
> +                }
> +            }
> +
> +            proxy.buildAxisService(synapseConfiguration,
> +                    configurationContext.getAxisConfiguration());
> +            log.info("Deployed Proxy service : " + proxy.getName());
> +            if (!proxy.isStartOnLoad()) {
> +                proxy.stop(synapseConfiguration);
> +            }
> +        }
> +    }
> +
> +    private void setupSynapse() throws AxisFault {
> +        addServerIPAndHostEnrties();
> +        setupMainMediation();
> +        setupProxyServiceMediation();
> +        setupEventSources();
> +    }
> +
> +    private void initDefault() {
> +
>  addDefaultBuildersAndFormatters(configurationContext.getAxisConfiguration());
> +        loadMediatorExtensions();
> +        setupDataSources();
> +    }
> +
> +    private void loadMediatorExtensions() {
> +        // this will deploy the mediators in the mediator extensions
> folder
> +        log.info("Loading mediator extensions...");
> +
>  configurationContext.getAxisConfiguration().getConfigurator().loadServices();
> +    }
> +
> +    private void setupEventSources() throws AxisFault {
> +        for (SynapseEventSource eventSource :
> synapseConfiguration.getEventSources()) {
> +
>  eventSource.buildService(configurationContext.getAxisConfiguration());
> +        }
> +    }
> +
> +    private void setupDataSources() {
> +        java.util.Properties synapseProperties =
> SynapsePropertiesLoader.loadSynapseProperties();
> +
> +        DataSourceInformationRepositoryHelper.
> +                initializeDataSourceInformationRepository(
> +                        configurationContext.getAxisConfiguration(),
> synapseProperties);
> +    }
> +
> +    private void addDefaultBuildersAndFormatters(AxisConfiguration
> axisConf) {
> +        if (axisConf.getMessageBuilder("text/plain") == null) {
> +            axisConf.addMessageBuilder("text/plain", new
> PlainTextBuilder());
> +        }
> +        if (axisConf.getMessageBuilder("application/octet-stream") ==
> null) {
> +            axisConf.addMessageBuilder("application/octet-stream", new
> BinaryBuilder());
> +        }
> +    }
> +
> +    private void addServerIPAndHostEnrties() {
> +        String hostName = information.getHostName();
> +        String ipAddress = information.getIpAddress();
> +        if (hostName != null && !"".equals(hostName)) {
> +            Entry entry = new Entry(SynapseConstants.SERVER_HOST);
> +            entry.setValue(hostName);
> +            synapseConfiguration.addEntry(SynapseConstants.SERVER_HOST,
> entry);
> +        }
> +
> +        if (ipAddress != null && !"".equals(ipAddress)) {
> +            Entry entry = new Entry(SynapseConstants.SERVER_IP);
> +            entry.setValue(ipAddress);
> +            synapseConfiguration.addEntry(SynapseConstants.SERVER_IP,
> entry);
> +        }
> +    }
> +
> +    private void handleFatal(String msg, Throwable e) {
> +        log.fatal(msg, e);
> +        throw new SynapseException(msg, e);
> +    }
> +
> +    private void handleFatal(String msg) {
> +        log.fatal(msg);
> +        throw new SynapseException(msg);
> +    }
> +}
>
> Added:
> synapse/trunk/java/modules/core/src/main/java/org/apache/synapse/ServerConfigurationInformation.java
> URL:
> http://svn.apache.org/viewvc/synapse/trunk/java/modules/core/src/main/java/org/apache/synapse/ServerConfigurationInformation.java?rev=749210&view=auto
>
> ==============================================================================
> ---
> synapse/trunk/java/modules/core/src/main/java/org/apache/synapse/ServerConfigurationInformation.java
> (added)
> +++
> synapse/trunk/java/modules/core/src/main/java/org/apache/synapse/ServerConfigurationInformation.java
> Mon Mar  2 06:20:35 2009
> @@ -0,0 +1,233 @@
> +/*
> + *  Licensed to the Apache Software Foundation (ASF) under one
> + *  or more contributor license agreements.  See the NOTICE file
> + *  distributed with this work for additional information
> + *  regarding copyright ownership.  The ASF licenses this file
> + *  to you under the Apache License, Version 2.0 (the
> + *  "License"); you may not use this file except in compliance
> + *  with the License.  You may obtain a copy of the License at
> + *
> + *   http://www.apache.org/licenses/LICENSE-2.0
> + *
> + *  Unless required by applicable law or agreed to in writing,
> + *  software distributed under the License is distributed on an
> + *   * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
> + *  KIND, either express or implied.  See the License for the
> + *  specific language governing permissions and limitations
> + *  under the License.
> + */
> +package org.apache.synapse;
> +
> +import org.apache.axis2.Constants;
> +import org.apache.commons.logging.Log;
> +import org.apache.commons.logging.LogFactory;
> +
> +import java.io.File;
> +import java.net.InetAddress;
> +import java.net.UnknownHostException;
> +import java.util.Map;
> +import java.util.HashMap;
> +
> +/**
> + * Encapsulates all server information
> + */
> +public class ServerConfigurationInformation {
> +
> +    private static final Log log =
> LogFactory.getLog(ServerConfigurationInformation.class);
> +
> +    /* The properties map */
> +    private final Map<String, String> properties = new HashMap<String,
> String>();
> +    /*The Axis2 repository location */
> +    private String axis2RepoLocation;
> +    /* The path to the axis2.xml file  */
> +    private String axis2Xml;
> +    /* The synapse home is the home directory of the Synapse installation
>   */
> +    private String synapseHome;
> +    /* The path to the synapse.xml file */
> +    private String synapseXMLLocation;
> +    /* The root directory to resolve paths for registry, default to
> synapse.home/repository  */
> +    private String resolveRoot;
> +    /* An optional server name to activate pinned services, tasks etc..
> and to differentiate instances on a cluster */
> +    private String serverName = "localhost";
> +    /* Server controller provider */
> +    private String serverControllerProvider =
> DEFAULT_SERVER_CONTROLLER_PROVIDER;
> +    /* The default synapse server controller*/
> +    private static final String DEFAULT_SERVER_CONTROLLER_PROVIDER =
> "org.apache.synapse.Axis2SynapseController";
> +    /* whether it is needed to create a new server instance*/
> +    private boolean createNewInstance = true;
> +    /* Server host name */
> +    private String hostName;
> +    /* Server IP address*/
> +    private String ipAddress;
> +    /* Deployment mode*/
> +    private String deploymentMode;
> +
> +    public ServerConfigurationInformation() {
> +        initServerHostAndIP();
> +    }
> +
> +    public void setAxis2RepoLocation(String axis2RepoLocation) {
> +        assertNullOrEmpty(axis2RepoLocation, Constants.AXIS2_REPO);
> +        if (!new File(axis2RepoLocation).isAbsolute() && synapseHome !=
> null) {
> +            this.axis2RepoLocation = synapseHome + File.separator +
> axis2RepoLocation;
> +        } else {
> +            this.axis2RepoLocation = axis2RepoLocation;
> +        }
> +    }
> +
> +    public void setAxis2Xml(String axis2Xml) {
> +        assertNullOrEmpty(axis2Xml, Constants.AXIS2_CONF);
> +        if (!new File(axis2Xml).isAbsolute() && synapseHome != null) {
> +            this.axis2Xml = synapseHome + File.separator + axis2Xml;
> +        } else {
> +            this.axis2Xml = axis2Xml;
> +        }
> +    }
> +
> +    public void setSynapseHome(String synapseHome) {
> +        assertNullOrEmpty(synapseHome, SynapseConstants.SYNAPSE_HOME);
> +        this.synapseHome = synapseHome;
> +    }
> +
> +    public void setResolveRoot(String resolveRoot) {
> +        if (resolveRoot == null || "".equals(resolveRoot)) {
> +            return;
> +        }
> +        if (!new File(resolveRoot).isAbsolute() && synapseHome != null) {
> +            this.resolveRoot = synapseHome + File.separator + resolveRoot;
> +        } else {
> +            this.resolveRoot = resolveRoot;
> +        }
> +    }
> +
> +    public void setSynapseXMLLocation(String synapseXMLLocation) {
> +        assertNullOrEmpty(synapseXMLLocation,
> SynapseConstants.SYNAPSE_XML);
> +        if (!new File(synapseXMLLocation).isAbsolute() && synapseHome !=
> null) {
> +            this.synapseXMLLocation = synapseHome + File.separator +
> synapseXMLLocation;
> +        } else {
> +            this.synapseXMLLocation = synapseXMLLocation;
> +        }
> +    }
> +
> +    public String getAxis2RepoLocation() {
> +        return axis2RepoLocation;
> +    }
> +
> +
> +    public String getAxis2Xml() {
> +        return axis2Xml;
> +    }
> +
> +
> +    public String getSynapseHome() {
> +        return synapseHome;
> +    }
> +
> +
> +    public String getSynapseXMLLocation() {
> +        return synapseXMLLocation;
> +    }
> +
> +
> +    public String getResolveRoot() {
> +        return resolveRoot;
> +    }
> +
> +
> +    public String getServerName() {
> +        return serverName;
> +    }
> +
> +    public void setServerName(String serverName) {
> +        this.serverName = serverName;
> +    }
> +
> +    public String getServerControllerProvider() {
> +        return serverControllerProvider;
> +    }
> +
> +    public void setServerControllerProvider(String
> serverControllerProvider) {
> +        this.serverControllerProvider = serverControllerProvider;
> +    }
> +
> +    public boolean isCreateNewInstance() {
> +        return createNewInstance;
> +    }
> +
> +    public void setCreateNewInstance(boolean createNewInstance) {
> +        this.createNewInstance = createNewInstance;
> +    }
> +
> +    public String getHostName() {
> +        return hostName;
> +    }
> +
> +    public void setHostName(String hostName) {
> +        this.hostName = hostName;
> +    }
> +
> +    public String getIpAddress() {
> +        return ipAddress;
> +    }
> +
> +    public void setIpAddress(String ipAddress) {
> +        this.ipAddress = ipAddress;
> +    }
> +
> +    public String getDeploymentMode() {
> +        return deploymentMode;
> +    }
> +
> +    public void setDeploymentMode(String deploymentMode) {
> +        this.deploymentMode = deploymentMode;
> +    }
> +
> +    public void addConfigurationProperty(String key, String value) {
> +        assertNullOrEmpty(key);
> +        assertNullOrEmpty(value, key);
> +        properties.put(key.trim(), value.trim());
> +    }
> +
> +    public String getConfigurationProperty(String key) {
> +        assertNullOrEmpty(key);
> +        return properties.get(key.trim());
> +    }
> +
> +    private void assertNullOrEmpty(String value, String paramter) {
> +        if (value == null || "".equals(value)) {
> +            handleFatal("The parameter - " + paramter + "  must be
> provided.");
> +        }
> +    }
> +
> +    private void assertNullOrEmpty(String key) {
> +        if (key == null || "".equals(key)) {
> +            handleFatal("A configuration parameter is null or empty.");
> +        }
> +    }
> +
> +    private void handleFatal(String msg) {
> +        log.fatal(msg);
> +        throw new SynapseException(msg);
> +    }
> +
> +    private void initServerHostAndIP() {
> +        try {
> +            InetAddress addr = InetAddress.getLocalHost();
> +            if (addr != null) {
> +
> +                // Get IP Address
> +                ipAddress = addr.getHostAddress();
> +                if (ipAddress != null) {
> +                }
> +
> +                // Get hostName
> +                hostName = addr.getHostName();
> +                if (hostName == null) {
> +                    hostName = ipAddress;
> +                }
> +            }
> +        } catch (UnknownHostException e) {
> +            log.warn("Unable to get the hostName or IP address of the
> server", e);
> +        }
> +    }
> +}
>
> Added:
> synapse/trunk/java/modules/core/src/main/java/org/apache/synapse/ServerConfigurationInformationFactory.java
> URL:
> http://svn.apache.org/viewvc/synapse/trunk/java/modules/core/src/main/java/org/apache/synapse/ServerConfigurationInformationFactory.java?rev=749210&view=auto
>
> ==============================================================================
> ---
> synapse/trunk/java/modules/core/src/main/java/org/apache/synapse/ServerConfigurationInformationFactory.java
> (added)
> +++
> synapse/trunk/java/modules/core/src/main/java/org/apache/synapse/ServerConfigurationInformationFactory.java
> Mon Mar  2 06:20:35 2009
> @@ -0,0 +1,250 @@
> +/*
> + *  Licensed to the Apache Software Foundation (ASF) under one
> + *  or more contributor license agreements.  See the NOTICE file
> + *  distributed with this work for additional information
> + *  regarding copyright ownership.  The ASF licenses this file
> + *  to you under the Apache License, Version 2.0 (the
> + *  "License"); you may not use this file except in compliance
> + *  with the License.  You may obtain a copy of the License at
> + *
> + *   http://www.apache.org/licenses/LICENSE-2.0
> + *
> + *  Unless required by applicable law or agreed to in writing,
> + *  software distributed under the License is distributed on an
> + *   * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
> + *  KIND, either express or implied.  See the License for the
> + *  specific language governing permissions and limitations
> + *  under the License.
> + */
> +package org.apache.synapse;
> +
> +import org.apache.axis2.description.Parameter;
> +import org.apache.axis2.engine.AxisConfiguration;
> +import org.apache.axis2.Constants;
> +import org.apache.commons.cli.CommandLine;
> +import org.apache.commons.logging.Log;
> +import org.apache.commons.logging.LogFactory;
> +
> +import javax.servlet.ServletConfig;
> +import java.io.File;
> +
> +/**
> + * Contains factory method for creating ServerConfigurationInformation
> based on various
> + */
> +public class ServerConfigurationInformationFactory {
> +
> +    private static final Log log =
> LogFactory.getLog(ServerConfigurationInformationFactory.class);
> +
> +    /**
> +     * Factory method for create a ServerConfigurationInformation
> +     * based on information from AxisConfiguration
> +     *
> +     * @param axisConfiguration AxisConfiguration instance
> +     * @return ServerConfigurationInformation instance
> +     */
> +    public static ServerConfigurationInformation
> createServerConfigurationInformation(
> +            AxisConfiguration axisConfiguration) {
> +
> +        ServerConfigurationInformation information = new
> ServerConfigurationInformation();
> +
> +
>  information.setSynapseHome(getAxis2ParameterValue(axisConfiguration,
> +                SynapseConstants.Axis2Param.SYNAPSE_HOME));
> +
>  information.setSynapseXMLLocation(getAxis2ParameterValue(axisConfiguration,
> +                SynapseConstants.Axis2Param.SYNAPSE_CONFIG_LOCATION));
> +
>  information.setServerName(getAxis2ParameterValue(axisConfiguration,
> +                SynapseConstants.Axis2Param.SYNAPSE_SERVER_NAME));
> +
>  information.setResolveRoot(getAxis2ParameterValue(axisConfiguration,
> +                SynapseConstants.Axis2Param.SYNAPSE_RESOLVE_ROOT));
> +
> +        return information;
> +
> +    }
> +
> +    /**
> +     * Factory method for create a ServerConfigurationInformation based on
> command line arguments
> +     *
> +     * @param cmd CommandLine instance
> +     * @return ServerConfigurationInformation instance
> +     */
> +    public static ServerConfigurationInformation
> createServerConfigurationInformation(
> +            CommandLine cmd) {
> +
> +        ServerConfigurationInformation information = new
> ServerConfigurationInformation();
> +
> +        information.setAxis2RepoLocation(getArgument(cmd,
> Constants.AXIS2_CONF));
> +        information.setAxis2Xml(getArgument(cmd,
> SynapseConstants.SYNAPSE_XML));
> +        information.setSynapseHome(getArgument(cmd,
> SynapseConstants.SYNAPSE_HOME));
> +        information.setSynapseXMLLocation(getArgument(cmd,
> SynapseConstants.SYNAPSE_XML));
> +        information.setResolveRoot(getArgument(cmd,
> SynapseConstants.RESOLVE_ROOT));
> +        information.setDeploymentMode(getArgument(cmd,
> SynapseConstants.DEPLOYMENT_MODE));
> +        information.setServerName(getArgument(cmd,
> SynapseConstants.SERVER_NAME));
> +
> +        return information;
> +    }
> +
> +    /**
> +     * Creates a ServerConfigurationInformation based on command line
> arguments
> +     *
> +     * @param args Command line arguments
> +     * @return ServerConfigurationInformation instance
> +     */
> +    public static ServerConfigurationInformation
> createServerConfigurationInformation(
> +            String[] args) {
> +
> +        ServerConfigurationInformation information = new
> ServerConfigurationInformation();
> +        information.setAxis2RepoLocation(args[0]);
> +        if (args.length == 1) {
> +            log.warn("Configuring server manager using deprecated " +
> +                    "system properties; please update your
> configuration");
> +
>  information.setAxis2Xml(System.getProperty(Constants.AXIS2_CONF));
> +
>  information.setSynapseHome(System.getProperty(SynapseConstants.SYNAPSE_HOME));
> +
>  information.setSynapseXMLLocation(System.getProperty(SynapseConstants.SYNAPSE_XML));
> +
>  information.setResolveRoot(System.getProperty(SynapseConstants.RESOLVE_ROOT));
> +
>  information.setServerName(System.getProperty(SynapseConstants.SERVER_NAME));
> +
>  information.setDeploymentMode(System.getProperty(SynapseConstants.DEPLOYMENT_MODE));
> +        } else if (args.length == 4) {
> +            information.setAxis2Xml(args[1]);
> +            information.setSynapseHome(args[2]);
> +            information.setSynapseXMLLocation(args[3]);
> +            information.setResolveRoot(args[2] + File.separator +
> "repository");
> +        } else if (args.length == 5) {
> +            information.setAxis2Xml(args[1]);
> +            information.setSynapseHome(args[2]);
> +            information.setSynapseXMLLocation(args[3]);
> +            information.setResolveRoot(args[4]);
> +        } else if (args.length == 6) {
> +            information.setAxis2Xml(args[1]);
> +            information.setSynapseHome(args[2]);
> +            information.setSynapseXMLLocation(args[3]);
> +            information.setResolveRoot(args[4]);
> +            information.setServerName(args[5]);
> +        } else if (args.length == 7) {
> +            information.setAxis2Xml(args[1]);
> +            information.setSynapseHome(args[2]);
> +            information.setSynapseXMLLocation(args[3]);
> +            information.setResolveRoot(args[4]);
> +            information.setServerName(args[5]);
> +            information.setDeploymentMode(args[6]);
> +        }
> +        return information;
> +
> +    }
> +
> +    /**
> +     * Factory method for create a ServerConfigurationInformation based on
> information from ServletConfig
> +     *
> +     * @param servletConfig ServletConfig instance
> +     * @return ServerConfigurationInformation instance
> +     */
> +    public static ServerConfigurationInformation
> createServerConfigurationInformation(
> +            ServletConfig servletConfig) {
> +
> +        ServerConfigurationInformation information = new
> ServerConfigurationInformation();
> +
> +        String synapseHome = loadParameter(servletConfig,
> SynapseConstants.SYNAPSE_HOME, false);
> +
> +        if (synapseHome == null) {
> +            log.info("synapse.home not set; using web application root as
> default value");
> +            String webinfPath =
> servletConfig.getServletContext().getRealPath("WEB-INF");
> +            if (webinfPath == null || !webinfPath.endsWith("WEB-INF")) {
> +                handleFatal("Unable to currentState web application root
> directory");
> +            } else {
> +                synapseHome = webinfPath.substring(0, webinfPath.length()
> - 7);
> +                log.info("Setting synapse.home to : " + synapseHome);
> +            }
> +        }
> +
> +        information.setSynapseHome(synapseHome);
> +        information.setSynapseXMLLocation(loadParameter(servletConfig,
> +                SynapseConstants.SYNAPSE_XML, true));
> +        information.setResolveRoot(loadParameter(servletConfig,
> +                SynapseConstants.RESOLVE_ROOT, false));
> +        information.setAxis2RepoLocation(loadParameter(servletConfig,
> +                org.apache.axis2.Constants.AXIS2_REPO, true));
> +        information.setAxis2Xml(loadParameter(servletConfig,
> +                org.apache.axis2.Constants.AXIS2_CONF, true));
> +        information.setSynapseHome(loadParameter(servletConfig,
> +                SynapseConstants.SERVER_NAME, false));
> +        information.setDeploymentMode(loadParameter(servletConfig,
> +                SynapseConstants.DEPLOYMENT_MODE, false));
> +
> +        return information;
> +    }
> +
> +    /**
> +     * Helper method to get a value of a parameters in the
> AxisConfiguration
> +     *
> +     * @param axisConfiguration AxisConfiguration instance
> +     * @param paramKey          The name / key of the parameter
> +     * @return The value of the parameter
> +     */
> +    private static String getAxis2ParameterValue(AxisConfiguration
> axisConfiguration,
> +                                                 String paramKey) {
> +
> +        Parameter parameter = axisConfiguration.getParameter(paramKey);
> +        if (parameter == null) {
> +            return null;
> +        }
> +        Object value = parameter.getValue();
> +        if (value != null && value instanceof String) {
> +            return (String) parameter.getValue();
> +        } else {
> +            return null;
> +        }
> +    }
> +
> +
> +    /**
> +     * Utility method to extract command line arguments
> +     *
> +     * @param cmd     Command line which capture all command line
> arguments
> +     * @param argName Name of the argument to be extracted
> +     * @return value of the argument if there is , o.w null
> +     */
> +    private static String getArgument(CommandLine cmd, String argName) {
> +
> +        if (cmd == null) {
> +            handleFatal("CommandLine is null");
> +        }
> +
> +        if (argName == null || "".equals(argName)) {
> +            if (log.isDebugEnabled()) {
> +                log.debug("Provided argument name is null. Returning null
> as value");
> +            }
> +            return null;
> +        }
> +
> +        if (cmd.hasOption(argName)) {
> +            return cmd.getOptionValue(argName);
> +        }
> +        return null;
> +    }
> +
> +    /*
> +     * Load synapse initialization parameters from servlet configuration
> +     */
> +    private static String loadParameter(ServletConfig servletConfig,
> String name,
> +                                        boolean required) {
> +
> +        if (System.getProperty(name) == null) {
> +
> +            String value = servletConfig.getInitParameter(name);
> +            log.debug("Init parameter '" + name + "' : " + value);
> +
> +            if ((value == null || value.trim().length() == 0) && required)
> {
> +                handleFatal("A valid system property or init parameter '"
> + name +
> +                        "' is required");
> +            } else {
> +                return value;
> +            }
> +        } else {
> +            return System.getProperty(name);
> +        }
> +        return null;
> +    }
> +
> +    private static void handleFatal(String msg) {
> +        log.fatal(msg);
> +        throw new SynapseException(msg);
> +    }
> +}
>
> Added:
> synapse/trunk/java/modules/core/src/main/java/org/apache/synapse/ServerContextInformation.java
> URL:
> http://svn.apache.org/viewvc/synapse/trunk/java/modules/core/src/main/java/org/apache/synapse/ServerContextInformation.java?rev=749210&view=auto
>
> ==============================================================================
> ---
> synapse/trunk/java/modules/core/src/main/java/org/apache/synapse/ServerContextInformation.java
> (added)
> +++
> synapse/trunk/java/modules/core/src/main/java/org/apache/synapse/ServerContextInformation.java
> Mon Mar  2 06:20:35 2009
> @@ -0,0 +1,51 @@
> +/*
> + *  Licensed to the Apache Software Foundation (ASF) under one
> + *  or more contributor license agreements.  See the NOTICE file
> + *  distributed with this work for additional information
> + *  regarding copyright ownership.  The ASF licenses this file
> + *  to you under the Apache License, Version 2.0 (the
> + *  "License"); you may not use this file except in compliance
> + *  with the License.  You may obtain a copy of the License at
> + *
> + *   http://www.apache.org/licenses/LICENSE-2.0
> + *
> + *  Unless required by applicable law or agreed to in writing,
> + *  software distributed under the License is distributed on an
> + *   * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
> + *  KIND, either express or implied.  See the License for the
> + *  specific language governing permissions and limitations
> + *  under the License.
> + */
> +package org.apache.synapse;
> +
> +import java.util.Map;
> +import java.util.HashMap;
> +
> +/**
> + * Encapsulates server context information
> + */
> +public class ServerContextInformation {
> +    /* Underlying server's context - EX : Axis2 ConfigurationConext */
> +    private Object serverContext;
> +    /* A map to hold any context information*/
> +    private final Map<String, Object> property = new HashMap<String,
> Object>();
> +
> +    public ServerContextInformation(Object serverContext) {
> +        this.serverContext = serverContext;
> +    }
> +
> +    public Object getServerContext() {
> +        return serverContext;
> +    }
> +    public void setServerContext(Object serverContext){
> +        this.serverContext = serverContext;
> +    }
> +
> +    public void addProperty(String key, Object value) {
> +        property.put(key, value);
> +    }
> +
> +    public Object getProperty(String key) {
> +        return property.get(key);
> +    }
> +}
>
> Modified:
> synapse/trunk/java/modules/core/src/main/java/org/apache/synapse/ServerManager.java
> URL:
> http://svn.apache.org/viewvc/synapse/trunk/java/modules/core/src/main/java/org/apache/synapse/ServerManager.java?rev=749210&r1=749209&r2=749210&view=diff
>
> ==============================================================================
> ---
> synapse/trunk/java/modules/core/src/main/java/org/apache/synapse/ServerManager.java
> (original)
> +++
> synapse/trunk/java/modules/core/src/main/java/org/apache/synapse/ServerManager.java
> Mon Mar  2 06:20:35 2009
> @@ -18,29 +18,15 @@
>  */
>  package org.apache.synapse;
>
> -import org.apache.axis2.context.ConfigurationContext;
> -import org.apache.axis2.context.ConfigurationContextFactory;
> -import org.apache.axis2.description.Parameter;
> -import org.apache.axis2.description.TransportInDescription;
> -import org.apache.axis2.description.AxisService;
> -import org.apache.axis2.description.AxisModule;
> -import org.apache.axis2.engine.ListenerManager;
>  import org.apache.commons.logging.Log;
>  import org.apache.commons.logging.LogFactory;
> -import org.apache.synapse.config.SynapseConfiguration;
> -import org.apache.synapse.core.SynapseEnvironment;
> -import org.apache.synapse.util.ClasspathURLStreamHandler;
> -
> -import java.io.File;
> -import java.net.*;
> -import java.util.Map;
>
>  /**
>  * This is the core class that starts up a Synapse instance.
> - *
> + * <p/>
>  * From the command line scripts synapse.sh and synapse-daemon.sh (though
> the wrapper.conf)
>  * the SynapseServer is invoked which inturn calls on this to start the
> instance
> - *
> + * <p/>
>  * When the WAR deployment is used, the SynapseStartUpServlet servlet calls
> on this class to
>  * initialize Synapse
>  */
> @@ -49,355 +35,138 @@
>
>     private static final Log log = LogFactory.getLog(ServerManager.class);
>
> -    /** The singleton server manager instance */
>     private final static ServerManager instance = new ServerManager();
>
> -    /** The Axis2 repository location */
> -    private String axis2Repolocation;
> -    /** The path to the axis2.xml file */
> -    private String axis2Xml;
> -    /** The synapse home is the home directory of the Synapse installation
> */
> -    private String synapseHome;
> -    /** The path to the synapse.xml file */
> -    private String synapseXMLPath;
> -    /** The root directory to resolve paths for registry, default to
> synapse.home/repository */
> -    private String resolveRoot;
> -    /** An optional server name to activate pinned services, tasks etc..
> and to differentiate instances on a cluster */
> -    private String serverName = "localhost";
> -
> -    /** The Axis2 listener Manager */
> -    private ListenerManager listenerManager;
> -    /** The Axis2 configuration context used by Synapse */
> -    private ConfigurationContext configctx;
> -    /** Reference to the Synapse configuration */
> -    private SynapseConfiguration synConfig = null;
> -    private Map callbackStore = null;
> +    /* The controller for synapse create and Destroy synapse artifacts in
> a particular environment*/
> +    private SynapseController synapseController;
> +    /* Server Configuration  */
> +    private ServerConfigurationInformation configurationInformation;
> +    /* Server context */
> +    private ServerContextInformation contextInformation;
> +    /* The state of the server - the state that marked at last operation
> on server */
> +    private ServerState serverState = ServerState.UNDETERMINED;
>
> -    /**
> -     * return the singleton server manager
> -     * @return  ServerManager Instance
> -     */
>     public static ServerManager getInstance() {
>         return instance;
>     }
>
>     /**
> -     * starting all the listeners
> +     * Initializes the server
> +     *
> +     * @param configurationInformation ServerConfigurationInformation
> instance
> +     * @param contextInformation       ServerContextInformation instance
> +     * @return ServerState - The state of the server after call this
> operation
>      */
> -    public void start() {
> -
> -        // validate if we can start
> -        validate();
> -
> -        // Register custom protocol handler classpath://
> -               try {
> -                       URL.setURLStreamHandlerFactory(new
> URLStreamHandlerFactoryImpl());
> -               } catch (Throwable t) {
> -                       log.debug("Unable to register a
> URLStreamHandlerFactory - " +
> -                                       "Custom URL protocols may not work
> properly (e.g. classpath://)");
> -               }
> -
> -        try {
> -            configctx = ConfigurationContextFactory.
> -
>  createConfigurationContextFromFileSystem(axis2Repolocation, axis2Xml);
> -
> -            listenerManager = configctx.getListenerManager();
> -            if (listenerManager == null) {
> -                listenerManager = new ListenerManager();
> -                listenerManager.init(configctx);
> -            }
> -
> -            for (Object o :
> configctx.getAxisConfiguration().getTransportsIn().keySet()) {
> -
> -                String trp = (String) o;
> -                TransportInDescription trsIn =
> -
>  configctx.getAxisConfiguration().getTransportsIn().get(trp);
> -
> -                String msg = "Starting transport " + trsIn.getName();
> -                if (trsIn.getParameter("port") != null) {
> -                    msg += " on port " +
> trsIn.getParameter("port").getValue();
> -                }
> -                log.info(msg);
> -
> -                listenerManager.addListener(trsIn, false);
> -            }
> -
> -            // now initialize SynapseConfig
> -            Parameter synEnv
> -                =
> configctx.getAxisConfiguration().getParameter(SynapseConstants.SYNAPSE_ENV);
> -            Parameter synCfg
> -                =
> configctx.getAxisConfiguration().getParameter(SynapseConstants.SYNAPSE_CONFIG);
> -
> -            String message = "Unable to initialize the Synapse
> Configuration : Cannot find the ";
> -            if (synCfg == null || synCfg.getValue() == null
> -                || !(synCfg.getValue() instanceof SynapseConfiguration)) {
> -                log.fatal(message + "Synapse Configuration");
> -                throw new SynapseException(message + "Synapse
> Configuration");
> -            } else {
> -                synConfig = (SynapseConfiguration) synCfg.getValue();
> -            }
> -
> -            if (synEnv == null || synEnv.getValue() == null
> -                || !(synEnv.getValue() instanceof SynapseEnvironment)) {
> -                log.fatal(message + "Synapse Environment");
> -                throw new SynapseException(message + "Synapse
> Environment");
> -            } else {
> -
> -                ((SynapseEnvironment)
> synEnv.getValue()).setInitialized(true);
> -
> -                // initialize the startups
> -                for (Startup stp : ((SynapseConfiguration)
> synCfg.getValue()).getStartups()) {
> -                    if (stp != null) {
> -                        stp.init((SynapseEnvironment) synEnv.getValue());
> -                    }
> -                }
> -            }
> -
> -            log.info("Ready for processing");
> -
> -        } catch (Throwable t) {
> -            log.fatal("Synapse startup failed...", t);
> -            throw new SynapseException("Synapse startup failed", t);
> -        }
> +    public ServerState init(ServerConfigurationInformation
> configurationInformation,
> +                            ServerContextInformation contextInformation) {
> +        this.configurationInformation = configurationInformation;
> +        this.contextInformation = contextInformation;
> +        this.synapseController = SynapseControllerFactory
> +                .createSynapseController(configurationInformation);
> +        doInit();
> +        return this.serverState;
>     }
>
>     /**
> -     * stop all the listeners
> +     * Starting up the server
> +     *
> +     * @return ServerState - The state of the server after call this
> operation
>      */
> -    public void stop() {
> -        try {
> -
> -            // stop all services
> -            if (configctx != null && configctx.getAxisConfiguration() !=
> null) {
> -                Map<String, AxisService> serviceMap =
> configctx.getAxisConfiguration().getServices();
> -                for (AxisService svc : serviceMap.values()) {
> -                    svc.setActive(false);
> -                }
> -
> -                // stop all modules
> -                Map<String, AxisModule> moduleMap =
> configctx.getAxisConfiguration().getModules();
> -                for (AxisModule mod : moduleMap.values()) {
> -                    if (mod.getModule() != null &&
> !"synapse".equals(mod.getName())) {
> -                        mod.getModule().shutdown(configctx);
> -                    }
> -                }
> -            }
> -
> -            // stop all transports
> -            if (listenerManager != null) {
> -                listenerManager.stop();
> -                listenerManager.destroy();
> -            }
> -
> -            // we need to call this method to clean the temp files we
> created.
> -            if (configctx != null) {
> -                configctx.terminate();
> -            }
> -        } catch (Exception e) {
> -            log.error("Error stopping the ServerManager", e);
> -        }
> +    public ServerState start() {
> +        doInit();
> +        doStart();
> +        return this.serverState;
>     }
>
>     /**
> -     * Expose the number of callbacks in the callback store
> -     * @return the number of callbacks (messages) waiting for responses
> +     * Stopping the server
> +     *
> +     * @return ServerState - The state of the server after call this
> operation
>      */
> -    public int pendingCallbacks() {
> -        if (callbackStore != null) {
> -            return callbackStore.size();
> -        } else {
> -            return 0;
> -        }
> -    }
> -
> -    private static final class URLStreamHandlerFactoryImpl implements
> URLStreamHandlerFactory {
> -
> -        public URLStreamHandler createURLStreamHandler(String protocol) {
> -
> -            if (protocol == null) {
> -                throw new IllegalArgumentException("'protocol' cannot be
> null");
> -            }
> -            URLStreamHandler urlSH = null;
> -            if (protocol.equals("classpath")) {
> -                urlSH = new ClasspathURLStreamHandler();
> -            }
> -            return urlSH;
> -        }
> +    public ServerState stop() {
> +        doStop();
> +        return this.serverState;
>     }
>
>     /**
> -     * Validate core settings for startup
> +     * Returns the ServerConfigurationInformation
> +     *
> +     * @return ServerConfigurationInformation insatnce
>      */
> -    private void validate() {
> -        if (synapseHome == null || !new File(synapseHome).exists()) {
> -            handleFatal("Synapse home");
> -        } else {
> -            log.info("Using Synapse home as : " + synapseHome);
> -        }
> -
> -        if (axis2Repolocation == null || !new
> File(axis2Repolocation).exists()) {
> -            handleFatal("Axis2 repository");
> -        } else {
> -            log.info("Using the Axis2 Repository : " + new
> File(axis2Repolocation).getAbsolutePath());
> -        }
> -
> -        if (axis2Xml == null || !new File(axis2Xml).exists()) {
> -            handleFatal("axis2.xml location");
> -        } else {
> -            log.info("Using the axis2.xml : " + new
> File(axis2Xml).getAbsolutePath());
> -        }
> -
> -        if (synapseXMLPath == null || !new File(synapseXMLPath).exists())
> {
> -            handleFatal("synapse.xml path");
> -        }
> -
> -        if (serverName == null) {
> -            try {
> -                serverName = InetAddress.getLocalHost().getHostName();
> -            } catch (UnknownHostException ignore) {}
> -            log.info("The server name was not specified, defaulting to :
> " + serverName);
> -        } else {
> -            log.info("Using server name : " + serverName);
> -        }
> -
> -        log.info("The timeout handler will run every : " +
> (getTimeoutHandlerInterval()/1000) + "s");
> -    }
> -
> -    public void handleFatal(String msgPre) {
> -        String msg = "The " + msgPre + " must be set as a system property
> or init-parameter";
> -        log.fatal(msg);
> -        throw new SynapseException(msg);
> -    }
> -
> -    // getters and setters
> -    public ConfigurationContext getConfigurationContext() {
> -        return configctx;
> +    public ServerConfigurationInformation getInformation() {
> +        return configurationInformation;
>     }
>
> -    public void setCallbackStore(Map callbackStore) {
> -        this.callbackStore = callbackStore;
> -    }
> -
> -    public void setAxis2Repolocation(String axis2Repolocation) {
> -        if (!new File(axis2Repolocation).isAbsolute() && synapseHome !=
> null) {
> -            this.axis2Repolocation = synapseHome + File.separator +
> axis2Repolocation;
> -        } else {
> -            this.axis2Repolocation = axis2Repolocation;
> -        }
> -    }
> -
> -    public void setAxis2Xml(String axis2Xml) {
> -        if (!new File(axis2Xml).isAbsolute() && synapseHome != null) {
> -            this.axis2Xml = synapseHome + File.separator + axis2Xml;
> -        } else {
> -            this.axis2Xml = axis2Xml;
> -        }
> +    /**
> +     * Retunrs the ServerContextInformation
> +     *
> +     * @return ServerContextInformation instance
> +     */
> +    public ServerContextInformation getContextInformation() {
> +        return contextInformation;
>     }
>
> -    public String getSynapseHome() {
> -        if (synapseHome != null) {
> -            return synapseHome;
> -        } else {
> -            return
> getParamValue(SynapseConstants.Axis2Param.SYNAPSE_HOME);
> -        }
> -    }
> +    /**
> +     * Helper method that to do init
> +     */
> +    private void doInit() {
>
> -    public void setSynapseHome(String synapseHome) {
> -        this.synapseHome = synapseHome;
> -    }
> +        this.serverState =
> ServerStateDetectionStrategy.currentState(serverState,
> +                configurationInformation);
>
> -    public String getResolveRoot() {
> -        if (resolveRoot != null) {
> -            return resolveRoot;
> -        } else {
> -            return
> getParamValue(SynapseConstants.Axis2Param.SYNAPSE_RESOLVE_ROOT);
> -        }
> -    }
> +        if (this.serverState == ServerState.INITIALIZABLE) {
> +
> +            this.synapseController.init(configurationInformation,
> contextInformation);
>
> -    public void setResolveRoot(String resolveRoot) {
> -        if (!new File(resolveRoot).isAbsolute() && synapseHome != null) {
> -            this.resolveRoot = synapseHome + File.separator + resolveRoot;
> -        } else {
> -            this.resolveRoot = resolveRoot;
> -        }
> -    }
> +            if (this.contextInformation == null) {
> +                this.contextInformation = new ServerContextInformation(
> +                        this.synapseController.getContext());
> +            } else if (this.contextInformation.getServerContext() == null)
> {
> +
>  this.contextInformation.setServerContext(this.synapseController.getContext());
> +            }
>
> -    public String getServerName() {
> -        if (serverName != null) {
> -            return serverName;
> -        } else {
> -            return
> getParamValue(SynapseConstants.Axis2Param.SYNAPSE_SERVER_NAME);
> +            this.serverState = ServerState.INITIALIZED;
>         }
>     }
>
> -    public void setServerName(String serverName) {
> -        this.serverName = serverName;
> -    }
> +    /**
> +     * Helper method that to do start
> +     */
> +    private void doStart() {
>
> -    public void setConfigurationContext(ConfigurationContext configctx) {
> -        this.configctx = configctx;
> -    }
> +        this.serverState =
> ServerStateDetectionStrategy.currentState(serverState,
> +                configurationInformation);
>
> -    public String getSynapseXMLPath() {
> -        if (synapseXMLPath != null) {
> -            return synapseXMLPath;
> -        } else {
> -            return
> getParamValue(SynapseConstants.Axis2Param.SYNAPSE_CONFIG_LOCATION);
> -        }
> -    }
> +        if (this.serverState == ServerState.INITIALIZED) {
>
> -    public void setSynapseXMLPath(String synapseXMLPath) {
> -        if (!new File(synapseXMLPath).isAbsolute() && synapseHome != null)
> {
> -            this.synapseXMLPath = synapseHome + File.separator +
> synapseXMLPath;
> -        } else {
> -            this.synapseXMLPath = synapseXMLPath;
> -        }
> -    }
> -
> -    public int getConnectTimeout() {
> -        if (synConfig == null) {
> -            return (int) SynapseConstants.DEFAULT_GLOBAL_TIMEOUT;
> -        } else {
> -            return (int) synConfig.getProperty(
> -                SynapseConstants.CONNECTTIMEOUT,
> SynapseConstants.DEFAULT_CONNECTTIMEOUT);
> -        }
> -    }
> -
> -    public int getReadTimeout() {
> -        if (synConfig == null) {
> -            return SynapseConstants.DEFAULT_READTIMEOUT;
> -        } else {
> -            return (int) synConfig.getProperty(
> -                SynapseConstants.READTIMEOUT,
> SynapseConstants.DEFAULT_READTIMEOUT);
> +            this.synapseController.createSynapseConfiguration();
> +            this.synapseController.createSynapseEnvironment();
> +            this.serverState = ServerState.STARTED;
> +            log.info("Ready for processing");
>         }
>     }
>
> -    public long getTimeoutHandlerInterval() {
> -        if (synConfig == null) {
> -            return SynapseConstants.DEFAULT_TIMEOUT_HANDLER_INTERVAL;
> -        } else {
> -            return synConfig.getProperty(
> -                SynapseConstants.TIMEOUT_HANDLER_INTERVAL,
> SynapseConstants.DEFAULT_TIMEOUT_HANDLER_INTERVAL);
> -        }
> -    }
> +    /**
> +     * Helper method that to do stop
> +     */
> +    private void doStop() {
>
> -    public long getGlobalTimeoutInterval() {
> -        if (synConfig == null) {
> -            return SynapseConstants.DEFAULT_GLOBAL_TIMEOUT;
> -        } else {
> -            return synConfig.getProperty(
> -                SynapseConstants.GLOBAL_TIMEOUT_INTERVAL,
> SynapseConstants.DEFAULT_GLOBAL_TIMEOUT);
> -        }
> -    }
> +        this.serverState =
> ServerStateDetectionStrategy.currentState(serverState,
> +                configurationInformation);
>
> -    private String getParamValue(String paramKey) {
> -        if (configctx != null) {
> -            Parameter synCfgParam =
> configctx.getAxisConfiguration().getParameter(paramKey);
> -            if (synCfgParam != null && synCfgParam.getValue() != null
> -                    && synCfgParam.getValue() instanceof String) {
> -                return synCfgParam.getValue().toString();
> +        switch (serverState) {
> +            case INITIALIZED: {
> +                this.synapseController.destroy();
> +                break;
> +            }
> +            case STARTED: {
> +                this.synapseController.destroySynapseConfiguration();
> +                this.synapseController.destroySynapseEnvironment();
> +                this.synapseController.destroy();
> +                break;
>             }
>         }
> -        return null;
> +        this.serverState = ServerState.STOPPED;
>     }
> -}
> \ No newline at end of file
> +}
> +
>
> Added:
> synapse/trunk/java/modules/core/src/main/java/org/apache/synapse/ServerState.java
> URL:
> http://svn.apache.org/viewvc/synapse/trunk/java/modules/core/src/main/java/org/apache/synapse/ServerState.java?rev=749210&view=auto
>
> ==============================================================================
> ---
> synapse/trunk/java/modules/core/src/main/java/org/apache/synapse/ServerState.java
> (added)
> +++
> synapse/trunk/java/modules/core/src/main/java/org/apache/synapse/ServerState.java
> Mon Mar  2 06:20:35 2009
> @@ -0,0 +1,31 @@
> +/*
> + *  Licensed to the Apache Software Foundation (ASF) under one
> + *  or more contributor license agreements.  See the NOTICE file
> + *  distributed with this work for additional information
> + *  regarding copyright ownership.  The ASF licenses this file
> + *  to you under the Apache License, Version 2.0 (the
> + *  "License"); you may not use this file except in compliance
> + *  with the License.  You may obtain a copy of the License at
> + *
> + *   http://www.apache.org/licenses/LICENSE-2.0
> + *
> + *  Unless required by applicable law or agreed to in writing,
> + *  software distributed under the License is distributed on an
> + *   * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
> + *  KIND, either express or implied.  See the License for the
> + *  specific language governing permissions and limitations
> + *  under the License.
> + */
> +package org.apache.synapse;
> +
> +/**
> + * Represents the server states
> + */
> +
> +public enum ServerState {
> +    UNDETERMINED,
> +    INITIALIZABLE,
> +    INITIALIZED,
> +    STARTED,
> +    STOPPED
> +}
>
> Added:
> synapse/trunk/java/modules/core/src/main/java/org/apache/synapse/ServerStateDetectionStrategy.java
> URL:
> http://svn.apache.org/viewvc/synapse/trunk/java/modules/core/src/main/java/org/apache/synapse/ServerStateDetectionStrategy.java?rev=749210&view=auto
>
> ==============================================================================
> ---
> synapse/trunk/java/modules/core/src/main/java/org/apache/synapse/ServerStateDetectionStrategy.java
> (added)
> +++
> synapse/trunk/java/modules/core/src/main/java/org/apache/synapse/ServerStateDetectionStrategy.java
> Mon Mar  2 06:20:35 2009
> @@ -0,0 +1,55 @@
> +/*
> + *  Licensed to the Apache Software Foundation (ASF) under one
> + *  or more contributor license agreements.  See the NOTICE file
> + *  distributed with this work for additional information
> + *  regarding copyright ownership.  The ASF licenses this file
> + *  to you under the Apache License, Version 2.0 (the
> + *  "License"); you may not use this file except in compliance
> + *  with the License.  You may obtain a copy of the License at
> + *
> + *   http://www.apache.org/licenses/LICENSE-2.0
> + *
> + *  Unless required by applicable law or agreed to in writing,
> + *  software distributed under the License is distributed on an
> + *   * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
> + *  KIND, either express or implied.  See the License for the
> + *  specific language governing permissions and limitations
> + *  under the License.
> + */
> +package org.apache.synapse;
> +
> +import org.apache.synapse.security.secret.SecretManager;
> +
> +/**
> + * Detects possible current server state
> + */
> +public class ServerStateDetectionStrategy {
> +
> +    private static final String PRODUCTION_MODE = "production";
> +
> +    /**
> +     * Determine the next possible server state based on current states
> and other facts
> +     *
> +     * @param previousState Previuos server state , a state where server
> was
> +     *                      there when last time check
> +     * @param information   ServerConfigurationInformation instance
> +     * @return The actual current state possible states for the server
> +     */
> +    public static ServerState currentState(ServerState previousState,
> +                                           ServerConfigurationInformation
> information) {
> +
> +        String deploymentMode = information.getDeploymentMode();
> +        if (previousState == ServerState.UNDETERMINED) {
> +
> +            if (deploymentMode != null &&
> PRODUCTION_MODE.equals(deploymentMode.trim())) {
> +                SecretManager secretManager = SecretManager.getInstance();
> +                if (secretManager.isInitialized()) {
> +                    return ServerState.INITIALIZABLE;
> +                }
> +            } else {
> +                return ServerState.INITIALIZABLE;
> +            }
> +        }
> +        return previousState;
> +    }
> +}
>
> Modified:
> synapse/trunk/java/modules/core/src/main/java/org/apache/synapse/SynapseConstants.java
> URL:
> http://svn.apache.org/viewvc/synapse/trunk/java/modules/core/src/main/java/org/apache/synapse/SynapseConstants.java?rev=749210&r1=749209&r2=749210&view=diff
>
> ==============================================================================
> ---
> synapse/trunk/java/modules/core/src/main/java/org/apache/synapse/SynapseConstants.java
> (original)
> +++
> synapse/trunk/java/modules/core/src/main/java/org/apache/synapse/SynapseConstants.java
> Mon Mar  2 06:20:35 2009
> @@ -276,6 +276,9 @@
>     /** Root for relative path */
>     public static final String RESOLVE_ROOT = "resolve.root";
>
> +    /* The deployment mode */
> +    public static final String DEPLOYMENT_MODE = "deployment.mode";
> +
>     /* URL connection read timeout and connection timeout */
>
>     public static final int DEFAULT_READTIMEOUT = 100000;
>
> Added:
> synapse/trunk/java/modules/core/src/main/java/org/apache/synapse/SynapseController.java
> URL:
> http://svn.apache.org/viewvc/synapse/trunk/java/modules/core/src/main/java/org/apache/synapse/SynapseController.java?rev=749210&view=auto
>
> ==============================================================================
> ---
> synapse/trunk/java/modules/core/src/main/java/org/apache/synapse/SynapseController.java
> (added)
> +++
> synapse/trunk/java/modules/core/src/main/java/org/apache/synapse/SynapseController.java
> Mon Mar  2 06:20:35 2009
> @@ -0,0 +1,82 @@
> +/*
> + *  Licensed to the Apache Software Foundation (ASF) under one
> + *  or more contributor license agreements.  See the NOTICE file
> + *  distributed with this work for additional information
> + *  regarding copyright ownership.  The ASF licenses this file
> + *  to you under the Apache License, Version 2.0 (the
> + *  "License"); you may not use this file except in compliance
> + *  with the License.  You may obtain a copy of the License at
> + *
> + *   http://www.apache.org/licenses/LICENSE-2.0
> + *
> + *  Unless required by applicable law or agreed to in writing,
> + *  software distributed under the License is distributed on an
> + *   * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
> + *  KIND, either express or implied.  See the License for the
> + *  specific language governing permissions and limitations
> + *  under the License.
> + */
> +package org.apache.synapse;
> +
> +import org.apache.synapse.config.SynapseConfiguration;
> +import org.apache.synapse.core.SynapseEnvironment;
> +
> +/**
> + * The controller for synapse
> + * Create and Destroy synapse artifacts in a particular environment
> + */
> +public interface SynapseController {
> +
> +    /**
> +     * Initialization of the synapse controller
> +     *
> +     * @param configurationInformation server information instance
> Information about the server
> +     * @param contextInformation    if there is a context already has been
> built.
> +     */
> +    public void init(ServerConfigurationInformation
> configurationInformation,
> +                     ServerContextInformation contextInformation);
> +
> +    /**
> +     * Destroy event for destroy synapse
> +     */
> +    public void destroy();
> +
> +    /**
> +     * Explicit check for initialization
> +     *
> +     * @return true if the initialization has been success.
> +     */
> +    public boolean isInitialized();
> +
> +    /**
> +     * Create the SynapseEnvironment instance
> +     *
> +     * @return SynapseEnvironment instance if success
> +     */
> +    public SynapseEnvironment createSynapseEnvironment();
> +
> +    /**
> +     * Destroy the SynapseEnvironment instance
> +     */
> +    public void destroySynapseEnvironment();
> +
> +    /**
> +     * Create the synapse configuration instance
> +     *
> +     * @return SynapseConfiguration instance if success
> +     */
> +    public SynapseConfiguration createSynapseConfiguration();
> +
> +    /**
> +     * Destroy the SynapseConfiguration instance
> +     */
> +    public void destroySynapseConfiguration();
> +
> +    /**
> +     * Returns underlying environment context
> +     *
> +     * @return Underlying environment context
> +     */
> +    public Object getContext();
> +
> +}
>
> Added:
> synapse/trunk/java/modules/core/src/main/java/org/apache/synapse/SynapseControllerFactory.java
> URL:
> http://svn.apache.org/viewvc/synapse/trunk/java/modules/core/src/main/java/org/apache/synapse/SynapseControllerFactory.java?rev=749210&view=auto
>
> ==============================================================================
> ---
> synapse/trunk/java/modules/core/src/main/java/org/apache/synapse/SynapseControllerFactory.java
> (added)
> +++
> synapse/trunk/java/modules/core/src/main/java/org/apache/synapse/SynapseControllerFactory.java
> Mon Mar  2 06:20:35 2009
> @@ -0,0 +1,124 @@
> +/*
> + *  Licensed to the Apache Software Foundation (ASF) under one
> + *  or more contributor license agreements.  See the NOTICE file
> + *  distributed with this work for additional information
> + *  regarding copyright ownership.  The ASF licenses this file
> + *  to you under the Apache License, Version 2.0 (the
> + *  "License"); you may not use this file except in compliance
> + *  with the License.  You may obtain a copy of the License at
> + *
> + *   http://www.apache.org/licenses/LICENSE-2.0
> + *
> + *  Unless required by applicable law or agreed to in writing,
> + *  software distributed under the License is distributed on an
> + *   * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
> + *  KIND, either express or implied.  See the License for the
> + *  specific language governing permissions and limitations
> + *  under the License.
> + */
> +package org.apache.synapse;
> +
> +import org.apache.commons.logging.Log;
> +import org.apache.commons.logging.LogFactory;
> +import org.apache.synapse.config.SynapseConfigUtils;
> +
> +import java.io.File;
> +import java.net.InetAddress;
> +import java.net.UnknownHostException;
> +
> +/**
> + * Factory method for create a  SynapseController instance
> + */
> +public class SynapseControllerFactory {
> +
> +    private static final Log log =
> LogFactory.getLog(SynapseControllerFactory.class);
> +
> +    /**
> +     * Create a SynapseController instance based on information in the
> ServerConfigurationInformation
> +     *
> +     * @param information ServerConfigurationInformation instance
> +     * @return SynapseController instance
> +     */
> +    public static SynapseController createSynapseController(
> +            ServerConfigurationInformation information) {
> +        validate(information);
> +        return loadSynapseController(information);
> +    }
> +
> +    private static SynapseController loadSynapseController(
> +            ServerConfigurationInformation information) {
> +        String provider = information.getServerControllerProvider();
> +        try {
> +
> +            Class aClass =
> SynapseControllerFactory.class.getClassLoader().loadClass(provider);
> +            Object instance = aClass.newInstance();
> +
> +            if (instance != null && instance instanceof SynapseController)
> {
> +                return (SynapseController) instance;
> +            } else {
> +                handleFatal("Invalid class as SecretRepositoryProvider :
> Class Name : " + provider);
> +            }
> +
> +        } catch (ClassNotFoundException e) {
> +            handleFatal("A Secret Provider cannot be found for class name
> : " + provider);
> +        } catch (IllegalAccessException e) {
> +            handleFatal("Error creating a instance from class : " +
> provider);
> +        } catch (InstantiationException e) {
> +            handleFatal("Error creating a instance from class : " +
> provider);
> +        }
> +        return null;
> +    }
> +
> +    private static void handleFatal(String msgPre) {
> +        String msg = "The " + msgPre + " must be set as a system property
> or init-parameter";
> +        log.fatal(msg);
> +        throw new SynapseException(msg);
> +    }
> +
> +    private static void validate(ServerConfigurationInformation
> information) {
> +
> +        String synapseHome = information.getSynapseHome();
> +        if (synapseHome == null || !new File(synapseHome).exists()) {
> +            handleFatal("Synapse home");
> +        } else {
> +            log.info("Using Synapse home as : " + synapseHome);
> +        }
> +
> +        if (information.isCreateNewInstance()) {
> +            String axis2Repolocation = information.getAxis2RepoLocation();
> +            if (axis2Repolocation == null || !new
> File(axis2Repolocation).exists()) {
> +                handleFatal("Axis2 repository");
> +            } else {
> +                log.info("Using the Axis2 Repository : " +
> +                        new File(axis2Repolocation).getAbsolutePath());
> +            }
> +
> +            String axis2Xml = information.getAxis2Xml();
> +            if (axis2Xml == null || !new File(axis2Xml).exists()) {
> +                handleFatal("axis2.xml location");
> +            } else {
> +                log.info("Using the axis2.xml : " + new
> File(axis2Xml).getAbsolutePath());
> +            }
> +        }
> +
> +        String synapseXMLPath = information.getSynapseXMLLocation();
> +        if (synapseXMLPath == null || !new File(synapseXMLPath).exists())
> {
> +            handleFatal("synapse.xml path");
> +        }
> +
> +        String serverName = information.getServerName();
> +        if (serverName == null) {
> +            try {
> +                serverName = InetAddress.getLocalHost().getHostName();
> +            } catch (UnknownHostException ignore) {
> +            }
> +            log.info("The server name was not specified, defaulting to :
> " + serverName);
> +        } else {
> +            log.info("Using server name : " + serverName);
> +        }
> +
> +        log.info("The timeout handler will run every : " +
> +                (SynapseConfigUtils.getTimeoutHandlerInterval() / 1000) +
> "s");
> +    }
> +
> +}
>
> Modified:
> synapse/trunk/java/modules/core/src/main/java/org/apache/synapse/SynapseServer.java
> URL:
> http://svn.apache.org/viewvc/synapse/trunk/java/modules/core/src/main/java/org/apache/synapse/SynapseServer.java?rev=749210&r1=749209&r2=749210&view=diff
>
> ==============================================================================
> ---
> synapse/trunk/java/modules/core/src/main/java/org/apache/synapse/SynapseServer.java
> (original)
> +++
> synapse/trunk/java/modules/core/src/main/java/org/apache/synapse/SynapseServer.java
> Mon Mar  2 06:20:35 2009
> @@ -19,11 +19,9 @@
>
>  package org.apache.synapse;
>
> -import org.apache.axis2.Constants;
>  import org.apache.commons.logging.Log;
>  import org.apache.commons.logging.LogFactory;
>
> -import java.io.File;
>  import java.util.concurrent.CountDownLatch;
>
>  /**
> @@ -38,8 +36,9 @@
>     private static final Log log = LogFactory.getLog(SynapseServer.class);
>
>     private static final String USAGE_TXT =
> -        "Usage: SynapseServer <axis2_repository> <axis2_xml>
> <synapse_home> <synapse_xml> <resolve_root>" +
> -        "\n Opts: -? this message";
> +            "Usage: SynapseServer <axis2_repository> <axis2_xml>
> <synapse_home> <synapse_xml> " +
> +                    "<resolve_root> <deployment mode>" +
> +                    "\n Opts: -? this message";
>
>     public static void printUsage() {
>         System.out.println(USAGE_TXT);
> @@ -49,36 +48,15 @@
>     public static void main(String[] args) throws Exception {
>
>         // first check if we should print usage
> -        if (args.length != 1 && args.length != 4 && args.length != 5 &&
> args.length != 6) {
> +        if (args.length != 1 && args.length != 4 && args.length != 5 &&
> args.length != 6
> +                && args.length != 6 && args.length != 7) {
>             printUsage();
>         }
>
> +        ServerConfigurationInformation configurationInformation =
> +
>  ServerConfigurationInformationFactory.createServerConfigurationInformation(args);
>         ServerManager serverManager = ServerManager.getInstance();
> -        serverManager.setAxis2Repolocation(args[0]);
> -        if (args.length == 1) {
> -            log.warn("Configuring server manager using deprecated system
> properties; please update your configuration");
> -
>  serverManager.setAxis2Xml(System.getProperty(Constants.AXIS2_CONF));
> -
>  serverManager.setSynapseHome(System.getProperty(SynapseConstants.SYNAPSE_HOME));
> -
>  serverManager.setSynapseXMLPath(System.getProperty(SynapseConstants.SYNAPSE_XML));
> -
>  serverManager.setResolveRoot(System.getProperty(SynapseConstants.RESOLVE_ROOT));
> -        } else if(args.length == 4) {
> -            serverManager.setAxis2Xml(args[1]);
> -            serverManager.setSynapseHome(args[2]);
> -            serverManager.setSynapseXMLPath(args[3]);
> -            serverManager.setResolveRoot(args[2] + File.separator +
> "repository");
> -        } else if(args.length == 5) {
> -            serverManager.setAxis2Xml(args[1]);
> -            serverManager.setSynapseHome(args[2]);
> -            serverManager.setSynapseXMLPath(args[3]);
> -            serverManager.setResolveRoot(args[4]);
> -        } else if(args.length == 6) {
> -            serverManager.setAxis2Xml(args[1]);
> -            serverManager.setSynapseHome(args[2]);
> -            serverManager.setSynapseXMLPath(args[3]);
> -            serverManager.setResolveRoot(args[4]);
> -            serverManager.setServerName(args[5]);
> -        }
> -
> +        serverManager.init(configurationInformation, null);
>         serverManager.start();
>         addShutdownHook();
>
>
> Modified:
> synapse/trunk/java/modules/core/src/main/java/org/apache/synapse/config/SynapseConfigUtils.java
> URL:
> http://svn.apache.org/viewvc/synapse/trunk/java/modules/core/src/main/java/org/apache/synapse/config/SynapseConfigUtils.java?rev=749210&r1=749209&r2=749210&view=diff
>
> ==============================================================================
> ---
> synapse/trunk/java/modules/core/src/main/java/org/apache/synapse/config/SynapseConfigUtils.java
> (original)
> +++
> synapse/trunk/java/modules/core/src/main/java/org/apache/synapse/config/SynapseConfigUtils.java
> Mon Mar  2 06:20:35 2009
> @@ -26,6 +26,8 @@
>  import org.apache.commons.logging.LogFactory;
>  import org.apache.synapse.SynapseException;
>  import org.apache.synapse.ServerManager;
> +import org.apache.synapse.SynapseConstants;
> +import org.apache.synapse.ServerConfigurationInformation;
>  import org.apache.synapse.security.definition.KeyStoreInformation;
>  import org.apache.synapse.security.definition.IdentityKeyStoreInformation;
>  import org.apache.synapse.security.definition.TrustKeyStoreInformation;
> @@ -145,7 +147,7 @@
>                         log.debug("Can not open a connection to the URL
> with a path :" +
>                                 path);
>                     }
> -                    String synapseHome =
> ServerManager.getInstance().getSynapseHome();
> +                    String synapseHome = getSynapseHome();
>                     if (synapseHome != null) {
>                         if (log.isDebugEnabled()) {
>                             log.debug("Trying  to resolve an absolute path
> of the " +
> @@ -319,14 +321,6 @@
>         return null;
>     }
>
> -    private static int getReadTimeout() {
> -        return ServerManager.getInstance().getReadTimeout();
> -    }
> -
> -    private static int getConnectionTimeout() {
> -        return ServerManager.getInstance().getConnectTimeout();
> -    }
> -
>     private static void handleException(String msg, Exception e) {
>         log.warn(msg, e);
>         throw new SynapseException(msg, e);
> @@ -467,7 +461,7 @@
>                 connection = url.openConnection();
>             }
>             connection.setReadTimeout(getReadTimeout());
> -            connection.setConnectTimeout(getConnectionTimeout());
> +            connection.setConnectTimeout(getConnectTimeout());
>             connection.setRequestProperty("Connection", "close"); // if
> http is being used
>             return connection;
>         } catch (IOException e) {
> @@ -518,7 +512,7 @@
>                         log.debug("Can not open a connection to the URL
> with a path :" +
>                                 path);
>                     }
> -                    String synapseHome =
> ServerManager.getInstance().getSynapseHome();
> +                    String synapseHome = getSynapseHome();
>                     if (synapseHome != null) {
>                         if (synapseHome.endsWith("/")) {
>                             synapseHome = synapseHome.substring(0,
> synapseHome.lastIndexOf("/"));
> @@ -610,6 +604,61 @@
>         return null;
>     }
>
> +    public static int getConnectTimeout() {
> +        return Integer.parseInt(SynapsePropertiesLoader.getPropertyValue(
> +                SynapseConstants.CONNECTTIMEOUT,
> +                String.valueOf(SynapseConstants.DEFAULT_CONNECTTIMEOUT)));
> +
> +    }
> +
> +    public static int getReadTimeout() {
> +        return Integer.parseInt(SynapsePropertiesLoader.getPropertyValue(
> +                SynapseConstants.READTIMEOUT,
> +                String.valueOf(SynapseConstants.DEFAULT_READTIMEOUT)));
> +
> +    }
> +
> +    public static long getTimeoutHandlerInterval() {
> +        return Long.parseLong(SynapsePropertiesLoader.getPropertyValue(
> +                SynapseConstants.TIMEOUT_HANDLER_INTERVAL,
> +
>  String.valueOf(SynapseConstants.DEFAULT_TIMEOUT_HANDLER_INTERVAL)));
> +
> +    }
> +
> +    public static long getGlobalTimeoutInterval() {
> +        return Long.parseLong(SynapsePropertiesLoader.getPropertyValue(
> +                SynapseConstants.GLOBAL_TIMEOUT_INTERVAL,
> +                String.valueOf(SynapseConstants.DEFAULT_GLOBAL_TIMEOUT)));
> +
> +    }
> +
> +    public static String getSynapseHome() {
> +        ServerConfigurationInformation information =
> +                ServerManager.getInstance().getInformation();
> +        if (information != null) {
> +            return information.getSynapseHome();
> +        }
> +        return "";
> +    }
> +
> +    public static String getServerName() {
> +        ServerConfigurationInformation information =
> +                ServerManager.getInstance().getInformation();
> +        if (information != null) {
> +            return information.getServerName();
> +        }
> +        return "";
> +    }
> +
> +    public static String getResolveRoot() {
> +        ServerConfigurationInformation information =
> +                ServerManager.getInstance().getInformation();
> +        if (information != null) {
> +            return information.getResolveRoot();
> +        }
> +        return "";
> +    }
> +
>     public static OMElement stringToOM(String xml) {
>         try {
>             return AXIOMUtil.stringToOM(xml);  // Just wrapp to add loging
> for any errors
>
> Modified:
> synapse/trunk/java/modules/core/src/main/java/org/apache/synapse/config/SynapseConfiguration.java
> URL:
> http://svn.apache.org/viewvc/synapse/trunk/java/modules/core/src/main/java/org/apache/synapse/config/SynapseConfiguration.java?rev=749210&r1=749209&r2=749210&view=diff
>
> ==============================================================================
> ---
> synapse/trunk/java/modules/core/src/main/java/org/apache/synapse/config/SynapseConfiguration.java
> (original)
> +++
> synapse/trunk/java/modules/core/src/main/java/org/apache/synapse/config/SynapseConfiguration.java
> Mon Mar  2 06:20:35 2009
> @@ -20,7 +20,6 @@
>  package org.apache.synapse.config;
>
>  import org.apache.axis2.AxisFault;
> -import org.apache.axis2.context.ConfigurationContext;
>  import org.apache.axis2.engine.AxisConfiguration;
>  import org.apache.commons.logging.Log;
>  import org.apache.commons.logging.LogFactory;
> @@ -40,8 +39,6 @@
>  import org.apache.synapse.endpoints.Endpoint;
>  import org.apache.synapse.endpoints.dispatch.SALSessions;
>  import org.apache.synapse.mediators.base.SequenceMediator;
> -import org.apache.synapse.mediators.ListMediator;
> -import org.apache.synapse.mediators.AbstractMediator;
>  import org.apache.synapse.registry.Registry;
>  import org.apache.axiom.om.OMNode;
>
> @@ -927,60 +924,19 @@
>         }
>
>         // initialize managed mediators
> -        for (SequenceMediator seq : getDefinedSequences().values()) {
> +        for (ManagedLifecycle seq : getDefinedSequences().values()) {
>             if (seq != null) {
>                 seq.init(se);
>             }
>         }
> -    }
> -
> -    public void init(ConfigurationContext cc) {
> -
> -        if (log.isDebugEnabled()) {
> -            log.debug("Initializing the Synapse Configuration using the
> ConfigurationContext");
> -        }
> -
> -        // Initialize endpoints
> -        for (Endpoint e : getDefinedEndpoints().values()) {
> -            initEndpoint(e, cc);
> -        }
> -
> -        for (SequenceMediator s : getDefinedSequences().values()) {
> -            initEndpointsOfChildren(s, cc);
> -        }
> -
> -        for (ProxyService p : getProxyServices()) {
> -            if (p.getTargetInLineEndpoint() != null) {
> -                initEndpoint(p.getTargetInLineEndpoint(), cc);
> -            }
> -
> -            if (p.getTargetInLineInSequence() != null) {
> -                initEndpointsOfChildren(p.getTargetInLineInSequence(),
> cc);
> -            }
> -
> -            if (p.getTargetInLineOutSequence() != null) {
> -                initEndpointsOfChildren(p.getTargetInLineOutSequence(),
> cc);
> -            }
> -
> -            if (p.getTargetInLineFaultSequence() != null) {
> -                initEndpointsOfChildren(p.getTargetInLineFaultSequence(),
> cc);
> +        // initialize the startups
> +        for (Startup stp : getStartups()) {
> +            if (stp != null) {
> +                stp.init(se);
>             }
>         }
>     }
>
> -    private void initEndpointsOfChildren(ListMediator s,
> ConfigurationContext cc) {
> -        for (Mediator m : s.getList()) {
> -            if (m instanceof AbstractMediator) {
> -                ((AbstractMediator)m).init(cc);
> -            }
> -        }
> -    }
> -
> -    private void initEndpoint(Endpoint e, ConfigurationContext cc) {
> -        e.init(cc);
> -    }
> -
> -
>     private void handleException(String msg) {
>                log.error(msg);
>                throw new SynapseException(msg);
>
>
>


-- 
Ruwan Linton
http://wso2.org - "Oxygenating the Web Services Platform"
http://ruwansblog.blogspot.com/

Mime
View raw message