Spring Web Service Client via JaxWsPortProxyFactoryBean
2013-05-31 07:37
2291 查看
0. Overview.
1. Maven Dependency.
2. Generate stubs by JAX-WS wsimport
Since 1.6, JDK provides a handy wsimport tool to generate web service classes, before configuring JaxWsPortProxyFactoryBean, we should have the classes exist first. Of course, wsimport is just a means and personal preference, not a must, we have a hold of
other alternatives to generate web service proxy classes.
1. Maven Dependency.
<dependency> <groupId>org.springframework.ws</groupId> <artifactId>spring-ws-core</artifactId> <version>2.1.3.RELEASE</version> </dependency>Note that the artifactId is 'spring-ws-core', rather than 'spring-ws', some out of date posts use the latter one, which would not work now.
2. Generate stubs by JAX-WS wsimport
Since 1.6, JDK provides a handy wsimport tool to generate web service classes, before configuring JaxWsPortProxyFactoryBean, we should have the classes exist first. Of course, wsimport is just a means and personal preference, not a must, we have a hold of
other alternatives to generate web service proxy classes.
wsimport -s wscdemo -p com.derek.demo.wsclient.stub http://127.0.0.1:8080/BetService.asmx?wsdl[/code] Next move: copy the newly generated classes to Eclipse,
3. Configure JaxWsPortProxyFactoryBean
To configure JaxWsPortProxyFactoryBean, we'd better look into the wsdl file and the generated interface carefully. In this case, the 'serviceInterface' value we should take the generated interface's qualified name, in other words, this property's value depends
on how we generate the stub classes. Another 4 properties' value lie in WSDL file, or you can resort to <Spring 3 in Action> for reference.<bean id="betService" class="org.springframework.remoting.jaxws.JaxWsPortProxyFactoryBean"> <property name="serviceInterface" value="com.derek.demo.wsclient.stub.BettingServiceSOAP" /> <property name="wsdlDocumentUrl"> <value>${uat.vip.wsdlurl}</value> </property> <property name="namespaceUri" value="http://tempuri.org/" /> <property name="serviceName" value="BettingService" /> <property name="portName" value="BettingServiceSOAP" /> </bean>
4. Inject JaxWsPortProxy
5. Timeout
We are able to set timeout via JAX-WS. The following configuration works:<bean id="betService" class="org.springframework.remoting.jaxws.JaxWsPortProxyFactoryBean"> <property name="serviceInterface" value="com.derek.demo.wsclient.stub.BettingServiceSOAP" /> <property name="wsdlDocumentUrl"> <value>${uat.vip.wsdlurl}</value> </property> <property name="namespaceUri" value="http://tempuri.org/" /> <property name="serviceName" value="BettingService" /> <property name="portName" value="BettingServiceSOAP" /> <property name="customProperties" ref="jaxwsCustomProperties" /> </bean> <util:map id="jaxwsCustomProperties"> <entry key="com.sun.xml.ws.request.timeout"> <value type="java.lang.Integer">2000</value> </entry> <entry key="com.sun.xml.ws.connect.timeout"> <value type="java.lang.Integer">2000</value> </entry> </util:map>For testing timeout, I set the value as small as 10, and call the service, encounter this exception, which proves the timeout setting works.org.springframework.remoting.RemoteAccessException: Could not access remote service at [null]; nested exception is javax.xml.ws.WebServiceException: java.net.SocketTimeoutException: Read timed out at org.springframework.remoting.jaxws.JaxWsPortClientInterceptor.doInvoke(JaxWsPortClientInterceptor.java:510) at org.springframework.remoting.jaxws.JaxWsPortClientInterceptor.invoke(JaxWsPortClientInterceptor.java:487) at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:172) at org.springframework.aop.framework.JdkDynamicAopProxy.invoke(JdkDynamicAopProxy.java:204) at $Proxy66.keepAlive(Unknown Source) at java.util.concurrent.ThreadPoolExecutor.runWorker(Unknown Source) at java.util.concurrent.ThreadPoolExecutor$Worker.run(Unknown Source) at java.lang.Thread.run(Unknown Source) Caused by: javax.xml.ws.WebServiceException: java.net.SocketTimeoutException: Read timed out at com.sun.xml.ws.transport.http.client.HttpClientTransport.readResponseCodeAndMessage(HttpClientTransport.java:211) at com.sun.xml.ws.transport.http.client.HttpTransportPipe.createResponsePacket(HttpTransportPipe.java:274) at com.sun.xml.ws.transport.http.client.HttpTransportPipe.process(HttpTransportPipe.java:265) at com.sun.xml.ws.transport.http.client.HttpTransportPipe.processRequest(HttpTransportPipe.java:184) at com.sun.xml.ws.transport.DeferredTransportPipe.processRequest(DeferredTransportPipe.java:109)
6. Concurrent JaxWsPortProxyFactoryBean
Reference:
1. <Spring 3 in Action>. Proxying JAX-WS services on the client side.
2. Timeout Configuration. http://helponjee.blogspot.hk/2011/10/set-timeout-while-calling-webservice-in.html. (This URL may not be accessible in mainland of China.)
相关文章推荐
- 通过spring JaxWsPortProxyFactoryBean调用webservice接口
- JaxWsProxyFactoryBean 与 JaxWsDynamicClientFactory
- CXF整合Spring之JaxWsProxyFactoryBean调用
- CXF----webservice和Spring之JaxWsProxyFactoryBean调用
- CXF整合Spring之JaxWsProxyFactoryBean调用
- JaxWsProxyFactoryBean 与 JaxWsDynamicClientFactory
- JaxWsProxyFactoryBean 与 JaxWsDynamicClientFactory
- CXF JaxWsProxyFactoryBean调用SOAP服务出现异常信息
- JaxWsServiceFactoryBean, 与JaxWsServerFactoryBean区别
- jaxws webservice spring 注入 解决NullPointerException
- Apache CXF实现Web Service(1)——不借助重量级Web容器和Spring实现一个纯的JAX-WS web service
- cxf JaxWsClientFactoryBean
- CXF 发布Web Service - JaxWsWebServicePublisherBeanPostProcessor
- Creating a Simple Web Service and Client with JAX-WS
- org.springframework.ws.client.WebServiceTransportException: Moved Temporarily [302]
- JaxWsProxyFactoryBean factory = new JaxWsProxyFactoryBean(); 报错
- 客户端利用CXF中的JaxWsProxyFactoryBean 对webservice地址进行调用
- JaxWsServiceFactoryBean与JaxWsServerFactoryBean区别(创建webService)
- spring aop(五)--ProxyFactoryBean创建代理的实现
- Spring的AOP实现方式—ProxyFactoryBean配置方式实现源码剖析