Java 使用apache camel调用外部服务,给出HttpOperationFailedException?

Java 使用apache camel调用外部服务,给出HttpOperationFailedException?,java,spring,apache-camel,Java,Spring,Apache Camel,服务路径.xml Service.java @Autowired private ProducerTemplate template; @Value("${svrHost}") private String svrHost; @Value("${svrApiKey}") private String svrApiKey; public Response process(Request re

服务路径.xml

Service.java

    @Autowired
    private ProducerTemplate template;
    
    @Value("${svrHost}")
    private String svrHost;
 
    @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("host", svrHost);
    headers.put("x-api-key", svrApiKey);
    return headers;
}
当我直接从邮递员处点击服务时,使用完全相同的标题值和相同的请求值,我得到的响应状态为200 OK,但当我从我的服务中测试它,然后使用camel调用外部服务时,则没有得到响应


无法找出问题的真正原因。

不太重要,因为在您的案例中,POST应该是默认方法,但正确的语法应该是(Exchange.HTTP\u方法是Java)。如果您发送的主机头=host.com与URL=somehost.com中的主机不同,那么应该读取多少内容?如果这对您很重要,您可能需要查看http端点上的“customHostHeader”参数:http:somehost.com/endpoint?customHostHeader=host.com。若这并没有帮助,从服务器端获取更多信息当然会有所帮助。但可能服务器不在您的控制范围内?@LaurentChabot,并不确定服务器是如何配置的,但它通过AWS平台中的API网关公开,并且服务器团队提供了一个“vpcs AWS URL”,可能存在SSL/TSL协议在客户端与服务器端不匹配的可能性。服务器团队希望它是TSL v1.2,我们可以在将其发送到云之前在producerTemplate客户端上进行配置。
svrRouteEndpoint=http://somehost.com/endpoint
svrRoute=direct:route
svrHost=host.com
svrApiKey=abc123
    @Autowired
    private ProducerTemplate template;
    
    @Value("${svrHost}")
    private String svrHost;
 
    @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("host", svrHost);
    headers.put("x-api-key", svrApiKey);
    return headers;
}
Exception with the message: {"message": "Forbidden"} and status code : 403.