解决 CXF 发送soap请求时由于缺少content-length

通过打出客户端cxf的报文信息:

lighttpd 返回"411 Length require"字样的错误。同时,在lighttpd的err日志里面,有如下的错误信息

2007-09-2716:17:39:(request.c.1110)POST-request,butcontent-length

missing -> 411

结果确定原因是cxf客户端调用时缺少了content-length属性,需要进行如下配置:

Client client = ClientProxy.getClient(greeter);

HTTPConduithttp=(HTTPConduit)client.getConduit();

HTTPClientPolicyhttpClientPolicy=http.getClient();

httpClientPolicy.setAllowChunking(false);

如果是xml可以采用以下配置:

  <beans xmlns="http://www.springframework.org/schema/beans

xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"

xmlns:sec="http://cxf.apache.org/configuration/security"

xmlns:http="http://cxf.apache.org/transports/http/configuration"

xmlns:jaxws="http://java.sun.com/xml/ns/jaxws"

xsi:schemaLocation="

http://cxf.apache.org/configuration/security

http://cxf.apache.org/schemas/configuration/security.xsd

http://cxf.apache.org/transports/http/configuration

http://cxf.apache.org/schemas/configuration/http-conf.xsd

http://www.springframework.org/schema/beans

http://www.springframework.org/schema/beans/spring-beans-2.0.xsd">

<http:conduitname="*.http-conduit">

<http:clientAllowChunking="false">

</http:conduit>

</beans>

相关推荐