com.planet_ink.coffee_mud.Common.interfaces
Interface HttpClient

All Superinterfaces:
java.lang.Cloneable, CMCommon, CMObject, java.lang.Comparable<CMObject>, Tickable
All Known Implementing Classes:
DefaultHttpClient

public interface HttpClient
extends Tickable, CMCommon

A simple utility for making HTTP requests, which is implemented as a builder-type object.


Nested Class Summary
static class HttpClient.Method
          HTTP Methods that are acceptable
 
Field Summary
 
Fields inherited from interface com.planet_ink.coffee_mud.core.interfaces.Tickable
STATUS_AFFECT, STATUS_ALIVE, STATUS_BEHAVIOR, STATUS_CLASS, STATUS_DEAD, STATUS_END, STATUS_FIGHT, STATUS_MISC, STATUS_MISC2, STATUS_MISC3, STATUS_MISC4, STATUS_MISC5, STATUS_MISC6, STATUS_MISC7, STATUS_NOT, STATUS_OTHER, STATUS_RACE, STATUS_REBIRTH, STATUS_SCRIPT, STATUS_START, STATUS_WEATHER, TICKID_AREA, TICKID_BEAMWEAPON, TICKID_CLAN, TICKID_CLANITEM, TICKID_DEADBODY_DECAY, TICKID_ELECTRONICS, TICKID_EMAIL, TICKID_EXIT_BEHAVIOR, TICKID_EXIT_REOPEN, TICKID_ITEM_BEHAVIOR, TICKID_ITEM_BOUNCEBACK, TICKID_LIGHT_FLICKERS, TICKID_LIVEAUCTION, TICKID_LONGERMASK, TICKID_MISCELLANEOUS, TICKID_MOB, TICKID_PROPERTY_SPECIAL, TICKID_QUEST, TICKID_READYTOSTOP, TICKID_ROOM_BEHAVIOR, TICKID_ROOM_ITEM_REJUV, TICKID_SOLITARYMASK, TICKID_SPECIALCOMBAT, TICKID_SPECIALMANEUVER, TICKID_SPELL_AFFECT, TICKID_SUPPORT, TICKID_TIMEAUCTION, TICKID_TRAP_DESTRUCTION, TICKID_TRAP_RESET
 
Method Summary
 HttpClient body(byte[] body)
          An http request builder method that sets the body to send.
 HttpClient body(java.lang.String body)
          An http request builder method that sets the body to send.
 HttpClient connectTimeout(int ms)
          An http request builder method that sets the maximum number of milliseconds that the reader will remain idle waiting for a connection to occur.
 HttpClient doGet(java.lang.String url)
          An http request builder method that causes this request to occur as a GET
 HttpClient doHead(java.lang.String url)
          An http request builder method that causes this request to occur as a HEAD
 HttpClient doRequest(java.lang.String url)
          An http request builder method that causes this request to occur.
 void finished()
          Closes this connection, entirely.
 java.util.Map<java.lang.String,java.util.List<java.lang.String>> getHeaders(java.lang.String urlStr)
          Calls GET on the given url, waiting no more than a few seconds for connection, and returns the headers from the response.
 byte[] getRawUrl(java.lang.String urlStr)
          Reads the simple raw return content from a given url and returns it as a byte array.
 byte[] getRawUrl(java.lang.String urlStr, int maxLength, int readTimeout)
          Reads the simple raw return content from a given url and returns it as a byte array.
 byte[] getRawUrl(java.lang.String urlStr, java.lang.String cookieStr)
          Reads the simple raw return content from a given url and returns it as a byte array.
 byte[] getRawUrl(java.lang.String urlStr, java.lang.String cookieStr, int maxLength, int readTimeout)
          Reads the simple raw return content from a given url and returns it as a byte array.
 java.io.InputStream getResponseBody()
          Returns an input stream to the body of the response to this request.
 int getResponseCode()
          Returns the http status code from the response
 int getResponseContentLength()
          Gets the length of the body of the response to this request.
 java.util.Map<java.lang.String,java.util.List<java.lang.String>> getResponseHeaders()
          Returns the headers in the response to this request
 HttpClient header(java.lang.String key, java.lang.String value)
          An http request builder method that adds a header.
 HttpClient maxReadBytes(int bytes)
          An http request builder method that sets the maximum number of bytes that can be read by the request processor.
 HttpClient method(HttpClient.Method meth)
          An http request builder method that sets the http method
 HttpClient readTimeout(int ms)
          An http request builder method that sets the maximum number of milliseconds that the reader will remain idle waiting for a byte of data.
 HttpClient reset()
          An http request builder method that resets the client obj so that the connection can be used for another request.
 
Methods inherited from interface com.planet_ink.coffee_mud.core.interfaces.Tickable
getTickStatus, name, tick
 
Methods inherited from interface com.planet_ink.coffee_mud.core.interfaces.CMObject
copyOf, ID, initializeClass, newInstance
 
