CXF调用WebService报错: HTTP response ‘411: Length Required’

CXF调用WebService报错: HTTP response ‘411: Length Required’

血的教训,今天碰到接口调用失败,找了很多资料,网上资料很少而且没有什么实际解决方案,此处特记录以供以后遗忘时使用。
使用CXF调用WebService的时候,接口地址使用域名,内网环境会出现如下错误:

javax.xml.ws.WebServiceException: Could not send Message.
...省略...
Caused by: org.apache.cxf.transport.http.HTTPException: HTTP response '411: Length Required' when communicating with http://www.xxxx.com/xxxx/xxxxx/xxxx.asmx?wsdl
...省略...

经过测试,内网通过域名可直接访问该wsdl地址,但是通过CXF调用就会出现该错误。(不明所以)

JaxWsProxyFactoryBean factoryBean = new JaxWsProxyFactoryBean();
factoryBean.getOutInterceptors().add(newLoggingOutInterceptor());
factoryBean.setServiceClass(xxxxxxService.class);
factoryBean.setAddress("http://www.xxxx.com/xxxx/xxxxx/xxxx.asmx?wsdl");
xxxxxxService impl = (xxxxxService) factoryBean.create();
String wsResultXml = impl.xxxxxxx(xml);

此时就可能出现:

HTTPException: HTTP response ‘411: Length Required’ when communicating with

将:factoryBean.setAddress(“http://www.xxxx.com/xxxx/xxxxx/xxxx.asmx?wsdl”);改为
factoryBean.setAddress(“http://192.168.1.123:321/xxxx/xxxxx/xxxx.asmx?wsdl”);即可

网上解决方案也一并发出来以供参考

1、cxf客户端调用时缺少了content-length属性,需要进行如下配置:
Client client = ClientProxy.getClient(greeter);
HTTPConduit http = (HTTPConduit) client.getConduit();
HTTPClientPolicy httpClientPolicy = http.getClient();
httpClientPolicy.setAllowChunking(false);
2、修改cxf.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:conduit name="*.http-conduit">  
<http:client AllowChunking="false">  
</http:conduit>  
</beans>

3、请求方式GET修改为POST,GET参数过长导致

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值