View Javadoc

    1   package org.codehaus.xfire.client.http;
    2
    3   import java.io.OutputStream;
    4
    5   import javax.xml.stream.XMLStreamException;
    6   import javax.xml.stream.XMLStreamReader;
    7   import javax.xml.stream.XMLStreamWriter;
    8
    9   import org.codehaus.xfire.client.ClientHandler;
    10  import org.codehaus.xfire.fault.XFireFault;
    11
    12  /***
    13   * A client which invokes REST style services.
    14   *
    15   * @author <a href="mailto:dan@envoisolutions.com">Dan Diephouse</a>
    16   * @since Oct 26, 2004
    17   */
    18  public class RestHttpClient
    19      extends AbstractHttpClient
    20  {
    21      private ClientHandler handler;
    22
    23      /***
    24       * Create a REST client.
    25       * @param bodyHandler The handler for the XML messages.
    26       * @param url The url to invoke.
    27       */
    28      public RestHttpClient(ClientHandler bodyHandler, String url)
    29      {
    30          super();
    31          this.handler = bodyHandler;
    32          setUrl( url );
    33      }
    34
    35      protected void writeRequest(OutputStream out)
    36      {
    37          if ( handler.hasRequest() )
    38              super.writeRequest(out);
    39      }
    40
    41      protected void writeRequest(XMLStreamWriter writer)
    42          throws XMLStreamException
    43      {
    44          writer.writeStartDocument();
    45          handler.writeRequest(writer);
    46          writer.writeEndDocument();
    47
    48          writer.close();
    49      }
    50
    51      protected void readResponse(XMLStreamReader reader)
    52          throws XMLStreamException, XFireFault
    53      {
    54          handler.handleResponse(reader);
    55      }
    56  }