在SSL套接字后面的Jhipster中设置Feign

时间:2019-07-19 15:12:20

标签: java ssl jhipster spring-cloud-feign

我已经在JHipster中设置了网关微服务配置,但似乎无法使微服务使用FeignClient与网关进行通信

一切正常,直到我开始关注 https://www.jhipster.tech/production/#https-support这些说明,以将https服务器用作网关。

微服务看起来像这样:

@RestController
@RequestMapping("/api")
public class MicroserviceResource {
    private final GatewayFeignClientProxy feignClient;

    public MicroserviceResource(GatewayFeignClientProxy feignClient) {
        this.feignClient = feignClient;
    }
    @GetMapping("/test-microservice")
    public ResponseEntity<String> testMicroservice() {
        String response = feignClient.testGateway().getBody();
        return ResponseEntity.ok(" Gateway returned " + response);
    }
}

使用伪装客户端代理:

@FeignClient(name="g", path="/api")
public interface GatewayFeignClientProxy {
    @GetMapping("/test-gateway")
    public ResponseEntity<String> testGateway();
}

网关看起来像这样:

@RestController
@RequestMapping("/api")
public class MyResource {
    @GetMapping("/test-gateway")
    public ResponseEntity<String> testGateway() {
        return ResponseEntity.ok("OK");
    }
}

...完整的代码(包括所有三个提交)可以在我的github https://github.com/ccornchip

上找到

在上一次提交中,我得到“网关返回确定”。但是,当我使用letencrypt将网关切换为https时,会出现以下异常:

com.netflix.hystrix.exception.HystrixRuntimeException: GatewayFeignClientProxy#testGateway() failed and no fallback available.
        at com.netflix.hystrix.AbstractCommand$22.call(AbstractCommand.java:822)
        at com.netflix.hystrix.AbstractCommand$22.call(AbstractCommand.java:807)
        at rx.internal.operators.OperatorOnErrorResumeNextViaFunction$4.onError(OperatorOnErrorResumeNextViaFunction.java:140)
        at rx.internal.operators.OnSubscribeDoOnEach$DoOnEachSubscriber.onError(OnSubscribeDoOnEach.java:87)
        at rx.internal.operators.OnSubscribeDoOnEach$DoOnEachSubscriber.onError(OnSubscribeDoOnEach.java:87)
        at com.netflix.hystrix.AbstractCommand$DeprecatedOnFallbackHookApplication$1.onError(AbstractCommand.java:1472)
        at com.netflix.hystrix.AbstractCommand$FallbackHookApplication$1.onError(AbstractCommand.java:1397)
...
Caused by: feign.RetryableException: No subject alternative names matching IP address 172.18.0.10 found executing GET http://g/api/test-gateway
        at feign.FeignException.errorExecuting(FeignException.java:84)
        at feign.SynchronousMethodHandler.executeAndDecode(SynchronousMethodHandler.java:113)
        at feign.SynchronousMethodHandler.invoke(SynchronousMethodHandler.java:78)
        at feign.hystrix.HystrixInvocationHandler$1.run(HystrixInvocationHandler.java:106)
        at com.netflix.hystrix.HystrixCommand$2.call(HystrixCommand.java:302)
        at com.netflix.hystrix.HystrixCommand$2.call(HystrixCommand.java:298)
        at rx.internal.operators.OnSubscribeDefer.call(OnSubscribeDefer.java:46)
        ... 167 common frames omitted
Caused by: javax.net.ssl.SSLHandshakeException: No subject alternative names matching IP address 172.18.0.10 found
        at java.base/sun.security.ssl.Alert.createSSLException(Unknown Source)
        at java.base/sun.security.ssl.TransportContext.fatal(Unknown Source)
        at java.base/sun.security.ssl.TransportContext.fatal(Unknown Source)
        at java.base/sun.security.ssl.TransportContext.fatal(Unknown Source)
        at java.base/sun.security.ssl.CertificateMessage$T12CertificateConsumer.checkServerCerts(Unknown Source)
        at java.base/sun.security.ssl.CertificateMessage$T12CertificateConsumer.onCertificate(Unknown Source)
        at java.base/sun.security.ssl.CertificateMessage$T12CertificateConsumer.consume(Unknown Source)
        at java.base/sun.security.ssl.SSLHandshake.consume(Unknown Source)

更多信息,可能有用: 我正在使用docker运行它,网关和微服务都在它们自己的容器中。

1 个答案:

答案 0 :(得分:0)

有消息:

Caused by: feign.RetryableException: No subject alternative names matching IP address 172.18.0.10 found executing GET http://g/api/test-gateway
        at feign.FeignException.errorExecuting(FeignException.java:84)

您确定您的主机是正确的:

http://g/api/test-gateway

实际上,据此:

In my before-last commit, I got " Gateway returned OK".
But when I switched the gateway to https using letsencrypt, I get this exception:

这:

http://g/api/test-gateway

您没有将配置切换为使用https(或类似方式-您在端口80上使用https,没有公开端口80,仅公开443,依此类推)。