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调用就会出现该错误。(不明所以)

  • 解决方案:
    将域名地址修改为IP地址即可。
  • 案例:
    • 域名地址为:http://www.xxxx.com/
    • 请求接口地址:http://www.xxxx.com/xxxx/xxxxx/xxxx.asmx?wsdl(C#提供的WebService接口地址)
    • 请求代码如下
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

  
  
  
  
  

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

你可能感兴趣的:(Java,WebService)