webservice超时设置
Posted
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了webservice超时设置相关的知识,希望对你有一定的参考价值。
参考技术A package com.primeton.mq.test;importcom.primeton.mq.service.DemoService;
importorg.apache.cxf.endpoint.Client;
importorg.apache.cxf.jaxws.JaxWsProxyFactoryBean;
importorg.apache.cxf.jaxws.endpoint.dynamic.JaxWsDynamicClientFactory;
importorg.apache.cxf.transport.http.HTTPConduit;
importorg.apache.cxf.transports.http.configuration.HTTPClientPolicy;
publicclassdemo
publicstaticvoid main(String[] args)
//创建动态客户端
JaxWsDynamicClientFactoryfactory =JaxWsDynamicClientFactory.newInstance();
Clientclient = factory.createClient("http://localhost:8090/demo/api?wsdl");
// 需要密码的情况需要加上用户名和密码
//client.getOutInterceptors().add(new ClientLoginInterceptor(USER_NAME,PASS_WORD));
HTTPConduitconduit = (HTTPConduit) client.getConduit();
HTTPClientPolicyhttpClientPolicy = newHTTPClientPolicy();
httpClientPolicy.setConnectionTimeout(2000);//连接超时
httpClientPolicy.setAllowChunking(false);//取消块编码
httpClientPolicy.setReceiveTimeout(120000);//响应超时
conduit.setClient(httpClientPolicy);
//client.getOutInterceptors().addAll(interceptors);//设置拦截器
try
Object[] objects = newObject[0];
// invoke("方法名",参数1,参数2,参数3....);
objects = client.invoke("sayHello","sujin");
System.out.println("返回数据:"+ objects[0]);
catch(Exceptione)
e.printStackTrace();
以上是关于webservice超时设置的主要内容,如果未能解决你的问题,请参考以下文章
java客户端调用webservice时 连接超时知道是网络原因 ,如何重试如果不重试程序就死琐了,