hessian http response code:411

记录一个好久之前的遇到的一个关于hessian的问题。

用 Hessian 实现 web service 过程当中,须要建立对象时,是使用 HTTP POST 方法来传递数据的。可是在有反向代理 (nginx) 的状况下,会抛出异常 (com.caucho.hessian.client.HessianConnectionException: 411:java.io.IOException: Server returned HTTP response code: 411 for URL:http://xxxx/xxx/xxxService) 。

首先来看下 HTTP 411 错误的解释: Length Required 服务器不能处理请求,除非客户发送一个 Content-Length 头。( HTTP 1.1 新)这是由于 Hessian 与服务端通讯默认是采起分块的方式 (chunked encoding) 发送数据,而反向代理要得到 Content-Length 这个头,才能处理请求,可是 Hessian 的请求中并无加入这个参数。

咱们使用的spring+hessian作服务化:
hessian本身的factory生成对象时:java

com.caucho.hessian.client.HessianProxyFactory中,默认ChunkedPost为true
    private boolean _isChunkedPost = true;
分块发送方式与服务端交换数据的参数,可是暂时nginx不支持

 


使用的spring的proxyfactorybean对象有一个setChunkedPost的方法,因此咱们能够在配置bean的时候给chunkedPost设置为false,从而透过nginx,实现通讯nginx

 

 

<bean id="xxx" class="org.springframework.remoting.caucho.HessianProxyFactoryBean">
        <property name="serviceUrl" value=""/>
        <property name="serviceInterface" value=""/>
    	<property name="chunkedPost" value="false"/>
    </bean>
相关文章
相关标签/搜索