View Javadoc

    1   package org.codehaus.xfire.server.http;
    2
    3   import org.codehaus.xfire.server.XFireServer;
    4   import org.codehaus.xfire.transport.http.XFireServlet;
    5   import org.mortbay.http.HttpContext;
    6   import org.mortbay.jetty.Server;
    7   import org.mortbay.jetty.servlet.ServletHandler;
    8   import org.mortbay.util.InetAddrPort;
    9
    10  /***
    11   * HTTP Server for XFire services.
    12   *
    13   * @version $Id$
    14   */
    15  public class XFireHttpServer
    16      implements XFireServer
    17  {
    18      // components
    19      private Server httpServer;
    20
    21      // properties
    22      private int port = 8081;
    23
    24      public void start()
    25          throws Exception
    26      {
    27          if (isStarted()) {
    28              return;
    29          }
    30
    31          httpServer = new Server();
    32          httpServer.addListener(new InetAddrPort(port));
    33
    34          HttpContext context = httpServer.getContext("/");
    35          context.setRequestLog(null);
    36
    37          ServletHandler handler = new ServletHandler();
    38          handler.addServlet("XFireServlet", "/*", XFireServlet.class.getName());
    39
    40          context.addHandler(handler);
    41
    42          httpServer.start();
    43      }
    44
    45      public void stop()
    46          throws Exception
    47      {
    48          if (isStarted())
    49          {
    50              httpServer.stop();
    51              httpServer = null;
    52          }
    53      }
    54
    55      public boolean isStarted()
    56      {
    57          return (httpServer != null) && httpServer.isStarted();
    58      }
    59
    60      public int getPort()
    61      {
    62          return port;
    63      }
    64
    65      public void setPort(int value)
    66      {
    67          port = value;
    68      }
    69
    70  }