Package org.intermine.client.util
Class HttpConnection
- java.lang.Object
-
- org.intermine.client.util.HttpConnection
-
public class HttpConnection extends java.lang.ObjectThe HttpConnection is class wrapping implementation details of http connection and the implementation can change easily.
-
-
Constructor Summary
Constructors Constructor Description HttpConnection(Request request)
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description protected voidcheckResponse()Called to check the response and generate an appropriate exception (on failure).voidclose()Closes connection.voidconnect()Opens connection.java.io.InputStreamgetResponseBodyAsStream()java.lang.StringgetResponseBodyAsString()Return the response body, ensuring that the connection is closed upon completion.intgetResponseCode()java.lang.StringgetResponseHeader(java.lang.String name)java.io.InputStreamgetResponseStream()protected voidhandleErrorResponse()Handles an error response received while executing a service request.booleanisOpened()voidsetRetryCount(int times)Sets retry count.voidsetTimeout(int timeout)Sets timeout.
-
-
-
Constructor Detail
-
HttpConnection
public HttpConnection(Request request)
- Parameters:
request- client request
-
-
Method Detail
-
getResponseStream
public java.io.InputStream getResponseStream()
- Returns:
- response stream
-
connect
public void connect()
Opens connection.
-
getResponseHeader
public java.lang.String getResponseHeader(java.lang.String name)
- Parameters:
name- header name- Returns:
- response header
-
close
public void close()
Closes connection.
-
setTimeout
public void setTimeout(int timeout)
Sets timeout.- Parameters:
timeout- timeout in milliseconds
-
setRetryCount
public void setRetryCount(int times)
Sets retry count.- Parameters:
times- The number of times to flog a dead horse. (3 by default).
-
getResponseCode
public int getResponseCode()
- Returns:
- response code.
-
isOpened
public boolean isOpened()
- Returns:
- true if connection is opened else false
-
checkResponse
protected void checkResponse()
Called to check the response and generate an appropriate exception (on failure). If the connection is not opened then it is opened and response checked.
-
handleErrorResponse
protected void handleErrorResponse() throws java.io.IOExceptionHandles an error response received while executing a service request. Throws a ServiceException or one of its subclasses, depending on the failure conditions.- Throws:
java.io.IOException- error reading the error response from the service.
-
getResponseBodyAsString
public java.lang.String getResponseBodyAsString()
Return the response body, ensuring that the connection is closed upon completion.- Returns:
- the response body body as the string
-
getResponseBodyAsStream
public java.io.InputStream getResponseBodyAsStream()
- Returns:
- the response body as the stream
-
-