You are viewing a plain text version of this content. The canonical link for it is here.
Posted to cvs@avalon.apache.org by ni...@apache.org on 2004/07/24 12:21:42 UTC
svn commit: rev 23211 - in avalon/trunk/planet/facilities/http: api/src/main/org/apache/avalon/http impl/src/main/org/apache/avalon/http/impl test/src/main/test/http util/src/main/org/apache/avalon/http/util
Author: niclas
Date: Sat Jul 24 03:21:40 2004
New Revision: 23211
Modified:
avalon/trunk/planet/facilities/http/api/src/main/org/apache/avalon/http/Handler.java
avalon/trunk/planet/facilities/http/impl/src/main/org/apache/avalon/http/impl/DefaultModelListener.java
avalon/trunk/planet/facilities/http/impl/src/main/org/apache/avalon/http/impl/DefaultServer.java
avalon/trunk/planet/facilities/http/test/src/main/test/http/TestComponent.java
avalon/trunk/planet/facilities/http/util/src/main/org/apache/avalon/http/util/HttpHandler.java
Log:
A series of changes to improve the overall support of components serving http requests.
Modified: avalon/trunk/planet/facilities/http/api/src/main/org/apache/avalon/http/Handler.java
==============================================================================
--- avalon/trunk/planet/facilities/http/api/src/main/org/apache/avalon/http/Handler.java (original)
+++ avalon/trunk/planet/facilities/http/api/src/main/org/apache/avalon/http/Handler.java Sat Jul 24 03:21:40 2004
@@ -52,5 +52,5 @@
*
*/
public void service( ServletRequest request, ServletResponse response )
- throws HandlerException, IOException;
+ throws HandlerException, IOException;
}
Modified: avalon/trunk/planet/facilities/http/impl/src/main/org/apache/avalon/http/impl/DefaultModelListener.java
==============================================================================
--- avalon/trunk/planet/facilities/http/impl/src/main/org/apache/avalon/http/impl/DefaultModelListener.java (original)
+++ avalon/trunk/planet/facilities/http/impl/src/main/org/apache/avalon/http/impl/DefaultModelListener.java Sat Jul 24 03:21:40 2004
@@ -46,8 +46,8 @@
* @author <a href="mailto:dev@avalon.apache.org">Avalon Development Team</a>
*/
public class DefaultModelListener extends AbstractLogEnabled
- implements Contextualizable, Serviceable, Initializable,
- CompositionListener
+ implements Contextualizable, Serviceable, Initializable,
+ CompositionListener
{
//---------------------------------------------------------
// state
Modified: avalon/trunk/planet/facilities/http/impl/src/main/org/apache/avalon/http/impl/DefaultServer.java
==============================================================================
--- avalon/trunk/planet/facilities/http/impl/src/main/org/apache/avalon/http/impl/DefaultServer.java (original)
+++ avalon/trunk/planet/facilities/http/impl/src/main/org/apache/avalon/http/impl/DefaultServer.java Sat Jul 24 03:21:40 2004
@@ -19,6 +19,7 @@
import java.io.File;
import java.net.UnknownHostException;
+import java.util.HashMap;
import org.apache.avalon.framework.logger.Logger;
import org.apache.avalon.framework.logger.LogEnabled;
@@ -53,19 +54,15 @@
* @avalon.service type="org.apache.avalon.http.HttpService"
* @author <a href="mailto:dev@avalon.apache.org">Avalon Development Team</a>
*/
-public class DefaultServer implements LogEnabled, Contextualizable, Configurable,
- Initializable, Startable, HttpService
+public class DefaultServer
+ implements LogEnabled, Contextualizable, Configurable,
+ Initializable, Startable, HttpService
{
//---------------------------------------------------------
// static
//---------------------------------------------------------
private static final String LISTENER_TYPE_ATTRIBUTE_NAME = "type";
- private static final String PORT_ATTRIBUTE_NAME = "port";
- private static final String HOST_ATTRIBUTE_NAME = "host";
- private static final String TIMEOUT_ATTRIBUTE_NAME = "timeout";
- private static final String PATH_ATTRIBUTE_NAME = "path";
- private static final String BASE_ATTRIBUTE_NAME = "dir";
private static final String KEYSTORE_ELEMENT_NAME = "keystore";
private static final String FILE_ELEMENT_NAME = "file";
private static final String PASSWORD_ELEMENT_NAME = "password";
@@ -98,6 +95,12 @@
* The working base directory.
*/
private File m_basedir;
+
+ /**
+ * Mapping table for URL space to Servlet
+ */
+ private HashMap m_ServletMap;
+
//---------------------------------------------------------
// LogEnabled
@@ -186,18 +189,6 @@
}
//
- // if no context entries are declared then create
- // a default context for the path "/" using static
- // content under the directory "root"
- //
-
- //if( null == m_config.getChild( "context", false ))
- //{
- // HttpContext context = createContext( "/", "./root/" );
- // m_server.addContext( context );
- //}
-
- //
// handle the children declared in the configuration
// (includes listeners, etc.)
//
@@ -207,16 +198,15 @@
{
Configuration child = children[i];
String name = child.getName();
- if( name.equalsIgnoreCase( "listener" ) )
+
+ if( "listeners".equalsIgnoreCase( name ) )
+ {
+ configureListeners( child );
+ }
+ else if( "mappings".equalsIgnoreCase( name ) )
{
- HttpListener listener = createListener( child );
- m_server.addListener( listener );
+ configureMappings( child );
}
- //else if( name.equalsIgnoreCase( "context" ) )
- //{
- // HttpContext context = createContext( child );
- // m_server.addContext( context );
- //}
else
{
final String error =
@@ -228,6 +218,30 @@
}
}
+ private void configureListeners( Configuration conf )
+ throws ConfigurationException, UnknownHostException
+ {
+ Configuration[] children = conf.getChildren( "listener" );
+ for( int i=0 ; i < children.length ; i++ )
+ {
+ HttpListener listener = createListener( children[i] );
+ m_server.addListener( listener );
+ }
+ }
+
+ private void configureMappings( Configuration conf )
+ {
+ Configuration[] children = conf.getChildren( "mapping" );
+ for( int i=0 ; i < children.length ; i++ )
+ {
+ Configuration servletConf = children[i];
+ String component = servletConf.getChild( "component" ).getValue( "" );
+ String url = servletConf.getChild( "url" ).getValue( "" );
+ if( ! "".equals( component ) && ! "".equals( url ) )
+ m_ServletMap.put( component.trim(), url.trim() );
+ }
+ }
+
//---------------------------------------------------------
// Startable
//---------------------------------------------------------
@@ -258,11 +272,13 @@
*/
public void register( ComponentModel model )
{
+ final String path = model.getPath();
+ final String url = (String) m_ServletMap.get( path );
+
getLogger().info(
"registering servlet: "
- + model );
-
- final String path = model.getPath();
+ + path + " to url: " + url );
+
HttpContext context = m_server.getContext( path + "*" );
ContainmentModelHandler handler =
getContainmentHandler( context, path );
@@ -302,7 +318,7 @@
* @param conf the listener configuration
*/
private HttpListener createListener( Configuration conf )
- throws Exception
+ throws UnknownHostException
{
HttpListener listener = null;
@@ -310,7 +326,7 @@
conf.getAttribute(
LISTENER_TYPE_ATTRIBUTE_NAME,
SOCKET_TYPE );
-
+
if( listenerType.equals( AJP_TYPE ) )
{
listener = createAJP13Listener( conf, 2345 );
@@ -341,10 +357,8 @@
throws UnknownHostException
{
AJP13Listener listener = new AJP13Listener();
- listener.setMaxIdleTimeMs(
- config.getAttributeAsInteger(
- TIMEOUT_ATTRIBUTE_NAME,
- 60000 ));
+ int timeout = config.getChild( "timeout" ).getValueAsInteger( 60000 );
+ listener.setMaxIdleTimeMs( timeout );
return setUpListener( listener, config, port );
}
@@ -357,10 +371,8 @@
throws UnknownHostException
{
SocketListener listener = new SocketListener();
- listener.setMaxIdleTimeMs(
- config.getAttributeAsInteger(
- TIMEOUT_ATTRIBUTE_NAME,
- 60000 ));
+ int timeout = config.getChild( "timeout" ).getValueAsInteger( 60000 );
+ listener.setMaxIdleTimeMs( timeout );
return setUpListener( listener, config, port );
}
@@ -371,33 +383,26 @@
* @return The newly created sun jsse listener
* @throws Exception
*/
- private HttpListener createSunJsseListener( Configuration configuration, int port )
- throws Exception
+ private HttpListener createSunJsseListener( Configuration conf, int port )
+ throws UnknownHostException
{
SunJsseListener listener = new SunJsseListener();
- listener.setMaxIdleTimeMs(
- configuration.getAttributeAsInteger(
- TIMEOUT_ATTRIBUTE_NAME,
- 60000 ));
-
- Configuration ksconfig =
- configuration.getChild(
- KEYSTORE_ELEMENT_NAME );
+ int timeout = conf.getChild( "timeout" ).getValueAsInteger( 60000 );
+ listener.setMaxIdleTimeMs( timeout );
- String fileName =
- ksconfig.getChild(
- FILE_ELEMENT_NAME ).getValue( "conf/.keystore" );
+ Configuration ksconfig = conf.getChild( KEYSTORE_ELEMENT_NAME );
+ Configuration fileconfig = ksconfig.getChild( FILE_ELEMENT_NAME );
+ String fileName = fileconfig.getValue( "conf/.keystore" );
File configuredFile = new File( fileName );
- if( !configuredFile.isAbsolute() )
+ if( ! configuredFile.isAbsolute() )
{
- listener.setKeystore(
- new File( m_basedir, fileName ).getAbsolutePath() );
+ File keystore = new File( m_basedir, fileName );
+ listener.setKeystore( keystore.getAbsolutePath() );
}
else
{
- listener.setKeystore(
- configuredFile.getAbsolutePath() );
+ listener.setKeystore( configuredFile.getAbsolutePath() );
}
listener.setPassword(
@@ -407,21 +412,18 @@
ksconfig.getChild(
KEYPASSWORD_ELEMENT_NAME ).getValue( null ) );
- return setUpListener( listener, configuration, port );
+ return setUpListener( listener, conf, port );
}
private HttpListener setUpListener(
- HttpListener listener, Configuration config, int port )
- throws UnknownHostException
+ HttpListener listener, Configuration config, int port )
+ throws UnknownHostException
{
- listener.setPort(
- config.getAttributeAsInteger(
- PORT_ATTRIBUTE_NAME,
- port ) );
- listener.setHost(
- config.getAttribute(
- HOST_ATTRIBUTE_NAME,
- "0.0.0.0" ) );
+ int configPort = config.getChild( "port" ).getValueAsInteger( port );
+ String host = config.getChild( "hostname" ).getValue( "0.0.0.0" );
+
+ listener.setPort( configPort );
+ listener.setHost( host );
return listener;
}
Modified: avalon/trunk/planet/facilities/http/test/src/main/test/http/TestComponent.java
==============================================================================
--- avalon/trunk/planet/facilities/http/test/src/main/test/http/TestComponent.java (original)
+++ avalon/trunk/planet/facilities/http/test/src/main/test/http/TestComponent.java Sat Jul 24 03:21:40 2004
@@ -47,7 +47,7 @@
* @author <a href="mailto:dev@avalon.apache.org">Avalon Development Team</a>
*/
public class TestComponent extends HttpHandler
- implements LogEnabled, Serviceable, Configurable
+ implements LogEnabled, Serviceable, Configurable
{
//----------------------------------------------------------
// state
Modified: avalon/trunk/planet/facilities/http/util/src/main/org/apache/avalon/http/util/HttpHandler.java
==============================================================================
--- avalon/trunk/planet/facilities/http/util/src/main/org/apache/avalon/http/util/HttpHandler.java (original)
+++ avalon/trunk/planet/facilities/http/util/src/main/org/apache/avalon/http/util/HttpHandler.java Sat Jul 24 03:21:40 2004
@@ -65,7 +65,8 @@
* @version $Revision: 1.1 $
*
*/
-public abstract class HttpHandler implements Handler, java.io.Serializable
+public abstract class HttpHandler
+ implements Handler, java.io.Serializable
{
private static final String METHOD_DELETE = "DELETE";
private static final String METHOD_HEAD = "HEAD";
---------------------------------------------------------------------
To unsubscribe, e-mail: cvs-unsubscribe@avalon.apache.org
For additional commands, e-mail: cvs-help@avalon.apache.org