`
jxh118
  • 浏览: 124099 次
  • 性别: Icon_minigender_1
  • 来自: 广州
社区版块
存档分类
最新评论

XFire与Spring结合

阅读更多

1、使用org.codehaus.xfire.spring.XFireSpringServlet与ServiceBean

1.1 web.xml的配置

 

<web-app>
 <display-name>Spring Image Database</display-name>
 <description>Spring Image Database sample application</description>
 <!--
  These values are used by ContextLoaderListener, defined immediately below.
        The files listed below are used to initialize the business logic portion of the application.
        Each dispatcher servlet (defined further down) has their own configuration file,
        which may or may not depend on items in these files.
    -->
    <context-param>
       <param-name>contextConfigLocation</param-name>
       <param-value>
     classpath:applicationContext-webservice.xml
    </param-value>
    </context-param>
 <!-- Log4j configuration listener-->
 <listener>
  <listener-class>org.springframework.web.util.Log4jConfigListener</listener-class>
 </listener>
 <!-- Spring framework -->
 <listener>
        <listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>
 </listener>

 <servlet>
        <servlet-name>XFireServlet</servlet-name>
        <display-name>XFire Servlet</display-name>
        <servlet-class>org.codehaus.xfire.spring.XFireSpringServlet</servlet-class>
    </servlet>
               
    <servlet-mapping>
        <servlet-name>XFireServlet</servlet-name>
        <url-pattern>/services/*</url-pattern>
    </servlet-mapping>

 <welcome-file-list>
  <welcome-file>index.jsp</welcome-file>
 </welcome-file-list>
 
</web-app>

 

1.2 applicationContext-webservice.xml的配置:

 

<beans>

    <import resource="classpath:org/codehaus/xfire/spring/xfire.xml"/>
    
    <bean name="echoService" class="org.codehaus.xfire.spring.ServiceBean">
        <property name="serviceBean" ref="echo"/>
        <property name="serviceClass" value="org.codehaus.xfire.test.Echo"/>
        <property name="inHandlers">
            <list>
                <ref bean="addressingHandler"/>
            </list>
        </property>
    </bean>

    <bean id="echo" class="org.codehaus.xfire.test.EchoImpl"/>

    <bean id="addressingHandler" class="org.codehaus.xfire.addressing.AddressingInHandler"/>
 
   <bean name="bookService" class="org.codehaus.xfire.spring.ServiceBean">
        <property name="serviceBean" ref="bookServiceBean"/>
        <property name="serviceClass" value="org.codehaus.xfire.demo.BookService"/>
    </bean>

    <bean id="bookServiceBean" class="org.codehaus.xfire.demo.BookServiceImpl"/>

</beans>

 

1.3 这样将会发布两个service,BookServiceEchoService。随后就可以使用client端进行测试了。

     //测试BookService

 

 public static void main(String args[])
    { 
        String serviceURL = "http://127.0.0.1:9001/xfire/services/BookService";
        Service serviceModel = new ObjectServiceFactory().create(BookService.class,null,"http://xfire.codehaus.org/BookService",null);
        XFireProxyFactory serviceFactory = new XFireProxyFactory();
        try
        {
            BookService service = (BookService) serviceFactory.create(serviceModel, serviceURL);
            Client client = Client.getInstance(service);
            client.addOutHandler(new OutHeaderHandler());
            Book[] books = service.getBooks();
            System.out.println("BOOKS:");
            for (int i = 0; i < books.length; i++)
            {
                System.out.println(books[i].getTitle());
            }
        }
        catch (MalformedURLException e)
        {
            e.printStackTrace();
        }
    }

 
1.4 忘了BookService及其实现了。

 

 public interface BookService
    {
              public Book[] getBooks();
    
              public Book findBook(String isbn);
    
             public Map getBooksMap();
   }

 

    public class BookServiceImpl implements BookService
    {
    private Book onlyBook;
    
    public BookServiceImpl()
    {
        onlyBook = new Book();
        onlyBook.setAuthor("Dan Diephouse");
        onlyBook.setTitle("Using XFire");
        onlyBook.setIsbn("0123456789");
     }

     public Book[] getBooks() 
     {
        return new Book[] { onlyBook };
     }
    
     public Book findBook(String isbn)
     {
        if (isbn.equals(onlyBook.getIsbn()))
            return onlyBook;
        
        return null;
     }

     public Map getBooksMap() {
  Map result = new HashMap();
  result.put(onlyBook.getIsbn(), onlyBook);
  return result;
     }
    }

 

1.5 简单的测试就是通过IE,输入http://ip:port/context/services/BookService?wsdl或者http://ip:port/context/services/EchoService?wsdl,将会出现相应的wsdl文档。

     如果只是输入http://ip:port/context/services/BookService,会出现Invalid SOAP request.这也说明配置正确。

2、直接集成Spring(通过Spring的org.springframework.web.servlet.DispatcherServlet)

2.1 web.xml配置

<web-app>
<!-- START SNIPPET: xfire -->
    <context-param>
        <param-name>contextConfigLocation</param-name>
        <param-value>
        classpath:org/codehaus/xfire/spring/xfire.xml</param-value>
    </context-param>

    <context-param>
        <param-name>log4jConfigLocation</param-name>
        <param-value>/WEB-INF/log4j.properties</param-value>
    </context-param>

    <listener>
        <listener-class>org.springframework.web.util.Log4jConfigListener</listener-class>
    </listener>

    <listener>
        <listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>
    </listener>

    <servlet>
        <servlet-name>xfire</servlet-name>
        <servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>
    </servlet>

    <servlet-mapping>
        <servlet-name>xfire</servlet-name>
        <url-pattern>/*</url-pattern>
    </servlet-mapping>
<!-- END SNIPPET: xfire -->
</web-app>

 
2.2 xfire-servlet.xml配置

<beans>
    <!-- START SNIPPET: xfire -->
    <bean class="org.springframework.web.servlet.handler.SimpleUrlHandlerMapping">
        <property name="urlMap">
            <map>
                <entry key="/EchoService">
                    <ref bean="echo"/>
                </entry>
            </map>
        </property>
    </bean>

    <bean id="echoBean" class="org.codehaus.xfire.spring.example.EchoImpl"/>

    <!-- Declare a parent bean with all properties common to both services -->
    <bean id="echo" class="org.codehaus.xfire.spring.remoting.XFireExporter">
        <property name="serviceFactory">
            <ref bean="xfire.serviceFactory"/>
        </property>
        <property name="xfire">
            <ref bean="xfire"/>
        </property>
        <property name="serviceBean">
            <ref bean="echoBean"/>
        </property>
        <property name="serviceClass">
            <value>org.codehaus.xfire.spring.example.Echo</value>
        </property>
    </bean>
    <!-- END SNIPPET: xfire -->
</beans>

 
2.3 余下的配置跟第一种方法一样。

分享到:
评论

相关推荐

    XFire与Spring组合发布webservices

    将XFire与Spring结合使用,可以实现以下几种发布Web服务的方式: 1. **基于Spring Bean的配置**:通过在Spring配置文件中定义Bean,可以将Web服务的实现类声明为一个Bean。Spring会自动检测该Bean上的JAX-WS注解...

    xfire+spring+webservice

    将XFire与Spring结合,可以充分发挥各自的优势。首先,Spring的IoC容器可以管理XFire的服务实例,使得服务的生命周期控制更加简洁。其次,通过Spring的AOP,我们可以方便地添加事务管理、日志记录等通用功能到Web...

    xfire+spring webservice

    将XFire与Spring结合,可以充分利用Spring的IoC(Inversion of Control)和AOP(Aspect Oriented Programming)特性,使Web服务的开发更为灵活和可维护。以下是如何在Spring中集成XFire的基本步骤: 1. **添加依赖*...

    xfire+spring+安全认证

    总的来说,"xfire+spring+安全认证"是一个关于利用XFire作为Web服务实现工具,结合Spring框架的安全模块,来构建安全的分布式应用程序的主题。它涵盖了Web服务开发、认证与授权、以及安全通信等多个IT领域的关键知识...

    XFire整合spring webservice

    将XFire与Spring整合可以充分利用Spring的优秀特性,提高Web服务的开发效率和可维护性。本教程主要针对初学者,旨在通过一个清晰、简单的项目,介绍如何将XFire与Spring进行整合。 1. **环境准备** 在开始整合前,...

    spring与xfire结合

    标题“spring与xfire结合”涉及的是在Java开发中整合Spring框架和XFire服务引擎的技术。Spring是一个广泛应用的开源框架,主要用于简化企业级应用的开发,而XFire(现已被Apache CXF所吸收)则是一个用于创建Web服务...

    使用XFire+Spring构建Web Service

    本文将深入探讨XFire与Spring结合构建Web Service的具体方法,以及这一组合所带来的优势。 #### 二、XFire特性解析 XFire相较于Axis和其他Web Service框架,展现出了诸多显著的优势: 1. **标准支持**:XFire全面...

    xfire+spring开发webservice

    本篇文章将深入探讨如何使用XFire与Spring框架一起开发Web服务。 首先,我们需要理解XFire的基本概念。XFire是为了解决Java Web服务开发中的复杂性问题而设计的,它提供了一个轻量级、高性能的框架,使得开发者可以...

    xfire 与Spring完整集成实例(WebService)

    标题 "xfire 与Spring完整集成实例(WebService)" 提示我们关注的是如何将XFire框架与Spring框架整合,以实现Web服务的功能。XFire是一个早期的Java Web Service框架,它提供了快速、轻量级的方式来创建和消费SOAP...

    xfire-spring.pdf

    本文档详细介绍了如何使用XFire与Spring框架结合来开发WebService。从开发环境的准备到具体的实现步骤,以及如何测试和扩展服务,都有详细的指导。对于初学者来说,这是一个很好的起点,可以帮助他们快速入门并掌握...

    xfire-spring

    - **基于J2EE平台的WebService服务**:XFire与Spring结合提供了一种高效、稳定的WebService开发方案,适用于J2EE环境,能够满足企业级应用的需求。 - **开发便捷性与简单配置**:XFire简化了WebService的开发流程,...

    Spring和XFIRE结合

    标题 "Spring和XFIRE结合" 暗示了本文将探讨如何在Java应用程序开发中整合Spring框架与XFire服务框架,以实现轻量级、基于XML的Web服务。Spring是Java领域广泛使用的依赖注入(DI)和面向切面编程(AOP)框架,而...

    使用XFire+Spring构建Web Service步骤以及源代码.rar

    本教程将详细介绍如何结合XFire和Spring来构建Web服务,并提供相关的源代码供参考。 首先,我们要理解XFire和Spring的基本概念。XFire(后被Apache CXF合并)是一个用于创建和消费SOAP Web服务的库,它支持WS-I基本...

    xfire整合spring发布web services

    【Xfire整合Spring发布Web Services】是将Xfire——一个基于Java的Web服务实现框架,与Spring——一个广泛使用的轻量级应用框架相结合,用于构建和发布Web服务的过程。这个整合使得开发人员能够利用Spring的强大功能...

    xfire与spring集成案例

    总之,"xfire与spring集成案例"是一个实用的教程,旨在帮助开发者理解和实践如何在Spring环境中利用XFire构建Web服务。这个案例提供了完整的流程,从配置到测试,对于初学者来说是一个很好的学习起点,同时也为有...

    webservice xfire spring2.0完整实例

    在这个“webservice xfire spring2.0完整实例”中,我们将会探讨如何结合XFire 1.2.6和Spring 2.0来创建和消费Web服务。首先,我们需要理解Spring 2.0中的Web服务抽象层,即Spring Web Services模块。这个模块提供了...

    spring+xfire( 编写webservice完整配置+案例)

    总之,Spring与XFire的结合提供了一种简洁、灵活的方式来创建和管理Web服务,使得开发者可以专注于业务逻辑,而不是底层的协议细节。虽然现在Spring社区更倾向于使用Spring-WS或其他现代的Web服务框架,如Apache CXF...

    使用xfire+spring构建webservice

    将两者结合,可以方便地在Spring应用中集成Web服务功能。 首先,我们需要理解Web服务的基本概念。Web服务是一种基于网络的应用程序接口,允许不同系统之间交换数据。SOAP是Web服务的一种通信协议,通过XML格式传输...

    XFire+Spring webwervice

    【XFire+Spring Web Service】是一个结合了XFire和Spring框架的解决方案,用于构建高效、易用的Web服务。XFire作为一个现代化的Web服务框架,它与Axis2齐名,但因其简洁的API和对Web服务标准的支持,如JSR181、WSDL...

Global site tag (gtag.js) - Google Analytics