Spring4.x整合Axis1.4发布WebService服务

文章目录

  • 一、服务端部署
    • 1. 在web.xml文件中添加映射路径和spring监听
    • 2. 添加spring-axis.xml配置文件
    • 3. 添加server-config.wsdd配置文件
    • 4. 对外发布服务外壳类
    • 5. 添加接口类
    • 6. 添加接口逻辑实现类
    • 7. 浏览器测试
  • 二、客户端部署
    • 2.1 axis1.4 工具类封装(企业版本)
    • 2.2 运行main方法测试
  • 三、多接口服务发布
    • 3.1 server-config.wsdd 添加服务
    • 3.2 添加对外暴露的外壳类
    • 3.3 添加服务接口
    • 3.4 添加服务接口逻辑处理类
    • 3.5 在spring-axis.xml 添加本地bean
    • 3.6 发布服务
    • 3.7 支持多个发布路径
    • 本文源码下载:

一、服务端部署

1. 在web.xml文件中添加映射路径和spring监听

<!-- webservices接口 axis 需要引入的 Servlet Start --><servlet><servlet-name>AxisServlet</servlet-name><servlet-class>org.apache.axis.transport.http.AxisServlet</servlet-class></servlet><servlet-mapping><servlet-name>AxisServlet</servlet-name><!-- 接口调用的后续路径设置 --><url-pattern>/services/*</url-pattern></servlet-mapping><!-- webservices接口 axis 需要引入的 Servlet End -->
<!-- 新增spring容器配置 Start --><listener><listener-class>org.springframework.web.context.ContextLoaderListener</listener-class></listener><context-param><param-name>contextConfigLocation</param-name><param-value>/WEB-INF/config/spring-*.xml</param-value></context-param><!-- 新增spring容器配置 End -->

注:
1、spring监控如果不添加,服务发布正常,可以省略
2、文件中的扫描文件路径根据项目具体位置而定

2. 添加spring-axis.xml配置文件

  • 文件名自定义即可,作用是本地bean
<?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:context="http://www.springframework.org/schema/context"xsi:schemaLocation="http://www.springframework.org/schema/beanshttp://www.springframework.org/schema/beans/spring-beans-3.0.xsdhttp://www.springframework.org/schema/contexthttp://www.springframework.org/schema/context/spring-context-3.0.xsd"><bean   id="nFisCommonWebServiceImpl"   class="com.gblfy.service.impl.GblfyCommonWebServiceImpl" />
</beans>

注:
1、 id默认是接口实现类的类名小写,也可以小写 自定义
2、 在web.xml配置文件中要配置spring监听

<?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:context="http://www.springframework.org/schema/context"xsi:schemaLocation="http://www.springframework.org/schema/beanshttp://www.springframework.org/schema/beans/spring-beans-3.0.xsdhttp://www.springframework.org/schema/contexthttp://www.springframework.org/schema/context/spring-context-3.0.xsd"><bean id="webServiceImpl"class="com.gblfy.axis.service.impl.WebServiceImpl" />
</beans>

3. 添加server-config.wsdd配置文件

<?xml version="1.0" encoding="UTF-8"?>
<deployment xmlns="http://xml.apache.org/axis/wsdd/"xmlns:java="http://xml.apache.org/axis/wsdd/providers/java"><globalConfiguration><parameter name="adminPassword" value="admin" /><parameter name="sendXsiTypes" value="true" /><parameter name="sendMultiRefs" value="true" /><parameter name="sendXMLDeclaration" value="true" /><parameter name="axis.sendMinimizedElements" value="true" /><requestFlow><handler type="java:org.apache.axis.handlers.JWSHandler"><parameter name="scope" value="session" /></handler><handler type="java:org.apache.axis.handlers.JWSHandler"><parameter name="scope" value="request" /><parameter name="extension" value=".jwr" /></handler></requestFlow></globalConfiguration><handler name="Authenticate"type="java:org.apache.axis.handlers.SimpleAuthenticationHandler" /><handler name="LocalResponder"type="java:org.apache.axis.transport.local.LocalResponder" /><handler name="URLMapper"type="java:org.apache.axis.handlers.http.URLMapper" /><service name="AdminService" provider="java:MSG"><parameter name="allowedMethods" value="AdminService" /><parameter name="enableRemoteAdmin" value="false" /><parameter name="className"value="org.apache.axis.utils.Admin" /><namespace>http://xml.apache.org/axis/wsdd/</namespace></service><service name="Version" provider="java:RPC"><parameter name="allowedMethods" value="getVersion" /><parameter name="className" value="org.apache.axis.Version" /></service><transport name="http"><requestFlow><handler type="URLMapper" /><handlertype="java:org.apache.axis.handlers.http.HTTPAuthHandler" /></requestFlow></transport><transport name="local"><responseFlow><handler type="LocalResponder" /></responseFlow></transport><!—北京接口服务  start--><service name="GblfyCommonServiceShell" provider="java:RPC"><parameter name="allowedMethods" value="*" /><parameter name="className"value="com.gblfy.controller.webservice.GblfyCommonServiceShell" /></service><!—北京接口服务  end-->
</deployment>


只修改截图部分即可!

4. 对外发布服务外壳类

  • 添加与server-config.wsdd配置文件,相对应对外发布服务外壳类
package com.gblfy.axis.controller;import javax.xml.rpc.ServiceException;import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.ApplicationContext;
import org.springframework.remoting.jaxrpc.ServletEndpointSupport;import com.gblfy.axis.service.IWebService;public class WebServiceShell extends ServletEndpointSupport {@Autowiredprivate ApplicationContext applicationContext;@Autowiredprivate IWebService iWebService;// 注入bean@Overrideprotected void onInit() throws ServiceException {// 初始化Spirng 配置applicationContext = super.getApplicationContext();iWebService = (IWebService) applicationContext.getBean("webServiceImpl");}public String webServiceForBJ(String tReqXml) throws Exception {return iWebService.webServiceForBJ(tReqXml);}
}

5. 添加接口类

package com.gblfy.axis.service;public interface IWebService {/*** 北京业务接口* * @param xml* @return* @throws Exception*/public String webServiceForBJ(String tReqXml) throws Exception;
}