Methods inherited from interface java.lang.Comparable
compareTo
 

Method Detail

getRawUrl

byte[] getRawUrl(java.lang.String urlStr,
                 int maxLength,
                 int readTimeout)
Reads the simple raw return content from a given url and returns it as a byte array. Good for getting files or web pages! Returns null if any error occurs, including a 404, timeouts, or read failures.

Parameters:
urlStr - the url to fetch
maxLength - the maximum size of the content, or 0 for any size
readTimeout - the maximum time, in ms, to wait for connects, and reads
Returns:
null or a completed byte array of the returned content

getRawUrl

byte[] getRawUrl(java.lang.String urlStr,
                 java.lang.String cookieStr)
Reads the simple raw return content from a given url and returns it as a byte array. Good for getting files or web pages! Returns null if any error occurs, including a 404, timeouts, or read failures.

Parameters:
urlStr - the url to fetch
cookieStr - cookies to send, or "", or null for none
Returns:
null or a completed byte array of the returned content

getRawUrl

byte[] getRawUrl(java.lang.String urlStr)
Reads the simple raw return content from a given url and returns it as a byte array. Good for getting files or web pages! Returns null if any error occurs, including a 404, timeouts, or read failures.

Parameters:
urlStr - the url to fetch
Returns:
null or a completed byte array of the returned content

getRawUrl

byte[] getRawUrl(java.lang.String urlStr,
                 java.lang.String cookieStr,
                 int maxLength,
                 int readTimeout)
Reads the simple raw return content from a given url and returns it as a byte array. Good for getting files or web pages! Returns null if any error occurs, including a 404, timeouts, or read failures.

Parameters:
urlStr - the url to fetch
cookieStr - cookies to send, or "", or null for none
maxLength - the maximum size of the content, or 0 for any size
readTimeout - the maximum time, in ms, to wait for connects, and reads
Returns:
null or a completed byte array of the returned content

getHeaders

java.util.Map<java.lang.String,java.util.List<java.lang.String>> getHeaders(java.lang.String urlStr)
Calls GET on the given url, waiting no more than a few seconds for connection, and returns the headers from the response.

Parameters:
urlStr - the url to GET
Returns:
the map of headers

maxReadBytes

HttpClient maxReadBytes(int bytes)
An http request builder method that sets the maximum number of bytes that can be read by the request processor.

Parameters:
bytes - max bytes to read, or 0 for no limit
Returns:
this

readTimeout

HttpClient readTimeout(int ms)
An http request builder method that sets the maximum number of milliseconds that the reader will remain idle waiting for a byte of data.

Parameters:
ms - the maximum number of ms to wait, or 0 for unlimited
Returns:
this

connectTimeout

HttpClient connectTimeout(int ms)
An http request builder method that sets the maximum number of milliseconds that the reader will remain idle waiting for a connection to occur.

Parameters:
ms - the maximum number of ms to wait, or 0 for unlimited
Returns:
this

reset

HttpClient reset()
An http request builder method that resets the client obj so that the connection can be used for another request.

Returns:
this

body

HttpClient body(java.lang.String body)
An http request builder method that sets the body to send.

Parameters:
body - the body to send
Returns:
this

body

HttpClient body(byte[] body)
An http request builder method that sets the body to send.

Parameters:
body - the body to send
Returns:
this

header

HttpClient header(java.lang.String key,
                  java.lang.String value)
An http request builder method that adds a header.

Parameters:
key - the header name
value - the header value
Returns:
this

method

HttpClient method(HttpClient.Method meth)
An http request builder method that sets the http method

Parameters:
meth - the method
Returns:
this

doGet

HttpClient doGet(java.lang.String url)
                 throws java.io.IOException
An http request builder method that causes this request to occur as a GET

Parameters:
url - the url to use
Returns:
this
Throws:
java.io.IOException - a socket error

doHead

HttpClient doHead(java.lang.String url)
                  throws java.io.IOException
An http request builder method that causes this request to occur as a HEAD

Parameters:
url - the url to use
Returns:
this
Throws:
java.io.IOException - a socket error

doRequest

HttpClient doRequest(java.lang.String url)
                     throws java.io.IOException
An http request builder method that causes this request to occur.

Parameters:
url - the url to use
Returns:
this
Throws:
java.io.IOException - a socket error

getResponseHeaders

java.util.Map<java.lang.String,java.util.List<java.lang.String>> getResponseHeaders()
Returns the headers in the response to this request

Returns:
the headers in the response to this request

getResponseCode

int getResponseCode()
Returns the http status code from the response

Returns:
the http status code from the response

getResponseBody

java.io.InputStream getResponseBody()
Returns an input stream to the body of the response to this request.

Returns:
an input stream to the body of the response

getResponseContentLength

int getResponseContentLength()
Gets the length of the body of the response to this request.

Returns:
the length of the body

finished

void finished()
Closes this connection, entirely. Always call this in a finally block!