Package com.clickhouse.client.http
Class ClickHouseHttpConnection
java.lang.Object
com.clickhouse.client.http.ClickHouseHttpConnection
- All Implemented Interfaces:
AutoCloseable
- Direct Known Subclasses:
ApacheHttpConnectionImpl,HttpUrlConnectionImpl
-
Field Summary
FieldsModifier and TypeFieldDescriptionprotected final ClickHouseConfigprotected final ClickHouseRequestManagerprotected final ClickHouseNodeprotected final String -
Constructor Summary
ConstructorsModifierConstructorDescriptionprotectedClickHouseHttpConnection(ClickHouseNode server, ClickHouseRequest<?> request, Map<String, Serializable> additionalParams) -
Method Summary
Modifier and TypeMethodDescriptionvoidclose()protected voidcreateDefaultHeaders(ClickHouseConfig config, ClickHouseNode server, String userAgent, String referer) protected Stringprotected Stringprotected static ProxygetProxy(ClickHouseConfig config) protected final Stringprotected booleanChecks whether the connection is reusable or not.mergeHeaders(Map<String, String> requestHeaders) Creates a merged map.protected static StringparseErrorFromException(String errorCode, String serverName, IOException e, byte[] bytes) abstract booleanping(int timeout) Sends a request to<baseUrl>/pingfor liveness detection.protected abstract ClickHouseHttpResponsepost(ClickHouseConfig config, String query, com.clickhouse.data.ClickHouseInputStream data, List<com.clickhouse.data.ClickHouseExternalTable> tables, com.clickhouse.data.ClickHouseOutputStream output, String url, Map<String, String> headers, Runnable postCloseAction) Posts query and data to server.protected static voidpostData(ClickHouseConfig config, byte[] boundary, String sql, com.clickhouse.data.ClickHouseInputStream data, List<com.clickhouse.data.ClickHouseExternalTable> tables, OutputStream requestStream) query(String query, List<com.clickhouse.data.ClickHouseExternalTable> tables, Map<String, String> headers)
-
Field Details
-
server
-
rm
-
config
-
defaultHeaders
-
url
-
-
Constructor Details
-
ClickHouseHttpConnection
protected ClickHouseHttpConnection(ClickHouseNode server, ClickHouseRequest<?> request, Map<String, Serializable> additionalParams)
-
-
Method Details
-
createDefaultHeaders
protected static Map<String,String> createDefaultHeaders(ClickHouseConfig config, ClickHouseNode server, String userAgent, String referer) -
getProxy
-
parseErrorFromException
protected static String parseErrorFromException(String errorCode, String serverName, IOException e, byte[] bytes) -
postData
protected static void postData(ClickHouseConfig config, byte[] boundary, String sql, com.clickhouse.data.ClickHouseInputStream data, List<com.clickhouse.data.ClickHouseExternalTable> tables, OutputStream requestStream) throws IOException - Throws:
IOException
-
closeQuietly
protected void closeQuietly() -
getBaseUrl
-
getDefaultUserAgent
-
getUserAgent
-
mergeHeaders
Creates a merged map.- Parameters:
requestHeaders- request headers- Returns:
- non-null merged headers
-
post
protected abstract ClickHouseHttpResponse post(ClickHouseConfig config, String query, com.clickhouse.data.ClickHouseInputStream data, List<com.clickhouse.data.ClickHouseExternalTable> tables, com.clickhouse.data.ClickHouseOutputStream output, String url, Map<String, String> headers, Runnable postCloseAction) throws IOExceptionPosts query and data to server.- Parameters:
query- non-blank queryconfig- non-null configurationdata- optionally input stream for batch updatingtables- optionally external tables for queryoutput- optionally output streamurl- optionally urlheaders- optionally request headerspostCloseAction- optionally post action- Returns:
- response
- Throws:
IOException- when error occured posting request and/or server failed to respond
-
isReusable
protected boolean isReusable()Checks whether the connection is reusable or not. This method will be called inClickHouseHttpClient.checkConnection(ClickHouseHttpConnection, ClickHouseNode, ClickHouseNode, ClickHouseRequest)for making a decision of whether to create a new connection. In addition to that, if a connection is NOT reusable, it will be closed right after corresponding ClickHouseResponse is closed.- Returns:
- true if it's reusable; false otherwise
-
ping
public abstract boolean ping(int timeout) Sends a request to<baseUrl>/pingfor liveness detection.- Parameters:
timeout- timeout in millisecond- Returns:
- true if server responded
Ok.; false otherwise
-
update
- Throws:
IOException
-
update
- Throws:
IOException
-
update
public ClickHouseHttpResponse update(String query, com.clickhouse.data.ClickHouseInputStream data) throws IOException - Throws:
IOException
-
update
public ClickHouseHttpResponse update(String query, com.clickhouse.data.ClickHouseInputStream data, Map<String, String> headers) throws IOException- Throws:
IOException
-
query
- Throws:
IOException
-
query
- Throws:
IOException
-
query
public ClickHouseHttpResponse query(String query, List<com.clickhouse.data.ClickHouseExternalTable> tables) throws IOException - Throws:
IOException
-
query
public ClickHouseHttpResponse query(String query, List<com.clickhouse.data.ClickHouseExternalTable> tables, Map<String, String> headers) throws IOException- Throws:
IOException
-
close
- Specified by:
closein interfaceAutoCloseable- Throws:
IOException
-