fix: 修正feign client 调用异常问题
author刘洪青 <hongqing.liu@supwisdom.com>
Thu, 5 Sep 2019 10:10:09 +0000 (18:10 +0800)
committer刘洪青 <hongqing.liu@supwisdom.com>
Thu, 5 Sep 2019 10:10:09 +0000 (18:10 +0800)
aggr/admin/pom.xml
common/core/pom.xml
common/core/src/main/java/com/supwisdom/institute/backend/common/core/feign/FeignClientBuilder.java
pom.xml

index f7fb563..013b8c2 100644 (file)
     
     <!-- openfeign's dependency -->
     <dependency>
+      <groupId>com.netflix.feign</groupId>
+      <artifactId>feign-httpclient</artifactId>
+    </dependency>
+
+    <!-- <dependency>
       <groupId>org.apache.httpcomponents</groupId>
       <artifactId>httpclient</artifactId>
-    </dependency>
+    </dependency> -->
 
 
     <dependency>
index 0193355..b0a7e56 100644 (file)
       <artifactId>spring-cloud-starter-openfeign</artifactId>
       <optional>true</optional>
     </dependency>
-
+    <dependency>
+      <groupId>com.netflix.feign</groupId>
+      <artifactId>feign-httpclient</artifactId>
+      <optional>true</optional>
+    </dependency>
+    
     <dependency>
       <groupId>com.alibaba</groupId>
       <artifactId>fastjson</artifactId>
index 2fe606f..181ad10 100644 (file)
@@ -11,6 +11,7 @@ import org.apache.http.ssl.SSLContexts;
 import org.springframework.util.ResourceUtils;
 
 import feign.Client;
+import feign.httpclient.ApacheHttpClient;
 
 @Slf4j
 @lombok.Builder
@@ -27,11 +28,11 @@ public class FeignClientBuilder {
   public Client client() {
 
     if (!enabled) {
-      return new Client.Default(null, null);
+      return new ApacheHttpClient();
     }
     
     if (keyStore == null || keyStore.isEmpty()) {
-      return new Client.Default(null, null);
+      return new ApacheHttpClient();
     } else {
       try {
         SSLContextBuilder sslContextBuilder = SSLContexts.custom();
@@ -55,7 +56,7 @@ public class FeignClientBuilder {
         
         SSLSocketFactory sslSocketFactory = sslContext.getSocketFactory();
 
-        Client trustSSLSockets = new Client.Default(sslSocketFactory, new NoopHostnameVerifier());
+        Client trustSSLSockets = new Client.Default(sslSocketFactory, new NoopHostnameVerifier());  // FIXME: feign Client
         log.info("feignClient load with ssl.");
         return trustSSLSockets;
       } catch (Exception e) {
@@ -63,7 +64,7 @@ public class FeignClientBuilder {
       }
     }
     
-    return new Client.Default(null, null);
+    return new ApacheHttpClient();
   }
 
 }
diff --git a/pom.xml b/pom.xml
index babdfb8..0d4638d 100644 (file)
--- a/pom.xml
+++ b/pom.xml
         <version>${project.version}</version>
       </dependency>
 
+      <!-- 使用Apache HttpClient替换Feign原生httpclient -->
+      <dependency>
+        <groupId>com.netflix.feign</groupId>
+        <artifactId>feign-httpclient</artifactId>
+        <version>8.17.0</version>
+      </dependency>
 
       <dependency>
         <groupId>mysql</groupId>