`

WebService框架整理(二) Axis1+Spring

 
阅读更多

WebService框架整理(二) Axis1+Spring

 (2010-11-18 16:13:06)
标签: 

杂谈

 
文章分类:Java编程
初识Axis1就要把它集成到Spring框架上。一方面是当时的项目要求,在一方面更是我对于Spring情有独钟。 
Axis1+Spring比较简单,这种便利得益于Spring的ServletEndpointSupport类支持。 

相关链接: 
WebService框架整理(一) Axis1 
WebService框架整理(二) Axis1+Spring 

我们将用到以下Jar: 
引用

activation.jar 
axis.jar 
commons-discovery.jar 
commons-logging.jar 
jaxrpc.jar 
log4j-1.2.15.jar 
mail.jar 
wsdl4j.jar 
spring.jar 

主要就是加入了spring.jar包! 

再看看web.xml,加入了Spring的相关内容。大家都熟悉Spring,我就不废话了! 
Xml代码  spring-axis-1 log4jConfigLocation classpath:log4j.xml log4jRefreshInterval 60000 contextConfigLocation /WEB-INF/applicationContext.xml UTF-8 Filter org.springframework.web.filter.CharacterEncodingFilter encoding UTF-8 forceEncoding true UTF-8 Filter public interface CalcService { int add(int a, int b); } " quality="high" allowscriptaccess="always" type="application/x-shockwave-flash" pluginspage="http://www.macromedia.com/go/getflashplayer">
  1.   
  2. public interface CalcService {  
  3.   
  4.       
  5.     int add(int a, int b);  
  6.   
  7. }  

给出对应的实现内容: 
Java代码 
  1. import org.zlex.axis.service.CalcService;  
  2.   
  3.   
  4. public class CalcServiceImpl implements CalcService {  
  5.   
  6.     @Override  
  7.     public int add(int a, int b) {  
  8.         return a + b;  
  9.     }  
  10.   
  11. }  

再简单不过的1+1问题!WebService框架整理(二) <wbr>Axis1+Spring 
将其注入到Spring的容器中,applicationContext.xml如下所示: 
Xml代码  " quality="high" allowscriptaccess="always" type="application/x-shockwave-flash" pluginspage="http://www.macromedia.com/go/getflashplayer">
  1. <?xml version="1.0" encoding="UTF-8"?>  
  2. <beans  
  3.     xmlns="http://www.springframework.org/schema/beans"  
  4.     xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"  
  5.     xmlns:context="http://www.springframework.org/schema/context"  
  6.     xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd  
  7.         http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context.xsd">  
  8.     <bean  
  9.         id="calcService"  
  10.         class="org.zlex.axis.service.impl.CalcServiceImpl" />  
  11. </beans>  

作为spring与axis1对接,需要做一个ServletEndpointSupport继承实现WebService,如下所示: 
Java代码 
  1. import javax.xml.rpc.ServiceException;  
  2.   
  3. import org.springframework.context.ApplicationContext;  
  4. import org.springframework.remoting.jaxrpc.ServletEndpointSupport;  
  5. import org.zlex.axis.service.CalcService;  
  6.   
  7.   
  8. public class WebService extends ServletEndpointSupport {  
  9.   
  10.     private ApplicationContext applicationContext;  
  11.     private CalcService calcService;  
  12.   
  13.       
  14.     @Override  
  15.     protected void onInit() throws ServiceException {  
  16.         // 初始化Spirng 配置  
  17.         applicationContext = super.getApplicationContext();  
  18.   
  19.         calcService = (CalcService) applicationContext.getBean("calcService");  
  20.   
  21.     }  
  22.   
  23.       
  24.     public String add(int a, int b) {  
  25.         return String.valueOf(calcService.add(a, b));  
  26.     }  
  27.   
  28. }  

这里为了便于在eclipse演示,将返回值定为String类型! 
现在我们将该服务植入Axis中,修改server-config.wsdd文件,在原文件中加入如下内容: 
Xml代码  " quality="high" allowscriptaccess="always" type="application/x-shockwave-flash" pluginspage="http://www.macromedia.com/go/getflashplayer">
  1. <!-- 自定义服务 -->  
  2. <service  
  3.     name="WebService"  
  4.     provider="java:RPC">  
  5.     <parameter  
  6.         name="className"  
  7.         value="org.zlex.axis.WebService" />  
  8. </service>  

修改后的server-config.wsdd文件如下所示: 
Xml代码  http://xml.apache.org/axis/wsdd/ " quality="high" allowscriptaccess="always" type="application/x-shockwave-flash" pluginspage="http://www.macromedia.com/go/getflashplayer">
  1. <?xml version="1.0" encoding="UTF-8"?>  
  2. <deployment  
  3.     xmlns="http://xml.apache.org/axis/wsdd/"  
  4.     xmlns:java="http://xml.apache.org/axis/wsdd/providers/java">  
  5.     <globalConfiguration>  
  6.         <parameter  
  7.             name="adminPassword"  
  8.             value="admin" />  
  9.         <parameter  
  10.             name="sendXsiTypes"  
  11.             value="true" />  
  12.         <parameter  
  13.             name="sendMultiRefs"  
  14.             value="true" />  
  15.         <parameter  
  16.             name="sendXMLDeclaration"  
  17.             value="true" />  
  18.         <parameter  
  19.             name="axis.sendMinimizedElements"  
  20.             value="true" />  
  21.         <requestFlow>  
  22.             <handler  
  23.                 type="java:org.apache.axis.handlers.JWSHandler">  
  24.                 <parameter  
  25.                     name="scope"  
  26.                     value="session" />  
  27.             </handler>  
  28.             <handler  
  29.                 type="java:org.apache.axis.handlers.JWSHandler">  
  30.                 <parameter  
  31.                     name="scope"  
  32.                     value="request" />  
  33.                 <parameter  
  34.                     name="extension"  
  35.                     value=".jwr" />  
  36.             </handler>  
  37.         </requestFlow>  
  38.     </globalConfiguration>  
  39.     <handler  
  40.         name="Authenticate"  
  41.         type="java:org.apache.axis.handlers.SimpleAuthenticationHandler" />  
  42.     <handler  
  43.         name="LocalResponder"  
  44.         type="java:org.apache.axis.transport.local.LocalResponder" />  
  45.     <handler  
  46.         name="URLMapper"  
  47.         type="java:org.apache.axis.handlers.http.URLMapper" />  
  48.     <service  
  49.         name="AdminService"  
  50.         provider="java:MSG">  
  51.         <parameter  
  52.             name="allowedMethods"  
  53.             value="AdminService" />  
  54.         <parameter  
  55.             name="enableRemoteAdmin"  
  56.             value="false" />  
  57.         <parameter  
  58.             name="className"  
  59.             value="org.apache.axis.utils.Admin" />  
  60.         <namespace>http://xml.apache.org/axis/wsdd/</namespace>  
  61.     </service>  
  62.     <service  
  63.         name="Version"  
  64.         provider="java:RPC">  
  65.         <parameter  
  66.             name="allowedMethods"  
  67.             value="getVersion" />  
  68.         <parameter  
  69.             name="className"  
  70.             value="org.apache.axis.Version" />  
  71.     </service>  
  72.     <transport  
  73.         name="http">  
  74.         <requestFlow>  
  75.             <handler  
  76.                 type="URLMapper" />  
  77.             <handler  
  78.                 type="java:org.apache.axis.handlers.http.HTTPAuthHandler" />  
  79.         </requestFlow>  
  80.     </transport>  
  81.     <transport  
  82.         name="local">  
  83.         <responseFlow>  
  84.             <handler  
  85.                 type="LocalResponder" />  
  86.         </responseFlow>  
  87.     </transport>  
  88.   
  89.     <!-- 自定义服务 -->  
  90.     <service  
  91.         name="WebService"  
  92.         provider="java:RPC">  
  93.         <parameter  
  94.             name="className"  
  95.             value="org.zlex.axis.WebService" />  
  96.     </service>  
  97. </deployment>  

我们随机抽取2个数进行求和运算,并验证WebService和本地计算结果是否一致,测试用例WebServiceTest如下: 
分享到:
评论

相关推荐

    axis2+spring webservice

    标题中的“axis2+spring webservice”指的是使用Apache Axis2框架与Spring框架集成来开发Web服务。Apache Axis2是Java环境中广泛使用的Web服务引擎,它提供了高性能、灵活且可扩展的架构。Spring框架则是一个全面的...

    axis2+Spring提供WebService服务

    Axis2和Spring框架的结合提供了一种高效且灵活的方式来创建和管理WebService。让我们深入了解一下这两个技术以及它们如何协同工作。 首先,Apache Axis2是Java平台上一个成熟的Web服务引擎,专门用于处理SOAP消息。...

    axis2+spring+hibernate Webservice

    标题 "axis2+spring+hibernate Webservice" 指出的是一个基于Java的开源项目,它结合了三个关键的技术框架:Axis2、Spring和Hibernate。这些技术都是企业级应用开发中的重要组件,用于构建高效、灵活且可扩展的服务...

    axis2+spring+ibatis

    标题中的"axis2+spring+ibatis"是一个典型的Java企业级应用架构组合,它涉及到三个主要的技术组件:Apache Axis2、Spring框架和iBATIS。接下来,我们将详细探讨这三个技术以及它们在项目集成中的作用。 1. Apache ...

    在自己的项目中利用axis2+spring发布webservice与客户端调用包括session

    标题中的“在自己的项目中利用axis2+spring发布webservice与客户端调用包括session”指出的是一个关于在实际项目开发中如何使用Axis2和Spring框架来发布Web服务,并且涉及了Web服务客户端调用以及会话(session)...

    axis2+spring2.5整合(webservice)

    当我们谈论“Axis2+Spring2.5整合(Web服务)”时,我们指的是将Apache Axis2和Spring框架结合在一起,以便更高效地开发和管理Web服务。 Apache Axis2是Apache软件基金会开发的一个Web服务引擎,它提供了SOAP消息...

    WebService(Axis+spring+jpa)

    【WebService(Axis+Spring+jpa)】是一种将Web服务与企业级Java技术相结合的应用实例,旨在提供基于HTTP的远程调用功能。在这个项目中,Apache Axis作为SOAP(简单对象访问协议)服务的生成器和客户端工具,Spring...

    axis2+spring 实现webservice需要jar包

    在构建基于Axis2和Spring的Web服务时,我们需要一系列的依赖库来支持整个框架的运行。这些库提供了从XML解析到服务部署的各种功能。以下是标题和描述中提及的关键知识点及其详细解释: 1. **Axis2**:Apache Axis2...

    webservice+axis2+myeclipse+tomcat

    Axis2 是 Apache 提供的一个高效且可扩展的 WebService 框架,它是 Axis1 的下一代产品,主要特点包括支持 SOAP 1.1/1.2、WS-* 规范、多种传输协议(如 HTTP、SMTP 等)以及多种消息格式(如 SOAP、RESTful)。...

    axis1.4+mybatis3+spring实现webservice

    在IT行业中,构建高效、可扩展的企业级应用是至关重要的,而 Axis1.4、MyBatis3 和 Spring3 的集成则为实现这样的目标提供了一种强大的解决方案。本项目通过将这三个框架组合在一起,旨在创建一个能够提供Web服务的...

    Axis2与Spring整合发布多个WebService

    通过以上步骤和最佳实践,开发者可以有效地利用Axis2和Spring框架整合发布多个WebService,同时借助Maven进行项目管理,提高开发效率和代码质量。这为构建复杂、可扩展的企业级Web服务解决方案提供了坚实的基础。

    Spring集成axis2实现webservice所用到的包

    1. **配置Axis2**:在Spring项目中,首先需要将Axis2的相关库添加到项目的类路径下。这些库通常包括`axis2-*.jar`, `axiom-*.jar`, `neethi-*.jar`, `wsdl4j-*.jar`, `commons-discovery-*.jar`, `commons-logging-*...

    SpringBoot开发WebService之Axis示例

    在本文中,我们将深入探讨如何使用SpringBoot框架开发基于Axis的Web服务。SpringBoot以其便捷的启动和配置方式,已经成为Java开发中的首选框架之一。而 Axis 是一个流行的Apache项目,用于创建和部署Web服务,它提供...

    axis2+EJB整合开发 源代码

    【标题】"Axis2+EJB整合开发 源代码"涉及的是在Java环境中,使用Axis2框架与Enterprise JavaBeans(EJB)技术进行Web服务整合的实践案例。这个标题暗示了我们将深入理解如何将EJB的功能集成到基于Axis2的Web服务中,...

    java webservice之axis2与spring集成(二)

    以下是关于"java webservice之axis2与spring集成(二)"的详细知识点讲解: 1. **Spring框架**: Spring是Java领域的一个开源框架,主要用于简化企业级应用的开发。它提供了一个全面的编程和配置模型,特别强调了...

    WebService流行框架之Axis和CXF=.docx

    Axis1是Apache软件基金会开发的早期版本的WebService框架。它支持JWS(Java Web Service)方式来发布WebService,这允许开发者直接将Java源码以`.jws`文件的形式部署,但这种方式有一定的限制,如源码不能包含包名...

    spring+axis集成webservice

    1. **设置环境**:确保你的开发环境中已经安装了Java JDK、Maven(或Gradle)构建工具,以及Apache Axis和Spring框架的相关依赖。这些可以通过在项目的pom.xml文件中添加相应的依赖来完成。 2. **创建Web服务**:...

    Spring 实现webService

    - "Spring+axis实现WebService说明.doc"文档应该详细介绍了如何设置环境、配置Spring和Axis,以及如何创建和调用Web服务。文档中可能包含了步骤指导、配置示例和代码片段,对于理解和实践这个主题非常有帮助。 6. ...

Global site tag (gtag.js) - Google Analytics