hivemind-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From hls...@apache.org
Subject cvs commit: jakarta-hivemind/framework/src/java/org/apache/hivemind/servlet HiveMindFilter.java
Date Wed, 22 Dec 2004 00:11:02 GMT
hlship      2004/12/21 16:11:02

  Modified:    src/documentation/content/xdocs filter.xml
               .        status.xml
               framework/src/test/org/apache/hivemind/servlet
                        TestHiveMindFilter.java
               framework/src/java/org/apache/hivemind/servlet
                        HiveMindFilter.java
  Added:       framework/src/test/org/apache/hivemind/servlet
                        webinf-hivemodule.xml
  Log:
  Change HiveMindFilter to load WEB-INF/hivemodule.xml if present.
  
  Revision  Changes    Path
  1.5       +2 -1      jakarta-hivemind/src/documentation/content/xdocs/filter.xml
  
  Index: filter.xml
  ===================================================================
  RCS file: /home/cvs/jakarta-hivemind/src/documentation/content/xdocs/filter.xml,v
  retrieving revision 1.4
  retrieving revision 1.5
  diff -u -r1.4 -r1.5
  --- filter.xml	21 Oct 2004 12:35:56 -0000	1.4
  +++ filter.xml	22 Dec 2004 00:11:02 -0000	1.5
  @@ -30,7 +30,8 @@
   			>servlet filter</fork> that can automatically construct the HiveMind
   			Registry and ensure that end-of-request thread cleanup occurs.</p>
   		<p>The filter class is <link href="&apiroot;/servlet/HiveMindFilter.html">
  -			HiveMindFilter</link>. It constructs a standard HiveMind Registry when
  +			HiveMindFilter</link>. It constructs a standard HiveMind Registry (and includes
  +      WEB-INF/hivemodule.xml, if present) when
   			initialized, and will shutdown the Registry when the containing
   			application is undeployed.</p>
   		<p>Each request will be terminated with a call to the <link
  
  
  
  1.87      +3 -0      jakarta-hivemind/status.xml
  
  Index: status.xml
  ===================================================================
  RCS file: /home/cvs/jakarta-hivemind/status.xml,v
  retrieving revision 1.86
  retrieving revision 1.87
  diff -u -r1.86 -r1.87
  --- status.xml	21 Dec 2004 12:52:01 -0000	1.86
  +++ status.xml	22 Dec 2004 00:11:02 -0000	1.87
  @@ -124,6 +124,9 @@
        <action type="update" dev="HLS">
         Move ContextResource from Tapestry to HiveMind.
        </action>
  +     <action type="change" dev="HLS">
  +      Change HiveMindFilter load WEB-INF/hivemodule.xml if present.
  +     </action>
       </release>
   
      <release version="1.0" date="Sep 22 2004">
  
  
  
  1.4       +84 -13    jakarta-hivemind/framework/src/test/org/apache/hivemind/servlet/TestHiveMindFilter.java
  
  Index: TestHiveMindFilter.java
  ===================================================================
  RCS file: /home/cvs/jakarta-hivemind/framework/src/test/org/apache/hivemind/servlet/TestHiveMindFilter.java,v
  retrieving revision 1.3
  retrieving revision 1.4
  diff -u -r1.3 -r1.4
  --- TestHiveMindFilter.java	9 Sep 2004 16:06:46 -0000	1.3
  +++ TestHiveMindFilter.java	22 Dec 2004 00:11:02 -0000	1.4
  @@ -15,10 +15,12 @@
   package org.apache.hivemind.servlet;
   
   import java.io.IOException;
  +import java.net.URL;
   
   import javax.servlet.Filter;
   import javax.servlet.FilterChain;
   import javax.servlet.FilterConfig;
  +import javax.servlet.ServletContext;
   import javax.servlet.ServletException;
   import javax.servlet.ServletRequest;
   import javax.servlet.ServletResponse;
  @@ -37,7 +39,7 @@
   
   /**
    * Tests for {@link org.apache.hivemind.servlet.HiveMindFilter}.
  - *
  + * 
    * @author Howard Lewis Ship
    */
   public class TestHiveMindFilter extends HiveMindTestCase
  @@ -88,12 +90,12 @@
       {
   
           private Registry _registry;
  -        
  +
           public Registry getRegistry()
           {
               return _registry;
           }
  -        
  +
           protected Registry constructRegistry(FilterConfig config)
           {
               _registry = super.constructRegistry(config);
  @@ -104,16 +106,47 @@
   
       private static class RebuildRegistryChainFixture implements FilterChain
       {
  -        public void doFilter(ServletRequest request, ServletResponse response)
  -            throws IOException, ServletException
  +        public void doFilter(ServletRequest request, ServletResponse response) throws IOException,
  +                ServletException
           {
               HiveMindFilter.rebuildRegistry((HttpServletRequest) request);
           }
       }
   
  +    /** @since 1.1 */
  +
  +    public void testLoadsFromWebInf() throws Exception
  +    {
  +        MockControl contextc = newControl(ServletContext.class);
  +        ServletContext context = (ServletContext) contextc.getMock();
  +
  +        MockControl configc = newControl(FilterConfig.class);
  +        FilterConfig config = (FilterConfig) configc.getMock();
  +
  +        config.getServletContext();
  +        configc.setReturnValue(context);
  +
  +        URL url = getClass().getResource("webinf-hivemodule.xml");
  +
  +        context.getResource(HiveMindFilter.HIVE_MODULE_XML);
  +        contextc.setReturnValue(url, 2);
  +
  +        replayControls();
  +
  +        RegistryExposingHiveMindFilterFixture f = new RegistryExposingHiveMindFilterFixture();
  +
  +        f.init(config);
  +
  +        Registry r = f.getRegistry();
  +
  +        assertEquals("was here", r.expandSymbols("${kilroy}", null));
  +
  +        verifyControls();
  +    }
  +
       public void testBasic() throws Exception
       {
  -        FilterConfig filterConfig = (FilterConfig) newMock(FilterConfig.class);
  +        FilterConfig filterConfig = newFilterConfig();
   
           replayControls();
   
  @@ -127,8 +160,7 @@
   
           assertNotNull(r);
   
  -        ThreadEventNotifier t =
  -            (ThreadEventNotifier) r.getService(
  +        ThreadEventNotifier t = (ThreadEventNotifier) r.getService(
                   HiveMind.THREAD_EVENT_NOTIFIER_SERVICE,
                   ThreadEventNotifier.class);
   
  @@ -176,7 +208,17 @@
   
       public void testShutdown() throws Exception
       {
  -        FilterConfig filterConfig = (FilterConfig) newMock(FilterConfig.class);
  +        MockControl contextc = newControl(ServletContext.class);
  +        ServletContext context = (ServletContext) contextc.getMock();
  +
  +        MockControl configc = newControl(FilterConfig.class);
  +        FilterConfig filterConfig = (FilterConfig) configc.getMock();
  +
  +        filterConfig.getServletContext();
  +        configc.setReturnValue(context);
  +
  +        context.getResource(HiveMindFilter.HIVE_MODULE_XML);
  +        contextc.setReturnValue(null);
   
           replayControls();
   
  @@ -190,8 +232,8 @@
   
           assertNotNull(r);
   
  -        ShutdownCoordinator coordinator =
  -            (ShutdownCoordinator) r.getService(ShutdownCoordinator.class);
  +        ShutdownCoordinator coordinator = (ShutdownCoordinator) r
  +                .getService(ShutdownCoordinator.class);
   
           ShutdownListenerFixture l = new ShutdownListenerFixture();
   
  @@ -204,11 +246,17 @@
   
           request.setAttribute(HiveMindFilter.REQUEST_KEY, r);
   
  -		request.setAttribute(HiveMindFilter.REBUILD_REQUEST_KEY, Boolean.TRUE);
  +        request.setAttribute(HiveMindFilter.REBUILD_REQUEST_KEY, Boolean.TRUE);
   
           request.getAttribute(HiveMindFilter.REBUILD_REQUEST_KEY);
           requestControl.setReturnValue(Boolean.TRUE);
   
  +        filterConfig.getServletContext();
  +        configc.setReturnValue(context);
  +
  +        context.getResource(HiveMindFilter.HIVE_MODULE_XML);
  +        contextc.setReturnValue(null);
  +
           replayControls();
   
           f.doFilter(request, response, chain);
  @@ -218,6 +266,29 @@
           assertEquals(true, l.getDidShutdown());
       }
   
  +    private FilterConfig newFilterConfig() throws Exception
  +    {
  +        MockControl control = newControl(ServletContext.class);
  +
  +        ServletContext context = (ServletContext) control.getMock();
  +
  +        context.getResource(HiveMindFilter.HIVE_MODULE_XML);
  +        control.setReturnValue(null);
  +
  +        return newFilterConfig(context);
  +    }
  +
  +    private FilterConfig newFilterConfig(ServletContext context)
  +    {
  +        MockControl control = newControl(FilterConfig.class);
  +        FilterConfig config = (FilterConfig) control.getMock();
  +
  +        config.getServletContext();
  +        control.setReturnValue(context);
  +
  +        return config;
  +    }
  +
       public void testExceptionInInit() throws Exception
       {
           Filter f = new FailingHiveMindFilterFixture();
  @@ -283,4 +354,4 @@
           verifyControls();
       }
   
  -}
  +}
  \ No newline at end of file
  
  
  
  1.1                  jakarta-hivemind/framework/src/test/org/apache/hivemind/servlet/webinf-hivemodule.xml
  
  Index: webinf-hivemodule.xml
  ===================================================================
  <?xml version="1.0"?>
  <!-- 
     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.
  -->
  
  <module id="webinf.module" version="1.0.0">
  
    <contribution configuration-id="hivemind.ApplicationDefaults">
      <default symbol="kilroy" value="was here"/>
    </contribution>
  
  </module>
  
  
  
  1.15      +28 -0     jakarta-hivemind/framework/src/java/org/apache/hivemind/servlet/HiveMindFilter.java
  
  Index: HiveMindFilter.java
  ===================================================================
  RCS file: /home/cvs/jakarta-hivemind/framework/src/java/org/apache/hivemind/servlet/HiveMindFilter.java,v
  retrieving revision 1.14
  retrieving revision 1.15
  diff -u -r1.14 -r1.15
  --- HiveMindFilter.java	10 Nov 2004 13:26:22 -0000	1.14
  +++ HiveMindFilter.java	22 Dec 2004 00:11:02 -0000	1.15
  @@ -20,6 +20,7 @@
   import javax.servlet.Filter;
   import javax.servlet.FilterChain;
   import javax.servlet.FilterConfig;
  +import javax.servlet.ServletContext;
   import javax.servlet.ServletException;
   import javax.servlet.ServletRequest;
   import javax.servlet.ServletResponse;
  @@ -33,6 +34,7 @@
   import org.apache.hivemind.impl.DefaultClassResolver;
   import org.apache.hivemind.impl.RegistryBuilder;
   import org.apache.hivemind.impl.XmlModuleDescriptorProvider;
  +import org.apache.hivemind.util.ContextResource;
   
   /**
    * Servlet filter that constructs the Registry at startup. It ensures that each request
is properly
  @@ -54,6 +56,9 @@
   
       static final String REBUILD_REQUEST_KEY = "org.apache.hivemind.RebuildRegistry";
   
  +    /** @since 1.1 */
  +    static final String HIVE_MODULE_XML = "/WEB-INF/hivemodule.xml";
  +
       private FilterConfig _filterConfig;
   
       private Registry _registry;
  @@ -99,9 +104,32 @@
           RegistryBuilder builder = new RegistryBuilder();
   
           ClassResolver resolver = new DefaultClassResolver();
  +
           builder.addModuleDescriptorProvider(getModuleDescriptorProvider(resolver));
   
  +        addWebInfDescriptor(config.getServletContext(), resolver, builder);
  +
           return builder.constructRegistry(getRegistryLocale());
  +    }
  +
  +    /**
  +     * Invoked from {@link #constructRegistry(FilterConfig)}&nbsp; to add WEB-INF/hivemodule.xml
to
  +     * the registry, if it exists.
  +     * 
  +     * @since 1.1
  +     */
  +
  +    protected void addWebInfDescriptor(ServletContext context, ClassResolver resolver,
  +            RegistryBuilder builder)
  +    {
  +        ContextResource r = new ContextResource(context, HIVE_MODULE_XML);
  +
  +        if (r.getResourceURL() != null)
  +        {
  +            ModuleDescriptorProvider provider = new XmlModuleDescriptorProvider(resolver,
r);
  +
  +            builder.addModuleDescriptorProvider(provider);
  +        }
       }
   
       /**
  
  
  

---------------------------------------------------------------------
To unsubscribe, e-mail: hivemind-cvs-unsubscribe@jakarta.apache.org
For additional commands, e-mail: hivemind-cvs-help@jakarta.apache.org


Mime
View raw message