CXF之定制超时配置实例

服务接口:

package cxf.server; import javax.jws.WebParam; import javax.jws.WebService; @WebService public interface HelloWorld { public String sayHi(@WebParam(name="stuName")String stuName); }  

 

服务实现类:

package cxf.server; import javax.jws.WebService; @WebService(endpointInterface="cxf.server.HelloWorld") public class HelloWorldImpl implements HelloWorld { @Override public String sayHi(String stuName) { try { Thread.sleep(15000); } catch (InterruptedException e) { e.printStackTrace(); } System.out.println("server: " + stuName); return stuName; } }  

 

服务端配置:

<?xml version="1.0" encoding="UTF-8"?> <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" xmlns:jaxws="http://cxf.apache.org/jaxws" xsi:schemaLocation=" http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd http://cxf.apache.org/transports/http/configuration http://cxf.apache.org/schemas/configuration/http-conf.xsd http://cxf.apache.org/jaxws http://cxf.apache.org/schemas/jaxws.xsd"> <import resource="classpath:META-INF/cxf/cxf.xml" /> <import resource="classpath:META-INF/cxf/cxf-extension-soap.xml" /> <import resource="classpath:META-INF/cxf/cxf-servlet.xml" /> <http-conf:destination name="*.http-destination"> <http-conf:server ReceiveTimeout="30000"/> </http-conf:destination> <jaxws:endpoint id="helloWorld" implementor="cxf.server.HelloWorldImpl" address="/HelloWorld" /> </beans>  

 

客户端配置:

<?xml version="1.0" encoding="UTF-8"?> <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" xmlns:jaxws="http://cxf.apache.org/jaxws" xsi:schemaLocation=" http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd http://cxf.apache.org/transports/http/configuration http://cxf.apache.org/schemas/configuration/http-conf.xsd http://cxf.apache.org/jaxws http://cxf.apache.org/schemas/jaxws.xsd"> <http-conf:conduit name="*.http-conduit"> <http-conf:client ConnectionTimeout="5000" ReceiveTimeout="8000"/> </http-conf:conduit> <jaxws:client id="client" address="http://localhost:8085/cxf-test-timeout/service/HelloWorld" serviceClass="cxf.server.HelloWorld"/> </beans>  

 

客户端调用:

package cxf.client; import org.springframework.context.support.ClassPathXmlApplicationContext; import cxf.server.HelloWorld; public class HelloWorldClient { public static void main(String[] args) { ClassPathXmlApplicationContext app = new ClassPathXmlApplicationContext("client.xml"); HelloWorld hw = (HelloWorld) app.getBean("client"); String s = hw.sayHi("rrrrrrrrrr"); System.out.println("client: " + s); } }  

 

请注意:<http-conf:destination> , <http-conf:conduit>

 

你可能感兴趣的:(webservice,server,String,import,interface,encoding)