Top Description Inners Constructors Methods
org.eclipse.jetty.http

public Class HttpTester

extends Object
Class Inheritance
Imports
java.io.ByteArrayOutputStream, .IOException, .InputStream, .UncheckedIOException, java.nio.ByteBuffer, java.nio.channels.ReadableByteChannel, java.nio.charset.Charset, .StandardCharsets, org.eclipse.jetty.util.BufferUtil, .StringUtil

HTTP Testing helper class.

Example usage:

try (SocketChannel channel = SocketChannel.open(new InetSocketAddress("www.google.com",80)))
{
    HttpTester.Request request = HttpTester.newRequest();
    request.setMethod("POST");
    request.setURI("/search");
    request.setVersion(HttpVersion.HTTP_1_0);
    request.put(HttpHeader.HOST, "www.google.com");
    request.put("Content-Type", "application/x-www-form-urlencoded");
    request.setContent("q=jetty%20server");

    ByteBuffer output = request.generate();
    channel.write(output);

    HttpTester.Response response = HttpTester.parseResponse(channel);
    System.err.printf("%s %s %s%n", response.getVersion(), response.getStatus(), response.getReason());
    for (HttpField field : response)
    {
        System.err.printf("%s: %s%n", field.getName(), field.getValue());
    }
    System.err.printf("%n%s%n", response.getContent());
}

Nested and Inner Type Summary

Modifier and TypeClass and Description
public abstract static class
public abstract static class
public static class
public static class

Constructor Summary

AccessConstructor and Description
private

Method Summary

Modifier and TypeMethod and Description
public static HttpTester.Input
from(String string)

public static HttpTester.Input
public static HttpTester.Input
from(InputStream stream)

public static HttpTester.Input
public static HttpTester.Request
private static void
public static HttpTester.Response
public static HttpTester.Response
public static HttpTester.Request
public static HttpTester.Request
public static HttpTester.Request
public static HttpTester.Request
public static HttpTester.Request
public static HttpTester.Response
private static HttpTester.Response
parseResponse(String response, boolean head)

public static HttpTester.Response
private static HttpTester.Response
parseResponse(ByteBuffer response, boolean head)

public static HttpTester.Response
public static HttpTester.Response
public static HttpTester.Response
public static HttpTester.Response
parseResponse(HttpTester.Input input, boolean head)

Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAlltoStringwaitwaitwait

Constructor Detail

HttpTesterback to summary
private HttpTester()

Method Detail

fromback to summary
public static HttpTester.Input from(String string)
fromback to summary
public static HttpTester.Input from(ByteBuffer data)
fromback to summary
public static HttpTester.Input from(InputStream stream)
fromback to summary
public static HttpTester.Input from(ReadableByteChannel channel)
newRequestback to summary
public static HttpTester.Request newRequest()
parseback to summary
private static void parse(HttpTester.Input input, HttpParser parser) throws IOException
parseHeadResponseback to summary
public static HttpTester.Response parseHeadResponse(String response)
parseHeadResponseback to summary
public static HttpTester.Response parseHeadResponse(ByteBuffer response)
parseRequestback to summary
public static HttpTester.Request parseRequest(String request)
parseRequestback to summary
public static HttpTester.Request parseRequest(ByteBuffer buffer)
parseRequestback to summary
public static HttpTester.Request parseRequest(InputStream stream) throws IOException
parseRequestback to summary
public static HttpTester.Request parseRequest(ReadableByteChannel channel) throws IOException
parseRequestback to summary
public static HttpTester.Request parseRequest(HttpTester.Input input) throws IOException
parseResponseback to summary
public static HttpTester.Response parseResponse(String response)
parseResponseback to summary
private static HttpTester.Response parseResponse(String response, boolean head)
parseResponseback to summary
public static HttpTester.Response parseResponse(ByteBuffer response)
parseResponseback to summary
private static HttpTester.Response parseResponse(ByteBuffer response, boolean head)
parseResponseback to summary
public static HttpTester.Response parseResponse(InputStream stream) throws IOException
parseResponseback to summary
public static HttpTester.Response parseResponse(ReadableByteChannel channel) throws IOException
parseResponseback to summary
public static HttpTester.Response parseResponse(HttpTester.Input input) throws IOException
parseResponseback to summary
public static HttpTester.Response parseResponse(HttpTester.Input input, boolean head) throws IOException
org.eclipse.jetty.http back to summary

public abstract Class HttpTester.Input

extends Object
Class Inheritance

Field Summary

Modifier and TypeField and Description
protected final ByteBuffer
protected boolean
protected HttpParser

Constructor Summary

AccessConstructor and Description
public
pack-priv
Input(ByteBuffer buffer)

Method Summary

Modifier and TypeMethod and Description
public abstract int
public ByteBuffer
public boolean
public void
public HttpParser
Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAlltoStringwaitwaitwait

Field Detail

_bufferback to summary
protected final ByteBuffer _buffer
_eofback to summary
protected boolean _eof
_parserback to summary
protected HttpParser _parser

Constructor Detail

Inputback to summary
public Input()
Inputback to summary
pack-priv Input(ByteBuffer buffer)

