## org.mortbay.jetty.testing
Class HttpTester

    java.lang.Object
      org.mortbay.jetty.testing.HttpTester

    public class HttpTester

extends java.lang.Object

Test support class. Assist with parsing and generating HTTP requests and responses.

          HttpTester tester = new HttpTester();

          tester.parse(
              "GET /uri HTTP/1.1\r\n"+
              "Host: fakehost\r\n"+
              "Content-Length: 10\r\n" +
              "\r\n");

          System.err.println(tester.getMethod());
          System.err.println(tester.getURI());
          System.err.println(tester.getVersion());
          System.err.println(tester.getHeader("Host"));
          System.err.println(tester.getContent());

Author:
  gregw
See Also:
  `ServletTester`

Field Summary
`protected HttpFields` `_fields`
`protected byte[]` `_genContent`
`protected java.lang.String` `_method`
`protected ByteArrayOutputStream2` `_parsedContent`
`protected java.lang.String` `_reason`
`protected int` `_status`
`protected java.lang.String` `_uri`
`protected java.lang.String` `_version`

Constructor Summary
`HttpTester()`
`HttpTester(java.lang.String charset)`

Method Summary
`void` `addDateHeader(java.lang.String name, long date)`
`void` `addHeader(java.lang.String name, java.lang.String value)`
`void` `addLongHeader(java.lang.String name, long value)`
`void` `addSetCookie(javax.servlet.http.Cookie cookie)`
`java.lang.String` `generate()`
`java.lang.String` `getCharacterEncoding()`
`java.lang.String` `getContent()`
`java.lang.String` `getContentType()`
`long` `getDateHeader(java.lang.String name)`
`java.lang.String` `getHeader(java.lang.String name)`
`java.util.Enumeration` `getHeaderNames()`
`java.util.Enumeration` `getHeaderValues(java.lang.String name)`
`long` `getLongHeader(java.lang.String name)`
`java.lang.String` `getMethod()`
`java.lang.String` `getReason()`
`int` `getStatus()`
`java.lang.String` `getURI()`
`java.lang.String` `getVersion()`
`java.lang.String` `parse(java.lang.String rawHTTP)` Parse one HTTP request or response
`void` `removeHeader(java.lang.String name)`
`void` `reset()`
`void` `setContent(java.lang.String content)`
`void` `setDateHeader(java.lang.String name, long date)`
`void` `setHeader(java.lang.String name, java.lang.String value)`
`void` `setLongHeader(java.lang.String name, long value)`
`void` `setMethod(java.lang.String method)`
`void` `setReason(java.lang.String reason)`
`void` `setStatus(int status)`
`void` `setURI(java.lang.String uri)`
`void` `setVersion(java.lang.String version)`

Methods inherited from class java.lang.Object
`clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait`

Field Detail

### _fields

    protected HttpFields _fields

### _method

    protected java.lang.String _method

### _uri

    protected java.lang.String _uri

### _version

    protected java.lang.String _version

### _status

    protected int _status

### _reason

    protected java.lang.String _reason

### _parsedContent

    protected ByteArrayOutputStream2 _parsedContent

### _genContent

    protected byte[] _genContent

Constructor Detail

### HttpTester

    public HttpTester()

### HttpTester

    public HttpTester(java.lang.String charset)

Method Detail

### reset

    public void reset()

### parse

    public java.lang.String parse(java.lang.String rawHTTP)
                           throws java.io.IOException

  Parse one HTTP request or response

  Parameters:
    `rawHTTP` - Raw HTTP to parse
  Returns:
    Any unparsed data in the rawHTTP (eg pipelined requests)
  Throws:
    `java.io.IOException`

### generate

    public java.lang.String generate()
                              throws java.io.IOException

  Throws:
    `java.io.IOException`

### getMethod

    public java.lang.String getMethod()

  Returns:
    the method

### setMethod

    public void setMethod(java.lang.String method)

  Parameters:
    `method` - the method to set

### getReason

    public java.lang.String getReason()

  Returns:
    the reason

### setReason

    public void setReason(java.lang.String reason)

  Parameters:
    `reason` - the reason to set

### getStatus

    public int getStatus()

  Returns:
    the status

### setStatus

    public void setStatus(int status)

  Parameters:
    `status` - the status to set

### getURI

    public java.lang.String getURI()

  Returns:
    the uri

### setURI

    public void setURI(java.lang.String uri)

  Parameters:
    `uri` - the uri to set

### getVersion

    public java.lang.String getVersion()

  Returns:
    the version

### setVersion

    public void setVersion(java.lang.String version)

  Parameters:
    `version` - the version to set

### getContentType

    public java.lang.String getContentType()

### getCharacterEncoding

    public java.lang.String getCharacterEncoding()

### addHeader

    public void addHeader(java.lang.String name,
                          java.lang.String value)
                   throws java.lang.IllegalArgumentException

  Parameters:
    `name` -
    `value` -
  Throws:
    `java.lang.IllegalArgumentException`
  See Also:
    `HttpFields.add(java.lang.String, java.lang.String)`

### addDateHeader

    public void addDateHeader(java.lang.String name,
                              long date)

  Parameters:
    `name` -
    `date` -
  See Also:
    `HttpFields.addDateField(java.lang.String, long)`

### addLongHeader

    public void addLongHeader(java.lang.String name,
                              long value)

  Parameters:
    `name` -
    `value` -
  See Also:
    `HttpFields.addLongField(java.lang.String, long)`

### addSetCookie

    public void addSetCookie(javax.servlet.http.Cookie cookie)

  Parameters:
    `cookie` -
  See Also:
    `HttpFields.addSetCookie(javax.servlet.http.Cookie)`

### getDateHeader

    public long getDateHeader(java.lang.String name)

  Parameters:
    `name` -
  Returns:
  See Also:
    `HttpFields.getDateField(java.lang.String)`

### getHeaderNames

    public java.util.Enumeration getHeaderNames()

  Returns:
  See Also:
    `HttpFields.getFieldNames()`

### getLongHeader

    public long getLongHeader(java.lang.String name)
                       throws java.lang.NumberFormatException

  Parameters:
    `name` -
  Returns:
  Throws:
    `java.lang.NumberFormatException`
  See Also:
    `HttpFields.getLongField(java.lang.String)`

### getHeader

    public java.lang.String getHeader(java.lang.String name)

  Parameters:
    `name` -
  Returns:
  See Also:
    `HttpFields.getStringField(java.lang.String)`

### getHeaderValues

    public java.util.Enumeration getHeaderValues(java.lang.String name)

  Parameters:
    `name` -
  Returns:
  See Also:
    `HttpFields.getValues(java.lang.String)`

### setHeader

    public void setHeader(java.lang.String name,
                          java.lang.String value)

  Parameters:
    `name` -
    `value` -
  See Also:
    `HttpFields.put(java.lang.String, java.lang.String)`

### setDateHeader

    public void setDateHeader(java.lang.String name,
                              long date)

  Parameters:
    `name` -
    `date` -
  See Also:
    `HttpFields.putDateField(java.lang.String, long)`

### setLongHeader

    public void setLongHeader(java.lang.String name,
                              long value)

  Parameters:
    `name` -
    `value` -
  See Also:
    `HttpFields.putLongField(java.lang.String, long)`

### removeHeader

    public void removeHeader(java.lang.String name)

  Parameters:
    `name` -
  See Also:
    `HttpFields.remove(java.lang.String)`

### getContent

    public java.lang.String getContent()

### setContent

    public void setContent(java.lang.String content)

Copyright © 1995-2010 Mort Bay Consulting. All Rights Reserved.