org.intermine.webservice.client.util
Class HttpConnection

java.lang.Object
  extended by org.intermine.webservice.client.util.HttpConnection

public class HttpConnection
extends java.lang.Object

The HttpConnection is class wrapping implementation details of http connection and the implementation can change easily.


Constructor Summary
HttpConnection(Request request)
           
 
Method Summary
protected  void checkResponse(java.lang.String url)
          Called to check the response and generate an appropriate exception (on failure).
 void close()
          Closes connection.
 void connect()
          Opens connection.
 java.io.InputStream getResponseBodyAsStream()
           
 java.lang.String getResponseBodyAsString()
           
 int getResponseCode()
           
 java.lang.String getResponseHeader(java.lang.String name)
           
 java.io.InputStream getResponseStream()
           
protected  void handleErrorResponse()
          Handles an error response received while executing a service request.
 boolean isOpened()
           
 void setTimeout(int timeout)
          Sets timeout.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

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

getResponseCode

public int getResponseCode()
Returns:
response code.

isOpened

public boolean isOpened()
Returns:
true if connection is opened else false

checkResponse

protected void checkResponse(java.lang.String url)
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.

Parameters:
url - a URL to quote in any error messages
Throws:
ServiceException - when an error happens

handleErrorResponse

protected void handleErrorResponse()
                            throws java.io.IOException
Handles an error response received while executing a service request. Throws a ServiceException or one of its subclasses, depending on the failure conditions.

Throws:
ServiceException - exception describing the failure.
java.io.IOException - error reading the error response from the service.

getResponseBodyAsString

public java.lang.String getResponseBodyAsString()
Returns:
the response body body as the string

getResponseBodyAsStream

public java.io.InputStream getResponseBodyAsStream()
Returns:
the response body as the stream