如何在 Camel 的 http 组件上配置 TLSv1.2 来调用外部服务?

问题描述

以下是我正在使用的配置路由,用于调用外部服务。

services_routes.xml

 <beans xmlns="http://www.springframework.org/schema/beans"
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    xmlns:context="http://www.springframework.org/schema/context"
    xsi:schemaLocation="http://www.springframework.org/schema/beans
    http://www.springframework.org/schema/beans/spring-beans-3.0.xsd
    http://www.springframework.org/schema/context
    http://www.springframework.org/schema/context/spring-context-3.0.xsd
    http://camel.apache.org/schema/spring http://camel.apache.org/schema/spring/camel-spring.xsd">


    <routeContext id="servicesCommonRoutes"
        xmlns="http://camel.apache.org/schema/spring">

        <route id="Route">
            <from uri="direct:route" />
            <marshal>
                <custom ref="Request" />
            </marshal>
            <setHeader name="Content-Type" inheritErrorHandler="true">
                <constant>application/json</constant>
            </setHeader>
            <setHeader name="CamelHttpMethod">
                <constant>POST</constant>
            </setHeader>
            <to uri="{{svrRouteEndpoint}}" />
            <unmarshal>
                <custom ref="Response" />
            </unmarshal>
        </route>

    </routeContext>
</beans> 

application.properties

svrRouteEndpoint=https://vpce-somehost.awazonaws.com/endpoint
svrApiKey=0123abcd

Service.java

@Autowired
private ProducerTemplate template;
    
 @Value("${svrApiKey}")
private String svrApiKey;


public Response process(Request req,Map<String,Object> headers) throws CamelExecutionException {
    Response response = template.requestBodyAndHeaders("direct:route",req,headers,Response.class);
    return response;
}

 public Map<String,Object> createHeaders(String xWuExternalrefid) {
    Map<String,Object> headers = new HashMap<>();
    headers.put("x-api-key",svrApiKey);
    return headers;
}

问题:

当我尝试使用提供的 vpce URL 访问托管在 amazon-aws 上的服务时,现在使用上述路由。我收到一个 Forbidden 响应代码 = "403" with {"message" : "Forbidden"}。

除了“x-api-key”之外,没有其他标头需要访问服务,因此TLS版本有可能以某种方式 在客户端与服务器端不匹配。

我需要使用 producerTemplate 调用服务,但为此我需要在 Camel 客户端上配置/确保 TLSv1.2

那么如何在我的路由上配置(xml)TLSv1.2 service_routes.xml(最低配置),这样producerTemplate/camel 客户端可以访问服务,并且强制SSL为TLSv1.2

解决方法

暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!

如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。

小编邮箱:dio#foxmail.com (将#修改为@)