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

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

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

    posts - 2,  comments - 2,  trackbacks - 0

    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集成在一起了,何必再引入其他的呢?以后的維護是不是也要有問題呢?

    ?在隨后的文章里將會介紹xfire與Jibx結合的例子。

    posted on 2006-09-21 09:42 吃飯不洗手 閱讀(1933) 評論(1)  編輯  收藏

    只有注冊用戶登錄后才能發表評論。


    網站導航:
     
    主站蜘蛛池模板: 亚洲娇小性色xxxx| 亚洲精品国产高清嫩草影院 | 亚洲大尺度无码无码专线一区| 亚洲综合激情五月丁香六月| 亚洲а∨精品天堂在线| 成人在线免费观看| 亚洲人成7777影视在线观看| 国内精自视频品线六区免费 | 免费看又黄又无码的网站| 亚洲av无码一区二区三区乱子伦 | 国产jizzjizz免费看jizz| 亚洲av综合av一区二区三区 | 欧洲黑大粗无码免费| 精品亚洲成在人线AV无码| 老司机免费午夜精品视频| 午夜国产大片免费观看| 一级做受视频免费是看美女| 在线看片免费不卡人成视频| 亚洲xxxx18| 四虎永久免费影院在线| 2022国内精品免费福利视频| 国产成人精品日本亚洲网站 | 久久精品a亚洲国产v高清不卡| 思思久久99热免费精品6| 国产亚洲精久久久久久无码AV| 91免费福利视频| 久久久久亚洲av无码专区导航| 日本亚洲免费无线码| 精品国产_亚洲人成在线| 夜夜春亚洲嫩草影院| 182tv免费视视频线路一二三| 国产亚洲情侣一区二区无| 国产精品免费看久久久| 亚洲日日做天天做日日谢| 四虎免费久久影院| 国产在线观看免费av站| 亚洲精品夜夜夜妓女网| 免费影院未满十八勿进网站| 日本系列1页亚洲系列| 久久亚洲免费视频| 在线精品免费视频|