View Javadoc

    1   package org.codehaus.xfire.transport.http;
    2
    3   import java.io.IOException;
    4
    5   import javax.servlet.ServletException;
    6   import javax.servlet.http.HttpServlet;
    7   import javax.servlet.http.HttpServletRequest;
    8   import javax.servlet.http.HttpServletResponse;
    9
    10  import org.codehaus.xfire.XFire;
    11  import org.codehaus.xfire.XFireFactory;
    12
    13  /***
    14   * A servlet which processes incoming XFire requests.
    15   * It delegates to the XFireController to process the request.
    16   *
    17   * @author <a href="mailto:dan@envoisolutions.com">Dan Diephouse </a>
    18   * @since Feb 13, 2004
    19   */
    20  public class XFireServlet
    21      extends HttpServlet
    22  {
    23      private XFire xfire;
    24
    25      private XFireServletController controller;
    26
    27      public void init()
    28          throws ServletException
    29      {
    30          super.init();
    31          xfire = createXFire();
    32          controller = createController();
    33      }
    34
    35      /***
    36       * Get the xfire instance. if it hasn't been created, then {@link #createXFire()} will be called.
    37       */
    38      public XFire getXFire() throws ServletException
    39      {
    40          if (xfire == null) xfire = createXFire();
    41
    42          return xfire;
    43      }
    44
    45      /***
    46       * Get the xfire controller. if it hasn't been created, then {@link #createController()} will be called.
    47       */
    48      public XFireServletController getController() throws ServletException
    49      {
    50          if(controller == null) controller = createController();
    51          return controller;
    52      }
    53
    54      public XFire createXFire()
    55          throws ServletException
    56      {
    57          try
    58          {
    59              XFireFactory factory = XFireFactory.newInstance();
    60              return factory.getXFire();
    61          }
    62          catch (Exception e)
    63          {
    64              throw new ServletException("Couldn't start XFire.", e);
    65          }
    66      }
    67
    68      public XFireServletController createController()
    69          throws ServletException
    70      {
    71          return new XFireServletController(xfire);
    72      }
    73
    74      /***
    75       * Delegates to {@link XFireServletController#doService(javax.servlet.http.HttpServletRequest, javax.servlet.http.HttpServletResponse)}.
    76       */
    77      protected void doGet(HttpServletRequest request,
    78                           HttpServletResponse response)
    79          throws ServletException, IOException
    80      {
    81          controller.doService(request, response);
    82      }
    83
    84      /***
    85       * Delegates to {@link XFireServletController#doService(javax.servlet.http.HttpServletRequest, javax.servlet.http.HttpServletResponse)}.
    86       */
    87      protected void doPost(HttpServletRequest req, HttpServletResponse res)
    88          throws ServletException, IOException
    89      {
    90          controller.doService(req, res);
    91      }
    92  }