Package edu.indiana.lib.twinpeaks.net
Class HttpTransaction
- java.lang.Object
-
- edu.indiana.lib.twinpeaks.net.HttpTransaction
-
public class HttpTransaction extends Object
Handle HTTP based search operations. Send (POST or GET) a query to the server, read up the response. The response text and HTTP details (status, character set, etc) are made available to caller.
-
-
Field Summary
Fields Modifier and Type Field Description static StringDEFAULTCSstatic StringMETHOD_GETstatic StringMETHOD_POST
-
Constructor Summary
Constructors Constructor Description HttpTransaction()Default constructor
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description voidclearParameters()Empty the parameter listintdoTransaction()Perform one command transactionintdoTransaction(String url)Perform one command transaction - add parameters and build the URLintdoTransaction(URL url)Perform one command transactionStringgetBaseUrlSpecification()Get the basic url specification for this connectionHttpURLConnectiongetConnection()Get an HttpURLConnection for this transactionStringgetDefaultCharacterSet()Get the default character set (use if none supplied by server)StringgetInputCharacterSet()Get the default character set (use if none supplied by server)StringgetParameter(String name)Get a named parameterStringgetParameterName(String value)Get parameter the name of first occurance of the supplied valuebyte[]getResponseBytes()Get the unfiltered response as sent by the server (debug)StringgetResponseCharacterSet()Get the response document character set (supplied by the server)intgetResponseCode()Get the response statusListgetResponseCookies()Get all provided cookiesStringgetResponseHeader(String key)Get a named HTTP responseCaseBlindHashMapgetResponseHeaders()Get all HTTP response headersStringgetResponseString()Get the character-set-encoded String rendition of the server responseStringgetUrl()Get the URL text sent to the servervoidinitialize(URL url, List cookieList)Initialize.voidinitialize(List cookieList)InitializevoidsetDefaultCharacterSet(String cs)Set the default character setvoidsetFollowRedirects(boolean follow)Honor redirects?voidsetInputCharacterSet(String cs)Set the input character setvoidsetParameter(String name, String value)Set up a name=value pairvoidsetPreserveBaseUrlFile(boolean state)Set the "preserve URL file" flagvoidsetTransactionType(String type)Set the transaction type
-
-
-
Field Detail
-
METHOD_GET
public static final String METHOD_GET
- See Also:
- Constant Field Values
-
METHOD_POST
public static final String METHOD_POST
- See Also:
- Constant Field Values
-
DEFAULTCS
public static final String DEFAULTCS
- See Also:
- Constant Field Values
-
-
Method Detail
-
initialize
public void initialize(List cookieList)
Initialize
-
setTransactionType
public void setTransactionType(String type)
Set the transaction type- Parameters:
type- (GET or POST)
-
setFollowRedirects
public void setFollowRedirects(boolean follow)
Honor redirects?- Parameters:
follow- Set as true to follow any redirects suggested
-
setParameter
public void setParameter(String name, String value)
Set up a name=value pair- Parameters:
name- Parameter namevalue- Parameter value
-
getParameter
public String getParameter(String name)
Get a named parameter- Parameters:
name- Parameter name- Returns:
- Parameter value
-
getParameterName
public String getParameterName(String value)
Get parameter the name of first occurance of the supplied value- Parameters:
value- Parameter value- Returns:
- Parameter name
-
clearParameters
public void clearParameters()
Empty the parameter list
-
getResponseCode
public int getResponseCode()
Get the response status- Returns:
- The HTTP response code
-
getUrl
public String getUrl()
Get the URL text sent to the server- Returns:
- URL string
-
setPreserveBaseUrlFile
public void setPreserveBaseUrlFile(boolean state)
Set the "preserve URL file" flag- Parameters:
state- true to preserve the URL file portion (default is false)
-
getBaseUrlSpecification
public String getBaseUrlSpecification() throws MalformedURLException
Get the basic url specification for this connection- Returns:
- protocol://hostname[:port][/file]
- Throws:
MalformedURLException
-
getResponseBytes
public byte[] getResponseBytes()
Get the unfiltered response as sent by the server (debug)- Returns:
- Response text as recieved
-
getResponseString
public String getResponseString()
Get the character-set-encoded String rendition of the server response- Returns:
- Response text as recieved
-
getResponseHeaders
public CaseBlindHashMap getResponseHeaders()
Get all HTTP response headers- Returns:
- CaseBlindHashMap of response-field/value pairs
-
getResponseHeader
public String getResponseHeader(String key)
Get a named HTTP response- Returns:
- Response value
-
getResponseCookies
public List getResponseCookies()
Get all provided cookies- Returns:
- CaseBlindHashMap of response-field/value pairs
-
getResponseCharacterSet
public String getResponseCharacterSet()
Get the response document character set (supplied by the server)- Returns:
- The character set (as a String, default to iso-8859-1)
-
setDefaultCharacterSet
public void setDefaultCharacterSet(String cs)
Set the default character set- Parameters:
cs- Character set (utf-8, etc) Note: the character set defaults to DEFAULTCS (above) if not overridden
-
getDefaultCharacterSet
public String getDefaultCharacterSet()
Get the default character set (use if none supplied by server)- Returns:
- The character set (iso-8859-1, utf-8, etc)
-
setInputCharacterSet
public void setInputCharacterSet(String cs)
Set the input character set- Parameters:
cs- Character set (utf-8, etc) Note: the character set defaults to DEFAULTCS (above) if not overridden
-
getInputCharacterSet
public String getInputCharacterSet()
Get the default character set (use if none supplied by server)- Returns:
- The character set (iso-8859-1, utf-8, etc)
-
getConnection
public HttpURLConnection getConnection() throws IOException
Get an HttpURLConnection for this transaction- Throws:
IOException
-
doTransaction
public int doTransaction(String url) throws IOException, DomException
Perform one command transaction - add parameters and build the URL- Parameters:
url- URL string to server-side resource- Returns:
- HTTP response code
- Throws:
IOExceptionDomException
-
doTransaction
public int doTransaction(URL url) throws IOException, DomException
Perform one command transaction- Parameters:
url- URL for server-side- Returns:
- HTTP response code
- Throws:
IOExceptionDomException
-
doTransaction
public int doTransaction() throws IOException, DomExceptionPerform one command transaction- Returns:
- HTTP response code
- Throws:
IOExceptionDomException
-
-