CXF 支持client 连接超时等设置吗?

141 views
Skip to first unread message

melin

unread,
May 12, 2008, 9:39:09 AM5/12/08
to cxf-zh
这个是我在https://jax-ws.dev.java.net/guide/上看到的
int timeout = ...;
Map<String, Object> ctxt =
((BindingProvider)proxy).getRequestContext();
ctxt.put(JAXWSProperties.CONNECT_TIMEOUT, timeout);

// setReadTimeout()
int timeout = ...;
Map<String, Object> ctxt =
((BindingProvider)proxy).getRequestContext();
ctxt.put("com.sun.xml.ws.request.timeout", timeout);

Freeman Fang

unread,
May 12, 2008, 9:53:00 AM5/12/08
to cxf...@googlegroups.com

支持,

通过code的方式

Client client = ClientProxy.getClient(proxy);
HTTPConduit conduit = (HTTPConduit)client.getConduit();
HTTPClientPolicy policy = conduit.getClient();
policy.setConnectionTimeout(300000);//单位是毫秒

通过spring配置的方式

<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:http-conf="http://cxf.apache.org/transports/http/configuration"
xsi:schemaLocation="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.xsd">

<http-conf:conduit
name="{http://apache.org/hello_world_soap_http}SoapPort.http-conduit">
<http-conf:client ConnectionTimeOut="30000"
/>
</http-conf:conduit>
</beans>


[1]是详细的配置信息
[1]http://cwiki.apache.org/CXF20DOC/client-http-transport.html

SkyTiger

unread,
May 13, 2008, 5:15:33 AM5/13/08
to cxf-zh
这是JETTY的配置吗?

On May 12, 6:53 pm, Freeman Fang <freeman.f...@gmail.com> wrote:
> 支持,
>
> 通过code的方式
>
> Client client = ClientProxy.getClient(proxy);
> HTTPConduit conduit = (HTTPConduit)client.getConduit();
> HTTPClientPolicy policy = conduit.getClient();
> policy.setConnectionTimeout(300000);//单位是毫秒
>
> 通过spring配置的方式
>
> <beans xmlns="http://www.springframework.org/schema/beans"
> xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
> xmlns:http-conf="http://cxf.apache.org/transports/http/configuration"
> xsi:schemaLocation="http://cxf.apache.org/transports/http/configurationhttp://cxf.apache.org/schemas/configuration/http-conf.xsdhttp://www.springframework.org/schema/beanshttp://www.springframework.org/schema/beans/spring-beans.xsd">

willem

unread,
May 13, 2008, 6:14:12 AM5/13/08
to cxf-zh
这是HTTPConduit的设置不是Jetty的设置 ,
有关Jetty[1] 和HTTPServer[2]的设置。

[1]http://cwiki.apache.org/CXF20DOC/jetty-configuration.html
[2]http://cwiki.apache.org/CXF20DOC/server-http-transport.html

姜宁 (Willem)
--------------------------------
http://willem.bokeland.com

On 5月13日, 下午5时15分, SkyTiger <darktemplars...@gmail.com> wrote:
> 这是JETTY的配置吗?
>
> On May 12, 6:53 pm, Freeman Fang <freeman.f...@gmail.com> wrote:
>
> > 支持,
>
> > 通过code的方式
>
> > Client client = ClientProxy.getClient(proxy);
> > HTTPConduit conduit = (HTTPConduit)client.getConduit();
> > HTTPClientPolicy policy = conduit.getClient();
> > policy.setConnectionTimeout(300000);//单位是毫秒
>
> > 通过spring配置的方式
>
> > <beans xmlns="http://www.springframework.org/schema/beans"
> > xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
> > xmlns:http-conf="http://cxf.apache.org/transports/http/configuration"
> > xsi:schemaLocation="http://cxf.apache.org/transports/http/configurationhttp://cxf.apache....">

Alex

unread,
May 13, 2008, 8:48:35 AM5/13/08
to cxf-zh
通过spring的方式在2.03的时候不行。。。我以前是code的方式的。
现在不知道怎样

On 5月12日, 下午9时53分, Freeman Fang <freeman.f...@gmail.com> wrote:
> 支持,
>
> 通过code的方式
>
> Client client = ClientProxy.getClient(proxy);
> HTTPConduit conduit = (HTTPConduit)client.getConduit();
> HTTPClientPolicy policy = conduit.getClient();
> policy.setConnectionTimeout(300000);//单位是毫秒
>
> 通过spring配置的方式
>
> <beans xmlns="http://www.springframework.org/schema/beans"
> xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
> xmlns:http-conf="http://cxf.apache.org/transports/http/configuration"
> xsi:schemaLocation="http://cxf.apache.org/transports/http/configurationhttp://cxf.apache.org/schemas/configuration/http-conf.xsdhttp://www.springframework.org/schema/beanshttp://www.springframework.org/schema/beans/spring-beans.xsd">

