`
sillycat
  • 浏览: 2542170 次
  • 性别: Icon_minigender_1
  • 来自: 成都
社区版块
存档分类
最新评论

Spring3 and Axis2 Integration(I)

阅读更多
Spring3 and Axis2 Integration(I)

I use spring3 and axis2.
1. we will have our spring configuration file and our spring bean configuration
main-context.xml:
<context:annotation-config />
<context:component-scan base-package="com.sillycat">
</context:component-scan>
<import resource="classpath:resource-context.xml" />
<import resource="classpath:core-context.xml" />
<import resource="classpath:dao-context.xml" />
<import resource="classpath:manager-context.xml" />

<import resource="classpath:service-easyaxis2proxy-context.xml" />

our webservice bean configuration file service-easyaxis2proxy-context.xml:
<bean id="personService" class="com.sillycat.easyaxis2proxy.service.PersonServiceImpl" >
<property name="personManager" ref="personManager"/>
</bean>

2. axis2 configuration is as the same as we did in easyaxis project

3. spring3 axis2 intergration
We will not have aar file, we will put the configuration file WEB-INF/services/PersonService/META-INF/services.xml
<?xml version="1.0" encoding="UTF-8"?>
<service name="PersonService">
<description>
Person Demo Service
    </description>
<parameter name="ServiceObjectSupplier">
org.apache.axis2.extensions.spring.receivers.SpringServletContextObjectSupplier
</parameter>
<parameter name="SpringBeanName">
personService
    </parameter>
<messageReceivers>
<messageReceiver mep="http://www.w3.org/2004/08/wsdl/in-out"
class="org.apache.axis2.rpc.receivers.RPCMessageReceiver" />
<messageReceiver mep="http://www.w3.org/2004/08/wsdl/in-only"
class="org.apache.axis2.rpc.receivers.RPCInOnlyMessageReceiver" />
</messageReceivers>
</service>

We can call spring bean named personService in our axis2 services.xml file directly.

Our web.xml will as follow:
<display-name>easyaxis2proxy</display-name>
<context-param>
<param-name>contextConfigLocation</param-name>
<param-value>classpath:main-context.xml</param-value>
</context-param>
<filter>
<filter-name>encodingFilter</filter-name>
<filter-class>org.springframework.web.filter.CharacterEncodingFilter</filter-class>
<init-param>
<param-name>encoding</param-name>
<param-value>UTF-8</param-value>
</init-param>
</filter>
<listener>
<listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>
</listener>
<listener>
<listener-class>org.springframework.web.util.IntrospectorCleanupListener</listener-class>
</listener>
<!-- axis2 start -->
<servlet>
<servlet-name>AxisServlet</servlet-name>
<servlet-class>org.apache.axis2.transport.http.AxisServlet</servlet-class>
<load-on-startup>1</load-on-startup>
</servlet>
<servlet>
       <servlet-name>SOAPMonitorService</servlet-name>
       <servlet-class>
         org.apache.axis2.soapmonitor.servlet.SOAPMonitorService
       </servlet-class>
       <init-param>
          <param-name>SOAPMonitorPort</param-name>
          <param-value>5001</param-value>
       </init-param>
       <load-on-startup>1</load-on-startup>
</servlet>
<servlet-mapping>
<servlet-name>AxisServlet</servlet-name>
<url-pattern>/servlet/AxisServlet</url-pattern>
</servlet-mapping>
<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>
<servlet-mapping>
        <servlet-name>SOAPMonitorService</servlet-name>
        <url-pattern>/SOAPMonitor</url-pattern>
</servlet-mapping>

4. Everything is ok, we can visit the listservice page
http://localhost:8080/easyaxis2proxy/services/listServices

we can get the WSDL file from here:
http://localhost:8080/easyaxis2proxy/services/PersonService?wsdl

5. Run my junit test, PersonServiceRemoteTest:
package com.sillycat.easyaxis2proxy.remote;

import javax.xml.namespace.QName;

import org.apache.axis2.addressing.EndpointReference;
import org.apache.axis2.client.Options;
import org.apache.axis2.rpc.client.RPCServiceClient;
import org.apache.axis2.transport.http.HTTPConstants;

import com.sillycat.core.BaseTestCase;
import com.sillycat.easyjpa.model.Person;

public class PersonServiceRemoteTest extends BaseTestCase
{

    public void setUp() throws Exception
    {
        super.setUp();
    }

    public void tearDown() throws Exception
    {
        super.tearDown();
    }

    @SuppressWarnings("unchecked")
    public void testGet()
    {
        RPCServiceClient serviceClient = null;
        try
        {
            serviceClient = new RPCServiceClient();
            Options options = serviceClient.getOptions();
            EndpointReference targetEPR = new EndpointReference("http://localhost:8080/easyaxis2proxy/services/PersonService");
            options.setTimeOutInMilliSeconds(1800000); // 10000 seconds
            options.setProperty(HTTPConstants.CHUNKED, Boolean.FALSE);
            options.setProperty(HTTPConstants.SO_TIMEOUT, 1800000);
            options.setProperty(HTTPConstants.CONNECTION_TIMEOUT, 1800000);
            options.setProperty(HTTPConstants.REUSE_HTTP_CLIENT, Boolean.TRUE);
            options.setExceptionToBeThrownOnSOAPFault(true);
            options.setTo(targetEPR);
           
            // Getting the person
            QName opGet = new QName("http://service.easyaxis2proxy.sillycat.com", "get");
            Object[] opGetArgs = new Object[] { 2 };
            Class[] returnTypes = new Class[] { Person.class };
            Object[] response = serviceClient.invokeBlocking(opGet, opGetArgs, returnTypes);

            Person result = (Person) response[0];

            if (result == null)
            {
                System.out.println("Person didn't initialize!");
                return;
            }
            // Displaying the result
            System.out.println("Name                          : " + result.getName());
            System.out.println("Age                           : " + result.getAge());
            System.out.println("Birthday                      : " + result.getBirthday());
            System.out.println("Sex                           : " + result.getSex());
            System.out.println("Id                            : " + result.getId());
        }
        catch (Exception e)
        {
            System.out.println("error:" + e);
        }
        finally
        {
            try
            {
                // clear up
                serviceClient.cleanupTransport();
            }
            catch (Exception e)
            {
                System.out.println("error:" + e);
            }
        }
    }

}

I got this error message when I run my junit test:
date string can not be less than 19 charactors

It seems that the axis2 can not deal with Date type well. So I think the easiest way to do this is to trans Date to String in WebService level.

ok, everything is running well, the sample project is easyaxis2proxy.

references:
http://wujianjun.iteye.com/blog/517150
http://wujianjun.iteye.com/blog/517152
http://axis.apache.org/axis2/java/core/docs/spring.html
http://cheney-mydream.iteye.com/blog/390232
分享到:
评论

相关推荐

    Spring整合axis2经典

    3. **Spring整合Axis2** 整合Spring和Axis2,主要是为了利用Spring的依赖注入和管理能力,以及Axis2的Web服务处理能力。整合过程主要包括以下步骤: - 配置Spring容器:首先在Spring配置文件中定义Web服务的bean,...

    Spring 实现webService

    Spring框架提供了两种主要的方式来实现Web服务:Spring-WS和Spring-Integration的Web服务支持。在这个场景中,描述中提到的是基于Apache Axis的实现,这可能涉及到Spring与Apache Axis的集成,Axis是一个流行的SOAP...

    axis插件生成客户端

    3. 使用Axis插件生成客户端:在命令行中,你可以使用Axis的wsdl2java工具,输入Web服务的WSDL URL或本地WSDL文件路径,该工具会自动生成对应的客户端Java stubs(存根类)。这些存根类包含了调用Web服务所需的所有...

    apache axis1.4 官网备份

    2. **UDDI(Universal Description, Discovery, and Integration)**:一种用于发现Web服务的目录服务标准。 3. **SOAP**:基于XML的协议,用于交换结构化信息。SOAP消息包含一个或多个操作调用。 4. **WS-I(Web ...

    WebService详细解析(axis,xfire,cxf,授权认证加密解密)

    WebService的核心技术包括SOAP(Simple Object Access Protocol)、WSDL(Web Services Description Language)和UDDI(Universal Description, Discovery, and Integration)。 【axis篇】 AXIS是Apache软件基金会...

    Java WebService 简单实例 方式三(axis1接口调用方式)

    4. UDDI(Universal Description, Discovery, and Integration)是一个目录服务,用于发布和查找Web服务。 二、Apache Axis1简介 Apache Axis是Apache软件基金会开发的一个开源项目,用于构建和部署Web服务。Axis1...

    WebService-xfire和axis开发指南

    这种技术的核心在于利用SOAP(Simple Object Access Protocol)作为消息传输机制,WSDL(Web Services Description Language)用于描述服务,以及UDDI(Universal Description, Discovery, and Integration)作为...

    WebServices开发-Axis实例CXF实例

    SOAP(Simple Object Access Protocol)作为消息传输协议,WSDL(Web Services Description Language)来定义服务接口,以及UDDI(Universal Description, Discovery, and Integration)用于服务注册和发现。...

    JAVA常用框架发布WebService

    Spring框架提供了对WebService的全面支持,可以通过Spring-WS或Spring-Integration模块方便地集成各种Web服务框架,如Axis2。Spring的依赖注入和AOP特性使得Web服务的开发更加灵活和易于测试。 7. 安全性考虑: ...

    webService接口

    WebService规范包括描述服务的WSDL(Web Service Description Language)、定位服务的UDDI(Universal Description, Discovery and Integration)以及通信协议SOAP(Simple Object Access Protocol)。 #### ...

    AxisSpring

    2. **Spring框架**: Spring以其依赖注入(DI)和面向切面编程(AOP)闻名,是Java开发中的基石。它简化了企业级应用的复杂性,通过提供事务管理、数据访问、安全管理等服务,使开发者能够专注于业务逻辑。 3. **...

    spring-xfire编写webservice

    - **UDDI**(Universal Description, Discovery and Integration):是服务发布和发现的标准,使得服务提供者能够登记服务,服务请求者能够搜索服务。 3. **XFire简介**: - XFire是一个快速发展的Web Service...

    wenseve

    通过深入学习这些文档,开发者可以掌握Web服务的核心概念,以及如何使用Apache Axis2和Spring框架来有效地开发和集成Web服务。这将有助于提高Java开发者在分布式系统和企业级应用开发中的技能。

    Webserver开发指南

    3. **Axis与Spring集成** - Spring框架是一个强大的企业级应用开发框架,它可以与Axis集成以管理Web服务的生命周期,实现依赖注入,并提供事务管理和安全控制等高级功能。 4. **开发流程与工具** - 使用Axis进行...

    Game physics

    5.4.2 Culling with Axis-Aligned Bounding Boxes 354 5.5 Variations 361 Chapter Physics and Shader Programs 6.1 Introduction 6.2 vertex and pixel shaders 6.3 Deformation by vertex Displacement ...

    Java的webservice开发与测试入门例子

    它们通常基于SOAP(Simple Object Access Protocol)协议,使用WSDL(Web Services Description Language)进行描述,并通过UDDI(Universal Description, Discovery, and Integration)服务进行发布和查找。...

    Java WebService大讲堂(1-10集,完整版)

    3. "使用services.xml文件发布WebService":这集内容深入解析了如何使用services.xml文件来定义和部署Web服务,这是Axis2中一个关键的配置文件。 4. "二进制文件传输":针对Web服务中可能涉及的非文本数据,如图片...

    webservice开发

    WSDL(Web Services Description Language)用于定义服务接口,UDDI(Universal Description, Discovery, and Integration)则提供服务注册和查找功能。这些技术共同构建了Web服务的基础架构。 二、XFire框架 XFire...

    web service的资料

    1. **Web服务基础**:介绍Web服务的基本概念,包括SOAP、WSDL、UDDI(Universal Description, Discovery, and Integration)等标准。 2. **Axis框架详解**:深入解析Axis的工作原理,如何创建、部署和调用Web服务,...

Global site tag (gtag.js) - Google Analytics