CN105068820B - 一种基于SSH框架集成Axis开发并发布Web Service的方法 - Google Patents
一种基于SSH框架集成Axis开发并发布Web Service的方法 Download PDFInfo
- Publication number
- CN105068820B CN105068820B CN201510579065.0A CN201510579065A CN105068820B CN 105068820 B CN105068820 B CN 105068820B CN 201510579065 A CN201510579065 A CN 201510579065A CN 105068820 B CN105068820 B CN 105068820B
- Authority
- CN
- China
- Prior art keywords
- web service
- web
- axis
- xml
- ssh
- Prior art date
- Legal status (The legal status is an assumption and is not a legal conclusion. Google has not performed a legal analysis and makes no representation as to the accuracy of the status listed.)
- Active
Links
Landscapes
- Information Transfer Between Computers (AREA)
- Stored Programmes (AREA)
Abstract
本发明涉及Java Web中的Web Service技术开发领域,具体的说是在一种SSH框架基础上集成Axis开发并且发布Web Service服务的方法。该方法包括以下步骤:1、搭建SSH框架基础开发平台。2、整合并且在SSH框架基础上配置Axis。3、编写Web Service实现类。4、编写WSDD文件。5、发布Web Service。本方法将组装SOAP消息的工作托管给AXIS来处理,相较于手工实现SOAP协议,实现更快捷,如果有新的接口业务要实现时,只需将所要发布的Web Service方法配置到WSDD文件中即可,不需额外手工编写WSDL文件。
Description
技术领域
本发明涉及Java Web中的Web Service技术开发领域,具体的说是在SSH框架基础上集成Axis开发并且发布Web Service服务的方法。
背景技术
Web Service技术的出现,使得运行在不同机器上的不同应用无须借助附加的、专门的第三方软件或硬件,就可相互交换数据或集成。依据Web Service规范实施的应用之间,无论它们所使用的语言、平台或内部协议是什么,都可以相互交换数据。Web Service为整个企业甚至多个组织之间的业务流程的集成提供了一个通用机制。
Web Service主要涉及的技术有1、XML(标准通用标记语言下的一个子集);2、SOAP(Simple Object Access Protocol,简单对象访问协议 ); 3、WSDL(Web ServicesDescription Language,Web Service 描述语言 )。
Web Service可以看成是远程函数。WSDL可以理解成函数的声明,它详细的定义了函数的原型,包括函数名、入口参数、出口参数、以及与远程地址的绑定。SOAP是WebService的访问协议,SOAP建立在XML之上,不同的就是对XML原本没有限制的格式加上了一些限制,需要有envelop,在envelope中,还要分header和body。如果利用SOAP开发WebService的程序,那就需要根据WSDL的定义来自行组装SOAP包。除了要配置SOAP请求头文件信息,还要根据SOAP定义的消息格式组装消息数据。这种手工组装SOAP消息的方式,工作量较大,而且日后的系统维护、升级、部署都有较高的复杂度。
Web Service的接口业务实现层,进行具体的业务实现处理,在Web Service接口中调用各种业务需求的实现方法。由于业务的复杂性,Web Service接口中对业务实现方法不可避免的会存在多重依赖性,对象之间的耦合度越高,业务变更时的维护成本就越高,因此对象的设计应使类和构件之间的耦合最小。
SSH为 Struts + Spring + Hibernate的一个集成框架,是目前较流行的一种Web应用程序开源框架。使用该框架,将对象之间的依赖关系交给Spring,降低组件之间的耦合性,开发者可以更专注于应用逻辑;降低了业务对象替换时所带来的复杂性和维护成本。
Axis全称Apache Extensible Interaction System,即阿帕奇可扩展交互系统。Axis本质上就是一个SOAP引擎,提供创建服务器端、客户端和网关SOAP操作的基本框架。
发明内容
本发明提供了一种基于SSH框架集成Axis开发并发布Web Service的方法,所述方法通过将组装SOAP消息的工作托管给AXIS来处理,通过SSH框架降低Web Service业务逻辑层的耦合度,能够在应用生产过程中快速的架设Web Service服务,降低系统复杂度,从而简化维护和部署。
为了实现上述的目的,本发明采用了以下的技术方案:
一种基于SSH框架集成Axis开发并发布Web Service的方法,该方法包括以下的步骤:
步骤1,搭建SSH框架基础开发平台,导入SSH框架所依赖的Jar包到工程中,修改web-info下的web.xml文件,增加struts2的配置;并在WEB-INF/classes目录下添加struts.xml配置文件;
步骤2,整合并且在SSH框架基础上配置Axis,修改web.xml增加Axis的配置描述,并在 web.xml 文件下加入 AxisServlet 配置后,系统就会对以后缀为 *.jws 及路径为/services/* 的请求进行监听,遇到此类请求时将把信息交由org.apache.axis.transport.http.AdminServlet类进行处理;Axis和struts2在整合过程中,在struts.xml增加<constant name="struts.action.excludePattern" value="/servlet/AxisServlet,/services/.*"/>配置,将Web Service的访问路径从struts2中拦截器中排除;
步骤3,编写Web Service实现类,采用基于spring的Web Service实现, WebService服务类需要继承spring提供的org.springframework.remoting.jaxrpc.ServletEndpointSupport类,Spring使用该类来暴露WebService;
步骤4,编写Web Service Deployment Descriptor文件;
步骤5,发布Web Service服务,在浏览器访问在web.xml里配置好的Axis处理地址AxisServlet,打开已配置并且发布好的Web Service,单击发布成功的接口名称打开其对应的WSDL文件,将WSDL文件保存后,根据该文件信息进行客户端的Web Service调用。
本方法将组装SOAP消息的工作托管给AXIS来处理,相较于手工实现SOAP协议,实现更快捷,如果有新的接口业务要实现时,只需将所要发布的Web Service方法配置到WSDD文件中即可,不需额外手工编写WSDL文件。
本方法实现了资源的可配置和易管理,降低了使用资源双方的依赖程度。通过Spring提供的IOC将Web Service接口与具体业务实现进行分离,将对象之间的依赖关系交给Spring,降低Web Service接口与接口业务实现层之间的耦合性。在接口业务需求变更时只需要将新的业务实现通过Spring注入到接口中即可,降低了业务对象变更或替换时所带来的复杂性和维护成本。
附图说明
图1为本发明方法的流图。
图2为发布成功的接口的示意图。
具体实施方式
如图1所示的一种基于SSH框架集成Axis开发并发布Web Service的方法,本方法共包含5个步骤。
步骤1,搭建SSH框架基础开发平台,具体实施方式如下:
导入SSH框架所依赖的Jar包到工程中,修改web-info下的web.xml文件,增加struts2的配置:
<filter>
<filter-name>struts2</filter-name>
<filter-class>
org.apache.struts2.dispatcher.ng.filter.StrutsPrepareAndExecuteFilter
</filter-class>
</filter>
<filter-mapping>
<filter-name>struts2</filter-name>
<url-pattern>/*</url-pattern>
</filter-mapping>
StrutsPrepareAndExecuteFilter过滤器的主要功能是对request请求转发到对应的action去处理,是struts2的核心过滤器。
在WEB-INF/classes目录下添加struts.xml配置文件:
<struts>
<constant name="struts.convention.action.suffix" value="Controller"/>
<constant name="struts.convention.default.parent.package" value="nbol"/>
<!-- 搜索此配置下的所有包中的类 -->
<constant name="struts.convention.package.locators.basePackage" value="net.nbol"/>
<!-- action存放的根包,如果不配,默认为struts、struts2、action、actions -->
<constant name="struts.convention.package.locators" value="controller" />
<!-- 返回页面的根路径 -->
<constant name="struts.convention.result.path" value="/WEB-INF/"/>
</struts>
配置Spring,修改web-info下的web.xml文件增加对spring的配置:
<listener>
<listener-class>
org.springframework.web.context.ContextLoaderListener
</listener-class>
</listener>
<context-param>
<param-name>contextConfigLocation</param-name>
<param-value>classpath*:spring/*.xml</param-value>
</context-param>
ContextLoaderListener监听器的作用就是启动Web容器时,自动装配ApplicationContext的配置信息。
在WEB-INF/classes目录下添加spring配置文件applicationContext.xml:
<aop:aspectj-autoproxy />
<context:annotation-config />
<context:component-scan base-package="net.nbol" />
<tx:annotation-driven />
配置hibernate,由于hibernate在SSH框架中负责数据持久化,在Web Service开发中并不是必须的,所以这里不具体描述如何配置hibernate。
步骤2,整合并且在SSH框架基础上配置Axis:
修改web.xml增加Axis的配置描述:
<display-name>Apache-Axis</display-name>
<listener>
<listener-class>org.apache.axis.transport.http.AxisHTTPSessionListener</listener-class>
</listener>
<!-- 服务管理 -->
<servlet>
<servlet-name>AdminServlet</servlet-name>
<servlet-class>
org.apache.axis.transport.http.AdminServlet
</servlet-class>
<load-on-startup>100</load-on-startup>
</servlet>
<servlet-mapping>
<servlet-name>AxisServlet</servlet-name>
<url-pattern>/servlet/AxisServlet</url-pattern>
</servlet-mapping>
<!-- 对../services/.wsdd请求和.../jws 都交由webService来处理 -->
<servlet-mapping>
<servlet-name>AxisServlet</servlet-name>
<url-pattern>*.jws</url-pattern>
</servlet-mapping>
<servlet-mapping>
<servlet-name>AxisServlet</servlet-name>
<url-pattern>/services/*</url-pattern>
</servlet-mapping>
在 web.xml 文件下加入 AxisServlet 配置后,系统就会对以后缀为 *.jws 及路径为 /services/* 的请求进行监听,遇到此类请求时将把信息交由org.apache.axis.transport.http.AdminServlet类进行处理。
Axis和struts2在整合过程中,struts会把Axis的地址也拦截了,默认当成一个action处理,会因为找不到action而报错,所以需要在struts.xml增加<constant name="struts.action.excludePattern" value="/servlet/AxisServlet,/services/.*"/>配置,将Web Service的访问路径从struts2中拦截器中排除。
步骤3,编写Web Service实现类,本方法发明了基于spring的Web Service实现,所以Web Service服务类需要继承spring提供的org.springframework.remoting.jaxrpc.ServletEndpointSupport类,Spring使用该类来暴露WebService,如下所示:
public class CertificateService extends ServletEndpointSupport {
private Logger log=Logger.getLogger(this.getClass());
private ITCertificateDao itCertificateDao;
private ITSAPPaymentService itsaPaymentService;
//该方法由Spring调用,将目标业务bean注入。
protected void onInit(){
this.itCertificateDao=(ITCertificateDao)getWebApplicationContext().getBean("TCertificateDaoImpl");
this.itsaPaymentService=(ITSAPPaymentService)getWebApplicationContext().getBean("TSAPPaymentService");
}
public void getCertificateInfo(CertificateBean certificate){
//webService 具体业务实现
}
}
WebService在每次请求时都会产生一个新实例,每次都会调用oninit方法,用来注入需要调用的业务接口。
步骤4,编写WSDD(Web Service Deployment Descriptor)文件,本方法采用WebService中的定制发布,与即时发布相比,定制发布更加繁琐也更加复杂,但是换来的却是更大的灵活性。定制发布需要编写一个WSDD文件,其实就是一个XML描述文件。
现在我们将该服务植入Axis中,创建server-config.wsdd文件:
<deployment xmlns="http://xml.apache.org/axis/wsdd/"
xmlns:java="http://xml.apache.org/axis/wsdd/providers/java">
<handler name="URLMapper" type="java:org.apache.axis.handlers.http.URLMapper" />
<service name="Certificate" provider="java:RPC" style="document" use="literal">
<operation name="getCertificateInfo"
soapAction=http://localhost:8080/project/services/Certificate xmlns:ns1="urn:functions">
<parameter name="CertificateBean"/>
</operation>
<parameter name="allowedMethods" value="*"/>
<parameter name="className" value="net.nbol.webservice.CertificateService"/>
<beanMapping languageSpecificType="java:net.nbol.webservice.CertificateBean" qname="ns2:CertificateBean" xmlns:ns2="urn:BeanService"/>
<beanMapping languageSpecificType="java:net.nbol.webservice.CertificateRow" qname="ns2:CertificateRow" xmlns:ns2="urn:BeanService"/>
</deployment>
步骤5,发布Web Service服务,在浏览器访问在web.xml里配置好的Axis处理地址AxisServlet,即地址为http://localhost:8080/project/servlet/AxisServlet,就可以打开已配置并且发布好的Web Service,单击图2中所示的发布成功的接口名称可以打开其对应的WSDL文件,将WSDL文件保存后,可以根据该文件信息进行客户端的Web Service调用。
这样基于SSH框架集成Axis的Web Service开发就完成了,如果有新的WebService接口加入,图1中的前面两个步骤无需执行,只需从第三步开始,重新编写继承ServletEndpointSupport类的子类,并且实现处理业务,在server-config.wsdd文件中加入对新接口的配置描述即可。
本方法将组装SOAP消息的工作托管给AXIS来处理,相较于手工实现SOAP协议,实现更快捷,如果有新的接口业务要实现时,只需将所要发布的Web Service方法配置到WSDD文件中即可,不需额外手工编写WSDL文件。
本方法实现了资源的可配置和易管理,降低了使用资源双方的依赖程度。通过Spring提供的IOC将Web Service接口与具体业务实现进行分离,将对象之间的依赖关系交给Spring,降低Web Service接口与接口业务实现层之间的耦合性。在接口业务需求变更时只需要将新的业务实现通过Spring注入到接口中即可,降低了业务对象变更或替换时所带来的复杂性和维护成本。
Claims (1)
1.一种基于SSH框架集成Axis开发并发布Web Service的方法,其特征在于,该方法包括以下的步骤:
步骤1,搭建SSH框架基础开发平台,导入SSH框架所依赖的Jar包到工程中,修改web-info下的web.xml文件,增加struts2的配置;并在WEB-INF/classes目录下添加struts.xml配置文件;
步骤2,整合并且在SSH框架基础上配置Axis,修改web.xml增加Axis的配置描述,并在web.xml 文件下加入 AxisServlet 配置后,系统就会对以后缀为 *.jws 及路径为 /services/* 的请求进行监听,遇到此类请求时将把信息交由org.apache.axis.transport.http.AdminServlet类进行处理;Axis和struts2在整合过程中,在struts.xml增加<constant name="struts.action.excludePattern" value="/servlet/AxisServlet,/services/.*"/>配置,将Web Service的访问路径从struts2中拦截器中排除;
步骤3,编写Web Service服务类,采用基于spring的Web Service实现, Web Service服务类需要继承spring提供的org.springframework.remoting.jaxrpc.ServletEndpointSupport类,Spring使用该类来暴露WebService;
步骤4,编写Web Service Deployment Descriptor文件;
步骤5,发布Web Service服务,在浏览器访问在web.xml里配置好的Axis处理地址AxisServlet,打开已配置并且发布好的Web Service,单击发布成功的接口名称打开其对应的WSDL文件,将WSDL文件保存后,根据该文件信息进行客户端的Web Service调用。
Priority Applications (1)
Application Number | Priority Date | Filing Date | Title |
---|---|---|---|
CN201510579065.0A CN105068820B (zh) | 2015-09-11 | 2015-09-11 | 一种基于SSH框架集成Axis开发并发布Web Service的方法 |
Applications Claiming Priority (1)
Application Number | Priority Date | Filing Date | Title |
---|---|---|---|
CN201510579065.0A CN105068820B (zh) | 2015-09-11 | 2015-09-11 | 一种基于SSH框架集成Axis开发并发布Web Service的方法 |
Publications (2)
Publication Number | Publication Date |
---|---|
CN105068820A CN105068820A (zh) | 2015-11-18 |
CN105068820B true CN105068820B (zh) | 2018-09-28 |
Family
ID=54498200
Family Applications (1)
Application Number | Title | Priority Date | Filing Date |
---|---|---|---|
CN201510579065.0A Active CN105068820B (zh) | 2015-09-11 | 2015-09-11 | 一种基于SSH框架集成Axis开发并发布Web Service的方法 |
Country Status (1)
Country | Link |
---|---|
CN (1) | CN105068820B (zh) |
Families Citing this family (4)
Publication number | Priority date | Publication date | Assignee | Title |
---|---|---|---|---|
CN106569821A (zh) * | 2016-11-04 | 2017-04-19 | 青岛海信网络科技股份有限公司 | 一种生成Webservice类的方法及装置 |
CN108427550B (zh) * | 2018-02-13 | 2021-09-03 | 深圳太极云软技术有限公司 | 一种Web服务生成方法、装置及设备 |
CN112329018B (zh) * | 2020-10-31 | 2024-07-12 | 方正株式(武汉)科技开发有限公司 | 一种struts替换方法 |
CN113783936B (zh) * | 2021-08-16 | 2024-07-23 | 科大国创云网科技有限公司 | 一种基于企业服务总线的webservice协议统一接口实现方法 |
Citations (4)
Publication number | Priority date | Publication date | Assignee | Title |
---|---|---|---|---|
CN101621534A (zh) * | 2009-08-11 | 2010-01-06 | 周相兵 | 一种面向服务体系结构的语义服务自动组合方法 |
CN103092589A (zh) * | 2011-11-03 | 2013-05-08 | 浙江省公众信息产业有限公司 | 一种基于ssh框架的代码自动生成方法 |
CN103473034A (zh) * | 2012-06-06 | 2013-12-25 | 阿里巴巴集团控股有限公司 | 一种动态发布Web 服务的方法和装置 |
US8839194B2 (en) * | 2008-11-20 | 2014-09-16 | Nhn Corporation | Component-based web application development framework used for creating web page |
-
2015
- 2015-09-11 CN CN201510579065.0A patent/CN105068820B/zh active Active
Patent Citations (4)
Publication number | Priority date | Publication date | Assignee | Title |
---|---|---|---|---|
US8839194B2 (en) * | 2008-11-20 | 2014-09-16 | Nhn Corporation | Component-based web application development framework used for creating web page |
CN101621534A (zh) * | 2009-08-11 | 2010-01-06 | 周相兵 | 一种面向服务体系结构的语义服务自动组合方法 |
CN103092589A (zh) * | 2011-11-03 | 2013-05-08 | 浙江省公众信息产业有限公司 | 一种基于ssh框架的代码自动生成方法 |
CN103473034A (zh) * | 2012-06-06 | 2013-12-25 | 阿里巴巴集团控股有限公司 | 一种动态发布Web 服务的方法和装置 |
Non-Patent Citations (3)
Title |
---|
Java创建Webservice步骤之JavachAxis开发WebService程序;匿名;《http://www.voidcn.com/article/p-sogfxnwa-oh.html》;20120229;第1-6页 * |
ssh搭建项目步骤;匿名;《http://www.voidcn.com/article/p-spdujtos-mg.html》;20120620;第1-5页 * |
通过Axis整合SSH项目创建WebService的流程步骤;匿名;《http://www.voidcn.com/article/p-ouxnzeum-nm.html》;20150424;第1-10页 * |
Also Published As
Publication number | Publication date |
---|---|
CN105068820A (zh) | 2015-11-18 |
Similar Documents
Publication | Publication Date | Title |
---|---|---|
US8856735B2 (en) | System and method of generating REST2REST services from WADL | |
US10462018B2 (en) | Managing a number of secondary clouds by a master cloud service manager | |
EP3700132A1 (en) | Supporting compilation and extensibility on unified graph-based intent models | |
CN105068820B (zh) | 一种基于SSH框架集成Axis开发并发布Web Service的方法 | |
US20170185507A1 (en) | Processing special requests at dedicated application containers | |
WO2016011764A1 (zh) | 一种基于可拼装通信协议栈的通信方法及系统 | |
CN110580154A (zh) | 基于h5接入方式的接入方法及其接入组件和移动终端 | |
WO2010130165A1 (zh) | 一种基于互联网的开放式电信业务生成系统及方法 | |
JP2011086291A (ja) | システムランドスケープ対応アプリケーション間通信インフラストラクチャ | |
US9871848B1 (en) | Integration engine for communications between source and target applications | |
CN110049001A (zh) | 一种实现WebService服务的方法、装置、存储介质和服务器 | |
US20210034338A1 (en) | Communications Enablement Platform, System, and Method | |
CN101997721B (zh) | 一种电信网络管理系统、方法及相应的装置 | |
CN104301401A (zh) | 一种基于快速服务封装的移动应用平台 | |
KR20100029106A (ko) | 모바일 단말기들의 웹 기반 오버―디―에어 제공 및 활성화 | |
Board | Jade web services integration gateway (wsig) guide | |
KR20110118000A (ko) | 모바일 단말에서 웹브라우저와 로컬 리소스의 연동 장치 및 그 방법 | |
Licciardi et al. | Analysis of NGN service creation technologies | |
Sefid‐Dashti et al. | A reference architecture for mobile SOA | |
CN105260179A (zh) | 一种实现flex与servlet交互的方法 | |
US8327389B2 (en) | Interface module | |
US9578090B1 (en) | Methods for provisioning application delivery service and devices thereof | |
CN104253703B (zh) | 一种通信的方法及设备 | |
Pop et al. | A Service Oriented Architecture Approach for an E-Business Platform | |
Jorstad et al. | An analysis of current mobile services and enabling technologies |
Legal Events
Date | Code | Title | Description |
---|---|---|---|
C06 | Publication | ||
PB01 | Publication | ||
C10 | Entry into substantive examination | ||
SE01 | Entry into force of request for substantive examination | ||
GR01 | Patent grant | ||
GR01 | Patent grant |