HttpConnector

public class HttpConnector

HttpConnector is a connector for making HTTP/S connections to an URL.

Author:Hugo Y. K. Lam

Constructors

HttpConnector

public HttpConnector(Object destUrl)

Creates a new instance of HttpConnector.

Parameters:
  • destUrl – the destination URL, either in String or URL format.
Throws:
  • MalformedURLException – if the URL is malformed.

Methods

addKeyManager

public void addKeyManager(KeyManager km)

Adds a key manager for SSL connection.

Parameters:
  • km – the key manager.

addTrustManager

public void addTrustManager(TrustManager tm)

Adds a trust manager for SSL connection.

Parameters:
  • tm – the trust manager.

createConnection

public HttpURLConnection createConnection()

Creates a new HTTP connection based on this connector’s properties.

Throws:
Returns:

a new HTTP connection.

getHostnameVerifier

public HostnameVerifier getHostnameVerifier()

Gets the host verifier for SSL connection.

Returns:the host name verifier.

getRequestHeaders

public Map getRequestHeaders()

Gets the HTTP request headers.

Returns:the HTTP headers, or null.

getSSLSocketFactory

public SSLSocketFactory getSSLSocketFactory()

Gets the SSL socket factory which is used in SSL connection.

Throws:
Returns:

the SSL socket factory.

send

public InputStream send(InputStream request)

Sends an HTTP/S request using the given HTTP connection.

Parameters:
  • request – the HTTP request content or null for a simple get request.
Throws:
Returns:

an input stream for reading the reply from the host.

send

public InputStream send(InputStream request, HttpURLConnection connection)

Sends an HTTP/S request using the given HTTP connection.

Parameters:
  • request – the HTTP request content or null for a simple get request.
  • connection – the HTTP connection for sending the request.
Throws:
Returns:

an input stream for reading the reply from the host.

setHostnameVerifier

public void setHostnameVerifier(HostnameVerifier hostnameVerifier)

Sets a host name verifier for SSL connection.

Parameters:
  • hostnameVerifier – the host name verifier.

setRequestHeaders

public void setRequestHeaders(Map headers)

Sets the HTTP request headers.

Parameters:
  • headers – the HTTP headers.