SimpleHttpMonitor

public class SimpleHttpMonitor implements Runnable

The SimpleHttpMonitor is a very very simple HTTP monitor used for testing.

Fields

CONTENT_LENGTH

public static final String CONTENT_LENGTH

CONTENT_TYPE

public static final String CONTENT_TYPE

CRLF

protected static final byte[] CRLF

HD_CT_LEN

protected static final byte[] HD_CT_LEN

HD_CT_TYPE

protected static final byte[] HD_CT_TYPE

HD_SERVIER

protected static final byte[] HD_SERVIER

STATUS_200

protected static final byte[] STATUS_200

Constructors

SimpleHttpMonitor

public SimpleHttpMonitor(int port)

Explicit Constructor.

Parameters:
  • port – The port number listening HTTP request.

Methods

getContentLength

public int getContentLength()
Returns:The content length of last HTTP request.

getContentStream

public InputStream getContentStream()

Get the input stream containing the HTTP body content from the last HTTP request. It is different from getInputStream() because that returns the stream containing (HTTP header + HTTP body content).

Returns:the input stream containing the HTTP body content from the last HTTP request.

getContentType

public String getContentType()
Returns:The content type of last HTTP request

getHeaders

public Map getHeaders()
Returns:Get the last HTTP request header monitored.

getInputStream

public InputStream getInputStream()
Returns:Get the last HTTP request content.

onAccept

protected void onAccept(Socket s)

[@EVENT] This method is invoked when a socket connection is accepted.

onRequest

protected void onRequest(InputStream ins)

[@EVENT] This method is invoked after the socket is accepted.

onResponse

protected void onResponse(OutputStream os)

[@EVENT] This method is invoked when the HTTP content has been parsed, and now ready to write content to socket.

onResponseLength

protected int onResponseLength()

[@EVENT] This method is invoked before calling onResponse. It ask the sub-class implementation for the content length of this response. Default return 0.

run

public void run()

The thread execution method.

start

public void start()

Start the HTTP monitor.

stop

public void stop()

Stop the HTTP monitor.