6. 添加接口逻辑实现类

package com.gblfy.axis.service.impl;import com.gblfy.axis.service.IWebService;public class WebServiceImpl implements IWebService {@Overridepublic String webServiceForBJ(String tReqXml) throws Exception {return "接收到服务了!!!";}
}

7. 浏览器测试

效果图截图:
http://localhost:8081/spring-axis/services/WebServiceShell?wsdl

二、客户端部署

2.1 axis1.4 工具类封装(企业版本)

package com.gblfy.axis.utils;import java.net.MalformedURLException;import javax.xml.namespace.QName;
import javax.xml.rpc.ParameterMode;
import javax.xml.rpc.ServiceException;import org.apache.axis.client.Call;
import org.apache.axis.client.Service;
import org.apache.ibatis.javassist.tools.rmi.RemoteException;/*** webService客户端*/
public class WebServiceClientUtil {public static void main(String[] args) throws MalformedURLException, RemoteException, ServiceException, Exception {String url = "http://localhost:8081/spring-axis/services/WebServiceShell?wsdl";String namespace = "http://localhost:8081/spring-axis/services/WebServiceShell?wsdl";String method = "webServiceForBJ";String tReqXml = "客户端调用webservice服务方成功了!!!";WebServiceClientUtil a = new WebServiceClientUtil();String dataResponse = a.RequestToResponse(url, namespace, method, tReqXml);System.out.println("%%%%%%%%%$$$$$" + dataResponse);}/*** * @param url       WebService地址* @param namespace 命名空间* @param method    方法* @param tReqXml   请求报文* @return resXml 响应报文* @throws ServiceException* @throws MalformedURLException* @throws RemoteException* @throws Exception*/public String RequestToResponse(String url, String namespace, String method, String tReqXml)throws ServiceException, MalformedURLException, RemoteException, Exception {Service service = new Service();Call call;String resXml = null;call = (Call) service.createCall();call.setTargetEndpointAddress(new java.net.URL(url));String subUrl = url.substring(url.lastIndexOf("/"));System.out.println("转发路径标志==" + subUrl.substring(1, subUrl.length()));// 针对北京业务添加判断,针对服务端有@Webservice 注解,有明确的参数因此,需要在客户端设置此设置// if判断 针对某个webservice服务 默认不走判断if ("BJServiceForClaim".equals(subUrl.substring(1, subUrl.length()))) {call.addParameter("xmlStr", org.apache.axis.Constants.XSD_STRING, ParameterMode.IN);call.setReturnType(org.apache.axis.Constants.XSD_STRING);}call.setOperationName(new QName(namespace, method));// 这是要调用的方法resXml = (String) call.invoke(new Object[] { tReqXml.toString() });return resXml;}}


2.2 运行main方法测试

控制台输出

转发路径标志==WebServiceShell?wsdl
%%%%%%%%%$$$$$接收到服务了!!!

三、多接口服务发布

3.1 server-config.wsdd 添加服务

3.2 添加对外暴露的外壳类

3.3 添加服务接口

3.4 添加服务接口逻辑处理类

3.5 在spring-axis.xml 添加本地bean

3.6 发布服务

3.7 支持多个发布路径

在web.xml文件中

