通过配置spring.xml实现通用Webservice调用
来源:互联网 发布:unity3d架构 编辑:程序博客网 时间:2024/05/22 10:35
- 写一个第三方服务调用通用类,把Axis参数作为属性定义在类中:
import java.net.MalformedURLException;import java.net.URL;import java.rmi.RemoteException;import java.util.Iterator;import java.util.Map;import java.util.Set;import javax.xml.namespace.QName;import javax.xml.rpc.ServiceException;import org.apache.axis.AxisProperties;import org.apache.axis.client.Call;import org.apache.axis.client.Service;package jastar.test;public class ThirdPartyService {private String endpoint; // 服务端点private String namespace; // 命名空间private String operationName; // 服务操作名称private QName returnType; // 服务获取的对象类型名称private Map<String, String> params; // 传入参数名称和类型对/** * 调用Web service并返回返回结果 * * @param args 传入的参数对象数组 * @return WebServices 调用结果 * @throws RepairServiceException */public Object getCallResult(Object[] args) throws RepairServiceException {AxisProperties.setProperty("http.proxyHost","192.168.1.22");AxisProperties.setProperty("http.proxyPort","808");Object ret = null;Service service = new Service();QName qn = new QName(namespace, operationName);Call call = null;try {call = (Call)service.createCall();} catch (ServiceException e) {throw new MyServiceException("创建Webservice调用对象失败!", e);}call.setOperationName(qn);Set<String> keys = params.keySet();for (Iterator<String> it = keys.iterator(); it.hasNext();) {String paramName = it.next();QName param = new QName(namespace, paramName);QName xmlType =new QName(namespace, (String)params.get(paramName));call.addParameter(param, xmlType,javax.xml.rpc.ParameterMode.IN);}try {call.setTargetEndpointAddress(new URL(endpoint));} catch (MalformedURLException e) {throw new MyServiceException("设置Service服务端失败!", e);}call.setReturnType(returnType);try {ret = call.invoke(args);} catch (RemoteException e) {throw new MyServiceException("调用WebService服务失败!", e);}return ret;}public String getEndpoint() {return endpoint;}public void setEndpoint(String endpoint) {this.endpoint = endpoint;}public String getNamespace() {return namespace;}public void setNamespace(String namespace) {this.namespace = namespace;}public String getOperationName() {return operationName;}public void setOperationName(String operationName) {this.operationName = operationName;}public QName getReturnType() {return returnType;}public void setReturnType(QName returnType) {this.returnType = returnType;}public Map getParams() {return params;}@SuppressWarnings ("unchecked")public void setParams(Map params) {this.params = params;}}
- 将这个ThirdPartService类注入到具体的业务Service中,在具体业务方法中调用ThirdPartyService的getCallResult,从而可以将第三方服务调用方便的封装起来。
- 在applicationContext.xml中配置服务调用相关参数:
<bean id="helloSupportService"class="jastar.HelloSupportService"><property name="gisSupportService"><beanclass="jastar.ThirdPartySupportService"><property name="endpoint"><value>http://192.168.1.1:8080/Service.asmx</value></property><property name="namespace"><value>http://service.jastar</value></property><property name="operationName"><value>sayHello</value></property><property name="returnType"><util:constantstatic-field="org.apache.axis.encoding.XMLType.SOAP_STRING" /></property><property name="params"><map><entry key="name" value="string" /><entry key="greeting" value="string" /></map></property></bean></property></bean>
0 0
- 通过配置spring.xml实现通用Webservice调用
- 通过配置spring.xml实现通用Webservice调用
- Spring-通过xml配置实现AOP
- 通过spring JaxWsPortProxyFactoryBean调用webservice接口
- 通过调用webservice实现查询天气预报系统
- Android通过调用Webservice实现天气预报
- Android通过调用Webservice实现天气预报
- Android通过调用Webservice实现天气预报
- spring mvc 配置xml数据格式,webservice
- 通过spring方式实现xfire webservice
- 使用xml实现Webservice信息传递--调用
- spring配置xfire生成webservice接口 和 调用webservice接口
- asp中解析通过asp调用webservice 返回的xml
- Webservice接口通用实现
- Spring AOP详解及通过XML配置实现的实现方法
- CXF调用WebService通用类
- 通过SSL调用WebService
- 通过Ajax调用webService
- LeetCode Merge Two Sorted Lists
- 防护与时代和方式的农夫和独一覆盖度u影
- 【JAVA】JAVA基础知识点备忘
- Java中空指针异常
- 五种常见的 PHP 设计模式
- 通过配置spring.xml实现通用Webservice调用
- html+css仿百度新闻首页(上)
- ACM训练方案-POJ题目分类
- jquery实现文本框Email自动提示后缀
- 使用Jekyll-bootstrap快速搭建博客
- 智能指针的实现--使用引用计数实现以及原理
- UVa 1586 - Molar Mass
- javascript数组的一些基本使用方法
- JavaScript 函数返回值