<rt id="bn8ez"></rt>
<label id="bn8ez"></label>

  • <span id="bn8ez"></span>

    <label id="bn8ez"><meter id="bn8ez"></meter></label>

    太陽雨

    痛并快樂著

    BlogJava 首頁 新隨筆 聯(lián)系 聚合 管理
      67 Posts :: 3 Stories :: 33 Comments :: 0 Trackbacks

    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 這樣將會(huì)發(fā)布兩個(gè)service,BookServiceEchoService。隨后就可以使用client端進(jìn)行測(cè)試了。

         //測(cè)試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及其實(shí)現(xiàn)了。

         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 簡(jiǎn)單的測(cè)試就是通過IE,輸入http://ip:port/context/services/BookService?wsdl或者http://ip:port/context/services/EchoService?wsdl,將會(huì)出現(xiàn)相應(yīng)的wsdl文檔。

         如果只是輸入http://ip:port/context/services/BookService,會(huì)出現(xiàn)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 余下的配置跟第一種方法一樣。

    posted on 2010-03-05 11:41 小蟲旺福 閱讀(6900) 評(píng)論(2)  編輯  收藏 所屬分類: javaEE

    Feedback

    # re: XFire與Spring結(jié)合的幾種方式 2012-06-28 19:30
    您好,我的wsdl文檔是生成了,但是客戶端調(diào)用service的時(shí)候,service里面的entityManager沒有被初始化,為null,spring是不是還有配置啊????  回復(fù)  更多評(píng)論
      

    # re: XFire與Spring結(jié)合的幾種方式 2012-06-29 13:00 樓主
    @羽
    xfire已經(jīng)很久沒有用過了,而且已經(jīng)轉(zhuǎn)變?yōu)镃XF了,同學(xué)還是看下CXF吧,而且支持注解很方便,要與時(shí)俱進(jìn)嘛  回復(fù)  更多評(píng)論
      

    主站蜘蛛池模板: 亚洲一卡2卡3卡4卡乱码 在线 | 亚洲另类春色校园小说| 成人无码区免费A∨直播| 久久精品国产亚洲5555| 黄页视频在线观看免费| www.91亚洲| 九九久久国产精品免费热6| 亚洲 欧洲 日韩 综合在线| 无码毛片一区二区三区视频免费播放| 免费高清小黄站在线观看| 亚洲人成色在线观看| 国产一区二区三区在线观看免费| 色婷婷六月亚洲综合香蕉| 国产又粗又猛又爽又黄的免费视频| 精品国产日韩亚洲一区91| 亚洲国产婷婷综合在线精品| 黄色网址免费在线观看| 亚洲AV午夜成人影院老师机影院| 久久亚洲免费视频| 色老板亚洲视频免在线观| 国产成人免费一区二区三区| 一级做a爱片特黄在线观看免费看| 亚洲中文字幕无码久久2017| 99热这里只有精品免费播放| 精品亚洲AV无码一区二区三区| 日本视频免费在线| 337p日本欧洲亚洲大胆艺术| 国产片AV片永久免费观看| 国产亚洲欧美在线观看| 成人午夜亚洲精品无码网站 | 91精品国产免费久久久久久青草| 亚洲综合精品第一页| 亚洲高清无码在线观看| 国产午夜无码精品免费看| 亚洲同性男gay网站在线观看| 国产成人免费片在线观看| 久久国产免费观看精品| 亚洲天堂2017无码中文| 亚洲午夜爱爱香蕉片| 青娱分类视频精品免费2| 一区二区三区视频免费|