dblevins    2004/12/19 01:17:15

  Modified:    modules/core/src/java/org/openejb/server/httpd
                        HttpServer.java
  Added:       modules/core/src/java/org/openejb/server/httpd
                        HttpServerGBean.java
  Log:

  Added GBean wrappers for HttpServer and StandardServiceStack.  The wrappers 
have an addGbean static method which is great for keeping Gbean code out of 
tests.
  Added a test that tests the HttpServer as a GBean with a POJO stack and 
another test that does the entire stack as GBeans.
  Revamped the services in the stack to make better use of logging.
  
  Revision  Changes    Path
  1.2       +28 -6     
openejb/modules/core/src/java/org/openejb/server/httpd/HttpServer.java
  
  Index: HttpServer.java
  ===================================================================
  RCS file: 
/home/projects/openejb/scm/openejb/modules/core/src/java/org/openejb/server/httpd/HttpServer.java,v
  retrieving revision 1.1
  retrieving revision 1.2
  diff -u -r1.1 -r1.2
  --- HttpServer.java   17 Dec 2004 05:10:23 -0000      1.1
  +++ HttpServer.java   19 Dec 2004 06:17:15 -0000      1.2
  @@ -55,11 +55,16 @@
   
   import org.openejb.server.ServerService;
   import org.openejb.server.ServiceException;
  +import org.openejb.server.SocketService;
   import org.openejb.util.Logger;
   import org.openejb.OpenEJBException;
   import org.openejb.ContainerIndex;
   import org.apache.commons.logging.Log;
   import org.apache.commons.logging.LogFactory;
  +import org.apache.geronimo.gbean.GBeanInfoBuilder;
  +import org.apache.geronimo.gbean.GBeanInfo;
  +import org.apache.geronimo.gbean.GBeanLifecycle;
  +import org.apache.geronimo.gbean.WaitingException;
   
   /**
    * This is the main class for the web administration.  It takes care of the
  @@ -67,15 +72,20 @@
    *
    * @since 11/25/2001
    */
  -public class HttpServer implements ServerService {
  +public class HttpServer implements SocketService, ServerService, 
GBeanLifecycle {
   
  -    Log log = LogFactory.getLog(HttpServer.class);
  +    private static Log log = LogFactory.getLog(HttpServer.class);
  +    private HttpListener listener;
   
       public HttpServer(ContainerIndex index){
  -
       }
  +
       public HttpServer(){}
   
  +    public HttpServer(HttpListener listener){
  +        this.listener = listener;
  +    }
  +
       public void service(Socket socket) throws ServiceException, IOException {
           /**
            * The InputStream used to receive incoming messages from the client.
  @@ -126,6 +136,10 @@
           return "";
       }
   
  +    public HttpListener getListener() {
  +        return listener;
  +    }
  +
   
       /**
        * Initalizes this instance and takes care of starting things up
  @@ -160,7 +174,7 @@
               try {
                   response.writeMessage(out);
               } catch (Throwable t2) {
  -                System.out.println("Could not write response");
  +                log.error("Could not write response", t2);
               }
           }
   
  @@ -208,7 +222,15 @@
       }
   
       private HttpListener getHttpListener(String uri) {
  -        return null;
  +        return listener;
       }
   
  +    public void doStart() throws WaitingException, Exception {
  +    }
  +
  +    public void doStop() throws WaitingException, Exception {
  +    }
  +
  +    public void doFail() {
  +    }
   }
  
  
  
  1.1                  
openejb/modules/core/src/java/org/openejb/server/httpd/HttpServerGBean.java
  
  Index: HttpServerGBean.java
  ===================================================================
  /**
   * Redistribution and use of this software and associated documentation
   * ("Software"), with or without modification, are permitted provided
   * that the following conditions are met:
   *
   * 1. Redistributions of source code must retain copyright
   *    statements and notices.  Redistributions must also contain a
   *    copy of this document.
   *
   * 2. Redistributions in binary form must reproduce the
   *    above copyright notice, this list of conditions and the
   *    following disclaimer in the documentation and/or other
   *    materials provided with the distribution.
   *
   * 3. The name "OpenEJB" must not be used to endorse or promote
   *    products derived from this Software without prior written
   *    permission of The OpenEJB Group.  For written permission,
   *    please contact [EMAIL PROTECTED]
   *
   * 4. Products derived from this Software may not be called "OpenEJB"
   *    nor may "OpenEJB" appear in their names without prior written
   *    permission of The OpenEJB Group. OpenEJB is a registered
   *    trademark of The OpenEJB Group.
   *
   * 5. Due credit should be given to the OpenEJB Project
   *    (http://openejb.org/).
   *
   * THIS SOFTWARE IS PROVIDED BY THE OPENEJB GROUP AND CONTRIBUTORS
   * ``AS IS'' AND ANY EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT
   * NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
   * FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL
   * THE OPENEJB GROUP OR ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
   * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
   * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
   * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
   * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
   * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
   * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
   * OF THE POSSIBILITY OF SUCH DAMAGE.
   *
   * Copyright 2001 (C) The OpenEJB Group. All Rights Reserved.
   *
   * $Id: HttpServerGBean.java,v 1.1 2004/12/19 06:17:15 dblevins Exp $
   */
  
  package org.openejb.server.httpd;
  
  import java.net.Socket;
  import javax.management.ObjectName;
  
  import org.apache.geronimo.gbean.GBeanData;
  import org.apache.geronimo.gbean.GBeanInfo;
  import org.apache.geronimo.gbean.GBeanInfoBuilder;
  import org.apache.geronimo.kernel.GBeanAlreadyExistsException;
  import org.apache.geronimo.kernel.GBeanNotFoundException;
  import org.apache.geronimo.kernel.Kernel;
  import org.apache.geronimo.kernel.jmx.JMXUtil;
  
  public class HttpServerGBean {
  
      public static final GBeanInfo GBEAN_INFO;
  
      static {
          GBeanInfoBuilder infoFactory = new GBeanInfoBuilder(HttpServer.class);
  
          infoFactory.addReference("Listener", HttpListener.class);
          infoFactory.addOperation("service", new Class[]{Socket.class});
          infoFactory.setConstructor(new String[]{"Listener"});
  
          GBEAN_INFO = infoFactory.getBeanInfo();
      }
  
      public static GBeanInfo getGBeanInfo() {
          return GBEAN_INFO;
      }
  
      public static ObjectName addGBean(Kernel kernel, String name, ObjectName 
listener) throws GBeanAlreadyExistsException, GBeanNotFoundException {
          ClassLoader classLoader = HttpServer.class.getClassLoader();
          ObjectName SERVICE_NAME = 
JMXUtil.getObjectName("openejb:type=HttpServer,name=" + name);
  
          GBeanData gbean = new GBeanData(SERVICE_NAME, 
HttpServerGBean.GBEAN_INFO);
          gbean.setReferencePattern("Listener", listener);
  
          kernel.loadGBean(gbean, classLoader);
          kernel.startGBean(SERVICE_NAME);
          return SERVICE_NAME;
      }
  }
  
  
  

Reply via email to