/** * Create a new HTTP client wrapper. */ public static HttpClientWrapper create() { return new HttpClientWrapper(); }
public NominatimGeocoderService() { m_clientWrapper = HttpClientWrapper.create() .dontReuseConnections(); if(m_useSystemProxy) { m_clientWrapper.useSystemProxySettings(); } }
HttpClientWrapper createHttpClient() { HttpClientWrapper clientWrapper = HttpClientWrapper.create() .setConnectionTimeout(getTimeout()) .setSocketTimeout(getTimeout()) .setRetries(getRetries()) .useBrowserCompatibleCookies(); setUseSystemProxyIfDefined(clientWrapper, m_parameterMap); return clientWrapper; } }
public static void setUseSystemProxyIfDefined(HttpClientWrapper httpClientWrapper, Map<String, Object> keyedParameters) { if (ParameterMap.getKeyedBoolean(keyedParameters, useSystemProxy.getKey(), false)) { httpClientWrapper.useSystemProxySettings(); LOG.debug("setting useSystemProxySettings() on HttpClientWrapper"); } }
/** * Set the connection timeout on connections. */ public HttpClientWrapper setConnectionTimeout(final Integer connectionTimeout) { LOG.debug("setConnectionTimeout: timeout={}", connectionTimeout); assertNotInitialized(); m_connectionTimeout = connectionTimeout; return this; }
public EmptyKeyRelaxedTrustProvider() { super(EmptyKeyRelaxedTrustSSLContext.ALGORITHM + "Provider", 1.0, null); put( "SSLContext." + EmptyKeyRelaxedTrustSSLContext.ALGORITHM, EmptyKeyRelaxedTrustSSLContext.class.getName() ); } }
public NominatimGeocoderService() { m_clientWrapper = HttpClientWrapper.create() .dontReuseConnections(); if(m_useSystemProxy) { m_clientWrapper.useSystemProxySettings(); } }
/** * Set the number of retries when making requests. */ public HttpClientWrapper setRetries(final Integer retries) { LOG.debug("setRetries: retries={}", retries); assertNotInitialized(); m_retries = retries; return this; }
/** * Set the Host header used when making requests. */ public HttpClientWrapper setVirtualHost(final String host) { LOG.debug("setVirtualHost: host={}", host); assertNotInitialized(); m_virtualHost = host; return this; }
/** * Set the HTTP version used when making requests. */ public HttpClientWrapper setVersion(final HttpVersion httpVersion) { LOG.debug("setVersion: version={}", httpVersion); assertNotInitialized(); m_version = httpVersion; return this; }
/** * Use browser-compatible cookies rather than the default. */ public HttpClientWrapper useBrowserCompatibleCookies() { LOG.debug("useBrowserCompatibleCookies()"); assertNotInitialized(); m_cookieSpec = CookieSpecs.BROWSER_COMPATIBILITY; return this; }
/** * Preemptively pass basic authentication headers, rather than waiting for the server * to response asking for it. */ public HttpClientWrapper usePreemptiveAuth() { LOG.debug("usePreemptiveAuth()"); assertNotInitialized(); m_usePreemptiveAuth = true; return this; }
/** * Use LAX redirect strategy. * Automatically redirects all HEAD, GET and POST requests. * This strategy relaxes restrictions on automatic redirection of POST methods imposed by the HTTP specification. */ public HttpClientWrapper useLaxRedirect() { LOG.debug("useLaxRedirect()"); assertNotInitialized(); m_useLaxRedirect = true; return this; }
/** * Add basic auth credentials to requests created by the HttpClientWrapper. * @param username The username to connect as * @param password The password to use */ public HttpClientWrapper addBasicCredentials(final String username, final String password) { LOG.debug("addBasicCredentials: username={}", username); assertNotInitialized(); m_username = username; m_password = password; return this; }
/** * Configure HttpClient to not reuse connections for multiple requests. */ public HttpClientWrapper dontReuseConnections() { LOG.debug("dontReuseConnections()"); assertNotInitialized(); m_reuseConnections = false; return this; }
/** * Configure HttpClient to honor the system java proxy settings (-Dhttp.proxyHost= -Dhttp.proxyPort=) */ public HttpClientWrapper useSystemProxySettings() { LOG.debug("useSystemProxySettings()"); assertNotInitialized(); m_useSystemProxySettings = true; return this; }
/** * Set the socket timeout on connections. */ public HttpClientWrapper setSocketTimeout(final Integer socketTimeout) { LOG.debug("setSocketTimeout: timeout={}", socketTimeout); assertNotInitialized(); m_socketTimeout = socketTimeout; return this; }
/** * Set the User-Agent header used when making requests. */ public HttpClientWrapper setUserAgent(final String userAgent) { LOG.debug("setUserAgent: userAgent={}", userAgent); assertNotInitialized(); m_userAgent = userAgent; return this; }
/** * Add an {@link HttpRequestInterceptor} for all requests. */ public HttpClientWrapper addRequestInterceptor(final HttpRequestInterceptor interceptor) { LOG.debug("addRequestInterceptor: {}", interceptor); assertNotInitialized(); m_requestInterceptors.add(interceptor); return this; }
/** * Add an {@link HttpResponseInterceptor} for all responses. * @return */ public HttpClientWrapper addResponseInterceptor(HttpResponseInterceptor interceptor) { LOG.debug("addResponseInterceptor: {}", interceptor); assertNotInitialized(); m_responseInterceptors.add(interceptor); return this; }