public class HttpConnector extends Object
| Modifier and Type | Field and Description |
|---|---|
static String |
PROXY_BYPASS_PRIVATE_NETWORKS |
static String |
PROXY_HTTP_HOST
The hostname of the http proxy.
|
static String |
PROXY_HTTP_PASSWORD
The password for the http proxy.
|
static String |
PROXY_HTTP_PORT
The port of the http proxy.
|
static String |
PROXY_HTTP_USERNAME
The username for the http proxy.
|
static String |
PROXY_HTTPS_HOST
The hostname of the https proxy.
|
static String |
PROXY_HTTPS_PASSWORD
The password for the https proxy.
|
static String |
PROXY_HTTPS_PORT
The port of the https proxy.
|
static String |
PROXY_HTTPS_USERNAME
The username for the https proxy.
|
static String |
USER_AGENT
The hostname of the http proxy.
|
| Constructor and Description |
|---|
HttpConnector()
Instantiates a new http connector.
|
HttpConnector(org.apache.commons.configuration.Configuration config)
Instantiates a new http connector.
|
HttpConnector(de.samply.common.config.Configuration config)
Instantiates new http connector with samply configuration.
|
HttpConnector(de.samply.common.config.Configuration config,
boolean followRedirects)
Instantiates new http connector with samply configuration.
|
HttpConnector(HashMap<String,String> config)
Instantiates a new http connector.
|
HttpConnector(HashMap<String,String> config,
org.apache.http.client.CredentialsProvider credentialsProvider)
Instantiates a new http connector with provided Credentials Provider.
|
HttpConnector(HashMap<String,String> config,
org.apache.http.client.CredentialsProvider credentialsProvider,
int timeout)
Instantiates a new http connector with provided Credentials Provider and a timeout.
|
HttpConnector(de.samply.common.config.Proxy config)
Instantiates new http connector with samply proxy configuration.
|
| Modifier and Type | Method and Description |
|---|---|
void |
addCredentials(org.apache.http.auth.AuthScope authScope,
org.apache.http.auth.Credentials credentials)
Add Credentials for a given Auth Scope.
|
void |
addCustomHeader(org.apache.http.Header customHeader)
Add custom Header and init client.
|
void |
addCustomHeader(String key,
String value) |
void |
addHttpAuth(String url,
String username,
String password)
Adds the http auth.
|
String |
addTrailingSlash(String in)
Adds the trailing slash.
|
void |
closeClients()
Closes the clients.
|
org.apache.http.client.methods.CloseableHttpResponse |
doAction(String action,
String url,
HashMap<String,String> headers,
HashMap<String,String> params,
String mediaType,
String request,
Boolean preemptiveAuth,
Boolean preemptiveProxyAuthentication)
Returns the result of a request submitted as ClosableHttpResponse NB: Do not forget to close
the Response when done with it.
|
org.apache.http.client.methods.CloseableHttpResponse |
doAction(String action,
String url,
HashMap<String,String> headers,
HashMap<String,String> params,
String mediaType,
String request,
Boolean preemptiveAuth,
Boolean preemptiveProxyAuthentication,
int retryCount)
Returns the result of a request submitted as ClosableHttpResponse NB: Do not forget to close
the Response when done with it.
|
HashMap<String,Object> |
doActionHashMap(String action,
String url,
HashMap<String,String> headers,
HashMap<String,String> params,
String contentType,
String request,
Boolean preemptiveAuth,
Boolean preemptiveProxy)
Returns the result of a request submitted as a HashMap with the fields: body: The Response body
as String statuscode: The Response statuscode as int headers: The Response headers as
Header[].
|
HashMap<String,Object> |
doActionHashMap(String action,
String url,
HashMap<String,String> headers,
HashMap<String,String> params,
String contentType,
String request,
Boolean preemptiveAuth,
Boolean preemptiveProxy,
int retryCount)
Returns the result of a request submitted as a HashMap with the fields: body: The Response body
as String statuscode: The Response statuscode as int headers: The Response headers as
Header[].
|
com.sun.jersey.api.client.Client |
getClient(org.apache.http.impl.client.CloseableHttpClient httpClient)
Get an Jersey Client.
|
com.sun.jersey.api.client.Client |
getClient(org.apache.http.impl.client.CloseableHttpClient httpClient,
Boolean failOnUnknownProperties)
Transforms a apache httpclient to a jersey client also enables POJO MAPPING as feature.
|
org.apache.http.client.CredentialsProvider |
getCp()
Gets the Credentials Provider.
|
List<org.apache.http.Header> |
getCustomHeaders() |
org.apache.http.impl.client.CloseableHttpClient |
getHttpc()
Deprecated.
|
org.apache.http.impl.client.CloseableHttpClient |
getHttpClient(org.apache.http.HttpHost target)
Returns the CloseableHttpClient based on a HttpHost.
|
org.apache.http.impl.client.CloseableHttpClient |
getHttpClient(String urlOrScheme)
Returns the CloseableHttpClient based on a given url or scheme.
|
org.apache.http.impl.client.CloseableHttpClient |
getHttpClient(URL url)
Returns the CloseableHttpClient based on a given URL.
|
org.apache.http.impl.client.CloseableHttpClient |
getHttpClientForHttp()
Returns the CloseableHttpClient (with http proxy if proxy is used).
|
org.apache.http.impl.client.CloseableHttpClient |
getHttpClientForHttps()
Returns the CloseableHttpClient (with https proxy if proxy is used).
|
org.apache.http.impl.client.CloseableHttpClient |
getHttpsc()
Deprecated.
|
com.sun.jersey.api.client.Client |
getJerseyClient(org.apache.http.HttpHost target)
Returns a jersey client for a given httphost.
|
com.sun.jersey.api.client.Client |
getJerseyClient(org.apache.http.HttpHost target,
Boolean failOnUnknownProperties)
Returns a jersey client for a given httphost.
|
com.sun.jersey.api.client.Client |
getJerseyClient(String urlOrScheme)
Returns a jersey client for a given url or Scheme.
|
com.sun.jersey.api.client.Client |
getJerseyClient(String urlOrScheme,
Boolean failOnUnknownProperties)
Returns a jersey client for a given url or Scheme.
|
com.sun.jersey.api.client.Client |
getJerseyClient(URL url)
Returns a jersey client for a given java.net.URL This client will fail on unknown properties.
|
com.sun.jersey.api.client.Client |
getJerseyClient(URL url,
Boolean failOnUnknownProperties)
Returns a jersey client for a given java.net.URL
|
com.sun.jersey.api.client.Client |
getJerseyClientForHttp()
Returns a jersey client for http connections.
|
com.sun.jersey.api.client.Client |
getJerseyClientForHttp(Boolean failOnUnknownProperties)
Returns a jersey client for http connections.
|
com.sun.jersey.api.client.Client |
getJerseyClientForHttps()
Returns a jersey client for https connections.
|
com.sun.jersey.api.client.Client |
getJerseyClientForHttps(Boolean failOnUnknownProperties)
Returns a jersey client for https connections.
|
org.apache.http.HttpHost |
getProxy(String target)
Returns the proxy needed for the given target.
|
String |
getUserAgent()
Get the current User Agent.
|
String |
removeDuplicateSlashes(String in)
Removes the duplicate slashes.
|
void |
setCp(org.apache.http.client.CredentialsProvider credentialsProvider)
Sets the Credentials Provider and reinitialized the clients.
|
void |
setCustomHeaders(List<org.apache.http.Header> customHeaders) |
void |
setUserAgent(String userAgent)
Set the User Agent.
|
public static final String PROXY_HTTPS_PASSWORD
public static final String PROXY_HTTPS_USERNAME
public static final String PROXY_HTTP_PASSWORD
public static final String PROXY_HTTP_USERNAME
public static final String PROXY_HTTPS_PORT
public static final String PROXY_HTTPS_HOST
public static final String PROXY_HTTP_PORT
public static final String PROXY_HTTP_HOST
public static final String USER_AGENT
public static final String PROXY_BYPASS_PRIVATE_NETWORKS
public HttpConnector()
public HttpConnector(org.apache.commons.configuration.Configuration config)
config - the configpublic HttpConnector(HashMap<String,String> config)
config - the configpublic HttpConnector(HashMap<String,String> config, org.apache.http.client.CredentialsProvider credentialsProvider)
config - the configcredentialsProvider - the preconfigured Credentials Providerpublic HttpConnector(HashMap<String,String> config, org.apache.http.client.CredentialsProvider credentialsProvider, int timeout)
config - the configcredentialsProvider - the preconfigured Credentials Providertimeout - timeout in secondspublic HttpConnector(de.samply.common.config.Configuration config)
config - Samply Configurationpublic HttpConnector(de.samply.common.config.Configuration config,
boolean followRedirects)
config - Samply ConfigurationfollowRedirects - if redirect must be performed or notpublic HttpConnector(de.samply.common.config.Proxy config)
config - Samply Proxy (no keystore settings!)public void closeClients()
throws IOException
IOException - ioExceptionpublic org.apache.http.client.methods.CloseableHttpResponse doAction(String action, String url, HashMap<String,String> headers, HashMap<String,String> params, String mediaType, String request, Boolean preemptiveAuth, Boolean preemptiveProxyAuthentication) throws HttpConnectorException
action - action method as string: get, posturl - The target URLheaders - HashMap<String,String> of headers to
be addedparams - HashMap<String,String> of params to
be added to the URLmediaType - Content-type of the request (defaults to
application/json)request - Request stringpreemptiveAuth - Whether or not to send preemptive web authorizationpreemptiveProxyAuthentication - Whether or not to send preemptive proxy authorizationHttpConnectorException - the http connector exceptionpublic org.apache.http.client.methods.CloseableHttpResponse doAction(String action, String url, HashMap<String,String> headers, HashMap<String,String> params, String mediaType, String request, Boolean preemptiveAuth, Boolean preemptiveProxyAuthentication, int retryCount) throws HttpConnectorException
action - action method as string: get, posturl - The target URLheaders - HashMap<String,String> of headers to
be addedparams - HashMap<String,String> of params to
be added to the URLmediaType - Content-type of the request (defaults to
application/json)request - Request stringpreemptiveAuth - Whether or not to send preemptive web authorizationpreemptiveProxyAuthentication - Whether or not to send preemptive proxy authorizationretryCount - how many times to retry; 0 means no retriesHttpConnectorException - the http connector exceptionpublic HashMap<String,Object> doActionHashMap(String action, String url, HashMap<String,String> headers, HashMap<String,String> params, String contentType, String request, Boolean preemptiveAuth, Boolean preemptiveProxy) throws HttpConnectorException
action - action method as string: get, posturl - The target urlheaders - HashMap<String,String> of headers to be addedparams - HashMap<String,String> of params to be added to
the urlcontentType - Content-type of the request (defaults to application/json)request - Request stringpreemptiveAuth - Whether or not to send preemptive web authorizationpreemptiveProxy - Whether or not to send preemptive proxy authorizationHttpConnectorException - the http connector exceptionpublic HashMap<String,Object> doActionHashMap(String action, String url, HashMap<String,String> headers, HashMap<String,String> params, String contentType, String request, Boolean preemptiveAuth, Boolean preemptiveProxy, int retryCount) throws HttpConnectorException
action - action method as string: get, posturl - The target urlheaders - HashMap<String,String> of headers to be addedparams - HashMap<String,String> of params to be added to
the urlcontentType - Content-type of the request (defaults to application/json)request - Request stringpreemptiveAuth - Whether or not to send preemptive web authorizationpreemptiveProxy - Whether or not to send preemptive proxy authorizationretryCount - how many times to retry; 0 means no retriesHttpConnectorException - the http connector exceptionpublic String addTrailingSlash(String in)
in - the inpublic String removeDuplicateSlashes(String in)
in - the inpublic com.sun.jersey.api.client.Client getClient(org.apache.http.impl.client.CloseableHttpClient httpClient,
Boolean failOnUnknownProperties)
httpClient - the http clientfailOnUnknownProperties - if the client shall fail on deserialisation on unknown or
unignorable propertiespublic com.sun.jersey.api.client.Client getClient(org.apache.http.impl.client.CloseableHttpClient httpClient)
httpClient - the httpclientThis client will fail on unknown
properties.public com.sun.jersey.api.client.Client getJerseyClientForHttp()
public com.sun.jersey.api.client.Client getJerseyClientForHttp(Boolean failOnUnknownProperties)
failOnUnknownProperties - if or not to fail on unknown propertiespublic com.sun.jersey.api.client.Client getJerseyClientForHttps()
public com.sun.jersey.api.client.Client getJerseyClientForHttps(Boolean failOnUnknownProperties)
failOnUnknownProperties - if or not to fail on unknown propertiespublic com.sun.jersey.api.client.Client getJerseyClient(org.apache.http.HttpHost target,
Boolean failOnUnknownProperties)
target - the targetfailOnUnknownProperties - if or not to fail on unknown propertiespublic com.sun.jersey.api.client.Client getJerseyClient(org.apache.http.HttpHost target)
target - the targetpublic com.sun.jersey.api.client.Client getJerseyClient(String urlOrScheme)
urlOrScheme - the url or schemepublic com.sun.jersey.api.client.Client getJerseyClient(String urlOrScheme, Boolean failOnUnknownProperties)
urlOrScheme - the url or schemefailOnUnknownProperties - if or not to fail on unknown propertiespublic com.sun.jersey.api.client.Client getJerseyClient(URL url)
url - the urlpublic com.sun.jersey.api.client.Client getJerseyClient(URL url, Boolean failOnUnknownProperties)
url - the urlfailOnUnknownProperties - if or not to fail on unknown propertiespublic org.apache.http.HttpHost getProxy(String target) throws MalformedURLException
target - A web-url / linkMalformedURLException - string not well formedpublic org.apache.http.client.CredentialsProvider getCp()
public void setCp(org.apache.http.client.CredentialsProvider credentialsProvider)
credentialsProvider - the new Credentials Provider.public String getUserAgent()
public void setUserAgent(String userAgent)
userAgent - the userAgent to setpublic org.apache.http.impl.client.CloseableHttpClient getHttpClient(org.apache.http.HttpHost target)
target - HttpHostpublic org.apache.http.impl.client.CloseableHttpClient getHttpClient(URL url)
url - URLpublic org.apache.http.impl.client.CloseableHttpClient getHttpClient(String urlOrScheme)
urlOrScheme - The web-link or scheme (http, https)@Deprecated public org.apache.http.impl.client.CloseableHttpClient getHttpc()
public org.apache.http.impl.client.CloseableHttpClient getHttpClientForHttp()
@Deprecated public org.apache.http.impl.client.CloseableHttpClient getHttpsc()
public org.apache.http.impl.client.CloseableHttpClient getHttpClientForHttps()
public void addHttpAuth(String url, String username, String password) throws MalformedURLException
url - the urlusername - the usernamepassword - the passwordMalformedURLException - the malformed url exceptionpublic void addCredentials(org.apache.http.auth.AuthScope authScope,
org.apache.http.auth.Credentials credentials)
authScope - the auth scopecredentials - the credentialspublic List<org.apache.http.Header> getCustomHeaders()
public void setCustomHeaders(List<org.apache.http.Header> customHeaders)
public void addCustomHeader(org.apache.http.Header customHeader)
customHeader - the custom headerCopyright © 2021 Samply Community. All rights reserved.