Class SimpleHttpClient
java.lang.Object
org.n52.sensorweb.server.helgoland.adapters.web.SimpleHttpClient
- All Implemented Interfaces:
HttpClient
- Direct Known Subclasses:
ArcgisRestHttpClient
-
Constructor Summary
ConstructorsModifierConstructorDescriptionCreates an instance withtimeout = 30000ms.SimpleHttpClient(int connectionTimeout) Creates an instance with a given connection timeout.SimpleHttpClient(int connectionTimeout, int socketTimeout) Creates an instance with the given timeouts.protectedSimpleHttpClient(org.apache.hc.client5.http.impl.classic.CloseableHttpClient httpclient) -
Method Summary
Modifier and TypeMethodDescriptionprotected org.apache.hc.client5.http.impl.classic.HttpClientBuilderMay be overwritten by subclasses that e.g.protected ResponsedoDelete(URI url, AbstractDeleteRequest request) protected Responseprotected ResponsedoGet(URI url, AbstractGetRequest request) protected Responseprotected ResponsedoPost(URI url, AbstractPostRequest<?> request) execute(String url, AbstractRequest request) execute(URI url, AbstractRequest request) org.apache.hc.core5.http.ClassicHttpResponseexecuteGet(String uri) org.apache.hc.core5.http.ClassicHttpResponseexecuteMethod(org.apache.hc.client5.http.classic.methods.HttpUriRequestBase method) org.apache.hc.core5.http.ClassicHttpResponseexecutePost(String uri, String payloadToSend) Sends the given payload as content-type text/xml with UTF-8 encoding to the determined URI.org.apache.hc.core5.http.ClassicHttpResponseexecutePost(String uri, String payloadToSend, org.n52.janmayen.http.MediaType contentType) Sends the given payload (marked to be of a specific content-type) to the determined URI.org.apache.hc.core5.http.ClassicHttpResponseexecutePost(String uri, org.apache.hc.core5.http.HttpEntity payloadToSend) Sends the given payload to the determined URI.protected org.apache.hc.client5.http.impl.classic.CloseableHttpClientprotected voidsetConnectionTimout(int timeout) setProxyHost(String proxyHost) setProxyPort(String proxyPort) setProxySslKey(boolean proxySslKey) setSocketTimout(int timeout)
-
Constructor Details
-
SimpleHttpClient
public SimpleHttpClient()Creates an instance withtimeout = 30000ms. -
SimpleHttpClient
public SimpleHttpClient(int connectionTimeout) Creates an instance with a given connection timeout.- Parameters:
connectionTimeout- the connection timeout in milliseconds.
-
SimpleHttpClient
public SimpleHttpClient(int connectionTimeout, int socketTimeout) Creates an instance with the given timeouts.- Parameters:
connectionTimeout- the connection timeout in milliseconds.socketTimeout- the socket timeout in milliseconds.
-
SimpleHttpClient
protected SimpleHttpClient(org.apache.hc.client5.http.impl.classic.CloseableHttpClient httpclient)
-
-
Method Details
-
execute
- Specified by:
executein interfaceHttpClient- Throws:
ProxyHttpClientException
-
execute
- Specified by:
executein interfaceHttpClient- Throws:
ProxyHttpClientException
-
executeGet
- Specified by:
executeGetin interfaceHttpClient- Throws:
IOException
-
executePost
public org.apache.hc.core5.http.ClassicHttpResponse executePost(String uri, String payloadToSend) throws IOException Description copied from interface:HttpClientSends the given payload as content-type text/xml with UTF-8 encoding to the determined URI. Callees are responsible for ensuring that the contents are actually encoded as UTF-8. If not UTF-8, useHttpClient.executePost(String, String, MediaType)instead.- Specified by:
executePostin interfaceHttpClient- Parameters:
uri- the target to send the POST request to.payloadToSend- the POST payload as XML encoded as UTF-8.- Returns:
- the HTTP response returned by the target.
- Throws:
IOException- if sending the request fails.
-
executePost
public org.apache.hc.core5.http.ClassicHttpResponse executePost(String uri, String payloadToSend, org.n52.janmayen.http.MediaType contentType) throws IOException Description copied from interface:HttpClientSends the given payload (marked to be of a specific content-type) to the determined URI.- Specified by:
executePostin interfaceHttpClient- Parameters:
uri- the target to send the POST request to.payloadToSend- the POST payload as XML.contentType- the content-type of the payload.- Returns:
- the HTTP response returned by the target.
- Throws:
IOException- if sending the request fails.
-
executePost
public org.apache.hc.core5.http.ClassicHttpResponse executePost(String uri, org.apache.hc.core5.http.HttpEntity payloadToSend) throws IOException Description copied from interface:HttpClientSends the given payload to the determined URI. Refer to the HTTP components docs to get more information which entity types are possible.- Specified by:
executePostin interfaceHttpClient- Parameters:
uri- the target to send the POST request to.payloadToSend- a more generic way to send arbitrary content.- Returns:
- the HTTP response returned by the target.
- Throws:
IOException- if sending the request fails.
-
executeMethod
public org.apache.hc.core5.http.ClassicHttpResponse executeMethod(org.apache.hc.client5.http.classic.methods.HttpUriRequestBase method) throws IOException - Specified by:
executeMethodin interfaceHttpClient- Parameters:
method- the HTTP method to execute.- Returns:
- the HTTP response returned by the target.
- Throws:
IOException- if sending the request fails
-
setConnectionTimout
-
setSocketTimout
-
setProxyHost
-
setProxyPort
-
setProxySslKey
-
doGet
- Throws:
ProxyHttpClientException
-
doGet
-
doPost
- Throws:
ProxyHttpClientException
-
doPost
protected Response doPost(URI url, String content, org.n52.janmayen.http.MediaType contentType) throws ProxyHttpClientException - Throws:
ProxyHttpClientException
-
doDelete
- Throws:
ProxyHttpClientException
-
getClient
protected org.apache.hc.client5.http.impl.classic.CloseableHttpClient getClient() -
recreateClient
protected void recreateClient() -
configureClient
protected org.apache.hc.client5.http.impl.classic.HttpClientBuilder configureClient()May be overwritten by subclasses that e.g. require specialized Headers- Returns:
- builder for the client instance
-