willem

unread,
May 13, 2008, 9:37:17 AM5/13/08
to cxf-zh
现在应该可以了,这个问题好像是在CXF2.0.4 中就Fix了。

姜宁 (Willem)
--------------------------------
http://willem.bokeland.com

On 5月13日, 下午8时48分, Alex <bianjiang.fore...@gmail.com> wrote:
> 通过spring的方式在2.03的时候不行。。。我以前是code的方式的。
> 现在不知道怎样
>
> On 5月12日, 下午9时53分, Freeman Fang <freeman.f...@gmail.com> wrote:
>
> > 支持,
>
> > 通过code的方式
>
> > Client client = ClientProxy.getClient(proxy);
> > HTTPConduit conduit = (HTTPConduit)client.getConduit();
> > HTTPClientPolicy policy = conduit.getClient();
> > policy.setConnectionTimeout(300000);//单位是毫秒
>
> > 通过spring配置的方式
>
> > <beans xmlns="http://www.springframework.org/schema/beans"
> > xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
> > xmlns:http-conf="http://cxf.apache.org/transports/http/configuration"
> > xsi:schemaLocation="http://cxf.apache.org/transports/http/configurationhttp://cxf.apache....">

stevenmo

unread,
May 14, 2008, 5:42:45 AM5/14/08
to cxf-zh
急求助
在jetty 的服务器上运行cxf 的客户端,传输数据量比较大 运行一分钟就报错
java.net.SocketTimeoutException: Read timed out
在调用代码中已经加上
Client client = ClientProxy.getClient(webCenterInfoClient);
HTTPConduit conduit = (HTTPConduit)client.getConduit();
HTTPClientPolicy policy = conduit.getClient();
int time =10*60*60*1000;
policy.setConnectionTimeout(0);//单位是毫秒 采用配置时间 10*60*60*1000 也报错

是否这个时间的配置还和jetty 配置有关?

stevenmo

unread,
May 14, 2008, 5:46:16 AM5/14/08
to cxf-zh
如果采用 java application 方式运行客户端调用webservice服务是可以正常运行的

Freeman Fang

unread,
May 14, 2008, 5:56:14 AM5/14/08
to cxf...@googlegroups.com
不是很明白你的意思, 你能详细描述自己的问题么?

你说
"在jetty 的服务器上运行cxf 的客户端"
是什么意思?

java.net.SocketTimeoutException: Read timed out
这个是哪里抛出来的? 完整的exception是什么?

Freeman Fang

unread,
May 14, 2008, 6:07:08 AM5/14/08
to cxf...@googlegroups.com
"在jetty 的服务器上运行cxf 的客户端"

是指把jetty做为 servlet container使用, 把cxf service部署到里面么?

然后client 连这个service出现问题?

Freeman

Message has been deleted

stevenmo

