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
352eb876
Commit
352eb876
authored
Apr 01, 2020
by
郑建
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
增加删除临时文件
parent
87f50b15
Changes
1
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
58 additions
and
84 deletions
+58
-84
HttpClientConfig.java
...roup/asset/distribution/config/http/HttpClientConfig.java
+58
-84
No files found.
src/main/java/com/quantgroup/asset/distribution/config/http/HttpClientConfig.java
View file @
352eb876
...
...
@@ -105,9 +105,7 @@ public class HttpClientConfig {
}
@Bean
(
"niwodaiHttpsClient"
)
public
CloseableHttpClient
niwodaiHttpsClient
()
throws
Exception
{
File
temp1
=
null
,
temp2
=
null
;
try
{
public
CloseableHttpClient
niwodaiHttpsClient
()
throws
Exception
{
/**
* 创建TrustManager
*/
...
...
@@ -127,11 +125,11 @@ public class HttpClientConfig {
};
String
classesPath
=
"/niwodai"
;
KeyStore
keyStore
=
KeyStore
.
getInstance
(
"PKCS12"
);
temp1
=
asFile
(
readJarFile
(
classesPath
+
"/qg-keystore.jks"
));
keyStore
.
load
(
new
FileInputStream
(
temp1
),
"password"
.
toCharArray
()
);
temp2
=
asFile
(
readJarFile
(
classesPath
+
"/qg-truststore.jks"
));
keyStore
.
load
(
HttpClientConfig
.
class
.
getResourceAsStream
(
classesPath
+
"/qg-keystore.jks"
),
"password"
.
toCharArray
(
));
KeyStore
trustStore
=
KeyStore
.
getInstance
(
"JKS"
);
trustStore
.
load
(
HttpClientConfig
.
class
.
getResourceAsStream
(
classesPath
+
"/qg-truststore.jks"
),
"password"
.
toCharArray
(
));
SSLContext
sslcontext
=
SSLContexts
.
custom
()
.
loadTrustMaterial
(
temp2
,
"password"
.
toCharArray
()
,
new
TrustSelfSignedStrategy
())
.
loadTrustMaterial
(
trustStore
,
new
TrustSelfSignedStrategy
())
.
loadKeyMaterial
(
keyStore
,
"password"
.
toCharArray
())
.
build
();
SSLConnectionSocketFactory
sslConnectionSocketFactory
=
new
SSLConnectionSocketFactory
(
...
...
@@ -170,31 +168,7 @@ public class HttpClientConfig {
.
setRetryHandler
(
retryHandler
)
.
setKeepAliveStrategy
(
keepAliveStrategy
)
.
build
();
}
finally
{
if
(
temp1
!=
null
){
temp1
.
delete
();
}
if
(
temp2
!=
null
){
temp2
.
delete
();
}
}
}
private
static
InputStream
readJarFile
(
String
fileName
)
throws
IOException
{
return
HttpClientConfig
.
class
.
getResourceAsStream
(
fileName
);
}
public
static
File
asFile
(
InputStream
inputStream
)
throws
IOException
{
File
tmp
=
File
.
createTempFile
(
"trustKey"
,
".jks"
,
new
File
(
""
));
OutputStream
os
=
new
FileOutputStream
(
tmp
);
int
bytesRead
=
0
;
byte
[]
buffer
=
new
byte
[
8192
];
while
((
bytesRead
=
inputStream
.
read
(
buffer
,
0
,
8192
))
!=
-
1
)
{
os
.
write
(
buffer
,
0
,
bytesRead
);
}
inputStream
.
close
();
return
tmp
;
}
}
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