You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@avalon.apache.org by Johan Sjöberg <jo...@avaintec.com> on 2003/06/06 16:54:25 UTC

[sevak-patch] Jetty configuration

Hi!

I have played a little with Jetty's configuration in Sevak and I have a 
first test patch that should make it possible to use Jetty's own 
configuration format. The idea is not mine, it came from posts by Leo 
Sutic and Peter Royal on avalon-users.

ATM the configuration can either be an external file or directly 
included in Jetty-Sevak's block configuration. If Jetty's conf is 
included in the block configuration and have nested elements it must be 
wrapped within a CDATA element. There might be some better way to do 
that but I haven't looked into it yet.

Note that this is only a test I made and many decisions about how to do 
things should be discussed first. There is also still much to do on the 
deployment of Sevak managed web applications, how to configure etc. But 
this could be a start...

If someone is interested, have a look at the patches. There is only one 
patch file in the attachment as my cvs didn't work and I had to create 
it with a GUI tool. Yack! I added a .cvsignore too.

Cheers,

//
Johan


Re: [sevak-patch] Jetty configuration

Posted by Johan Sjöberg <jo...@avaintec.com>.

Peter Royal wrote:
> 
> My only concern is the added use of System.setProperties().. In what 
> circumstances would that be needed? Can it be safely removed?

Yes, I used that to play with system properties that Jetty looks for 
(jetty.home). I agree that it can be evil to have a possibility to set 
system properties in a conf file. If we want to use Jetty's 
configuration without changes I think jetty.home must be set, but that 
can be done with only one hard coded property.

Anyway, before applying those patches there are some things to address.

1) The jetty block is now very close to a normal Jetty distribution, it 
mounts jetty's (minimal) root app under /, has a webapps directory for 
auto publishing web applications and it includes all jars.

-There are probably licensing issues with all those jars. They couldn't 
be included in a dist could they?

-Should we try to make the container blocks look like standard dists of 
the servlet container in question? Would a clean structure with no demo 
apps be better? Personally I think so, a configuration that mounts a 
webapps directory with a directory "root" within should do. A really 
simple index.html in the "root" dir would be all.


2) The sevak demo was moved to /sevak, but only for the jetty block.

-If the demo is wanted in a distribution this update should be done for 
the catalina and jo blocks too, or undone for jetty. As I said I would 
only want a clean dist with no demos or anything. Perhaps a build task 
jetty-demo, jo-demo... would do?

3) There are some tabs in the patches.

For some reason there seems to be some tabs in the patches. These must 
be removed. I hate tabs and for some reason they show up in my own 
patches, UGH :(

4) It would be nice to have a real block that publishes webapps to a 
sevak handled container.

-Now we only have the demos, showing how to create a block that deploys 
a webapp to sevak. As this is a very common use case (the most important 
I guess), a block taking web contexts and their local file url in its 
configuration would be great. It would be easy to make too. Perhaps it 
could be extended to take a webapps type of directory and deploy all 
applications in it to sevak.

5) ....

//
Johan


---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@avalon.apache.org
For additional commands, e-mail: dev-help@avalon.apache.org


Re: [sevak-patch] Jetty configuration

Posted by Peter Royal <pr...@apache.org>.
On Saturday, June 21, 2003, at 07:03  PM, Janne wrote:
> Is this patch going to be integrated into sevak CVS in the near 
> future? This is just what I need. Ofcourse I can always patch it in my 
> workspace  .

Nothing like a good reminder :)

My only concern is the added use of System.setProperties().. In what 
circumstances would that be needed? Can it be safely removed?
-pete


---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@avalon.apache.org
For additional commands, e-mail: dev-help@avalon.apache.org


Re: [sevak-patch] Jetty configuration

Posted by Janne <no...@mermit.fi>.
Is this patch going to be integrated into sevak CVS in the near future? 
This is just what I need. Ofcourse I can always patch it in my workspace  .

- Janne


