Package org.apache.ws.resource.handler.axis

Source Code of org.apache.ws.resource.handler.axis.ContainerConfig

/*=============================================================================*
*  Copyright 2004 The Apache Software Foundation
*
*  Licensed 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.ws.resource.handler.axis;

import org.apache.axis.AxisEngine;
import org.apache.axis.EngineConfiguration;
import org.apache.axis.MessageContext;
import org.apache.axis.WSDDEngineConfiguration;
import org.apache.axis.client.AxisClient;
import org.apache.axis.configuration.FileProvider;
import org.apache.axis.deployment.wsdd.WSDDDeployment;
import org.apache.axis.deployment.wsdd.WSDDGlobalConfiguration;
import org.apache.axis.server.AxisServer;
import org.apache.ws.resource.i18n.Keys;
import org.apache.ws.resource.i18n.MessagesImpl;
import org.apache.ws.util.i18n.Messages;

import java.io.IOException;
import java.net.URL;
import java.util.Hashtable;

/**
* This class makes global container configuration variables available to the application.
*/
public class ContainerConfig
{
   public static final Messages MSG = MessagesImpl.getInstance();
   /**
    * DOCUMENT_ME
    */
   public static final String WSRF_LOCATION = "wsrfLocation";

   /**
    * DOCUMENT_ME
    */
   public static final String CONTAINER_HANDLERS = "containerHandlers";

   /**
    * DOCUMENT_ME
    */
   public static final String CONTAINER_THREADS = "containerThreads";

   /**
    * DOCUMENT_ME
    */
   public static final String CONTAINER_THREADS_MAX = "containerThreadsMax";

   /**
    * DOCUMENT_ME
    */
   public static final String CONTAINER_THREADS_WATERMARK = "containerThreadsHighWaterMark";

   /**
    * DOCUMENT_ME
    */
   public static final String THREAD_REAP_INTERVAL = "containerThreadsReapInterval";

   /**
    * DOCUMENT_ME
    */
   public static final String LOGICAL_HOST = "logicalHost";

   /**
    * DOCUMENT_ME
    */
   public static final String PUBLISH_HOST_NAME = "publishHostName";

   /**
    * DOCUMENT_ME
    */
   public static final String DOMAIN_NAME = "domainName";

   /**
    * DOCUMENT_ME
    */
   public static final String DISABLE_DNS = "disableDNS";

   /**
    * DOCUMENT_ME
    */
   public static final String WSRF_HOST = "wsrfHost";

   /**
    * DOCUMENT_ME
    */
   public static final String WEB_CONTEXT = "webContext";

   /**
    * Config property used to specify external web root location published in wsdl files.
    */
   public static final String EXTERNAL_WEB_ROOT = "webroot.external";

   private static final String CONTAINER_SYSPROP_BASE = "org.apache.ws.container";

   /**
    * System property used to specify external web root location published in wsdl files.
    */
   public static final String EXTERNAL_WEB_ROOT_PROPERTY = CONTAINER_SYSPROP_BASE + "." + EXTERNAL_WEB_ROOT;

   /**
    * Config property used to specify internal web root location.
    */
   public static final String INTERNAL_WEB_ROOT = "webroot.internal";

   /**
    * System property used to specify internal web root location.
    */
   public static final String INTERNAL_WEB_ROOT_PROPERTY = CONTAINER_SYSPROP_BASE + "." + INTERNAL_WEB_ROOT;

   /**
    * Enables WebStart support in standalone container. Must be set to <code>enable</code> to enable the support.
    * <i>Standalone container only.</i>
    */
   public static final String WEB_START_PROPERTY = CONTAINER_SYSPROP_BASE + ".webstart";

   /**
    * DOCUMENT_ME
    */
   public static final String CONFIG_PROFILE   = "config.profile";
   private static AxisEngine  s_axisClientEngine = null;

   // XXX: this is not cleared - maybe use SoftReferences?
   private static Hashtable s_serverEngines = new Hashtable(  );

   /**
    * DOCUMENT_ME
    */
   public static final String     DEFAULT_SERVER_CONFIG = "server-config.wsdd";
   private static final String DEFAULT_SERVICES_BASE_URL_PATH = "wsrf/services/";

   private AxisEngine              m_engine;
   private static ContainerConfig  s_config;
   private WSDDGlobalConfiguration m_globalConfig;

   /**
    * Creates a new {@link ContainerConfig} object.
    *
    * @param engine DOCUMENT_ME
    */
   protected ContainerConfig( AxisEngine engine )
   {
      if ( engine == null )
      {
         throw new IllegalArgumentException(  );
      }

      EngineConfiguration config = engine.getConfig(  );
      if ( !( config instanceof WSDDEngineConfiguration ) )
      {
         throw new IllegalArgumentException( MSG.getMessage(Keys.EXCEPTION_EXPECTED_TYPE,WSDDEngineConfiguration.class.getName(  ),config.getClass().getName() ));
      }

      WSDDDeployment deployment = ( (WSDDEngineConfiguration) config ).getDeployment(  );

      m_globalConfig    = deployment.getGlobalConfiguration(  );
      m_engine          = engine;
   }