Method Detail

fillBufferback to summary
public abstract int fillBuffer() throws IOException
getBufferback to summary
public ByteBuffer getBuffer()
isEOFback to summary
public boolean isEOF()
setHttpParserback to summary
public void setHttpParser(HttpParser parser)
takeHttpParserback to summary
public HttpParser takeHttpParser()
org.eclipse.jetty.http back to summary

public abstract Class HttpTester.Message

extends MutableHttpFields
implements HttpHandler
Class Inheritance
All Implemented Interfaces
org.eclipse.jetty.http.HttpParser.HttpHandler
Known Direct Subclasses
org.eclipse.jetty.http.HttpTester.Request, org.eclipse.jetty.http.HttpTester.Response

Field Summary

Modifier and TypeField and Description
pack-priv boolean
pack-priv ByteArrayOutputStream
pack-priv boolean
pack-priv HttpVersion

Constructor Summary

AccessConstructor and Description
public

Method Summary

Modifier and TypeMethod and Description
public void
badMessage(HttpException
the failure with the bad message information
failure
)

Overrides default org.eclipse.jetty.http.HttpParser.HttpHandler.badMessage.

Called to signal that a bad HTTP message has been received.
public boolean
public boolean
public void
earlyEOF()

Implements org.eclipse.jetty.http.HttpParser.HttpHandler.earlyEOF.

Called to signal that an EOF was received unexpectedly during the parsing of an HTTP message
public ByteBuffer
public String
public ByteBuffer
public byte[]
public abstract MetaData
public HttpVersion
public boolean
public boolean
public boolean
public boolean
public void
parsedHeader(HttpField
The field parsed
field
)

Implements org.eclipse.jetty.http.HttpParser.HttpHandler.parsedHeader.

This is the method called by parser when an HTTP Header name and value is found
public void
setContent(byte[] bytes)

public void
setContent(String content)

public void
public void
setVersion(String version)

public void
Inherited from org.eclipse.jetty.http.MutableHttpFields:
addaddasImmutableclearcomputeFieldcomputeFieldcomputeFieldequalsgetFieldgetFieldgetFieldhashCodeiteratorlistIteratorlistIteratorputputputputremoveremoveremovesizestreamtoString

Field Detail

_completeback to summary
pack-priv boolean _complete
_contentback to summary
pack-priv ByteArrayOutputStream _content
_earlyEOFback to summary
pack-priv boolean _earlyEOF
_versionback to summary
pack-priv HttpVersion _version

Constructor Detail

Messageback to summary
public Message()

Method Detail

badMessageback to summary
public void badMessage(HttpException failure)

Overrides default org.eclipse.jetty.http.HttpParser.HttpHandler.badMessage.

Doc from org.eclipse.jetty.http.HttpParser.HttpHandler.badMessage.

Called to signal that a bad HTTP message has been received.

Parameters
failure:HttpException

the failure with the bad message information

Annotations
@Override
contentback to summary
public boolean content(ByteBuffer ref)

Implements org.eclipse.jetty.http.HttpParser.HttpHandler.content.

Annotations
@Override
contentCompleteback to summary
public boolean contentComplete()

Implements org.eclipse.jetty.http.HttpParser.HttpHandler.contentComplete.

Annotations
@Override
earlyEOFback to summary
public void earlyEOF()

Implements org.eclipse.jetty.http.HttpParser.HttpHandler.earlyEOF.

Doc from org.eclipse.jetty.http.HttpParser.HttpHandler.earlyEOF.

Called to signal that an EOF was received unexpectedly during the parsing of an HTTP message

Annotations
@Override
generateback to summary
public ByteBuffer generate()
getContentback to summary
public String getContent()
getContentByteBufferback to summary
public ByteBuffer getContentByteBuffer()
getContentBytesback to summary
public byte[] getContentBytes()
getMetaDataback to summary
public abstract MetaData getMetaData()
getVersionback to summary
public HttpVersion getVersion()
headerCompleteback to summary
public boolean headerComplete()

Implements org.eclipse.jetty.http.HttpParser.HttpHandler.headerComplete.

Annotations
@Override
isCompleteback to summary
public boolean isComplete()
isEarlyEOFback to summary
public boolean isEarlyEOF()
messageCompleteback to summary
public boolean messageComplete()

Implements org.eclipse.jetty.http.HttpParser.HttpHandler.messageComplete.

Annotations
@Override
parsedHeaderback to summary
public void parsedHeader(HttpField field)

Implements org.eclipse.jetty.http.HttpParser.HttpHandler.parsedHeader.

Doc from org.eclipse.jetty.http.HttpParser.HttpHandler.parsedHeader.

This is the method called by parser when an HTTP Header name and value is found

Parameters
field:HttpField

The field parsed

Annotations
@Override
setContentback to summary
public void setContent(byte[] bytes)
setContentback to summary
public void setContent(String content)
setContentback to summary
public void setContent(ByteBuffer content)
setVersionback to summary
public void setVersion(String version)
setVersionback to summary
public void setVersion(HttpVersion version)
org.eclipse.jetty.http back to summary

public Class HttpTester.Request

