【问题标题】:Cannot call HTTPS endpoint from Spring integration outbound gateway无法从 Spring 集成出站网关调用 HTTPS 端点
【发布时间】:2021-07-27 12:43:11
【问题描述】:

我有两个微服务和一个网关。一个微服务是用JHipster和spring boot(Service1)开发的,另一个是spring集成框架(IntegrationService)。现在我需要从 IntegrationService 调用 service1 API。我在这两个微服务中都使用 HTTPS 进行通信。但是当调用 API 时,我得到了以下错误日志。

2021-05-05 11:05:45.503 INFO 22105 --- [XNIO-1 task-4] cmasIntegrationService:IntegrationService org.springframework.messaging.MessageHandlingException 中的异常:URI [https:// //gateway/services/service1/api/viewrecords?id=100100100100157] 在 [bean 'outboundGateway';定义在:'类路径资源 [com/esi/app/service/IntegrationService.class]';来源:'org.springframework.core.type.classreading.SimpleMethodMetadata@3fa2213'];嵌套异常是 org.springframework.web.client.ResourceAccessException:“https:///gateway/services/service1/api/viewrecords”的 GET 请求出现 I/O 错误:PKIX 路径构建失败:sun .security.provider.certpath.SunCertPathBuilderException:无法找到请求目标的有效证书路径;嵌套异常是 javax.net.ssl.SSLHandshakeException:PKIX 路径构建失败:sun.security.provider.certpath.SunCertPathBuilderException:无法找到请求目标的有效证书路径, failedMessage=GenericMessage [payload={custId=100100100100157 }, headers={http_requestMethod=GET, errorChannel=org.springframework.messaging.core.GenericMessagingTemplate$TemporaryReplyChannel@703c6baf, Connection=Keep-Alive, Host=:port强>,接受= / em>的,授权=承载eyJhbGciOiJIUzUxMiJ9.eyJzdWIiOiJhZG1pbiIsImF1dGgiOiJST0xFX0FETUlOLFJPTEVfVVNFUiIsImV4cCI6MTYyMDI3ODk4NH0.-4ByR7OQY-G_dZh7XUHYOSo3FRS2Ug6JxVOkq6XOmhUV05LnQj10puEGotcJk1EUlYDvt4n2dAJFSuR3evnvHA,replyChannel=org.springframework.messaging.core.GenericMessagingTemplate$TemporaryReplyChannel@703c6baf,的 http_requestUrl = HTTP:/ /:/api/getrecordsfromservice1?transactionId=1111111111&id=100100100100157, id=1eec8d00-4040-c9b2-cdb1-4f2d8743d007, 内容-长度=0,http_userPrincipal=org.springframework.security.authentication.UsernamePasswordAuthenticationToken@143b9e60:主体:org.springframework.security.core.userdetails.User@586034f:用户名:admin;密码保护];启用:真; AccountNonExpired:真;凭据非过期:真; AccountNonLocked:真;授予权限:ROLE_ADMIN,ROLE_USER;凭证:[受保护];已认证:真实;详细信息:空;授予权限:ROLE_ADMIN、ROLE_USER、accept-encoding=gzip、deflate、br、user-agent=PostmanRuntime/7.28.0、timestamp=1620192945487}]

我用来调用 IntegrationService 的 API 端点是,

https:///gateway/services/integration/api/getrecordsfromservice1?transactionId=1111111111&id=100100100100157

integration是在网关中注册的IntegrationService服务名称。同样,service1 用于 Service1。

我无法理解的事情是:

  1. “http_requestUrl”如何更改为日志中的那个,而不是我点击的端点?
  2. 为什么我在两个微服务中都使用了 HTTPS,却出现了“SunCertPathBuilderException”?
  3. 要获取“Host”消息头,Spring 框架是在配置文件 application.yml 上查找 IP 和端口,而不是检查 URL?

有人可以帮忙吗? @artem

我的入站和出站网关如下:

@ServiceActivator(inputChannel = "channelOutbound")
    @Bean
    public HttpRequestExecutingMessageHandler outboundGateway() {
        final HttpRequestExecutingMessageHandler handler = new HttpRequestExecutingMessageHandler(
                viewrecordsEndpoint + "{id}");
        handler.setExpectedResponseType(String.class);
        handler.setHttpMethod(HttpMethod.GET);
        handler.setOutputChannelName("channelOutboundResponse");

        final ExpressionParser parser = new SpelExpressionParser();
        final Expression exp = parser.parseExpression("payload[id]");
        final Map<String, Expression> uriExp = new HashMap<>();
        uriExp.put(Constants.ID, exp);
        handler.setUriVariableExpressions(uriExp);
        return handler;
    }

@Bean
    public HttpRequestHandlingMessagingGateway inboundGateway() {
        final HttpRequestHandlingMessagingGateway gateway = new HttpRequestHandlingMessagingGateway();
        gateway.setRequestMapping(requestMapping());
        gateway.setRequestChannelName("channelInbound");
        gateway.setReplyChannelName("channelInboundReply");
        gateway.setErrorChannelName("channelInboundError");
        return gateway;
    }

private RequestMapping getGoldLoansForUcicInboundRequestMapping() {
        final RequestMapping mapping = new requestMapping();
        mapping.setPathPatterns("/api/getrecordsfromservice1");
        mapping.setMethods(HttpMethod.GET);
        return mapping;
    }

【问题讨论】:

    标签: java spring-boot spring-integration spring-integration-http


    【解决方案1】:

    Spring Integration 与 HTTPS 无关。它是标准的 SSL Java 配置,必须在双方都正确提供。将 HTTP 架构更改为 HTTPS 是不够的。

    在网上查看一些可能的解决方案:https://docs.oracle.com/cd/E19906-01/820-4916/6ngbm6hre/index.html

    回复。你的网址有问题。这可能就是 API Gateway 的工作原理。因此,它只是在外部请求到达其端点时剥离自己的上下文。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2017-04-12
      • 2014-06-08
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2018-09-22
      相关资源
      最近更新 更多