diff --git a/src/connector/jdbc/pom.xml b/src/connector/jdbc/pom.xml index 4d647669e4beaae39373bc2585c42f12e9c177ba..c2a086347ad1aef6fcd2365e9102f4f0e5e024ea 100755 --- a/src/connector/jdbc/pom.xml +++ b/src/connector/jdbc/pom.xml @@ -34,23 +34,9 @@ UTF-8 1.8 3.6.0 - 1.1.2 - 3.5 - - commons-logging - commons-logging - ${commons-logging.version} - - - * - * - - - - junit junit @@ -64,23 +50,12 @@ httpclient 4.5.8 - - org.apache.commons - commons-lang3 - 3.9 - com.alibaba fastjson 1.2.58 - - - org.apache.commons - commons-dbcp2 - 2.7.0 - diff --git a/src/connector/jdbc/src/main/java/com/taosdata/jdbc/rs/RestfulDriver.java b/src/connector/jdbc/src/main/java/com/taosdata/jdbc/rs/RestfulDriver.java index a8a92e412303b7e5ef871b86a9788c1fa774de0e..3e1eea2fbf9d37fd6415cbc467f5ceb6479f5bae 100644 --- a/src/connector/jdbc/src/main/java/com/taosdata/jdbc/rs/RestfulDriver.java +++ b/src/connector/jdbc/src/main/java/com/taosdata/jdbc/rs/RestfulDriver.java @@ -5,7 +5,7 @@ import com.alibaba.fastjson.JSONObject; import com.taosdata.jdbc.AbstractDriver; import com.taosdata.jdbc.TSDBConstants; import com.taosdata.jdbc.TSDBDriver; -import com.taosdata.jdbc.rs.util.HttpClientPoolUtil; +import com.taosdata.jdbc.utils.HttpClientPoolUtil; import java.sql.*; import java.util.Properties; diff --git a/src/connector/jdbc/src/main/java/com/taosdata/jdbc/rs/RestfulStatement.java b/src/connector/jdbc/src/main/java/com/taosdata/jdbc/rs/RestfulStatement.java index f0c24375e6dbaaaa9fbc49b742d6ad16a271fd86..8d67586be257fab2bf516f8aecad825e1dfdc02e 100644 --- a/src/connector/jdbc/src/main/java/com/taosdata/jdbc/rs/RestfulStatement.java +++ b/src/connector/jdbc/src/main/java/com/taosdata/jdbc/rs/RestfulStatement.java @@ -7,7 +7,7 @@ import com.taosdata.jdbc.AbstractStatement; import com.taosdata.jdbc.TSDBConstants; import com.taosdata.jdbc.TSDBError; import com.taosdata.jdbc.TSDBErrorNumbers; -import com.taosdata.jdbc.rs.util.HttpClientPoolUtil; +import com.taosdata.jdbc.utils.HttpClientPoolUtil; import com.taosdata.jdbc.utils.SqlSyntaxValidator; import java.sql.*; diff --git a/src/connector/jdbc/src/main/java/com/taosdata/jdbc/rs/util/HttpClientPoolUtil.java b/src/connector/jdbc/src/main/java/com/taosdata/jdbc/utils/HttpClientPoolUtil.java similarity index 93% rename from src/connector/jdbc/src/main/java/com/taosdata/jdbc/rs/util/HttpClientPoolUtil.java rename to src/connector/jdbc/src/main/java/com/taosdata/jdbc/utils/HttpClientPoolUtil.java index 9b1681ff948dc9257e7b775d947c598d9dc60378..5e2440fd1d0e551690c5f17fe60b30c1d4a377dc 100644 --- a/src/connector/jdbc/src/main/java/com/taosdata/jdbc/rs/util/HttpClientPoolUtil.java +++ b/src/connector/jdbc/src/main/java/com/taosdata/jdbc/utils/HttpClientPoolUtil.java @@ -1,6 +1,5 @@ -package com.taosdata.jdbc.rs.util; +package com.taosdata.jdbc.utils; -import org.apache.commons.lang3.StringUtils; import org.apache.http.HeaderElement; import org.apache.http.HeaderElementIterator; import org.apache.http.HttpEntity; @@ -39,7 +38,7 @@ public class HttpClientPoolUtil { /** * 初始化连接池 */ - public static synchronized void initPools() { + private static synchronized void initPools() { if (httpClient == null) { cm = new PoolingHttpClientConnectionManager(); cm.setDefaultMaxPerRoute(count); @@ -51,7 +50,7 @@ public class HttpClientPoolUtil { /** * Http connection keepAlive 设置 */ - public static ConnectionKeepAliveStrategy defaultStrategy = (response, context) -> { + private static ConnectionKeepAliveStrategy defaultStrategy = (response, context) -> { HeaderElementIterator it = new BasicHeaderElementIterator(response.headerIterator(HTTP.CONN_KEEP_ALIVE)); int keepTime = Http_Default_Keep_Time * 1000; while (it.hasNext()) { @@ -69,14 +68,6 @@ public class HttpClientPoolUtil { return keepTime; }; - public static CloseableHttpClient getHttpClient() { - return httpClient; - } - - public static PoolingHttpClientConnectionManager getHttpConnectionManager() { - return cm; - } - /** * 执行http post请求 * 默认采用Content-Type:application/json,Accept:application/json @@ -95,8 +86,10 @@ public class HttpClientPoolUtil { initPools(); } method = (HttpEntityEnclosingRequestBase) getRequest(uri, HttpPost.METHOD_NAME, DEFAULT_CONTENT_TYPE, 0); - method.setHeader("Authorization", "Taosd " + token); method.setHeader("Content-Type", "text/plain"); + method.setHeader("Connection", "keep-alive"); + method.setHeader("Authorization", "Taosd " + token); + method.setEntity(new StringEntity(data, Charset.forName("UTF-8"))); HttpContext context = HttpClientContext.create(); CloseableHttpResponse httpResponse = httpClient.execute(method, context); @@ -131,7 +124,7 @@ public class HttpClientPoolUtil { * @return HttpRequestBase 返回类型 * @author lisc */ - public static HttpRequestBase getRequest(String uri, String methodName, String contentType, int timeout) { + private static HttpRequestBase getRequest(String uri, String methodName, String contentType, int timeout) { if (httpClient == null) { initPools(); } @@ -152,7 +145,7 @@ public class HttpClientPoolUtil { method = new HttpPost(uri); } - if (StringUtils.isBlank(contentType)) { + if (contentType == null || contentType.isEmpty() || contentType.replaceAll("\\s", "").isEmpty()) { contentType = DEFAULT_CONTENT_TYPE; } method.addHeader("Content-Type", contentType); diff --git a/src/connector/jdbc/src/test/java/com/taosdata/jdbc/rs/AuthenticationTest.java b/src/connector/jdbc/src/test/java/com/taosdata/jdbc/rs/AuthenticationTest.java index 11d4a143535d7e116d92875a6eb52b5bf7a5b6e0..aba591ba56146f44787aa7d38367d6a6aee594bd 100644 --- a/src/connector/jdbc/src/test/java/com/taosdata/jdbc/rs/AuthenticationTest.java +++ b/src/connector/jdbc/src/test/java/com/taosdata/jdbc/rs/AuthenticationTest.java @@ -3,14 +3,16 @@ package com.taosdata.jdbc.rs; import org.junit.Before; import org.junit.Test; +import java.io.UnsupportedEncodingException; +import java.net.URLEncoder; import java.sql.*; public class AuthenticationTest { private static final String host = "127.0.0.1"; - // private static final String host = "master"; + // private static final String host = "master"; private static final String user = "root"; - private static final String password = "123456"; + private static final String password = "taos?data"; private Connection conn; @Test