feign 忽略 ssl 证书
This commit is contained in:
parent
2f747f3433
commit
d5c2d86146
@ -0,0 +1,41 @@
|
|||||||
|
package cn.skcks.docking.gb28181.media.feign;
|
||||||
|
|
||||||
|
import feign.Client;
|
||||||
|
import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean;
|
||||||
|
import org.springframework.context.annotation.Bean;
|
||||||
|
import org.springframework.context.annotation.Configuration;
|
||||||
|
|
||||||
|
import javax.net.ssl.SSLContext;
|
||||||
|
import javax.net.ssl.TrustManager;
|
||||||
|
import javax.net.ssl.X509TrustManager;
|
||||||
|
import java.security.cert.CertificateException;
|
||||||
|
import java.security.cert.X509Certificate;
|
||||||
|
|
||||||
|
@Configuration
|
||||||
|
public class IgnoreHttpsSSLClient {
|
||||||
|
@Bean
|
||||||
|
@ConditionalOnMissingBean
|
||||||
|
public Client feignClient() {
|
||||||
|
try {
|
||||||
|
SSLContext ctx = SSLContext.getInstance("SSL");
|
||||||
|
X509TrustManager tm = new X509TrustManager() {
|
||||||
|
@Override
|
||||||
|
public void checkClientTrusted(X509Certificate[] chain,String authType) throws CertificateException {
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void checkServerTrusted(X509Certificate[] chain,String authType) throws CertificateException {
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public X509Certificate[] getAcceptedIssuers() {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
};
|
||||||
|
ctx.init(null, new TrustManager[]{tm}, null);
|
||||||
|
return new Client.Default(ctx.getSocketFactory(), (hostname, session) -> true);
|
||||||
|
} catch (Exception e) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,15 @@
|
|||||||
|
package cn.skcks.docking.gb28181.media.feign;
|
||||||
|
|
||||||
|
import feign.Client;
|
||||||
|
import org.springframework.boot.autoconfigure.condition.ConditionalOnBean;
|
||||||
|
import org.springframework.context.annotation.Bean;
|
||||||
|
|
||||||
|
public class IgnoreSSLFeignClientConfig {
|
||||||
|
|
||||||
|
// 加载自定义Client
|
||||||
|
@Bean
|
||||||
|
@ConditionalOnBean(IgnoreHttpsSSLClient.class)
|
||||||
|
public Client generateClient(IgnoreHttpsSSLClient ignoreHttpsSSLClient) {
|
||||||
|
return ignoreHttpsSSLClient.feignClient();
|
||||||
|
}
|
||||||
|
}
|
@ -8,6 +8,7 @@ import cn.skcks.docking.gb28181.media.dto.response.ZlmResponse;
|
|||||||
import cn.skcks.docking.gb28181.media.dto.rtp.*;
|
import cn.skcks.docking.gb28181.media.dto.rtp.*;
|
||||||
import cn.skcks.docking.gb28181.media.dto.snap.Snap;
|
import cn.skcks.docking.gb28181.media.dto.snap.Snap;
|
||||||
import cn.skcks.docking.gb28181.media.dto.version.VersionResp;
|
import cn.skcks.docking.gb28181.media.dto.version.VersionResp;
|
||||||
|
import cn.skcks.docking.gb28181.media.feign.IgnoreSSLFeignClientConfig;
|
||||||
import org.springframework.cloud.openfeign.FeignClient;
|
import org.springframework.cloud.openfeign.FeignClient;
|
||||||
import org.springframework.http.ResponseEntity;
|
import org.springframework.http.ResponseEntity;
|
||||||
import org.springframework.web.bind.annotation.GetMapping;
|
import org.springframework.web.bind.annotation.GetMapping;
|
||||||
@ -17,7 +18,7 @@ import org.springframework.web.bind.annotation.RequestParam;
|
|||||||
|
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
@FeignClient(name="zlmMediaServerProxy", url = "${media.url}")
|
@FeignClient(name="zlmMediaServerProxy", url = "${media.url}", configuration = IgnoreSSLFeignClientConfig.class)
|
||||||
public interface ZlmMediaHttpClient {
|
public interface ZlmMediaHttpClient {
|
||||||
@GetMapping("/index/api/getApiList")
|
@GetMapping("/index/api/getApiList")
|
||||||
ZlmResponse<List<String>> getApiList(@RequestParam String secret);
|
ZlmResponse<List<String>> getApiList(@RequestParam String secret);
|
||||||
|
Loading…
Reference in New Issue
Block a user