JettyOnePortSocketListenerTest xref

    1   /***
    2    *
    3    * Copyright 2004 Hiram Chirino
    4    *
    5    * Licensed under the Apache License, Version 2.0 (the "License");
    6    * you may not use this file except in compliance with the License.
    7    * You may obtain a copy of the License at
    8    *
    9    * http://www.apache.org/licenses/LICENSE-2.0
    10   *
    11   * Unless required by applicable law or agreed to in writing, software
    12   * distributed under the License is distributed on an "AS IS" BASIS,
    13   * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
    14   * See the License for the specific language governing permissions and
    15   * limitations under the License.
    16   *
    17   **/
    18  package org.activeio.oneport;
    19
    20  import org.activeio.oneport.JettyOnePortSocketListener;
    21  import org.mortbay.http.HttpContext;
    22  import org.mortbay.http.HttpServer;
    23  import org.mortbay.jetty.servlet.ServletHandler;
    24
    25  import EDU.oswego.cs.dl.util.concurrent.Slot;
    26
    27  /***
    28   *
    29   */
    30  public class JettyOnePortSocketListenerTest extends OnePortAsyncChannelServerTest {
    31
    32      static public Slot staticResultSlot;
    33
    34      private HttpServer jetty;
    35
    36      protected void startHTTPServer() throws Exception {
    37          staticResultSlot = resultSlot;
    38
    39          // Create the server
    40          jetty = new HttpServer();
    41
    42          // Create a port listener
    43          JettyOnePortSocketListener listener = new JettyOnePortSocketListener(server);
    44          jetty.addListener(listener);
    45
    46          // Create a context
    47          HttpContext context = new HttpContext();
    48          context.setContextPath("/");
    49          jetty.addContext(context);
    50
    51          // Create a servlet container
    52          ServletHandler servlets = new ServletHandler();
    53          context.addHandler(servlets);
    54
    55          // Map a servlet onto the container
    56          servlets.addServlet("Test", "*", TestServlet.class.getName());
    57
    58          // Start the http server
    59          jetty.start();
    60      }
    61
    62      protected void stopHTTPServer() throws InterruptedException {
    63          jetty.stop();
    64      }
    65  }