@Deprecated public abstract class HTTPSearcher extends ClusterSearcher<Connection>
This simply provides some utility methods for working with http connections and implements ping against the service.
This searcher contains code from the Apache httpcomponents client library, licensed to the Apache Software Foundation under the Apache License, Version 2.0. Please refer to http://www.apache.org/licenses/LICENSE-2.0 for details.
This class automatically adds a meta hit containing latency and other meta information about the obtained HTTP data using createRequestMeta(). The fields available in the hit are:
Modifier and Type | Class and Description |
---|---|
protected static class |
HTTPSearcher.SearcherHttpClient
Deprecated.
|
private static class |
HTTPSearcher.SearcherHttpRequest
Deprecated.
|
private static class |
HTTPSearcher.SearcherHttpRequestRetryHandler
Deprecated.
A retry handler which avoids retrying forever on errors misclassified as transient
|
protected static class |
HTTPSearcher.ThrowingCertificateStore
Deprecated.
|
Modifier and Type | Field and Description |
---|---|
private String |
certificateApplicationId
Deprecated.
The (optional) certificate application ID.
|
protected org.apache.http.HttpHost |
certificateProxy
Deprecated.
The (optional) certificate server proxy
|
private long |
certificateRetry
Deprecated.
Certificate server retry rate in the cache if no cert is found, in ms
|
private com.yahoo.jdisc.http.CertificateStore |
certificateStore
Deprecated.
|
private long |
certificateTtl
Deprecated.
Certificate cache TTL in ms
|
private com.yahoo.statistics.Counter |
connectTimeouts
Deprecated.
|
private HTTPParameters |
httpParameters
Deprecated.
The HTTP parameters to use.
|
static String |
IP_ADDRESS_UNKNOWN
Deprecated.
|
private static Charset |
iso8859Charset
Deprecated.
|
protected Logger |
log
Deprecated.
|
static String |
LOG_CONNECT_TIMEOUT_PREFIX
Deprecated.
|
static String |
LOG_HEADER_PREFIX
Deprecated.
|
static String |
LOG_HITCOUNT
Deprecated.
|
static String |
LOG_HOST
Deprecated.
|
static String |
LOG_IP_ADDRESS
Deprecated.
|
static String |
LOG_LATENCY_CONNECT
Deprecated.
|
static String |
LOG_LATENCY_FINISH
Deprecated.
|
static String |
LOG_LATENCY_START
Deprecated.
|
static String |
LOG_PATH
Deprecated.
|
static String |
LOG_PORT
Deprecated.
|
static String |
LOG_PROXY_HOST
Deprecated.
|
static String |
LOG_PROXY_PORT
Deprecated.
|
static String |
LOG_PROXY_TYPE
Deprecated.
|
static String |
LOG_QUERY_PARAM_PREFIX
Deprecated.
|
static String |
LOG_READ_TIMEOUT_PREFIX
Deprecated.
|
static String |
LOG_RESPONSE_HEADER_PREFIX
Deprecated.
|
static String |
LOG_SCHEME
Deprecated.
|
static String |
LOG_STATUS
Deprecated.
|
static String |
LOG_URI
Deprecated.
|
private static org.apache.http.conn.scheme.SchemeRegistry |
schemeRegistry
Deprecated.
|
private org.apache.http.conn.ClientConnectionManager |
sharedConnectionManager
Deprecated.
Set at construction if this is using persistent connections
|
private ThreadLocal<org.apache.http.impl.conn.SingleClientConnManager> |
singleClientConnManagerThreadLocal
Deprecated.
Set at construction if using non-persistent connections
|
protected boolean |
useCertificate
Deprecated.
Whether to use certificates
|
protected static String |
YCA_HTTP_HEADER
Deprecated.
|
Constructor and Description |
---|
HTTPSearcher(com.yahoo.component.ComponentId componentId,
List<Connection> connections,
HTTPParameters parameters,
com.yahoo.statistics.Statistics statistics)
Deprecated.
|
HTTPSearcher(com.yahoo.component.ComponentId componentId,
List<Connection> connections,
HTTPParameters parameters,
com.yahoo.statistics.Statistics statistics,
com.yahoo.jdisc.http.CertificateStore certificateStore)
Deprecated.
Creates a http searcher
|
HTTPSearcher(com.yahoo.component.ComponentId componentId,
List<Connection> connections,
String path,
com.yahoo.statistics.Statistics statistics)
Deprecated.
|
HTTPSearcher(com.yahoo.component.ComponentId componentId,
List<Connection> connections,
String path,
com.yahoo.statistics.Statistics statistics,
com.yahoo.jdisc.http.CertificateStore certificateStore)
Deprecated.
Creates a http searcher with default connection and read timeouts (currently 2 and 5s respectively)
|
Modifier and Type | Method and Description |
---|---|
protected void |
checkPing(org.apache.http.HttpResponse response,
Pong pong)
Deprecated.
Checks if the response is valid.
|
protected void |
cleanupHttpEntity(org.apache.http.HttpEntity entity)
Deprecated.
|
protected org.apache.http.client.HttpClient |
createClient(org.apache.http.params.HttpParams params)
Deprecated.
Creates a http client for one request.
|
protected ErrorMessage |
createMalformedUrlError(Query query,
Exception e)
Deprecated.
Utility method for creating error messages when a url is incorrect
|
protected org.apache.http.client.methods.HttpUriRequest |
createRequest(String method,
URI uri)
Deprecated.
Creates a HttpRequest.
|
protected org.apache.http.client.methods.HttpUriRequest |
createRequest(String method,
URI uri,
org.apache.http.HttpEntity entity)
Deprecated.
Creates a HttpRequest.
|
protected Hit |
createRequestMeta()
Deprecated.
Creates a meta hit dedicated to holding logging information.
|
private String |
createServerReporterErrorMessage(org.apache.http.StatusLine statusLine,
org.apache.http.HttpEntity entity)
Deprecated.
|
private Map<String,String> |
generateYCAHeaders()
Deprecated.
|
protected org.apache.http.conn.ClientConnectionManager |
getConnectionManager(org.apache.http.params.HttpParams params)
Deprecated.
Get a connection manager which may be used safely from this thread
|
protected org.apache.http.HttpEntity |
getEntity(URI uri,
Hit requestMeta,
Query query)
Deprecated.
Gets the HTTP entity that holds the response contents.
|
protected org.apache.http.HttpEntity |
getEntity(URI uri,
Query query)
Deprecated.
Same a
getEntity(uri, null) . |
private String |
getIpAddress(org.apache.http.protocol.HttpContext context)
Deprecated.
|
HTTPParameters |
getParameters()
Deprecated.
Returns the HTTP parameters used in this.
|
protected String |
getPath()
Deprecated.
Called by getURI() to get the path of the URI for the external service.
|
protected String |
getPingPath()
Deprecated.
Called by getPingURI() to get the path of the URI for pinging the
external service.
|
private org.apache.http.HttpResponse |
getPingResponse(URI uri,
Ping ping)
Deprecated.
|
protected URI |
getPingURI(Connection connection)
Deprecated.
The URI that is used to check if the provider is up or down.
|
Map<String,String> |
getQueryMap(Query query)
Deprecated.
Returns the key-value pairs that should be added as properties to the request url sent to the service.
|
protected org.apache.http.HttpEntity |
getRequestEntity(Query query,
Hit requestMeta)
Deprecated.
Returns the HTTP request entity to use when making the request for this query.
|
protected Map<String,String> |
getRequestHeaders(Query query,
Hit requestMeta)
Deprecated.
Returns the set of headers to be passed in the http request to provider backend.
|
protected org.apache.http.HttpResponse |
getResponse(URI uri,
Hit requestMeta,
int connectionTimeout,
int readTimeout)
Deprecated.
Executes an HTTP request and gets the response.
|
protected org.apache.http.HttpResponse |
getResponse(URI uri,
Hit requestMeta,
Query query)
Deprecated.
Executes an HTTP request and gets the response.
|
protected org.apache.http.HttpResponse |
getResponse(URI uri,
org.apache.http.HttpEntity reqEntity,
Map<String,String> reqHeaders,
Hit requestMeta,
int connectionTimeout,
int readTimeout)
Deprecated.
Executes an HTTP request and gets the response.
|
protected org.apache.http.HttpResponse |
getResponse(URI uri,
Query query)
Deprecated.
Same as
getResponse(uri, null) . |
protected URI |
getURI(Query query,
Connection connection)
Deprecated.
Same a
getURI(query, offset, hits, null) . |
protected URI |
getURI(Query query,
Hit requestMeta,
Connection connection)
Deprecated.
Creates the URI for a query.
|
private void |
initializeCertificate(HTTPParameters parameters,
com.yahoo.jdisc.http.CertificateStore certificateStore)
Deprecated.
Initialize certificate store and proxy if they have been set to non-null,
non-empty values.
|
private void |
initializeCertificate(String applicationId,
long ttl,
long retry,
com.yahoo.jdisc.http.CertificateStore certificateStore)
Deprecated.
Initialize the certificate.
|
private void |
initializeProxy(String host,
int port)
Deprecated.
Initialize the certificate proxy setting.
|
private boolean |
isAscii(String value)
Deprecated.
|
protected void |
logResponseLatency(long latency)
Deprecated.
|
Pong |
ping(Ping ping,
Connection connection)
Deprecated.
Pinging in HTTPBackend is done by creating a PING uri from http://host:port/path.
|
void |
shutdownConnectionManagers()
Deprecated.
Only for testing.
|
deconstruct, failed, fill, fill, getFirstConnection, getHasher, getMonitor, log, ping, robustSearch, search, search, search, shouldRetry, timedOut, working
ping
ensureFilled, getLogger, process, toString
getAnnotatedDependencies, getDefaultAnnotatedDependencies, getDependencies, initDependencies
clone, compareTo, getClassName, getId, getIdString, hasInitializedId, initId, isDeconstructable, setIsDeconstructable
equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
pingIterationCompleted
protected static final String YCA_HTTP_HEADER
private static final Charset iso8859Charset
public static final String LOG_PATH
public static final String LOG_PORT
public static final String LOG_HOST
public static final String LOG_IP_ADDRESS
public static final String IP_ADDRESS_UNKNOWN
public static final String LOG_SCHEME
public static final String LOG_URI
public static final String LOG_PROXY_PORT
public static final String LOG_PROXY_HOST
public static final String LOG_PROXY_TYPE
public static final String LOG_STATUS
public static final String LOG_LATENCY_FINISH
public static final String LOG_LATENCY_START
public static final String LOG_LATENCY_CONNECT
public static final String LOG_QUERY_PARAM_PREFIX
public static final String LOG_HEADER_PREFIX
public static final String LOG_RESPONSE_HEADER_PREFIX
public static final String LOG_HITCOUNT
public static final String LOG_CONNECT_TIMEOUT_PREFIX
public static final String LOG_READ_TIMEOUT_PREFIX
protected final Logger log
private HTTPParameters httpParameters
private final com.yahoo.statistics.Counter connectTimeouts
protected boolean useCertificate
private final com.yahoo.jdisc.http.CertificateStore certificateStore
private String certificateApplicationId
protected org.apache.http.HttpHost certificateProxy
private long certificateTtl
private long certificateRetry
private org.apache.http.conn.ClientConnectionManager sharedConnectionManager
private ThreadLocal<org.apache.http.impl.conn.SingleClientConnManager> singleClientConnManagerThreadLocal
private static final org.apache.http.conn.scheme.SchemeRegistry schemeRegistry
public HTTPSearcher(com.yahoo.component.ComponentId componentId, List<Connection> connections, String path, com.yahoo.statistics.Statistics statistics)
public HTTPSearcher(com.yahoo.component.ComponentId componentId, List<Connection> connections, String path, com.yahoo.statistics.Statistics statistics, com.yahoo.jdisc.http.CertificateStore certificateStore)
public HTTPSearcher(com.yahoo.component.ComponentId componentId, List<Connection> connections, HTTPParameters parameters, com.yahoo.statistics.Statistics statistics)
@Inject public HTTPSearcher(com.yahoo.component.ComponentId componentId, List<Connection> connections, HTTPParameters parameters, com.yahoo.statistics.Statistics statistics, com.yahoo.jdisc.http.CertificateStore certificateStore)
componentId
- the id of this instanceconnections
- the connections to establish to the backend nodesparameters
- the http parameters to use. This object will be frozen if it isn't alreadyprivate void initializeCertificate(HTTPParameters parameters, com.yahoo.jdisc.http.CertificateStore certificateStore)
public HTTPParameters getParameters()
public Map<String,String> getQueryMap(Query query)
getURI(com.yahoo.search.Query, com.yahoo.search.federation.http.Connection)
(from which this is called) is overridden.
This default implementation returns an empty LinkedHashMap.
private void initializeCertificate(String applicationId, long ttl, long retry, com.yahoo.jdisc.http.CertificateStore certificateStore)
private void initializeProxy(String host, int port)
protected URI getURI(Query query, Connection connection) throws MalformedURLException, URISyntaxException
getURI(query, offset, hits, null)
.MalformedURLException
URISyntaxException
getURI(Query, Hit, Connection)
protected URI getURI(Query query, Hit requestMeta, Connection connection) throws MalformedURLException, URISyntaxException
requestMeta
meta hit with the created URI HTTP properties.requestMeta
- a meta hit that holds logging information about this request (may be null
).MalformedURLException
URISyntaxException
protected String getPath()
protected URI getPingURI(Connection connection) throws MalformedURLException, URISyntaxException
protected String getPingPath()
protected void checkPing(org.apache.http.HttpResponse response, Pong pong)
response
- The response from the ping requestpong
- The pong result to return back to the calling method. This method
will add an error to the pong result (using addError) if the status of the HTTP response is 300 or above.public Pong ping(Ping ping, Connection connection)
ping
in class ClusterSearcher<Connection>
private org.apache.http.HttpResponse getPingResponse(URI uri, Ping ping) throws IOException
IOException
protected org.apache.http.HttpEntity getEntity(URI uri, Query query) throws IOException
getEntity(uri, null)
.uri
- resource to fetchquery
- the originating queryTimeoutException
- If query.timeLeft() equal to or lower than 0IOException
protected org.apache.http.HttpEntity getEntity(URI uri, Hit requestMeta, Query query) throws IOException
uri
- the request URI.requestMeta
- a meta hit that holds logging information about this request (may be null
).query
- the originating queryIOException
- Whenever HTTP status code is in the 300 or higher range.TimeoutException
- If query.timeLeft() equal to or lower than 0private String createServerReporterErrorMessage(org.apache.http.StatusLine statusLine, org.apache.http.HttpEntity entity)
protected Hit createRequestMeta()
protected void cleanupHttpEntity(org.apache.http.HttpEntity entity)
protected org.apache.http.HttpResponse getResponse(URI uri, Query query) throws IOException
getResponse(uri, null)
.IOException
protected org.apache.http.HttpResponse getResponse(URI uri, Hit requestMeta, Query query) throws IOException
uri
- the request URI.requestMeta
- a meta hit that holds logging information about this request (may be null
).query
- the originating query, used to calculate timeoutsIOException
protected Map<String,String> getRequestHeaders(Query query, Hit requestMeta)
protected org.apache.http.HttpEntity getRequestEntity(Query query, Hit requestMeta)
Do return a repeatable entity if HTTP retry is active.
protected org.apache.http.HttpResponse getResponse(URI uri, Hit requestMeta, int connectionTimeout, int readTimeout) throws IOException
uri
- the request URI.requestMeta
- a meta hit that holds logging information about this request (may be null
).connectionTimeout
- how long to wait for getting a connectionreadTimeout
- timeout for reading HTTP dataIOException
protected org.apache.http.HttpResponse getResponse(URI uri, org.apache.http.HttpEntity reqEntity, Map<String,String> reqHeaders, Hit requestMeta, int connectionTimeout, int readTimeout) throws IOException
uri
- the request URI.requestMeta
- a meta hit that holds logging information about this request (may be null
).connectionTimeout
- how long to wait for getting a connectionreadTimeout
- timeout for reading HTTP dataIOException
private String getIpAddress(org.apache.http.protocol.HttpContext context)
private boolean isAscii(String value)
protected void logResponseLatency(long latency)
protected org.apache.http.client.HttpClient createClient(org.apache.http.params.HttpParams params)
return new SearcherHttpClient(getConnectionManager(params), params);
protected org.apache.http.client.methods.HttpUriRequest createRequest(String method, URI uri)
return new HttpRequest(method,uri);
protected org.apache.http.client.methods.HttpUriRequest createRequest(String method, URI uri, org.apache.http.HttpEntity entity)
return new HttpRequest(method,uri);
protected org.apache.http.conn.ClientConnectionManager getConnectionManager(org.apache.http.params.HttpParams params)
protected ErrorMessage createMalformedUrlError(Query query, Exception e)
public void shutdownConnectionManagers()
Copyright © 2018. All rights reserved.