extends Message
implements RequestHandler
Class Inheritance
All Implemented Interfaces
org.eclipse.jetty.http.HttpParser.RequestHandler, org.eclipse.jetty.http.HttpParser.HttpHandler

Field Summary

Modifier and TypeField and Description
private String
private String
Inherited from org.eclipse.jetty.http.HttpTester.Message:
_complete_content_earlyEOF_version

Constructor Summary

AccessConstructor and Description
public

Method Summary

Modifier and TypeMethod and Description
public MetaData.Request
public String
public String
public void
setHeader(String name, String value)

public void
setMethod(String method)

public void
public void
startRequest(String
The method
method
,
String
The raw bytes of the URI. These are copied into a ByteBuffer that will not be changed until this parser is reset and reused.
uri
,
HttpVersion
the http version in use
version
)

Implements org.eclipse.jetty.http.HttpParser.RequestHandler.startRequest.

This is the method called by parser when the HTTP request line is parsed
public String
toString()

Overrides org.eclipse.jetty.http.MutableHttpFields.toString.

Returns a string representation of the object.
Inherited from org.eclipse.jetty.http.HttpTester.Message:
badMessagecontentcontentCompleteearlyEOFgenerategetContentgetContentByteBuffergetContentBytesgetVersionheaderCompleteisCompleteisEarlyEOFmessageCompleteparsedHeadersetContentsetContentsetContentsetVersionsetVersion

Field Detail

_methodback to summary
private String _method
_uriback to summary
private String _uri

Constructor Detail

Requestback to summary
public Request()

Method Detail

getMetaDataback to summary
public MetaData.Request getMetaData()

Implements abstract org.eclipse.jetty.http.HttpTester.Message.getMetaData.

Annotations
@Override
getMethodback to summary
public String getMethod()
getURIback to summary
public String getURI()
setHeaderback to summary
public void setHeader(String name, String value)
setMethodback to summary
public void setMethod(String method)
setURIback to summary
public void setURI(String uri)
startRequestback to summary
public void startRequest(String method, String uri, HttpVersion version)

Implements org.eclipse.jetty.http.HttpParser.RequestHandler.startRequest.

Doc from org.eclipse.jetty.http.HttpParser.RequestHandler.startRequest.

This is the method called by parser when the HTTP request line is parsed

Parameters
method:String

The method

uri:String

The raw bytes of the URI. These are copied into a ByteBuffer that will not be changed until this parser is reset and reused.

version:HttpVersion

the http version in use

Annotations
@Override
toStringback to summary
public String toString()

Overrides org.eclipse.jetty.http.MutableHttpFields.toString.

Doc from java.lang.Object.toString.

Returns a string representation of the object.

Returns:String

a string representation of the object.

Annotations
@Override
org.eclipse.jetty.http back to summary

public Class HttpTester.Response

extends Message
implements ResponseHandler
Class Inheritance
All Implemented Interfaces
org.eclipse.jetty.http.HttpParser.ResponseHandler, org.eclipse.jetty.http.HttpParser.HttpHandler

Field Summary

Modifier and TypeField and Description
private String
private int
Inherited from org.eclipse.jetty.http.HttpTester.Message:
_complete_content_earlyEOF_version

Constructor Summary

AccessConstructor and Description
public

Method Summary

Modifier and TypeMethod and Description
public MetaData.Response
public String
public int
public void
startResponse(HttpVersion
the http version in use
version
,
int
the response status
status
,
String
the response reason phrase
reason
)

Implements org.eclipse.jetty.http.HttpParser.ResponseHandler.startResponse.

This is the method called by parser when the HTTP request line is parsed
public String
toString()

Overrides org.eclipse.jetty.http.MutableHttpFields.toString.

Returns a string representation of the object.
Inherited from org.eclipse.jetty.http.HttpTester.Message:
badMessagecontentcontentCompleteearlyEOFgenerategetContentgetContentByteBuffergetContentBytesgetVersionheaderCompleteisCompleteisEarlyEOFmessageCompleteparsedHeadersetContentsetContentsetContentsetVersionsetVersion

Field Detail

_reasonback to summary
private String _reason
_statusback to summary
private int _status

Constructor Detail

Responseback to summary
public Response()

Method Detail

getMetaDataback to summary
public MetaData.Response getMetaData()

Implements abstract org.eclipse.jetty.http.HttpTester.Message.getMetaData.

Annotations
@Override
getReasonback to summary
public String getReason()
getStatusback to summary
public int getStatus()
startResponseback to summary
public void startResponse(HttpVersion version, int status, String reason)

Implements org.eclipse.jetty.http.HttpParser.ResponseHandler.startResponse.

Doc from org.eclipse.jetty.http.HttpParser.ResponseHandler.startResponse.

This is the method called by parser when the HTTP request line is parsed

Parameters
version:HttpVersion

the http version in use

status:int

the response status

reason:String

the response reason phrase

Annotations
@Override
toStringback to summary
public String toString()

Overrides org.eclipse.jetty.http.MutableHttpFields.toString.

Doc from java.lang.Object.toString.

Returns a string representation of the object.

Returns:String

a string representation of the object.

Annotations
@Override