Skip to Content.
Sympa Menu

notify-dpml - r1455 - in trunk/main: metro/runtime/src/main/net/dpml/metro/runtime planet/http planet/http/impl planet/http/impl/src/main/net/dpml/http planet/http/impl/src/test/net/dpml/http planet/http/server

notify-dpml AT lists.ibiblio.org

Subject: DPML Notify

List archive

Chronological Thread  
  • From: mcconnell at BerliOS <mcconnell AT mail.berlios.de>
  • To: notify-dpml AT lists.ibiblio.org
  • Subject: r1455 - in trunk/main: metro/runtime/src/main/net/dpml/metro/runtime planet/http planet/http/impl planet/http/impl/src/main/net/dpml/http planet/http/impl/src/test/net/dpml/http planet/http/server
  • Date: Tue, 23 May 2006 19:05:09 +0200

Author: mcconnell
Date: 2006-05-23 19:04:52 +0200 (Tue, 23 May 2006)
New Revision: 1455

Added:

trunk/main/planet/http/impl/src/main/net/dpml/http/ContextHandlerCollection.java
Modified:

trunk/main/metro/runtime/src/main/net/dpml/metro/runtime/DefaultComponentHandler.java
trunk/main/planet/http/impl/build.xml

trunk/main/planet/http/impl/src/main/net/dpml/http/ContextHandlerContext.java
trunk/main/planet/http/impl/src/main/net/dpml/http/ContextHelper.java
trunk/main/planet/http/impl/src/main/net/dpml/http/LoggerAdapter.java
trunk/main/planet/http/impl/src/main/net/dpml/http/Server.java

trunk/main/planet/http/impl/src/test/net/dpml/http/AbstractContextHandlerTestCase.java
trunk/main/planet/http/module.xml
trunk/main/planet/http/server/project.xml
Log:
update http package to support a formal context handler collection

Modified:
trunk/main/metro/runtime/src/main/net/dpml/metro/runtime/DefaultComponentHandler.java
===================================================================
---
trunk/main/metro/runtime/src/main/net/dpml/metro/runtime/DefaultComponentHandler.java
2006-05-23 05:52:18 UTC (rev 1454)
+++
trunk/main/metro/runtime/src/main/net/dpml/metro/runtime/DefaultComponentHandler.java
2006-05-23 17:04:52 UTC (rev 1455)
@@ -401,13 +401,6 @@
+ "]." );
}

- // check if this component can handle the request
-
- //if( isaCandidate( service ) )
- //{
- // return this;
- //}
-
// check if a child component can handle the request

Component[] components = m_parts.getComponents();

Modified: trunk/main/planet/http/impl/build.xml
===================================================================
--- trunk/main/planet/http/impl/build.xml 2006-05-23 05:52:18 UTC (rev
1454)
+++ trunk/main/planet/http/impl/build.xml 2006-05-23 17:04:52 UTC (rev
1455)
@@ -73,6 +73,12 @@
</services>
</type>

+ <type xmlns="metro" class="net.dpml.http.ContextHandlerCollection"
threadsafe="true" name="context">
+ <services>
+ <service class="org.mortbay.jetty.handler.HandlerCollection"/>
+ </services>
+ </type>
+
<type xmlns="metro" name="server" class="net.dpml.http.Server"
threadsafe="true" collection="hard">
<services>
<service class="net.dpml.http.Server"/>

