Bläddra i källkod

配置读取方式修改

sakuya 3 år sedan
förälder
incheckning
3aa193076a

+ 16 - 13
eladmin-sign/src/main/java/me/zhengjie/sign/connector/HttpConnector.java

@@ -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 += "/";

+ 0 - 4
eladmin-system/src/main/java/me/zhengjie/base/util/CFCACertUtil.java

@@ -359,8 +359,6 @@ public class CFCACertUtil {
 	 * @throws Exception
 	 */
 	public String download(String filePath, String contractNo) throws Exception {
-		httpConnector.init();
-
 		byte[] fileBtye = httpConnector
 				.getFile("platId/" + httpConnector.getPlatID() + "/contractNo/" + contractNo + "/downloading");
 
@@ -401,7 +399,6 @@ public class CFCACertUtil {
 	 * @throws PKIException
 	 */
 	private String requestAPI(Object txReqVO, String txCode, File file) throws Exception {
-		httpConnector.init();
 		String req = new JsonObjectMapper().writeValueAsString(txReqVO);
 		System.out.println("req:" + req);
 		String signature = SecurityUtil.p7SignMessageDetach(httpConnector.getKeyStorePath(), httpConnector.getKeyStorePassword(),
@@ -427,7 +424,6 @@ public class CFCACertUtil {
 	 */
 	private String requestAPI(Object txReqVO, String txCode, InputStream file, String fileName)
 			throws Exception {
-		httpConnector.init();
 		String req = new JsonObjectMapper().writeValueAsString(txReqVO);
 		System.out.println("req:" + req);
 		String signature = SecurityUtil.p7SignMessageDetach(httpConnector.getKeyStorePath(), httpConnector.getKeyStorePassword(),