unread,
May 14, 2008, 11:09:04 PM5/14/08
to cxf-zh
项目中使用是这样的 有两个系统 一个是前置服务器系统(采用jetty做为servlet container 其实也就是一个后台程序 不过提
供了一个cxf webservice给其它系统调用) 一个是信息中心系统(暂时采用tomcat作为servlet container 提供
一个cxf webservice给前置服务器调用 上传数据 传输过程中采用了gzip压缩数据) 传输是前置服务器系统通过quartz定时器定时
在后台调用的 现在的问题是如果前置服务器上传的数据量比较大的时候(超过10m吧 一分钟后就报Read timed out错误,少量数据几m
的时候是可以正常运行的), 然后猜想是客户端连接超时的问题 加上前面的设置client链接时间后结果还是一样 是否是说还有什么方面要配置
的 错误信息如下:
java.net.SocketTimeoutException: Read timed out
at java.net.SocketInputStream.socketRead0(Native Method)
at java.net.SocketInputStream.read(SocketInputStream.java:129)
at java.io.BufferedInputStream.fill(BufferedInputStream.java:218)
at java.io.BufferedInputStream.read1(BufferedInputStream.java:258)
at java.io.BufferedInputStream.read(BufferedInputStream.java:317)
at sun.net.www.http.HttpClient.parseHTTPHeader(HttpClient.java:632)
at sun.net.www.http.HttpClient.parseHTTP(HttpClient.java:577)
at
sun.net.www.protocol.http.HttpURLConnection.getInputStream(HttpURLConnection.java:
1004)
at java.net.HttpURLConnection.getResponseCode(HttpURLConnection.java:
373)
at org.apache.cxf.transport.http.HTTPConduit
$WrappedOutputStream.handleResponse(HTTPConduit.java:1896)
at org.apache.cxf.transport.http.HTTPConduit
$WrappedOutputStream.close(HTTPConduit.java:1824)
at java.util.zip.DeflaterOutputStream.close(DeflaterOutputStream.java:
149)
at
com.syscanhc.webservice.cxf.StreamInterceptor.StreamInterceptor.handleMessage(StreamInterceptor.java:
88)
at
org.apache.cxf.phase.PhaseInterceptorChain.doIntercept(PhaseInterceptorChain.java:
221)
at org.apache.cxf.endpoint.ClientImpl.invoke(ClientImpl.java:276)
at org.apache.cxf.endpoint.ClientImpl.invoke(ClientImpl.java:222)
at org.apache.cxf.frontend.ClientProxy.invokeSync(ClientProxy.java:
73)
at org.apache.cxf.jaxws.JaxWsClientProxy.invoke(JaxWsClientProxy.java:
177)
at $Proxy33.pushOutpatientpaytypes(Unknown Source)
at
com.syscanhc.oa.util.CenterInfoDataUploadServiceImpl.upload(CenterInfoDataUploadServiceImpl.java:
228)
at com.syscanhc.oa.util.CenterInfoDataUploadServiceImpl$
$FastClassByCGLIB$$176b11d4.invoke(<generated>)
at net.sf.cglib.proxy.MethodProxy.invoke(MethodProxy.java:149)
at org.springframework.aop.framework.Cglib2AopProxy
$CglibMethodInvocation.invokeJoinpoint(Cglib2AopProxy.java:695)
at
org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:
144)
at
org.springframework.transaction.interceptor.TransactionInterceptor.invoke(TransactionInterceptor.java:
107)
at
org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:
166)
at org.springframework.aop.framework.Cglib2AopProxy
$DynamicAdvisedInterceptor.intercept(Cglib2AopProxy.java:630)
at com.syscanhc.oa.util.CenterInfoDataUploadServiceImpl$
$EnhancerByCGLIB$$96847f20.upload(<generated>)
at
com.syscanhc.oa.util.CenterInfoDataUpload.uploadData(CenterInfoDataUpload.java:
115)
at
com.syscanhc.oa.util.CenterInfoDataUpload.reScheduleJob(CenterInfoDataUpload.java:
133)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at
sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:
39)
at
sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:
25)
at java.lang.reflect.Method.invoke(Method.java:597)
at org.springframework.util.MethodInvoker.invoke(MethodInvoker.java:
283)
at
org.springframework.scheduling.quartz.MethodInvokingJobDetailFactoryBean
$MethodInvokingJob.executeInternal(MethodInvokingJobDetailFactoryBean.java:
272)
at
org.springframework.scheduling.quartz.QuartzJobBean.execute(QuartzJobBean.java:
86)
at org.quartz.core.JobRunShell.run(JobRunShell.java:202)
at org.quartz.simpl.SimpleThreadPool
$WorkerThread.run(SimpleThreadPool.java:529)

Freeman Fang

unread,
May 14, 2008, 11:33:32 PM5/14/08
to cxf...@googlegroups.com

cool, 等于你是在jetty这个servlet container里面使用了cxf client, 去叫另外
一个tomcat servlet container中的cxf service, right?


1. 你的问题在我看来还是http conduit超时的问题,我比较怀疑是你的代码没有设
置对, 你能把你client的代码都提供出来么?我觉得可能是你没有把正确的http
conduit配置写到相应的client proxy上, Willem, 你的意见是什么?

2. 我不是很清楚你的wsdl接口以及怎么使用gzip压缩实现的, 一般来讲大数据的
传输我们应该用附件的形式例如mtom来传. 如果你不方便把接口和代码发到整个论
坛上, 可以直接给我或者Willem写信

Freeman

willem

unread,
May 14, 2008, 11:44:38 PM5/14/08
to cxf-zh
看了你对问题的详细描述,我发现咱们得另开一个帖子了。
你的问题不是连接超时的问题,而是接收超时的问题 :)

你对HttpConduit 的 HTTPClientPolicy设置的项目出错了应该设置

HTTPClientPolicy policy = conduit.getClient();
// 一直等到接收, 缺省的接收等待时间是60秒
policy.setReceiveTimeout(0)

有关HTTP 传输设置的其他参数还有很多,建议你好好看一下CXF 的wiki [1]