Added:
trunk/main/planet/http/impl/src/main/net/dpml/http/ContextHandlerCollection.java
===================================================================
---
trunk/main/planet/http/impl/src/main/net/dpml/http/ContextHandlerCollection.java
2006-05-23 05:52:18 UTC (rev 1454)
+++
trunk/main/planet/http/impl/src/main/net/dpml/http/ContextHandlerCollection.java
2006-05-23 17:04:52 UTC (rev 1455)
@@ -0,0 +1,88 @@
+/*
+ * Copyright 2006 Stephen McConnell.
+ *
+ * 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 net.dpml.http;
+
+import java.net.URI;
+import java.net.URL;
+import java.util.ArrayList;
+
+import net.dpml.logging.Logger;
+
+import net.dpml.metro.PartsManager;
+import net.dpml.metro.ComponentHandler;
+import net.dpml.component.Provider;
+
+import org.mortbay.jetty.Handler;
+
+/**
+ * HTTP server implementation.
+ * @author <a href="@PUBLISHER-URL@">@PUBLISHER-NAME@</a>
+ * @version @PROJECT-VERSION@
+ */
+public class ContextHandlerCollection extends
org.mortbay.jetty.handler.ContextHandlerCollection
+{
+ /**
+ * Internal parts management interface.
+ */
+ public interface Parts extends PartsManager
+ {
+ }
+
+ private final Logger m_logger;
+ private final Parts m_parts;
+
+ /**
+ * Creation of a new HTTP server implementation.
+ * @param logger the assigned logging channel
+ * @param parts the parts manager
+ * @exception Exception if an instantiation error occurs
+ */
+ public ContextHandlerCollection( Logger logger, Parts parts ) throws
Exception
+ {
+ super();
+
+ m_logger = logger;
+ m_parts = parts;
+
+ getLogger().debug( "commencing handler addition" );
+ String[] keys = parts.getKeys();
+ getLogger().debug( "handler count: " + keys.length );
+ for( int i=0; i<keys.length; i++ )
+ {
+ String key = keys[i];
+ ComponentHandler handler = parts.getComponentHandler( key );
+ getLogger().info( "adding context handler: " + handler );
+ try
+ {
+ Provider provider = handler.getProvider();
+ org.mortbay.jetty.Handler ch =
+ (org.mortbay.jetty.Handler) provider.getValue( false );
+ super.addHandler( ch );
+ }
+ catch( Throwable e )
+ {
+ final String error =
+ "Failed to deploy handler: " + handler;
+ throw new Exception( error, e );
+ }
+ }
+ }
+
+ private Logger getLogger()
+ {
+ return m_logger;
+ }
+}

Modified:
trunk/main/planet/http/impl/src/main/net/dpml/http/ContextHandlerContext.java
===================================================================
---
trunk/main/planet/http/impl/src/main/net/dpml/http/ContextHandlerContext.java
2006-05-23 05:52:18 UTC (rev 1454)
+++
trunk/main/planet/http/impl/src/main/net/dpml/http/ContextHandlerContext.java
2006-05-23 17:04:52 UTC (rev 1455)
@@ -34,11 +34,12 @@
String[] getVirtualHosts( String[] hosts );

/**
- * Get the array of hosts.
- * @param hosts the default host array
+ * Get the array of connectors. The function returns the set of
+ * connectors in the form <tt>host:port</tt>.
+ * @param connectors the default connector array
* @return the resolved host array
*/
- String[] getHosts( String[] hosts );
+ String[] getConnectors( String[] hosts );

/**
* Get the array of welcome files.

Modified:
trunk/main/planet/http/impl/src/main/net/dpml/http/ContextHelper.java
===================================================================
--- trunk/main/planet/http/impl/src/main/net/dpml/http/ContextHelper.java
2006-05-23 05:52:18 UTC (rev 1454)
+++ trunk/main/planet/http/impl/src/main/net/dpml/http/ContextHelper.java
2006-05-23 17:04:52 UTC (rev 1455)
@@ -60,10 +60,10 @@
handler.setDisplayName( name );
}

- String[] hosts = context.getHosts( null );
+ String[] hosts = context.getConnectors( null );
if( null != hosts )
{
- handler.setHosts( hosts );
+ handler.setConnectors( hosts );
}

String[] virtual = context.getVirtualHosts( null );

Modified:
trunk/main/planet/http/impl/src/main/net/dpml/http/LoggerAdapter.java
===================================================================
--- trunk/main/planet/http/impl/src/main/net/dpml/http/LoggerAdapter.java
2006-05-23 05:52:18 UTC (rev 1454)
+++ trunk/main/planet/http/impl/src/main/net/dpml/http/LoggerAdapter.java
2006-05-23 17:04:52 UTC (rev 1455)
@@ -36,10 +36,10 @@
System.setProperty( "org.mortbay.log.class",
LoggerAdapter.class.getName() );
m_LOGGER.debug( "logging adapter established" );
}
- else
- {
- throw new IllegalStateException( "m_LOGGER already initialized."
);
- }
+ //else
+ //{
+ // throw new IllegalStateException( "m_LOGGER already
initialized." );
+ //}
}

private final Logger m_logger;

Modified: trunk/main/planet/http/impl/src/main/net/dpml/http/Server.java
===================================================================
--- trunk/main/planet/http/impl/src/main/net/dpml/http/Server.java
2006-05-23 05:52:18 UTC (rev 1454)
+++ trunk/main/planet/http/impl/src/main/net/dpml/http/Server.java
2006-05-23 17:04:52 UTC (rev 1455)
@@ -83,6 +83,12 @@
* @return the default thread pool.
*/
ThreadPool getThreadPool();
+
+ /**
+ * Return the context handler collection.
+ * @return the configured context handler collection.
+ */
+ ContextHandlerCollection getContextHandlerCollection();
}

private final Logger m_logger;
@@ -133,12 +139,15 @@
}

//
- // add connectors, realms and context handlers
+ // add connectors, realms and handlers
//

