解决 CXF 发送soap请求时因为缺少content-length 返回 "411 Length require"

错误信息记录:

2013-3-8 14:41:48 org.apache.cxf.phase.PhaseInterceptorChain doIntercept
信息: Interceptor has thrown exception, unwinding now
org.apache.cxf.interceptor.Fault: Response was of unexpected text/html ContentType.  Incoming portion of HTML stream: <html>
<head><title>411 Length Required</title></head>
<body bgcolor="white">
<center><h1>411 Length Required</h1></center>
<hr><center>nginx/1.2.2</center>
</body>
</html>


at org.apache.cxf.interceptor.StaxInInterceptor.handleMessage(StaxInInterceptor.java:73)
at org.apache.cxf.phase.PhaseInterceptorChain.doIntercept(PhaseInterceptorChain.java:226)
at org.apache.cxf.endpoint.ClientImpl.onMessage(ClientImpl.java:619)
at org.apache.cxf.transport.http.HTTPConduit$WrappedOutputStream.handleResponseInternal(HTTPConduit.java:2054)
at org.apache.cxf.transport.http.HTTPConduit$WrappedOutputStream.handleResponse(HTTPConduit.java:1939)
at org.apache.cxf.transport.http.HTTPConduit$WrappedOutputStream.close(HTTPConduit.java:1865)
at org.apache.cxf.transport.AbstractConduit.close(AbstractConduit.java:66)
at org.apache.cxf.transport.http.HTTPConduit.close(HTTPConduit.java:599)
at org.apache.cxf.interceptor.MessageSenderInterceptor$MessageSenderEndingInterceptor.handleMessage(MessageSenderInterceptor.java:62)
at org.apache.cxf.phase.PhaseInterceptorChain.doIntercept(PhaseInterceptorChain.java:226)
at org.apache.cxf.endpoint.ClientImpl.invoke(ClientImpl.java:449)
at org.apache.cxf.endpoint.ClientImpl.invoke(ClientImpl.java:279)
at org.apache.cxf.endpoint.ClientImpl.invoke(ClientImpl.java:231)
at org.apache.cxf.frontend.ClientProxy.invokeSync(ClientProxy.java:73)
at org.apache.cxf.jaxws.JaxWsClientProxy.invoke(JaxWsClientProxy.java:117)
at $Proxy28.getProjectList(Unknown Source)
at com.TegstMain.main(TegstMain.java:26)



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

lighttpd 返回"411 Length require"字样的错误。同时,在lighttpd的err日志里面,有如下的错误信息 
2007-09-27 16:17:39: (request.c.1110) POST-request, but content-length 
missing -> 411

 

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

 

Client client = ClientProxy.getClient(greeter); 
HTTPConduit http = (HTTPConduit) client.getConduit(); 
HTTPClientPolicy httpClientPolicy = 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:conduit name="*.http-conduit">  
<http:client AllowChunking="false">  
</http:conduit>  
</beans>


注:第一个设置客户端属性验证通过,第二个测试失败,也许我的配置不正确。 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值