change
This commit is contained in:
parent
b352fc3228
commit
a02e695211
|
@ -34,23 +34,9 @@
|
||||||
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
|
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
|
||||||
<java.version>1.8</java.version>
|
<java.version>1.8</java.version>
|
||||||
<maven-compiler-plugin.version>3.6.0</maven-compiler-plugin.version>
|
<maven-compiler-plugin.version>3.6.0</maven-compiler-plugin.version>
|
||||||
<commons-logging.version>1.1.2</commons-logging.version>
|
|
||||||
<commons-lang3.version>3.5</commons-lang3.version>
|
|
||||||
<maven.test.jvmargs></maven.test.jvmargs>
|
<maven.test.jvmargs></maven.test.jvmargs>
|
||||||
</properties>
|
</properties>
|
||||||
<dependencies>
|
<dependencies>
|
||||||
<dependency>
|
|
||||||
<groupId>commons-logging</groupId>
|
|
||||||
<artifactId>commons-logging</artifactId>
|
|
||||||
<version>${commons-logging.version}</version>
|
|
||||||
<exclusions>
|
|
||||||
<exclusion>
|
|
||||||
<groupId>*</groupId>
|
|
||||||
<artifactId>*</artifactId>
|
|
||||||
</exclusion>
|
|
||||||
</exclusions>
|
|
||||||
</dependency>
|
|
||||||
|
|
||||||
<dependency>
|
<dependency>
|
||||||
<groupId>junit</groupId>
|
<groupId>junit</groupId>
|
||||||
<artifactId>junit</artifactId>
|
<artifactId>junit</artifactId>
|
||||||
|
@ -64,23 +50,12 @@
|
||||||
<artifactId>httpclient</artifactId>
|
<artifactId>httpclient</artifactId>
|
||||||
<version>4.5.8</version>
|
<version>4.5.8</version>
|
||||||
</dependency>
|
</dependency>
|
||||||
<dependency>
|
|
||||||
<groupId>org.apache.commons</groupId>
|
|
||||||
<artifactId>commons-lang3</artifactId>
|
|
||||||
<version>3.9</version>
|
|
||||||
</dependency>
|
|
||||||
<dependency>
|
<dependency>
|
||||||
<groupId>com.alibaba</groupId>
|
<groupId>com.alibaba</groupId>
|
||||||
<artifactId>fastjson</artifactId>
|
<artifactId>fastjson</artifactId>
|
||||||
<version>1.2.58</version>
|
<version>1.2.58</version>
|
||||||
</dependency>
|
</dependency>
|
||||||
|
|
||||||
<!-- https://mvnrepository.com/artifact/org.apache.commons/commons-dbcp2 -->
|
|
||||||
<dependency>
|
|
||||||
<groupId>org.apache.commons</groupId>
|
|
||||||
<artifactId>commons-dbcp2</artifactId>
|
|
||||||
<version>2.7.0</version>
|
|
||||||
</dependency>
|
|
||||||
</dependencies>
|
</dependencies>
|
||||||
|
|
||||||
<build>
|
<build>
|
||||||
|
|
|
@ -5,7 +5,7 @@ import com.alibaba.fastjson.JSONObject;
|
||||||
import com.taosdata.jdbc.AbstractDriver;
|
import com.taosdata.jdbc.AbstractDriver;
|
||||||
import com.taosdata.jdbc.TSDBConstants;
|
import com.taosdata.jdbc.TSDBConstants;
|
||||||
import com.taosdata.jdbc.TSDBDriver;
|
import com.taosdata.jdbc.TSDBDriver;
|
||||||
import com.taosdata.jdbc.rs.util.HttpClientPoolUtil;
|
import com.taosdata.jdbc.utils.HttpClientPoolUtil;
|
||||||
|
|
||||||
import java.sql.*;
|
import java.sql.*;
|
||||||
import java.util.Properties;
|
import java.util.Properties;
|
||||||
|
|
|
@ -7,7 +7,7 @@ import com.taosdata.jdbc.AbstractStatement;
|
||||||
import com.taosdata.jdbc.TSDBConstants;
|
import com.taosdata.jdbc.TSDBConstants;
|
||||||
import com.taosdata.jdbc.TSDBError;
|
import com.taosdata.jdbc.TSDBError;
|
||||||
import com.taosdata.jdbc.TSDBErrorNumbers;
|
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 com.taosdata.jdbc.utils.SqlSyntaxValidator;
|
||||||
|
|
||||||
import java.sql.*;
|
import java.sql.*;
|
||||||
|
|
|
@ -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.HeaderElement;
|
||||||
import org.apache.http.HeaderElementIterator;
|
import org.apache.http.HeaderElementIterator;
|
||||||
import org.apache.http.HttpEntity;
|
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) {
|
if (httpClient == null) {
|
||||||
cm = new PoolingHttpClientConnectionManager();
|
cm = new PoolingHttpClientConnectionManager();
|
||||||
cm.setDefaultMaxPerRoute(count);
|
cm.setDefaultMaxPerRoute(count);
|
||||||
|
@ -51,7 +50,7 @@ public class HttpClientPoolUtil {
|
||||||
/**
|
/**
|
||||||
* Http connection keepAlive 设置
|
* 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));
|
HeaderElementIterator it = new BasicHeaderElementIterator(response.headerIterator(HTTP.CONN_KEEP_ALIVE));
|
||||||
int keepTime = Http_Default_Keep_Time * 1000;
|
int keepTime = Http_Default_Keep_Time * 1000;
|
||||||
while (it.hasNext()) {
|
while (it.hasNext()) {
|
||||||
|
@ -69,14 +68,6 @@ public class HttpClientPoolUtil {
|
||||||
return keepTime;
|
return keepTime;
|
||||||
};
|
};
|
||||||
|
|
||||||
public static CloseableHttpClient getHttpClient() {
|
|
||||||
return httpClient;
|
|
||||||
}
|
|
||||||
|
|
||||||
public static PoolingHttpClientConnectionManager getHttpConnectionManager() {
|
|
||||||
return cm;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 执行http post请求
|
* 执行http post请求
|
||||||
* 默认采用Content-Type:application/json,Accept:application/json
|
* 默认采用Content-Type:application/json,Accept:application/json
|
||||||
|
@ -95,8 +86,10 @@ public class HttpClientPoolUtil {
|
||||||
initPools();
|
initPools();
|
||||||
}
|
}
|
||||||
method = (HttpEntityEnclosingRequestBase) getRequest(uri, HttpPost.METHOD_NAME, DEFAULT_CONTENT_TYPE, 0);
|
method = (HttpEntityEnclosingRequestBase) getRequest(uri, HttpPost.METHOD_NAME, DEFAULT_CONTENT_TYPE, 0);
|
||||||
method.setHeader("Authorization", "Taosd " + token);
|
|
||||||
method.setHeader("Content-Type", "text/plain");
|
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")));
|
method.setEntity(new StringEntity(data, Charset.forName("UTF-8")));
|
||||||
HttpContext context = HttpClientContext.create();
|
HttpContext context = HttpClientContext.create();
|
||||||
CloseableHttpResponse httpResponse = httpClient.execute(method, context);
|
CloseableHttpResponse httpResponse = httpClient.execute(method, context);
|
||||||
|
@ -131,7 +124,7 @@ public class HttpClientPoolUtil {
|
||||||
* @return HttpRequestBase 返回类型
|
* @return HttpRequestBase 返回类型
|
||||||
* @author lisc
|
* @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) {
|
if (httpClient == null) {
|
||||||
initPools();
|
initPools();
|
||||||
}
|
}
|
||||||
|
@ -152,7 +145,7 @@ public class HttpClientPoolUtil {
|
||||||
method = new HttpPost(uri);
|
method = new HttpPost(uri);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (StringUtils.isBlank(contentType)) {
|
if (contentType == null || contentType.isEmpty() || contentType.replaceAll("\\s", "").isEmpty()) {
|
||||||
contentType = DEFAULT_CONTENT_TYPE;
|
contentType = DEFAULT_CONTENT_TYPE;
|
||||||
}
|
}
|
||||||
method.addHeader("Content-Type", contentType);
|
method.addHeader("Content-Type", contentType);
|
|
@ -3,6 +3,8 @@ package com.taosdata.jdbc.rs;
|
||||||
import org.junit.Before;
|
import org.junit.Before;
|
||||||
import org.junit.Test;
|
import org.junit.Test;
|
||||||
|
|
||||||
|
import java.io.UnsupportedEncodingException;
|
||||||
|
import java.net.URLEncoder;
|
||||||
import java.sql.*;
|
import java.sql.*;
|
||||||
|
|
||||||
public class AuthenticationTest {
|
public class AuthenticationTest {
|
||||||
|
@ -10,7 +12,7 @@ public class AuthenticationTest {
|
||||||
private static final String host = "127.0.0.1";
|
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 user = "root";
|
||||||
private static final String password = "123456";
|
private static final String password = "taos?data";
|
||||||
private Connection conn;
|
private Connection conn;
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
|
|
Loading…
Reference in New Issue