Skip to Content.
Sympa Menu

notify-dpml - r1037 - in trunk/main/planet/web: . server server/src/main/net/dpml/web/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: r1037 - in trunk/main/planet/web: . server server/src/main/net/dpml/web/server
  • Date: Sun, 5 Feb 2006 17:57:19 +0100

Author: mcconnell
Date: 2006-02-05 17:57:18 +0100 (Sun, 05 Feb 2006)
New Revision: 1037

Added:

trunk/main/planet/web/server/src/main/net/dpml/web/server/ServletContextHandler.java
Modified:
trunk/main/planet/web/module.xml
trunk/main/planet/web/server/build.xml
Log:
consolidate the servlet handler to a specialized configurable context handler

Modified: trunk/main/planet/web/module.xml
===================================================================
--- trunk/main/planet/web/module.xml 2006-02-05 16:17:48 UTC (rev 1036)
+++ trunk/main/planet/web/module.xml 2006-02-05 16:57:18 UTC (rev 1037)
@@ -14,6 +14,7 @@
<dependencies>
<include ref="dpml/metro/dpml-metro-model"/>
<include ref="dpml/util/dpml-logging-api"/>
+ <include ref="dpml/util/dpml-configuration-api"/>
<include urn="artifact:jar:jetty/servlet-api-2.5#20060131"/>
<include urn="artifact:jar:tomcat/jasper-runtime#5.5.12"/>
<include urn="artifact:jar:tomcat/jasper-compiler#5.5.12"/>

Modified: trunk/main/planet/web/server/build.xml
===================================================================
--- trunk/main/planet/web/server/build.xml 2006-02-05 16:17:48 UTC (rev
1036)
+++ trunk/main/planet/web/server/build.xml 2006-02-05 16:57:18 UTC (rev
1037)
@@ -36,12 +36,18 @@
</services>
</type>

- <type xmlns="metro" name="context"
class="net.dpml.web.server.ResourceContextHandler" threadsafe="true" >
+ <type xmlns="metro" name="static"
class="net.dpml.web.server.ResourceContextHandler" threadsafe="true" >
<services>
<service class="net.dpml.web.server.ResourceContextHandler"/>
</services>
</type>

+ <type xmlns="metro" name="static"
class="net.dpml.web.server.ServletContextHandler" threadsafe="true" >
+ <services>
+ <service class="net.dpml.web.server.ServletContextHandler"/>
+ </services>
+ </type>
+
<type xmlns="metro" name="server" class="net.dpml.web.server.Server"
threadsafe="true" collection="hard">
<services>
<service class="net.dpml.web.server.Server"/>
@@ -87,30 +93,24 @@
<component key="context"
type="net.dpml.web.server.ResourceContextHandler">
<context>
<entry key="server" validate="false"/>
- <entry key="resourceBase" value="${dpml.share}/docs"/>
+ <entry key="resourceBase" value="$${dpml.share}/docs"/>
<entry key="contextPath" value="/docs"/>
</context>
</component>
- <component key="servlets" type="net.dpml.web.server.ContextHandler">
+ <component key="servlets"
type="net.dpml.web.server.ServletContextHandler">
<context>
<entry key="server" validate="false"/>
<entry key="resourceBase" value="${dpml.data}"/>
<entry key="contextPath" value="/"/>
- <entry key="handler" class="net.dpml.web.server.ServletHandler">
- <array class="net.dpml.web.server.ServletHolder">
- <value>
- <value value="data"/>
- <value value="org.mortbay.jetty.servlet.DefaultServlet"/>
- </value>
- </array>
- <array class="net.dpml.web.server.ServletMapping">
- <value>
- <value value="data"/>
- <value value="/"/>
- </value>
- </array>
- </entry>
</context>
+ <configuration>
+ <servlets>
+ <servlet name="data"
class="org.mortbay.jetty.servlet.DefaultServlet"/>
+ </servlets>
+ <mappings>
+ <map servlet="data" path="/"/>
+ </mappings>
+ </configuration>
</component>
</parts>
</component>

Added:
trunk/main/planet/web/server/src/main/net/dpml/web/server/ServletContextHandler.java
===================================================================
---
trunk/main/planet/web/server/src/main/net/dpml/web/server/ServletContextHandler.java
2006-02-05 16:17:48 UTC (rev 1036)
+++
trunk/main/planet/web/server/src/main/net/dpml/web/server/ServletContextHandler.java
2006-02-05 16:57:18 UTC (rev 1037)
@@ -0,0 +1,104 @@
+/*
+ * 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.web.server;
+
+import java.util.ArrayList;
+
+import net.dpml.transit.util.PropertyResolver;
+
+import net.dpml.logging.Logger;
+
+import net.dpml.configuration.Configuration;
+import net.dpml.configuration.ConfigurationException;
+
+import org.mortbay.jetty.Handler;
+
+/**
+ * Servlet context handler.
+ */
+public class ServletContextHandler extends ResolvingContextHandler
+{
+ /**
+ * HTTP static resource vontext handler parameters.
+ */
+ public interface Context
+ {
+ /**
+ * Get the required HTTP server.
+ * @return the assigned http server
+ */
+ Server getServer();
+
+ /**
+ * Get the http context resource base. The value may contain symbolic
+ * property references and should resolve to a local directory.
+ *
+ * @return the resource base
+ */
+ String getResourceBase();
+
+ /**
+ * Get the context path under which the http context instance will
+ * be associated.
+ *
+ * @return the assigned context path
+ */
+ String getContextPath();
+ }
+
+ private int m_priority = 0;
+
+ public ServletContextHandler( Context context, Configuration config )
throws Exception
+ {
+ String base = context.getResourceBase();
+ super.setResourceBase( base );
+ String path = context.getContextPath();
+ super.setContextPath( path );
+ Handler handler = buildHandler( config );
+ super.setHandler( handler );
+ Server server = context.getServer();
+ server.addHandler( this );
+ }
+
+ private Handler buildHandler( Configuration config ) throws
ConfigurationException
+ {
+ Configuration servlets = config.getChild( "servlets" );
+ ArrayList servletList = new ArrayList();
+ Configuration[] servletConfigs = servlets.getChildren( "servlet" );
+ for( int i=0; i<servletConfigs.length; i++ )
+ {
+ Configuration servletConfig = servletConfigs[i];
+ String name = servletConfig.getAttribute( "name" );
+ String classname = servletConfig.getAttribute( "class" );
+ ServletHolder holder = new ServletHolder( name, classname );
+ servletList.add( holder );
+ }
+ ArrayList mappingList = new ArrayList();
+ Configuration mappings = config.getChild( "mappings" );
+ Configuration[] servletMappings = config.getChildren( "map" );
+ for( int i=0; i<servletMappings.length; i++ )
+ {
+ Configuration servletMap = servletMappings[i];
+ String name = servletMap.getAttribute( "servlet" );
+ String path = servletMap.getAttribute( "path" );
+ ServletMapping mapping = new ServletMapping( name, path );
+ mappingList.add( mapping );
+ }
+ ServletHolder[] servletArray = (ServletHolder[])
servletList.toArray( new ServletHolder[0] );
+ ServletMapping[] mappingArray = (ServletMapping[])
mappingList.toArray( new ServletMapping[0] );
+ return new ServletHandler( servletArray, mappingArray );
+ }
+}




  • r1037 - in trunk/main/planet/web: . server server/src/main/net/dpml/web/server, mcconnell at BerliOS, 02/05/2006

Archive powered by MHonArc 2.6.24.

Top of Page