   /**
    * Get the default Axis client engine.
    */
   public static synchronized AxisEngine getClientEngine(  )
   {
      if ( s_axisClientEngine == null )
      {
         s_axisClientEngine = new AxisClient(  );
      }

      return s_axisClientEngine;
   }

   /**
    * Gets a default <code>ContainerConfig</code> instance initialized with a default AxisServer engine.
    */
   public static synchronized ContainerConfig getConfig(  )
   {
      if ( s_config == null )
      {
         s_config = new ContainerConfig( getEngine(  ) );
      }

      return s_config;
   }

   /**
    * DOCUMENT_ME
    *
    * @param engine DOCUMENT_ME
    *
    * @return DOCUMENT_ME
    */
   public static ContainerConfig getConfig( AxisEngine engine )
   {
      return new ContainerConfig( engine );
   }

   /**
    * Gets MessageContext associated with the current thread. If MessageContext is not associated with the current
    * thread a new one is created, initialized with client AxisEngine.
    */
   public static MessageContext getContext(  )
   {
      MessageContext ctx = MessageContext.getCurrentContext(  );
      if ( ctx == null )
      {
         ctx = new MessageContext( getClientEngine(  ) );
         ctx.setEncodingStyle( "" );
         ctx.setProperty( AxisClient.PROP_DOMULTIREFS, Boolean.FALSE );
      }

      return ctx;
   }

   /**
    * Get the default Axis server engine.
    */
   public static AxisServer getEngine(  )
   {
      return getServerEngine( null );
   }

   /**
    * Returns external web root location. The external web root location the published and virtual base location from
    * which schema files, etc. are resolved from. The wsdl import location attribute value (if it is a file) in the
    * service wsdl will be prepended with this location.
    */
   public static String getExternalWebRoot( MessageContext ctx )
   throws IOException
   {
      String webRoot = System.getProperty( EXTERNAL_WEB_ROOT_PROPERTY );
      if ( webRoot == null )
      {
         ContainerConfig config = new ContainerConfig( ctx.getAxisEngine(  ) );
         webRoot = config.getOption( EXTERNAL_WEB_ROOT );
         if ( webRoot == null )
         {
            String webContext = config.getOption( WEB_CONTEXT );
            if ( webContext == null )
            {
               webContext = "/";
            }
            else
            {
               webContext = "/" + webContext + "/";
            }

            URL webRootUrl =
               new URL( ServiceHost.getProtocol( ctx ),
                        ServiceHost.getHost( ctx ),
                        ServiceHost.getPort( ctx ), webContext );
            webRoot = webRootUrl.toExternalForm(  );
         }
      }

      return webRoot;
   }

   /**
    * DOCUMENT_ME
    *
    * @return DOCUMENT_ME
    */
   public static String getGlobusLocation(  )
   {
      String value = System.getProperty( "GLOBUS_LOCATION" );
      return ( value == null ) ? "." : value;
   }

   /**
    * Returns internal web root location. The internal web root location is a path to a directory on a file system.
    * Schema files, etc. are loaded from this location.
    */
   public String getInternalWebRoot(  )
   {
      String webRoot = System.getProperty( INTERNAL_WEB_ROOT_PROPERTY );
      if ( webRoot == null )
      {
         webRoot = getOption( INTERNAL_WEB_ROOT );
         if ( webRoot == null )
         {
            webRoot = getGlobusLocation(  );
         }
      }

      return webRoot;
   }

   /**
    * DOCUMENT_ME
    *
    * @param name  DOCUMENT_ME
    * @param value DOCUMENT_ME
    */
   public void setOption( String name,
                          String value )
   {
      this.m_globalConfig.setParameter( name, value );
   }

   /**
    * DOCUMENT_ME
    *
    * @param name DOCUMENT_ME
    *
    * @return DOCUMENT_ME
    */
   public String getOption( String name )
   {
      return this.m_globalConfig.getParameter( name );
   }

   /**
    * DOCUMENT_ME
    *
    * @param name         DOCUMENT_ME
    * @param defaultValue DOCUMENT_ME
    *
    * @return DOCUMENT_ME
    */
   public String getOption( String name,
                            String defaultValue )
   {
      String value = this.m_globalConfig.getParameter( name );
      return ( value != null ) ? value : defaultValue;
   }

   /**
    * DOCUMENT_ME
    *
    * @param config DOCUMENT_ME
    *
    * @return DOCUMENT_ME
    */
   public static synchronized AxisServer getServerEngine( String config )
   {
      config = ( config == null ) ? DEFAULT_SERVER_CONFIG : config;
      AxisServer engine = (AxisServer) s_serverEngines.get( config );
      if ( engine == null )
      {
         engine = new AxisServer( new FileProvider( config ) );
         s_serverEngines.put( config, engine );
      }

      return engine;
   }

   /**
    * DOCUMENT_ME
    *
    * @return DOCUMENT_ME
    */
   public String getServicesBaseUrlPath(  )
   {
      return getOption( ContainerConfig.WSRF_LOCATION, DEFAULT_SERVICES_BASE_URL_PATH );
   }
}
TOP

Related Classes of org.apache.ws.resource.handler.axis.ContainerConfig

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