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 余下的配置跟第一种方法一样。

3、另外xfire的官方文档上还有一种方法,是通过XBean与Spring结合来实现webservice的expose。还是觉得上面的两种方法比较好。既然已经与spring集成在一起了,何必再引入其他的呢?以后的维护是不是也要有问题呢?

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
提供的源码资源涵盖了安卓应用、小程序、Python应用和Java应用等多个领域,每个领域都包含了丰富的实例和项目。这些源码都是基于各自平台的最新技术和标准编写,确保了在对应环境下能够无缝运行。同时,源码中配备了详细的注释和文档,帮助用户快速理解代码结构和实现逻辑。 适用人群: 这些源码资源特别适合大学生群体。无论你是计算机相关专业的学生,还是对其他领域编程感兴趣的学生,这些资源都能为你提供宝贵的学习和实践机会。通过学习和运行这些源码,你可以掌握各平台开发的基础知识,提升编程能力和项目实战经验。 使用场景及目标: 在学习阶段,你可以利用这些源码资源进行课程实践、课外项目或毕业设计。通过分析和运行源码,你将深入了解各平台开发的技术细节和最佳实践,逐步培养起自己的项目开发和问题解决能力。此外,在求职或创业过程中,具备跨平台开发能力的大学生将更具竞争力。 其他说明: 为了确保源码资源的可运行性和易用性,特别注意了以下几点:首先,每份源码都提供了详细的运行环境和依赖说明,确保用户能够轻松搭建起开发环境;其次,源码中的注释和文档都非常完善,方便用户快速上手和理解代码;最后,我会定期更新这些源码资源,以适应各平台技术的最新发展和市场需求。

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值