Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
慢慢CG
TDengine
提交
a02e6952
T
TDengine
项目概览
慢慢CG
/
TDengine
与 Fork 源项目一致
Fork自
taosdata / TDengine
通知
1
Star
0
Fork
0
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
0
列表
看板
标记
里程碑
合并请求
0
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
T
TDengine
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
0
Issue
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
提交
Issue看板
提交
a02e6952
编写于
2月 25, 2021
作者:
Z
zyyang
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
change
上级
b352fc32
变更
5
隐藏空白更改
内联
并排
Showing
5 changed file
with
14 addition
and
44 deletion
+14
-44
src/connector/jdbc/pom.xml
src/connector/jdbc/pom.xml
+0
-25
src/connector/jdbc/src/main/java/com/taosdata/jdbc/rs/RestfulDriver.java
...dbc/src/main/java/com/taosdata/jdbc/rs/RestfulDriver.java
+1
-1
src/connector/jdbc/src/main/java/com/taosdata/jdbc/rs/RestfulStatement.java
.../src/main/java/com/taosdata/jdbc/rs/RestfulStatement.java
+1
-1
src/connector/jdbc/src/main/java/com/taosdata/jdbc/utils/HttpClientPoolUtil.java
...main/java/com/taosdata/jdbc/utils/HttpClientPoolUtil.java
+8
-15
src/connector/jdbc/src/test/java/com/taosdata/jdbc/rs/AuthenticationTest.java
...rc/test/java/com/taosdata/jdbc/rs/AuthenticationTest.java
+4
-2
未找到文件。
src/connector/jdbc/pom.xml
浏览文件 @
a02e6952
...
...
@@ -34,23 +34,9 @@
<project.build.sourceEncoding>
UTF-8
</project.build.sourceEncoding>
<java.version>
1.8
</java.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>
</properties>
<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>
<groupId>
junit
</groupId>
<artifactId>
junit
</artifactId>
...
...
@@ -64,23 +50,12 @@
<artifactId>
httpclient
</artifactId>
<version>
4.5.8
</version>
</dependency>
<dependency>
<groupId>
org.apache.commons
</groupId>
<artifactId>
commons-lang3
</artifactId>
<version>
3.9
</version>
</dependency>
<dependency>
<groupId>
com.alibaba
</groupId>
<artifactId>
fastjson
</artifactId>
<version>
1.2.58
</version>
</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>
<build>
...
...
src/connector/jdbc/src/main/java/com/taosdata/jdbc/rs/RestfulDriver.java
浏览文件 @
a02e6952
...
...
@@ -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
;
...
...
src/connector/jdbc/src/main/java/com/taosdata/jdbc/rs/RestfulStatement.java
浏览文件 @
a02e6952
...
...
@@ -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.*
;
...
...
src/connector/jdbc/src/main/java/com/taosdata/jdbc/
rs/util
/HttpClientPoolUtil.java
→
src/connector/jdbc/src/main/java/com/taosdata/jdbc/
utils
/HttpClientPoolUtil.java
浏览文件 @
a02e6952
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 {
/**
* 初始化连接池
*/
p
ublic
static
synchronized
void
initPools
()
{
p
rivate
static
synchronized
void
initPools
()
{
if
(
httpClient
==
null
)
{
cm
=
new
PoolingHttpClientConnectionManager
();
cm
.
setDefaultMaxPerRoute
(
count
);
...
...
@@ -51,7 +50,7 @@ public class HttpClientPoolUtil {
/**
* Http connection keepAlive 设置
*/
p
ublic
static
ConnectionKeepAliveStrategy
defaultStrategy
=
(
response
,
context
)
->
{
p
rivate
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
*/
p
ublic
static
HttpRequestBase
getRequest
(
String
uri
,
String
methodName
,
String
contentType
,
int
timeout
)
{
p
rivate
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
);
...
...
src/connector/jdbc/src/test/java/com/taosdata/jdbc/rs/AuthenticationTest.java
浏览文件 @
a02e6952
...
...
@@ -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
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录