Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
A
asset-distribution
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
data-spider
asset-distribution
Commits
87f50b15
Commit
87f50b15
authored
Apr 01, 2020
by
郑建
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
增加删除临时文件
parent
b406378d
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
68 additions
and
55 deletions
+68
-55
HttpClientConfig.java
...roup/asset/distribution/config/http/HttpClientConfig.java
+68
-55
No files found.
src/main/java/com/quantgroup/asset/distribution/config/http/HttpClientConfig.java
View file @
87f50b15
...
@@ -106,66 +106,79 @@ public class HttpClientConfig {
...
@@ -106,66 +106,79 @@ public class HttpClientConfig {
@Bean
(
"niwodaiHttpsClient"
)
@Bean
(
"niwodaiHttpsClient"
)
public
CloseableHttpClient
niwodaiHttpsClient
()
throws
Exception
{
public
CloseableHttpClient
niwodaiHttpsClient
()
throws
Exception
{
/**
File
temp1
=
null
,
temp2
=
null
;
* 创建TrustManager
try
{
*/
/**
X509TrustManager
xtm
=
new
X509TrustManager
()
{
* 创建TrustManager
@Override
*/
public
void
checkClientTrusted
(
X509Certificate
[]
chain
,
String
authType
)
{
X509TrustManager
xtm
=
new
X509TrustManager
()
{
}
@Override
public
void
checkClientTrusted
(
X509Certificate
[]
chain
,
String
authType
)
{
}
@Override
@Override
public
void
checkServerTrusted
(
X509Certificate
[]
chain
,
String
authType
)
{
public
void
checkServerTrusted
(
X509Certificate
[]
chain
,
String
authType
)
{
}
}
@Override
@Override
public
X509Certificate
[]
getAcceptedIssuers
()
{
public
X509Certificate
[]
getAcceptedIssuers
()
{
return
null
;
return
null
;
}
}
};
};
String
classesPath
=
"/niwodai"
;
String
classesPath
=
"/niwodai"
;
KeyStore
keyStore
=
KeyStore
.
getInstance
(
"PKCS12"
);
KeyStore
keyStore
=
KeyStore
.
getInstance
(
"PKCS12"
);
keyStore
.
load
(
new
FileInputStream
(
asFile
(
readJarFile
(
classesPath
+
"/qg-keystore.jks"
))),
"password"
.
toCharArray
());
temp1
=
asFile
(
readJarFile
(
classesPath
+
"/qg-keystore.jks"
));
SSLContext
sslcontext
=
SSLContexts
.
custom
()
keyStore
.
load
(
new
FileInputStream
(
temp1
),
"password"
.
toCharArray
());
.
loadTrustMaterial
(
asFile
(
readJarFile
(
classesPath
+
"/qg-truststore.jks"
)),
"password"
.
toCharArray
(),
new
TrustSelfSignedStrategy
())
temp2
=
asFile
(
readJarFile
(
classesPath
+
"/qg-truststore.jks"
));
.
loadKeyMaterial
(
keyStore
,
"password"
.
toCharArray
())
SSLContext
sslcontext
=
SSLContexts
.
custom
()
.
build
();
.
loadTrustMaterial
(
temp2
,
"password"
.
toCharArray
(),
new
TrustSelfSignedStrategy
())
SSLConnectionSocketFactory
sslConnectionSocketFactory
=
new
SSLConnectionSocketFactory
(
.
loadKeyMaterial
(
keyStore
,
"password"
.
toCharArray
())
sslcontext
,
.
build
();
new
String
[]{
"TLSv1.2"
},
SSLConnectionSocketFactory
sslConnectionSocketFactory
=
new
SSLConnectionSocketFactory
(
null
,
sslcontext
,
SSLConnectionSocketFactory
.
getDefaultHostnameVerifier
());
new
String
[]{
"TLSv1.2"
},
Registry
<
ConnectionSocketFactory
>
socketFactoryRegistry
=
RegistryBuilder
.<
ConnectionSocketFactory
>
create
()
null
,
.
register
(
"http"
,
PlainConnectionSocketFactory
.
getSocketFactory
())
SSLConnectionSocketFactory
.
getDefaultHostnameVerifier
());
.
register
(
"https"
,
sslConnectionSocketFactory
)
Registry
<
ConnectionSocketFactory
>
socketFactoryRegistry
=
RegistryBuilder
.<
ConnectionSocketFactory
>
create
()
.
build
();
.
register
(
"http"
,
PlainConnectionSocketFactory
.
getSocketFactory
())
// connection manager
.
register
(
"https"
,
sslConnectionSocketFactory
)
PoolingHttpClientConnectionManager
connectionManager
=
new
PoolingHttpClientConnectionManager
(
socketFactoryRegistry
);
.
build
();
connectionManager
.
setMaxTotal
(
10000
);
// connection manager
connectionManager
.
setDefaultMaxPerRoute
(
1000
);
PoolingHttpClientConnectionManager
connectionManager
=
new
PoolingHttpClientConnectionManager
(
socketFactoryRegistry
);
connectionManager
.
setMaxTotal
(
10000
);
connectionManager
.
setDefaultMaxPerRoute
(
1000
);
HttpRequestRetryHandler
retryHandler
=
new
HttpRequestRetryHandler
()
{
HttpRequestRetryHandler
retryHandler
=
new
HttpRequestRetryHandler
()
{
@Override
@Override
public
boolean
retryRequest
(
IOException
arg0
,
int
retryTimes
,
HttpContext
arg2
)
{
public
boolean
retryRequest
(
IOException
arg0
,
int
retryTimes
,
HttpContext
arg2
)
{
if
(
retryTimes
>=
2
)
if
(
retryTimes
>=
2
)
return
false
;
if
(
arg0
instanceof
UnknownHostException
||
arg0
instanceof
ConnectTimeoutException
||
!(
arg0
instanceof
SSLException
)
||
arg0
instanceof
SocketTimeoutException
)
return
true
;
HttpClientContext
clientContext
=
HttpClientContext
.
adapt
(
arg2
);
HttpRequest
request
=
clientContext
.
getRequest
();
if
(!(
request
instanceof
HttpEntityEnclosingRequest
))
// 如果请求被认为是幂等的,那么就重试。即重复执行不影响程序其他效果的
return
true
;
return
false
;
return
false
;
if
(
arg0
instanceof
UnknownHostException
||
arg0
instanceof
ConnectTimeoutException
}
||
!(
arg0
instanceof
SSLException
)
||
arg0
instanceof
SocketTimeoutException
)
};
return
true
;
// keep alive strategy
HttpClientContext
clientContext
=
HttpClientContext
.
adapt
(
arg2
);
ConnectionKeepAliveStrategy
keepAliveStrategy
=
new
DefaultConnectionKeepAliveStrategy
();
HttpRequest
request
=
clientContext
.
getRequest
();
return
HttpClients
.
custom
()
if
(!(
request
instanceof
HttpEntityEnclosingRequest
))
// 如果请求被认为是幂等的,那么就重试。即重复执行不影响程序其他效果的
.
setConnectionManager
(
connectionManager
)
return
true
;
.
setRetryHandler
(
retryHandler
)
return
false
;
.
setKeepAliveStrategy
(
keepAliveStrategy
)
.
build
();
}
finally
{
if
(
temp1
!=
null
){
temp1
.
delete
();
}
}
};
if
(
temp2
!=
null
){
// keep alive strategy
temp2
.
delete
();
ConnectionKeepAliveStrategy
keepAliveStrategy
=
new
DefaultConnectionKeepAliveStrategy
();
}
return
HttpClients
.
custom
()
}
.
setConnectionManager
(
connectionManager
)
.
setRetryHandler
(
retryHandler
)
.
setKeepAliveStrategy
(
keepAliveStrategy
)
.
build
();
}
}
private
static
InputStream
readJarFile
(
String
fileName
)
throws
IOException
private
static
InputStream
readJarFile
(
String
fileName
)
throws
IOException
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment