public static class HttpConnection.Response extends HttpConnection.Base<Connection.Response> implements Connection.Response
Modifier and Type | Field and Description |
---|---|
private InputStream |
bodyStream |
private ByteBuffer |
byteData |
private String |
charset |
private String |
contentType |
private boolean |
executed |
private boolean |
inputStreamRead |
private static String |
LOCATION |
private static int |
MAX_REDIRECTS |
private int |
numRedirects |
private Connection.Request |
req |
private static SSLSocketFactory |
sslSocketFactory |
private int |
statusCode |
private String |
statusMessage |
private static Pattern |
xmlContentTypeRxp |
cookies, headers, method, url
Modifier | Constructor and Description |
---|---|
(package private) |
Response() |
private |
Response(HttpConnection.Response previousResponse) |
Modifier and Type | Method and Description |
---|---|
String |
body()
Get the body of the response as a plain string.
|
byte[] |
bodyAsBytes()
Get the body of the response as an array of bytes.
|
BufferedInputStream |
bodyStream()
Get the body of the response as a (buffered) InputStream.
|
Connection.Response |
bufferUp()
Read the body of the response into a local buffer, so that
Connection.Response.parse() may be called repeatedly on the
same connection response (otherwise, once the response is read, its InputStream will have been drained and
may not be re-read). |
String |
charset()
Get the character set name of the response, derived from the content-type header.
|
HttpConnection.Response |
charset(String charset)
Set / override the response character set.
|
String |
contentType()
Get the response content type (e.g.
|
private static HttpURLConnection |
createConnection(Connection.Request req) |
private static LinkedHashMap<String,List<String>> |
createHeaderMap(HttpURLConnection conn) |
(package private) static HttpConnection.Response |
execute(Connection.Request req) |
(package private) static HttpConnection.Response |
execute(Connection.Request req,
HttpConnection.Response previousResponse) |
private static HostnameVerifier |
getInsecureVerifier()
Instantiate Hostname Verifier that does nothing.
|
private static String |
getRequestCookieString(Connection.Request req) |
private static void |
initUnSecureTSL()
Initialise Trust manager that does not validate certificate chains and
add it to current SSLContext.
|
Document |
parse()
Read and parse the body of the response as a Document.
|
private void |
prepareByteData() |
(package private) void |
processResponseHeaders(Map<String,List<String>> resHeaders) |
private void |
safeClose()
Call on completion of stream read, to close the body (or error) stream
|
private static void |
serialiseRequestUrl(Connection.Request req) |
private static String |
setOutputContentType(Connection.Request req) |
private void |
setupFromConnection(HttpURLConnection conn,
Connection.Response previousResponse) |
int |
statusCode()
Get the status code of the response.
|
String |
statusMessage()
Get the status message of the response.
|
private static void |
writePost(Connection.Request req,
OutputStream outputStream,
String bound) |
addHeader, cookie, cookie, cookies, hasCookie, hasHeader, hasHeaderWithValue, header, header, headers, headers, method, method, multiHeaders, removeCookie, removeHeader, url, url
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
addHeader, cookie, cookie, cookies, hasCookie, hasHeader, hasHeaderWithValue, header, header, headers, headers, method, method, multiHeaders, removeCookie, removeHeader, url, url
private static final int MAX_REDIRECTS
private static SSLSocketFactory sslSocketFactory
private static final String LOCATION
private int statusCode
private String statusMessage
private ByteBuffer byteData
private InputStream bodyStream
private String contentType
private boolean executed
private boolean inputStreamRead
private int numRedirects
private Connection.Request req
private static final Pattern xmlContentTypeRxp
Response()
private Response(HttpConnection.Response previousResponse) throws IOException
IOException
static HttpConnection.Response execute(Connection.Request req) throws IOException
IOException
static HttpConnection.Response execute(Connection.Request req, HttpConnection.Response previousResponse) throws IOException
IOException
public int statusCode()
Connection.Response
statusCode
in interface Connection.Response
public String statusMessage()
Connection.Response
statusMessage
in interface Connection.Response
public String charset()
Connection.Response
charset
in interface Connection.Response
public HttpConnection.Response charset(String charset)
Connection.Response
charset
in interface Connection.Response
charset
- to decode body aspublic String contentType()
Connection.Response
contentType
in interface Connection.Response
public Document parse() throws IOException
Connection.Response
Connection.Response.bufferUp()
first.parse
in interface Connection.Response
IOException
- on errorprivate void prepareByteData()
public String body()
Connection.Response
body
in interface Connection.Response
public byte[] bodyAsBytes()
Connection.Response
bodyAsBytes
in interface Connection.Response
public Connection.Response bufferUp()
Connection.Response
Connection.Response.parse()
may be called repeatedly on the
same connection response (otherwise, once the response is read, its InputStream will have been drained and
may not be re-read). Calling Connection.Response.body()
or Connection.Response.bodyAsBytes()
has the same effect.bufferUp
in interface Connection.Response
public BufferedInputStream bodyStream()
Connection.Response
This method is useful for writing large responses to disk, without buffering them completely into memory first.
bodyStream
in interface Connection.Response
private static HttpURLConnection createConnection(Connection.Request req) throws IOException
IOException
private void safeClose()
private static HostnameVerifier getInsecureVerifier()
private static void initUnSecureTSL() throws IOException
IOException
- on SSL init errorsprivate void setupFromConnection(HttpURLConnection conn, Connection.Response previousResponse) throws IOException
IOException
private static LinkedHashMap<String,List<String>> createHeaderMap(HttpURLConnection conn)
void processResponseHeaders(Map<String,List<String>> resHeaders)
private static String setOutputContentType(Connection.Request req)
private static void writePost(Connection.Request req, OutputStream outputStream, String bound) throws IOException
IOException
private static String getRequestCookieString(Connection.Request req)
private static void serialiseRequestUrl(Connection.Request req) throws IOException
IOException
WebARTS Library Licensed Under the GNU - General Public License. Other Libraries licensed under their respective Open Source Licenses