[1]http://cwiki.apache.org/CXF20DOC/client-http-transport-including-
ssl-support.html

姜宁 (Willem)
--------------------------------
http://willem.bokeland.com

On 5月15日, 上午11时09分, stevenmo <mokai...@gmail.com> wrote:
> 项目中使用是这样的 有两个系统 一个是前置服务器系统(采用jetty做为servlet container 其实也就是一个后台程序 不过提
> 供了一个cxf webservice给其它系统调用) 一个是信息中心系统(暂时采用tomcat作为servlet container 提供
> 一个cxf webservice给前置服务器调用 上传数据 传输过程中采用了gzip压缩数据) 传输是前置服务器系统通过quartz定时器定时
> 在后台调用的 现在的问题是如果前置服务器上传的数据量比较大的时候(超过10m吧 一分钟后就报Read timed out错误,少量数据几m
> 的时候是可以正常运行的), 然后猜想是客户端连接超时的问题 加上前面的设置client链接时间后结果还是一样 是否是说还有什么方面要配置
> 的 错误信息如下:
> java.net.SocketTimeoutException: Read timed out
> at java.net.SocketInputStream.socketRead0(Native Method)
> at java.net.SocketInputStream.read(SocketInputStream.java:129)
> at java.io.BufferedInputStream.fill(BufferedInputStream.java:218)
> at java.io.BufferedInputStream.read1(BufferedInputStream.java:258)
> at java.io.BufferedInputStream.read(BufferedInputStream.java:317)
> at sun.net.www.http.HttpClient.parseHTTPHeader(HttpClient.java:632)
> at sun.net.www.http.HttpClient.parseHTTP(HttpClient.java:577)
> at
> sun.net.www.protocol.http.HttpURLConnection.getInputStream(HttpURLConnection....

stevenmo

unread,
May 15, 2008, 4:55:53 AM5/15/08
to cxf-zh
今天早上在测试Willem说的解决办法 设置接收时间为0后 系统跑稍微再大点的数据也不再报错了(我是采用传输泛型集合的方式上传的 原来数
据传输只能在大概一万多条左右 现在可以传输3w多条记录 不过假如测试数据有十万条左右 系统就不动弹了 :) )
在信息中心服务系统这块webservice 我配置的接口是采用 泛型集合类型上传 如: void test(List<model>
list) throws AppBizException; 前置服务器方便取数据 也方便信息中心服务系统把数据写入数据库 不知泛型集合可否
通过配置 bean.xml 文件采用 mtom 方式设置上传?

前置服务器系统的webservice我是采用byte[]数组形式做数据上传的 如 void test(byte[] content)
throws AppBizException; 在测试读取40m文件数据进行传输没问题
不过还是想请教下 Freeman Fang 和Willem 我这种做法是否合理 和mtom 比较有什么不足的地方 是否是采用 mtom
附件上传的方式比较好 谢谢两位了 呵呵

Freeman Fang

unread,
May 15, 2008, 7:13:02 AM5/15/08
to cxf...@googlegroups.com
Hi,

你的这种方式实际是在soap body里面传很大的二进制,但是编码格式是
base64binary, 这是一种可打印的编码格式,意味着要使用较大的空间来表示二进
制数据(通常的二进制你是没有办法打印出来的,都是乱码之类的), 如果你说数据
有十兆那就意味着你的soap body有十兆,这不是good practice

但是使用mtom 之后, soap消息中的base64binary编码可以转化为真正的二进制附
件,也就是大数据其实是以http 附件的形式来传送,我们用http都知道,附件再大也
不怕,
这个应该可以解决你传输层面超市的问题.

目前cxf支持mtom比较简单的方式是wsdl first, 你需要在想mtom格式的数据
element后边加上xmime:expectedContentTypes="application/octet- stream"
你可以看下kit中的mtom 这个例子.


如果是java first的方式,会比较复杂, 你需要自己写DataHandler的wrapper bean
并且加上annotation
例如

@XmlType
public class Picture {
private String title;

@XmlMimeType("application/octet-stream") private DataHandler imageData;

public String getTitle() { return title; }
public void setTitle(String title) { this.title = title; }

public DataHandler getImageData() { return imageData; }
public void setImageData(DataHandler imageData) { this.imageData =
imageData; }
}

如果你能到用wsdl first的方式还是wsdl first 吧

stevenmo

unread,
May 19, 2008, 10:57:33 PM5/19/08
to cxf-zh
谢谢 Freeman Fang 设计中我犯了严重的错误 已经及时修正过来 万分感谢 不过在采用mtom的过程中 还有几个问题需要
请教 我另开一贴
Reply all
Reply to author
Forward
0 new messages