  • 默认 /services/*
  • 新增加/gblfy/services/*

本文源码下载:

链接 https://pan.baidu.com/s/1fVe3Fq_n4Ru9CHG_XCXVOg
提取码 0iv1

Spring4.x整合Axis1.4发布WebService服务相关推荐

  1. Spring和CXF整合发布WebService(服务端、客户端)

    参考Spring和CXF整合发布WebService(服务端.客户端) 转载于:https://www.cnblogs.com/timspace/p/11113576.html

  2. Axis1.4发布WebService

    本章节主要介绍Axis1.4发布WebService.这里只说明发布相关内容,调用方法后续会说明. 1.下载安装 下载地址:http://archive.apache.org/dist/axis/ 本 ...

  3. Aixs2发布webservice服务

    http://www.blogjava.net/pzxsheng/archive/2012/12/21/393319.html 开发前准备:     1.Eclipse Java EE IDE(Jun ...

  4. 使用CXF发布WebService服务简单实例

    一.说明: 前面介绍了使用axis2来发布Webservice服务,现在介绍一种更popular,更高效的Webservice服务发布技术:CXF Apache CXF = Celtix + XFir ...

  5. dubbo发布webservice服务

    dubbo发布webservice服务 学习了:https://blog.csdn.net/zhangyunpengchang/article/details/51567127 https://blo ...

  6. 基于jws发布webservice服务

    基于jws发布webservice服务 用途 用于验证基于jws搭建的webservice服务端与客户端. WebService服务端 1.目录结构 D:. │ pom.xml # maven配置 │ ...

  7. CXF框架发布WebService服务的例子

    1.CXF框架概念介绍 Apache CXF 是一个开源的 WebService 框架,CXF可以用来构建和开发 WebService,这些服务可以支持多种协议,比如:SOAP.POST/HTTP.H ...

  8. 如何发布webservice服务端

    如何发布webservice服务端 还是使用jdk提供的工具进行webservice进行发布(从jdk1.6以后)对soap1.2协议支持的不是很好 使用Endpoint里面的publish方法进行发 ...

  9. 服务端使用Axis2-1.6.3发布webservice服务、客户端使用Axis1.4实现调用

    一.准备工作 下载Axis2-1.6.3-war.zip 下载链接 下载Axis1.4相关jar包 下载链接 二.开发Webservice服务端代码 使用环境:myeclipse6.6+tomcat6 ...

最新文章

  1. Hello world!
  2. Java Maven Profiles多环境一键部署
  3. python怎么设置函数超时时间_在python运行时为函数设置超时秒数
  4. C#new出来的结构体内存分配
  5. pwa程序,清单文件测试有效,为什么不起效果?
  6. CRM_ORDER_PR_ASSIGN_SELECT_CB
  7. ECSHOP2.7.3删除后台左侧菜单中的云服务中心
  8. 统计学常见分布、概念
  9. SpringBoot参数传递bean自动填充
  10. 异常检测时间序列_神经病学时间序列/异常检测:分层时间记忆
  11. 通信原理及系统系列4—— AWGN信道(信噪比SNR、Es/N0和Eb/N0概念的辨析、转换及使用)
  12. linkedin 分享_如何将您的LinkedIn个人资料添加到WordPress
  13. 【翻译】智能制造中EDA 应用及益处系列之四:精密故障检测与分类(FDC)
  14. 什么是cve什么是cwe_什么是CVE 2020 0601又名Curveball,为何如此危险
  15. vue高德地图绘制行政区边界
  16. pythonSSL证书错误
  17. 科沃斯擦玻璃机器人使用感受_科沃斯擦玻璃机器人怎么样?有人用过自动擦窗机器人吗?价格是多少...
  18. 用友OA漏洞学习——test.jsp SQL注入漏洞
  19. 天融信防火墙web配置_常见web系统默认口令总结
  20. 忧伤岁月,挡不住四季的温暖

热门文章

  1. html与java接口,JavaWeb学习——Servlet相关的接口和类
  2. java基础之多线程笔记
  3. 语音识别学习日志 2019-7-15 语音识别基础知识准备4 {Baun-Welch算法}
  4. Hive 行转列,列传行 - Impala 暂不支持
  5. 一线技术人的成长思考总结
  6. 一撕得:全员参与低代码开发,全面实现企业数字化管理
  7. 阿里云助力江苏省财政厅力推统一公共支付平台
  8. 深度强化学习在时序数据压缩中的应用--ICDE 2020收录论文
  9. 勒索病毒如何防治?看阿里云双拳出击不留隐患
  10. 2020年阿里云年中大促【福利】【选品】全攻略