avalon-cvs mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From mcconn...@apache.org
Subject cvs commit: avalon/merlin/facilities/http/test/src/java/test/http Counter.java DefaultCounter.java TestServlet.java
Date Tue, 03 Feb 2004 14:49:53 GMT
mcconnell    2004/02/03 06:49:53

  Modified:    merlin/facilities/http README.TXT
               merlin/facilities/http/test/src/java/test/http
                        TestServlet.java
  Added:       merlin/facilities/http/test/src/java/test/http Counter.java
                        DefaultCounter.java
  Log:
  Make the test servlet more visibly a component.
  
  Revision  Changes    Path
  1.3       +1 -22     avalon/merlin/facilities/http/README.TXT
  
  Index: README.TXT
  ===================================================================
  RCS file: /home/cvs/avalon/merlin/facilities/http/README.TXT,v
  retrieving revision 1.2
  retrieving revision 1.3
  diff -u -r1.2 -r1.3
  --- README.TXT	2 Feb 2004 11:31:37 -0000	1.2
  +++ README.TXT	3 Feb 2004 14:49:52 -0000	1.3
  @@ -4,26 +4,5 @@
     $ cd merlin\facilities\http\test
     $ merlin -execute -kernel conf\kernel.xml conf\test.xml
   
  -All this does is launch (a) a http server as a facility and (b) a model listener (defined
under kernel.xml).  The model listener needs to be updated to check if a component is a servlet
and if so, get the context path that it should be added to - then register the component with
the server.  
  +The point you we browser to http://localhost:8080/test/hello
   
  -Lots of little things still to be done - like:
  -
  -  (a) servlet recognition
  -  (b) how do we associate a context at the <compoent> directive level
  -  (c) servlet/component registration
  -
  -Update:
  -
  -  Recognition - the listener now recognizes components that 
  -  are themselves Servlets.  One issue that came up was the 
  -  availability of the servlet apis - the workaround was to 
  -  update the kernel factory meta to include servlet api in the 
  -  general api for merlin - but we will need a better solution
  -  in the long term to support comman api addition (perhaps 
  -  using a AVALON_HOME/lib as a location for common apis).
  -
  -Next Steps:
  -
  -  Assiciation with the server and context stuff.
  -
  -Steve.
  
  
  
  1.4       +50 -3     avalon/merlin/facilities/http/test/src/java/test/http/TestServlet.java
  
  Index: TestServlet.java
  ===================================================================
  RCS file: /home/cvs/avalon/merlin/facilities/http/test/src/java/test/http/TestServlet.java,v
  retrieving revision 1.3
  retrieving revision 1.4
  diff -u -r1.3 -r1.4
  --- TestServlet.java	2 Feb 2004 21:10:52 -0000	1.3
  +++ TestServlet.java	3 Feb 2004 14:49:52 -0000	1.4
  @@ -19,6 +19,13 @@
   
   import java.io.IOException;
   import java.io.PrintWriter;
  +import java.util.Date;
  +
  +import org.apache.avalon.framework.logger.LogEnabled;
  +import org.apache.avalon.framework.logger.Logger;
  +import org.apache.avalon.framework.service.ServiceManager;
  +import org.apache.avalon.framework.service.Serviceable;
  +import org.apache.avalon.framework.service.ServiceException;
   
   import javax.servlet.ServletException;
   import javax.servlet.http.HttpServlet;
  @@ -30,13 +37,47 @@
    * and registration of the kernel base URL under the servlet 
    * context using the key.
    * 
  - * @avalon.component name="test" lifestyle="transient"
  + * @avalon.component name="test" lifestyle="thread"
    * @author <a href="mailto:mcconnell@apache.org">Stephen McConnell</a>
    * @avalon.service type="javax.servlet.Servlet"
    */
  -public class TestServlet extends HttpServlet
  +public class TestServlet extends HttpServlet implements LogEnabled, Serviceable
   {
       //----------------------------------------------------------
  +    // state
  +    //----------------------------------------------------------
  +
  +    private Logger m_logger;
  +
  +    private int m_count;
  +
  +    private Counter m_counter;
  +
  +    //----------------------------------------------------------
  +    // lifecycle
  +    //----------------------------------------------------------
  +
  +    public void enableLogging( Logger logger )
  +    {
  +        m_logger = logger;
  +    }
  +
  +    protected Logger getLogger()
  +    {
  +        return m_logger;
  +    }
  +
  +   /**
  +    * Service the servlet.
  +    * @param manager the service manager
  +    * @avalon.dependency type="test.http.Counter" key="counter"
  +    */
  +    public void service( ServiceManager manager ) throws ServiceException
  +    {
  +        m_counter = (Counter) manager.lookup( "counter" );
  +    }
  +
  +    //----------------------------------------------------------
       // Servlet
       //----------------------------------------------------------
   
  @@ -73,6 +114,12 @@
                         HttpServletResponse response)
         throws IOException, ServletException {
   
  +        int count = m_counter.increment();
  +        
  +        m_count++;
  +
  +        getLogger().info( "get " + new Date() + ", (" + m_count + "/" + count + ")" );
  +
           response.setContentType("text/html");
           PrintWriter writer = response.getWriter();
           String context = request.getContextPath();
  @@ -82,7 +129,7 @@
           writer.println("</head>");
           writer.println("<body>" );
           writer.println("<hr/>");
  -        writer.println("<h3>Hello.</h3>");
  +        writer.println("<h3>Hello (" + m_count + "/" + count + ").</h3>");
           writer.println("<hr/>");
           writer.println("<p>I'm an Avalon component.<br/>");
           writer.println("I'm also a Servlet.<br/>");
  
  
  
  1.1                  avalon/merlin/facilities/http/test/src/java/test/http/Counter.java
  
  Index: Counter.java
  ===================================================================
  /* 
   * Copyright 2004 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.
   */
  
  package test.http;
  
  import java.io.IOException;
  import java.io.PrintWriter;
  import java.util.Date;
  
  import org.apache.avalon.framework.logger.LogEnabled;
  import org.apache.avalon.framework.logger.Logger;
  
  import javax.servlet.ServletException;
  import javax.servlet.http.HttpServlet;
  import javax.servlet.http.HttpServletRequest;
  import javax.servlet.http.HttpServletResponse;
  
  /**
   * @author <a href="mailto:mcconnell@apache.org">Stephen McConnell</a>
   */
  public interface Counter
  {
     /**
      * Return an incremented value.
      * @return a incremented value
      */
      int increment();
  
  }
  
  
  
  1.1                  avalon/merlin/facilities/http/test/src/java/test/http/DefaultCounter.java
  
  Index: DefaultCounter.java
  ===================================================================
  /* 
   * Copyright 2004 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.
   */
  
  package test.http;
  
  import java.io.IOException;
  import java.io.PrintWriter;
  import java.util.Date;
  
  import org.apache.avalon.framework.logger.LogEnabled;
  import org.apache.avalon.framework.logger.Logger;
  
  import javax.servlet.ServletException;
  import javax.servlet.http.HttpServlet;
  import javax.servlet.http.HttpServletRequest;
  import javax.servlet.http.HttpServletResponse;
  
  /**
   * A singleton component that increments a counter.
   * 
   * @avalon.component name="test" lifestyle="singleton"
   * @author <a href="mailto:mcconnell@apache.org">Stephen McConnell</a>
   * @avalon.service type="test.http.Counter"
   */
  public class DefaultCounter implements Counter
  {
      //----------------------------------------------------------
      // state
      //----------------------------------------------------------
  
      private int m_count = 0;
  
      //----------------------------------------------------------
      // Counter
      //----------------------------------------------------------
  
      public int increment()
      {
          m_count++;
          return m_count;
      }
  }
  
  
  

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


Mime
View raw message