gpt4 book ai didi

java - Camel cxf客户端请求中的Http header Content-Length

转载 作者:行者123 更新时间:2023-11-30 06:22:18 25 4
gpt4 key购买 nike

我们有一个简单的 Camel 路线“从->到”:

<from uri="cxf:bean:testServiceProvider?loggingFeatureEnabled=true" />
<to uri="cxf:bean:testServiceClient?loggingFeatureEnabled=true" />

此路由的作用类似于第三方 Web 服务的路由器或代理:

  • 客户端将其用作端点。
  • 将 WSS header 添加到 Soap 消息中。
  • 将请求路由到真实端点。

此代理中的服务和客户端是使用 cxf beans 创建的。

端点的 Web 服务似乎需要 Content-Length HTTP header ,但默认情况下,对端点的 cxf 请求不包含此 header 。该代理完成的所有请求都会收到相同的响应:

HTTP response '411: Length required' when communicating with https://host:port/testService

我们尝试使用 OutInterceptor 添加此 header ,将其添加到 PROTOCOL_HEADERS:

Map<String, List> headers = (Map<String, List>) message.get(Message.PROTOCOL_HEADERS);
headers.put("Content-Length", Collections.singletonList(String.valueOf(messageLength)));

两个问题:

如何知道messageLength的值?有没有更简单的方法来做到这一点?

谢谢!

最佳答案

您可以尝试使用http:conduit,禁用AllowChunking。这将强制 cxf 在请求中包含 Content-Length header 。默认情况下,cxf 行为是允许分块,因此它可能会生成您面临的问题,甚至指定 Content-length header 。

<http:conduit name="{http://namespace}WebService.http-conduit">
<http:client AllowChunking="false" CacheControl="No-Cache"
ContentType="text/xml;charset=UTF-8" ConnectionTimeout="900000"
ReceiveTimeout="900000" Connection="Keep-Alive" />
</http:conduit>

关于java - Camel cxf客户端请求中的Http header Content-Length,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/47872631/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com