Johan Sjöberg wrote:
> Let's try again... If the patches get stripped again I'll send directly 
> to interested ones.
> 
> //
> J
> 
> 
> ------------------------------------------------------------------------
> 
> Index: sevak/catalina.xml
> ===================================================================
> RCS file: /home/cvspublic/avalon-sandbox/sevak/catalina.xml,v
> retrieving revision 1.14
> diff -u -r1.14 catalina.xml
> --- sevak/catalina.xml	25 Apr 2003 06:04:05 -0000	1.14
> +++ sevak/catalina.xml	6 Jun 2003 15:38:06 -0000
> @@ -1,6 +1,6 @@
>  <?xml version="1.0"?>
>  
> -<project default="main" basedir=".">
> +<project default="sar" basedir=".">
>  
>      <!-- set up properties -->
>      <property file="${user.home}/build.properties"/>
> 
> 
> ------------------------------------------------------------------------
> 
> Index: sevak/jetty.xml
> ===================================================================
> RCS file: /home/cvspublic/avalon-sandbox/sevak/jetty.xml,v
> retrieving revision 1.16
> diff -u -r1.16 jetty.xml
> --- sevak/jetty.xml	11 Apr 2003 00:52:19 -0000	1.16
> +++ sevak/jetty.xml	6 Jun 2003 15:39:02 -0000
> @@ -144,6 +144,14 @@
>                  <include name="sevak-demo.war"/>
>              </zipfileset>
>  
> +            <zipfileset dir="jetty-download/Jetty-${jetty.rel}/Jetty-${jetty.rel}/etc" prefix="etc">
> +                <include name="jetty.xml"/>
> +            </zipfileset >
> +
> +            <zipfileset dir="jetty-download/Jetty-${jetty.rel}/Jetty-${jetty.rel}/webapps" prefix="webapps">
> +                <include name="**/*"/>
> +            </zipfileset >
> +
>          </sar>
>  
>          <!-- Copy build/lib contents to dist/ folder -->
> 
> 
> ------------------------------------------------------------------------
> 
> Index: sevak/src/demo/conf/jetty-config.xml
> ===================================================================
> RCS file: /home/cvspublic/avalon-sandbox/sevak/src/demo/conf/jetty-config.xml,v
> retrieving revision 1.5
> diff -u -r1.5 jetty-config.xml
> --- sevak/src/demo/conf/jetty-config.xml	4 Apr 2003 22:04:07 -0000	1.5
> +++ sevak/src/demo/conf/jetty-config.xml	6 Jun 2003 15:39:53 -0000
> @@ -1,12 +1,60 @@
>  <?xml version="1.0"?>
> -
>  <config>
> +    <sevak>
> +	    <!-- Sevak host -->
> +		<!--
> +             Sevak managed web applications will be deployed to this virtual
> +             host. If it doesn't exist or is left empty the applications will
> +             be deployed to all existing hosts. The default is null (all hosts).
> +        -->
> +        <hostname>localhost</hostname>
> +
> +        <!--
> +		     Define if Sevak managed Web Application Archives should be extracted.
> +			 The default is true.
> +        -->
> +	    <extract-war>true</extract-war>
> +
> +        <!--
> +             Define if Jetty's request log should be redirected to this
> +             components log. Note that this will override any request log
> +             defined later in Jetty's own configuration. The default is true.
> +        -->
> +        <redirect-request-log>false</redirect-request-log>
> +
> +        <!-- Jetty system parameters -->
> +        <!--
> +               If a parameter begins with "${app-home}", it will be prefixed
> +               with the application's home directory.
> +        -->
> +        <system-parameters>
> +            <parameter name="jetty.home">${app-home}</parameter>
> +        </system-parameters>
> +
> +        <!-- Jetty's configuration file -->
> +        <!--
> +               If a the config file begins with "${app-home}", it will be
> +               prefixed with the application's home directory. Note that
> +               applications defined in Jetty's own configuration will not be
> +               handeled by Sevak.
> +        -->
> +        <jetty-config-file>${app-home}/etc/jetty.xml</jetty-config-file>
>  
> -  <sevak>
> -      <hostname>localhost</hostname>
> -  </sevak>
> -  <sevakTest>
> -      <Context docBase="/" path="sevak-demo.war"/>
> -  </sevakTest>
> +        <!-- Jetty's configuration -->
> +        <!--
> +              If no jetty-config-file element exists Jetty will be configured
> +              with the data inside the following element. Note that the
> +              configuration always begins with a <Configure> element. In case
> +              your Jetty configuration includes nested XML data you will have
> +              to wrap the configuration within a <![CDATA[ ..... ]]> element.
> +              Note that applications defined in Jetty's own configuration will
> +              not be handeled by Sevak.
> +        -->
> +        <jetty-config>
> +        </jetty-config>
> +    </sevak>
>  
> +    <sevakTest>
> +        <Context docBase="/sevak" path="sevak-demo.war"/>
> +    </sevakTest>
>  </config>
> 
> 
> ------------------------------------------------------------------------
> 
> Index: sevak/src/java/org/apache/avalon/apps/sevak/blocks/jetty/JettySevak.java
> ===================================================================
> RCS file: /home/cvspublic/avalon-sandbox/sevak/src/java/org/apache/avalon/apps/sevak/blocks/jetty/JettySevak.java,v
> retrieving revision 1.21
> diff -u -r1.21 JettySevak.java
> --- sevak/src/java/org/apache/avalon/apps/sevak/blocks/jetty/JettySevak.java	11 Apr 2003 00:29:11 -0000	1.21
> +++ sevak/src/java/org/apache/avalon/apps/sevak/blocks/jetty/JettySevak.java	6 Jun 2003 15:41:16 -0000
> @@ -60,6 +60,7 @@
>  import org.apache.avalon.framework.configuration.Configurable;
>  import org.apache.avalon.framework.configuration.Configuration;
>  import org.apache.avalon.framework.configuration.ConfigurationException;
> +import org.apache.avalon.framework.configuration.DefaultConfigurationSerializer;
>  import org.apache.avalon.framework.context.Context;
>  import org.apache.avalon.framework.context.ContextException;
>  import org.apache.avalon.framework.context.Contextualizable;
> @@ -72,6 +73,8 @@
>  import org.mortbay.jetty.servlet.WebApplicationContext;
>  import org.mortbay.util.Log;
>  import org.mortbay.util.MultiException;
> +import org.mortbay.xml.XmlConfiguration;
> +
>  
>  /**
>   * @phoenix:block
> @@ -90,16 +93,23 @@
>      implements Sevak, Startable, Contextualizable, Configurable, Initializable, Serviceable
>  {
>  
> +	private final static String c_appHome = "${app-home}";
> +
> +    /** The Jetty server */
>      private Server m_server;
>  
> -    /** Virtual host to bind the Jetty to.  null implies all hosts are in context. */
> +	/** Jetty's configuration */
> +	private String m_jettyConfiguration;
> +
> +	/** Jetty's configuration file */
> +	private String m_jettyConfFile;
> +
> +    /** Virtual host to deploy web applications to, null for all hosts. */
>      private String m_hostName;
>  
>      private HashMap m_webapps = new HashMap();
> -    private int m_port;
> -    private int m_minThreads;
> -    private int m_maxThreads;
>      private boolean m_extractWebArchive;
> +    private boolean m_redirectRequestLog;
>      private File m_sarRootDir;
>      private SevakContext m_sevakContext;
>      private Context m_context;
> @@ -128,49 +138,112 @@
>      /**
>       * Configure
>       * @param configuration the configuration
> -     * @throws ConfigurationException if a problem
> +     * @throws ConfigurationException if the component couldn't be configured
>       *
>       * @phoenix:configuration-schema type="http://relaxng.org/ns/structure/1.0"
>       */
>      public void configure( final Configuration configuration ) throws ConfigurationException
>      {
> -        m_hostName = configuration.getChild( "hostname" ).getValue( null );
> -        m_port = configuration.getChild( "port" ).getValueAsInteger( 8080 );
> -        m_minThreads = configuration.getChild( "minthreads" ).getValueAsInteger( 5 );
> -        m_maxThreads = configuration.getChild( "maxthreads" ).getValueAsInteger( 250 );
> -        m_extractWebArchive = configuration.getChild( "extract-war" ).getValueAsBoolean( true );
> +		m_jettyConfFile = configuration.getChild( "jetty-config-file" ).getValue( null );
> +		if( null == m_jettyConfFile )
> +		{
> +			m_jettyConfiguration = configuration.getChild( "jetty-config" ).getValue( null );
> +			if( null == m_jettyConfiguration )
> +			{
> +		    	try
> +		    	{
> +		        	DefaultConfigurationSerializer serializer =
> +		        	  new DefaultConfigurationSerializer();
> +		        	m_jettyConfiguration =  serializer.serialize(
> +		        	  configuration.getChild( "jetty-config" ).getChild( "Configure" ) );
> +		    	}
> +		    	catch( Exception e )
> +		    	{
> +		    		final String message = "Serialization of Jetty's configuration failed.";
> +		    		getLogger().fatalError( message, e );
> +		    		throw new ConfigurationException( message, e );
> +		    	}
> +			}
> +            if( m_jettyConfiguration.indexOf ("?>") >= 0 )
> +            {
> +                m_jettyConfiguration = m_jettyConfiguration.substring(
> +                  m_jettyConfiguration.indexOf ("?>") + 2 );
> +            }
> +			getLogger().info( "Configurating Jetty from component configuration." );
> +		}
> +		else
> +		{
> +			if( m_jettyConfFile.startsWith( c_appHome ) )
> +			{
> +				m_jettyConfFile = m_sarRootDir.getAbsolutePath() +
> +			  	  m_jettyConfFile.substring( c_appHome.length() );
> +			}
> +			if( m_jettyConfFile.startsWith( c_appHome ) )
> +			{
> +				m_jettyConfFile = m_jettyConfFile.substring( c_appHome.length() );
> +			}
> +		  	m_jettyConfFile = m_jettyConfFile.replace( '\\', File.separatorChar );
> +			m_jettyConfFile = m_jettyConfFile.replace( '/', File.separatorChar );
> +			getLogger().info( "Configurating Jetty from file [" + m_jettyConfFile + "]." );
> +		}
>  
> -        if( m_maxThreads < m_minThreads )
> +        Configuration systemParameters = configuration.getChild( "system-parameters", false );
> +        if( null != systemParameters )
>          {
> -            throw new ConfigurationException( "maxthreads must be greater than minthreads" );
> +        	Configuration parameters[] = systemParameters.getChildren( "parameter" );
> +        	for( int i = 0; i < parameters.length; i ++ )
> +        	{
> +        		String key = parameters[i].getAttribute( "name" );
> +        		String value = parameters[i].getValue( "" );
> +				if( value.startsWith( c_appHome ) )
> +				{
> +					value = m_sarRootDir.getAbsolutePath() + value.substring( c_appHome.length() );
> +				}
> +				getLogger().debug( "Adding system property [" + key + "] = [" + value + "]" );        		
> +        		System.setProperty( key, value );
> +        	}
>          }
> +
> +        m_hostName = configuration.getChild( "hostname" ).getValue( null );
> +        m_extractWebArchive = configuration.getChild( "extract-war" ).getValueAsBoolean( true );
> +        m_redirectRequestLog = configuration.getChild( "redirect-request-log")
> +          .getValueAsBoolean( true );
>      }
>  
>      /**
>       * Initialize
> -     * @throws Exception if a problem
> +     *
> +     * @throws Exception If Jetty couldn't be created
>       */
>      public void initialize() throws Exception
>      {
> -        m_server = new Server();
> -        SocketListener listener = new SocketListener();
> -
> -        if( null != m_hostName )
> +    	try
> +    	{
> +        	if( null == m_jettyConfFile )
> +        	{
> +         		m_server = (Server) new XmlConfiguration( m_jettyConfiguration ).newInstance();
> +        	}
> +        	else
> +        	{
> +        		m_server = new Server( m_jettyConfFile );
> +        	}
> +        }
> +        catch( Exception e )
>          {
> -            listener.setHost( m_hostName );
> +        	getLogger().fatalError( "Couldn't configure and initialize Jetty. " +
> +        	  "Check the configuration. Your service manager's log might also help." );
> +        	throw e;
>          }
> -
> -        listener.setPort( m_port );
> -        listener.setMinThreads( m_minThreads );
> -        listener.setMaxThreads( m_maxThreads );
> -        m_server.addListener( listener );
> -        PhoenixLogSink phoenixLogSink = new PhoenixLogSink();
> -        phoenixLogSink.enableLogging( getLogger() );
> -        Log.instance().add( phoenixLogSink );
> -
> -        RequestLogger logger = (RequestLogger)
> -            m_sevakContext.getServiceManager().lookup( RequestLogger.ROLE );
> -        m_server.setRequestLog( new JettyRequestLogAdapter( logger ) );
> +        
> +        if( m_redirectRequestLog )
> +        {
> +        	PhoenixLogSink phoenixLogSink = new PhoenixLogSink();
> +        	phoenixLogSink.enableLogging( getLogger() );
> +        	Log.instance().add( phoenixLogSink );
> +        	RequestLogger logger = (RequestLogger)
> +          	 m_sevakContext.getServiceManager().lookup( RequestLogger.ROLE );
> +        	m_server.setRequestLog( new JettyRequestLogAdapter( logger ) );
> +    	}
>      }
>  
>      /**
> 
> 
> ------------------------------------------------------------------------
> 
> Index: sevak/src/java/org/apache/avalon/apps/sevak/blocks/jetty/JettySevak-schema.xml
> ===================================================================
> RCS file: /home/cvspublic/avalon-sandbox/sevak/src/java/org/apache/avalon/apps/sevak/blocks/jetty/JettySevak-schema.xml,v
> retrieving revision 1.2
> diff -u -r1.2 JettySevak-schema.xml
> --- sevak/src/java/org/apache/avalon/apps/sevak/blocks/jetty/JettySevak-schema.xml	10 Feb 2003 20:38:22 -0000	1.2
> +++ sevak/src/java/org/apache/avalon/apps/sevak/blocks/jetty/JettySevak-schema.xml	6 Jun 2003 15:42:21 -0000
> @@ -9,16 +9,23 @@
>              <element name="hostname"><text/></element>
>          </optional>
>          <optional>
> -            <element name="port"><data type="integer"/></element>
> +            <element name="extract-war"><data type="boolean"/></element>
>          </optional>
>          <optional>
> -            <element name="minthreads"><data type="integer"/></element>
> +            <element name="redirect-request-log"><data type="boolean"/></element>
>          </optional>
>          <optional>
> -            <element name="maxthreads"><data type="integer"/></element>
> +          <element name="system-parameters">
> +            <oneOrMore>
> +              <element name="parameter"><attribute name="name"/><text/></element>
> +            </oneOrMore>
> +          </element>
>          </optional>
>          <optional>
> -            <element name="extract-war"><data type="boolean"/></element>
> +          <element name="jetty-config-file"><text/></element>
>          </optional>
> +        <optional>
> +          <element name="jetty-config"></element>
> +        </optional>    
>      </interleave>
>  </element>
> 
> 
> ------------------------------------------------------------------------
> 
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: dev-unsubscribe@avalon.apache.org
> For additional commands, e-mail: dev-help@avalon.apache.org


-- 
- Janne
k a r i o at m e r m i t dot f i


---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@avalon.apache.org
For additional commands, e-mail: dev-help@avalon.apache.org


Re: [sevak-patch] Jetty configuration

Posted by Johan Sjöberg <jo...@avaintec.com>.
Let's try again... If the patches get stripped again I'll send directly 
to interested ones.

//
J

Re: [sevak-patch] Jetty configuration

Posted by Johan Sjöberg <jo...@avaintec.com>.
Is someone/something removing attachments from the emails?

//
Johan


---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@avalon.apache.org
For additional commands, e-mail: dev-help@avalon.apache.org