|
|
@@ -6,6 +6,7 @@ import me.zhengjie.sign.constant.MIMEType;
|
|
|
import me.zhengjie.sign.constant.Request;
|
|
|
import me.zhengjie.sign.constant.SystemConst;
|
|
|
import me.zhengjie.sign.util.CommonUtil;
|
|
|
+import org.springframework.beans.factory.InitializingBean;
|
|
|
import org.springframework.beans.factory.annotation.Value;
|
|
|
import org.springframework.stereotype.Component;
|
|
|
|
|
|
@@ -15,6 +16,10 @@ import java.io.InputStream;
|
|
|
import java.io.UnsupportedEncodingException;
|
|
|
import java.net.HttpURLConnection;
|
|
|
import java.net.URLEncoder;
|
|
|
+import java.nio.file.Files;
|
|
|
+import java.nio.file.Path;
|
|
|
+import java.nio.file.Paths;
|
|
|
+import java.nio.file.StandardCopyOption;
|
|
|
import java.util.HashMap;
|
|
|
import java.util.Map;
|
|
|
import java.util.Map.Entry;
|
|
|
@@ -22,7 +27,7 @@ import java.util.Map.Entry;
|
|
|
@Component
|
|
|
@Getter
|
|
|
@RequiredArgsConstructor
|
|
|
-public class HttpConnector {
|
|
|
+public class HttpConnector implements InitializingBean {
|
|
|
private final HttpClient httpClient;
|
|
|
@Value("${axq.connect.connectTimeout}")
|
|
|
private int connectTimeout;
|
|
|
@@ -30,8 +35,6 @@ public class HttpConnector {
|
|
|
private int readTimeout;
|
|
|
@Value("${axq.connect.isSSL}")
|
|
|
private boolean isSSL;
|
|
|
- @Value("${axq.request.jksPath}")
|
|
|
- private String jksPath;
|
|
|
@Value("${axq.request.jksPWD}")
|
|
|
private String keyStorePassword;
|
|
|
@Value("${axq.request.jksPWD}")
|
|
|
@@ -44,24 +47,24 @@ public class HttpConnector {
|
|
|
private String alias;
|
|
|
@Value("${axq.request.platID}")
|
|
|
private String platID;
|
|
|
+ @Value("${axq.request.jksPath}")
|
|
|
private String keyStorePath;
|
|
|
+ @Value("${axq.request.jksPath}")
|
|
|
private String trustStorePath;
|
|
|
|
|
|
- public void init() {
|
|
|
- String path = HttpConnector.class.getClassLoader().getResource("").getPath() + jksPath;
|
|
|
- keyStorePath = path;
|
|
|
- trustStorePath = path;
|
|
|
+ @Override
|
|
|
+ public void afterPropertiesSet() throws Exception {
|
|
|
+ Path temp = Paths.get(HttpConnector.class.getClassLoader().getResource("").getPath().concat(keyStorePath));
|
|
|
+ Files.copy(HttpClient.class.getClassLoader().getResourceAsStream(keyStorePath), temp, StandardCopyOption.REPLACE_EXISTING);
|
|
|
+ keyStorePath = temp.toFile().getPath();
|
|
|
+ trustStorePath = keyStorePath;
|
|
|
httpClient.config.connectTimeout = connectTimeout;
|
|
|
httpClient.config.readTimeout = readTimeout;
|
|
|
httpClient.httpConfig.userAgent = "TrustSign FEP";
|
|
|
httpClient.httpConfig.contentType = MIMEType.FORM;
|
|
|
httpClient.httpConfig.accept = MIMEType.JSON;
|
|
|
- try {
|
|
|
- if (isSSL) {
|
|
|
- httpClient.initSSL(keyStorePath, keyStorePassword.toCharArray(), trustStorePath, trustStorePassword.toCharArray());
|
|
|
- }
|
|
|
- } catch (Exception e) {
|
|
|
- e.printStackTrace();
|
|
|
+ if (isSSL) {
|
|
|
+ httpClient.initSSL(keyStorePath, keyStorePassword.toCharArray(), trustStorePath, trustStorePassword.toCharArray());
|
|
|
}
|
|
|
if (!url.endsWith("/")) {
|
|
|
url += "/";
|