addConnectors( parts );
addUserRealms( parts );
- addHandlers( parts );
+
+ ContextHandlerCollection collection =
parts.getContextHandlerCollection();
+ setHandler( collection );
+
getLogger().debug( "server established" );
}

@@ -168,33 +177,6 @@
setConnectors( connectors );
}

- private void addHandlers( PartsManager parts ) throws Exception
- {
- getLogger().debug( "commencing handler addition" );
- ComponentHandler[] handlers = parts.getComponentHandlers(
Handler.class );
- getLogger().debug( "handler count: " + handlers.length );
- HandlerCollection collection = new HandlerCollection();
- for( int i=0; i<handlers.length; i++ )
- {
- ComponentHandler handler = handlers[i];
- getLogger().debug( "adding handler: " + handler );
- try
- {
- Provider provider = handler.getProvider();
- org.mortbay.jetty.Handler ch =
- (org.mortbay.jetty.Handler) provider.getValue( false );
- collection.addHandler( ch );
- }
- catch( Throwable e )
- {
- final String error =
- "Failed to deploy handler: " + handler;
- throw new Exception( error, e );
- }
- }
- super.setHandler( collection );
- }
-
private void addUserRealms( PartsManager parts ) throws Exception
{
getLogger().debug( "commencing realm addition" );

Modified:
trunk/main/planet/http/impl/src/test/net/dpml/http/AbstractContextHandlerTestCase.java
===================================================================
---
trunk/main/planet/http/impl/src/test/net/dpml/http/AbstractContextHandlerTestCase.java
2006-05-23 05:52:18 UTC (rev 1454)
+++
trunk/main/planet/http/impl/src/test/net/dpml/http/AbstractContextHandlerTestCase.java
2006-05-23 17:04:52 UTC (rev 1455)
@@ -18,6 +18,7 @@

package net.dpml.http;

+import java.util.Arrays;
import java.util.Map;
import java.util.Hashtable;

@@ -32,7 +33,7 @@
public abstract class AbstractContextHandlerTestCase extends TestCase
{
private static final String[] VIRTUAL_HOSTS = new
String[]{"virtual.acme.org", "virtual.secret.acme.org"};
- private static final String[] HOSTS = new String[]{"www.acme.org",
"secret.acme.org"};
+ private static final String[] CONNECTORS = new String[]{"www.acme.org",
"secret.acme.org"};
private static final String[] WELCOME_FILES = new String[]{"about.html",
"index.html", "index.htm"};
private static final ClassLoader CLASSLOADER =
AbstractContextHandlerTestCase.class.getClassLoader();
private static final Map MIME_TYPES = new Hashtable();
@@ -48,7 +49,7 @@
{
Map map = new Hashtable();
map.put( "virtualHosts", VIRTUAL_HOSTS );
- map.put( "hosts", HOSTS );
+ map.put( "connectors", CONNECTORS );
map.put( "welcomeFiles", WELCOME_FILES );
map.put( "classLoader", CLASSLOADER );
map.put( "contextPath", CONTEXT_PATH );
@@ -70,16 +71,28 @@
*/
public void testVirtualHosts() throws Exception
{
- assertEquals( "virtualHosts", VIRTUAL_HOSTS,
getContextHandler().getVirtualHosts() );
+ String[] hosts = getContextHandler().getVirtualHosts();
+ if( !Arrays.equals( VIRTUAL_HOSTS, hosts ) )
+ {
+ final String error =
+ "Supplied virtual hosts array does not equal return value.";
+ fail( error );
+ }
}

/**
* Test hosts assignment integrity.
* @throws Exception if an error occurs during test execution
*/
- public void testHosts() throws Exception
+ public void testConnectors() throws Exception
{
- assertEquals( "hosts", HOSTS, getContextHandler().getHosts() );
+ String[] connectors = getContextHandler().getConnectors();
+ if( !Arrays.equals( CONNECTORS, connectors ) )
+ {
+ final String error =
+ "Supplied connector array does not equal return value.";
+ fail( error );
+ }
}

/**
@@ -88,9 +101,15 @@
*/
public void testWelcomeFiles() throws Exception
{
- assertEquals( "welcomeFiles", WELCOME_FILES,
getContextHandler().getWelcomeFiles() );
+ String[] files = getContextHandler().getWelcomeFiles();
+ if( !Arrays.equals( WELCOME_FILES, files ) )
+ {
+ final String error =
+ "Supplied welcome files array does not equal return value.";
+ fail( error );
+ }
}
-
+
/**
* Test classloader assignment integrity.
* @throws Exception if an error occurs during test execution

Modified: trunk/main/planet/http/module.xml
===================================================================
--- trunk/main/planet/http/module.xml 2006-05-23 05:52:18 UTC (rev 1454)
+++ trunk/main/planet/http/module.xml 2006-05-23 17:04:52 UTC (rev 1455)
@@ -4,9 +4,10 @@
<properties>
<property
name="project.xsd.builder.artifact:xsd:dpml/lang/dpml-component#1.0"
value="link:part:dpml/metro/dpml-metro-runtime"/>
- <property name="jetty.version" value="6.0.0-R516"/>
+ <property name="jetty.version" value="6.0.0-R534"/>
<property name="jasper.version" value="5.5.15"/>
- <property name="sl4j.version" value="1.0-rc5"/>
+ <!--<property name="sl4j.version" value="1.0-rc5"/>-->
+ <property name="sl4j.version" value="1.0.1"/>
</properties>

<project name="dpml-http-impl" basedir="impl">

Modified: trunk/main/planet/http/server/project.xml
===================================================================
--- trunk/main/planet/http/server/project.xml 2006-05-23 05:52:18 UTC (rev
1454)
+++ trunk/main/planet/http/server/project.xml 2006-05-23 17:04:52 UTC (rev
1455)
@@ -44,48 +44,55 @@
</context>
</component>
<!--
- Add a web application.
+ Add context handler collection.
-->
- <component key="webapp" type="net.dpml.http.WebAppContextHandler">
- <context>
- <entry key="contextPath" value="/"/>
- <entry key="war"
value="link:war:dpml/planet/http/dpml-http-app"/>
- </context>
+ <component key="contextHandlerCollection"
type="net.dpml.http.ContextHandlerCollection">
+ <parts>
+ <!--
+ Creation of a HTTP server configured to present static content
in
+ the ${dpml.share}/docs directory.
+ -->
+ <component key="docs"
type="net.dpml.http.ResourceContextHandler">
+ <context>
+ <entry key="resourceBase" value="${dpml.share}/docs"/>
+ <entry key="contextPath" value="/docs"/>
+ </context>
+ </component>
+ <!--
+ Add an experimental servlet context.
+ (Need to add context cloassloader configuration but this
requires
+ per-component threads - currently limited to classes declared
within
+ the part classloader).
+ -->
+ <component key="servlets"
type="net.dpml.http.ServletContextHandler">
+ <context>
+ <entry key="resourceBase" value="${dpml.data}"/>
+ <entry key="contextPath" value="/data"/>
+ <entry key="servletHolders">
+ <param class="net.dpml.http.ServletHolder">
+ <param value="data"/>
+ <param value="org.mortbay.jetty.servlet.DefaultServlet"/>
+ </param>
+ </entry>
+ <entry key="servletEntries">
+ <param class="net.dpml.http.ServletEntry">
+ <param value="data"/>
+ <param value="/"/>
+ </param>
+ </entry>
+ </context>
+ </component>
+ <!--
+ Add a web application.
+ -->
+ <component key="webapp"
type="net.dpml.http.WebAppContextHandler">
+ <context>
+ <entry key="contextPath" value="/"/>
+ <entry key="war"
value="link:war:dpml/planet/http/dpml-http-app"/>
+ </context>
+ </component>
+ </parts>
</component>
- <!--
- Creation of a HTTP server configured to present static content in
- the ${dpml.share}/docs directory.
- -->
- <component key="context" type="net.dpml.http.ResourceContextHandler">
- <context>
- <entry key="resourceBase" value="${dpml.share}/docs"/>
- <entry key="contextPath" value="/docs"/>
- </context>
- </component>
- <!--
- Add an experimental servlet context.
- (Need to add context cloassloader configuration but this requires
- per-component threads - currently limited to classes declared within
- the part classloader).
- -->
- <component key="servlets" type="net.dpml.http.ServletContextHandler">
- <context>
- <entry key="resourceBase" value="${dpml.data}"/>
- <entry key="contextPath" value="/data"/>
- <entry key="servletHolders">
- <param class="net.dpml.http.ServletHolder">
- <param value="data"/>
- <param value="org.mortbay.jetty.servlet.DefaultServlet"/>
- </param>
- </entry>
- <entry key="servletEntries">
- <param class="net.dpml.http.ServletEntry">
- <param value="data"/>
- <param value="/"/>
- </param>
- </entry>
- </context>
- </component>
</parts>
</type>
</types>




  • r1455 - in trunk/main: metro/runtime/src/main/net/dpml/metro/runtime planet/http planet/http/impl planet/http/impl/src/main/net/dpml/http planet/http/impl/src/test/net/dpml/http planet/http/server, mcconnell at BerliOS, 05/23/2006

Archive powered by MHonArc 2.6.24.

Top of Page