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

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

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

    馬光軍--------BLOG

    BlogJava 聯系 聚合 管理
      1 Posts :: 25 Stories :: 5 Comments :: 0 Trackbacks
    首先,我們應當創建一個實體類一個接口和一個實現類(User.java、UserService.java、UserServiceImpl.java)

    package com.mgj.xfiretext.domain;

    import java.io.Serializable;
    import java.util.Date;

    /**
     *
     * User.java com.mgj.xfiretext.domain xfire
     *
     * @author magj mailto:m441748725@163.com 2008-10-17 下午04:18:26
     *
     */
    public class User implements Serializable {
     
     private static final long serialVersionUID = 6517808321041980976L;

     private Long userId;

     private String accountId;

     private String userName;

     private Date lastLogin;

     public String getAccountId() {
      return accountId;
     }

     public void setAccountId(String accountId) {
      this.accountId = accountId;
     }

     public Date getLastLogin() {
      return lastLogin;
     }

     public void setLastLogin(Date lastLogin) {
      this.lastLogin = lastLogin;
     }

     public Long getUserId() {
      return userId;
     }

     public void setUserId(Long userId) {
      this.userId = userId;
     }

     public String getUserName() {
      return userName;
     }

     public void setUserName(String userName) {
      this.userName = userName;
     }
    }


    package com.mgj.xfiretext.webserver;

    import com.mgj.xfiretext.domain.User;
    /**
     *
     * UserService.java
     * com.mgj.xfiretext.webserver
     * xfire
     * @author magj mailto:m441748725@163.com
     *  2008-10-17  下午04:16:09
     *
     */
         
    public interface UserService {     
        public User queryUserByAccoutId(String accountId);     
        
    }

    package com.mgj.xfiretext.webserver;

    import java.util.Date;

    import org.apache.commons.logging.Log;
    import org.apache.commons.logging.LogFactory;

    import com.mgj.xfiretext.domain.User;

    /**
     *
     * UserServiceImpl.java
     * com.mgj.xfiretext.webserver
     * xfire
     * @author magj mailto:m441748725@163.com
     *  2008-10-17  下午04:17:26
     *
     */
    public class UserServiceImpl  implements UserService{     
        private static final Log log = LogFactory.getLog(UserServiceImpl.class);     
             
        public User queryUserByAccoutId(String accountId){      
            log.debug("accountId=" + accountId);      
            User user = new User();      
            user.setAccountId("testAccount");      
            user.setLastLogin(new Date());      
            user.setUserName("mgj");      
            user.setUserId(new Long(123L));     
            return user;      
            }     
    }

    創建一個bulild.xml文件:
    <?xml version="1.0"?>
    <project name="xfire" default="genfiles" basedir=".">
        <property name="lib" value="${basedir}/../WebRoot/WEB-INF/lib" />
        <path id="myclasspath">
            <fileset dir="${lib}">
                <include name="*.jar" /> 
            </fileset> 
            <pathelement location="${genfiles}" />
        </path>
     <!--${basedir}/../src表示放在src下面 -->
     <!--${basedir}/../../ssh/src表示放在另外一個工程(ssh)下的src下面 -->
     <!--${basedir}表示當前目錄-->
        <!--通過XFire ant任務生成客戶端代碼的存放位置-->
        <property name="code_path" value="${basedir}/../src" /> 
        <!--需要生成客戶端代碼的wsdl文件-->
        <property name="wsdl_path" value="http://localhost:8090/xfire/services/UserService?wsdl" />
        <!--生成客戶端代碼的包名-->
        <property name="code_package" value="com.mgj.xfiretext.webserver.client" />
       
        <!-- Remove classes directory for clean build -->
        <target name="clean" description="Prepare for clean build"> 
            <delete dir="${code_path}"/>
            <mkdir dir="${code_path}"/>
        </target>
       
        <!--<target name="genfiles" depends="clean" description="Generate the files">  -->
        <target name="genfiles" description="Generate the files">
            <taskdef name="wsgen" classname="org.codehaus.xfire.gen.WsGenTask" classpathref="myclasspath" />
            <!--outputDirectory屬性定義創建的代碼所在的文件夾
                wsdl是web服務的wsdl文件
                package代表創建的代碼的package
            -->
            <wsgen outputDirectory="${code_path}" wsdl="${wsdl_path}" package="${code_package}" binding="xmlbeans" /> 
        </target>
    </project>
    Spring 的配置文件:

    <?xml version="1.0" encoding="UTF-8"?>
    <!DOCTYPE beans PUBLIC "-//SPRING//DTD BEAN//EN" "http://www.springframework.org/dtd/spring-beans.dtd">
    <beans>
     <import resource="classpath:org/codehaus/xfire/spring/xfire.xml" />

     <bean id="userService"
      class="com.mgj.xfiretext.webserver.UserServiceImpl" />
     <bean id="addressingHandler"
      class="org.codehaus.xfire.addressing.AddressingInHandler" />

     <bean name="UserService"
      class="org.codehaus.xfire.spring.ServiceBean">
      <property name="serviceBean" ref="userServiceBean" />
      <property name="serviceClass"
       value="com.mgj.xfiretext.webserver.UserService" />
      <property name="inHandlers">
       <list>
        <ref bean="addressingHandler" />
       </list>
      </property>
     </bean>
     
     <bean id="userServiceBean"
      class="com.mgj.xfiretext.webserver.UserServiceImpl" />
    </beans>

    測試類:

    package test;

    import java.net.MalformedURLException;
    import org.codehaus.xfire.client.XFireProxyFactory;
    import org.codehaus.xfire.service.Service;
    import org.codehaus.xfire.service.binding.ObjectServiceFactory;
    import com.mgj.xfiretext.domain.User;
    import com.mgj.xfiretext.webserver.UserService;

    package test;

    import java.net.MalformedURLException;

    import org.apache.xmlbeans.XmlObject;
    import org.codehaus.xfire.client.XFireProxyFactory;
    import org.codehaus.xfire.service.Service;
    import org.codehaus.xfire.service.binding.ObjectServiceFactory;
    import org.dom4j.Document;
    import org.dom4j.DocumentException;
    import org.dom4j.DocumentHelper;
    import org.dom4j.Element;

    import com.zx.xfiretext.domain.User;
    import com.zx.xfiretext.webserver.UserService;
    import com.zx.xfiretext.webserver.client.UserServiceClient;
    import com.zx.xfiretext.webserver.client.UserServicePortType;

    /**
     *
     * MyClient.java test xfire
     *
     * @author magj mailto:m441748725@163.com 2008-10-17 下午06:00:05
     *
     */
    public class MyClient {
     public static void main(String[] args) {
      try {
       Service serviceModel = new ObjectServiceFactory()
         .create(UserService.class);
       UserService service = (UserService) new XFireProxyFactory().create(
         serviceModel,
         "http://localhost:8090/xfire/services/UserService");
       User user = service.queryUserByAccoutId("123");
       System.out
         .println("userId=" + user.getUserId() + ", userName="
           + user.getUserName() + ", lastLogin="
           + user.getLastLogin());
      } catch (MalformedURLException e) {
       e.printStackTrace();
      }

      UserServiceClient userServiceClient = new UserServiceClient();
      UserServicePortType userServicePortType = userServiceClient
        .getUserServiceHttpPort();
      XmlObject userXml = userServicePortType.queryUserByAccoutId("123");
      System.out.println(userXml.toString());
      Document userdocument = null;
      try {
       userdocument = DocumentHelper.parseText(userXml.toString());
       Element rootElement = userdocument.getRootElement();
       Element accountIdElement = rootElement.element("accountId");
       Element userIdElement = rootElement.element("userId");
       System.out.println("accountId: " + accountIdElement.getTextTrim()
         + "  userId:" + userIdElement.getTextTrim());
      } catch (DocumentException e) {
       e.printStackTrace();
      }
     }
    }

     

    說明:WEB服務器為TOMCAT,端口:8090.
    接下來,我們按照一下步驟來。
    (1)啟動TOMCAT
    (2)我們應當執行build.xml文件,因為是在ECLIPSE中開發,所以只要點擊【右鍵】之后,找到【ANT BUILD】選項,然后點擊。就會生成UserServiceClient.java、UserServiceImpl、UserServicePortType這個三個類。
    (3)執行測試類。
    我們就會看到結果:
    userId=123, userName=mgj, lastLogin=Sat Nov 01 17:27:50 CST 2008
    <out xmlns="http://webserver.xfiretext.zx.com" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
      <accountId xmlns="http://domain.xfiretext.zx.com">testAccount</accountId>
      <lastLogin xmlns="http://domain.xfiretext.zx.com">2008-11-01T17:27:51.343+08:00</lastLogin>
      <userId xmlns="http://domain.xfiretext.zx.com">123</userId>
      <userName xmlns="http://domain.xfiretext.zx.com">mgj</userName>
    </out>
    accountId: testAccount  userId:123

    說明:以上我也是根據網上前輩做的例子,在結合自己的一些實踐做出來的。
    posted on 2008-11-01 16:29 馬光軍 閱讀(405) 評論(0)  編輯  收藏 所屬分類: XFIRE

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


    網站導航:
     
    主站蜘蛛池模板: 亚洲色偷偷综合亚洲AV伊人| 免费无遮挡无码永久在线观看视频| 亚洲精品tv久久久久久久久久| 亚洲色偷偷综合亚洲AV伊人蜜桃| 日韩免费一区二区三区在线播放 | 亚洲XX00视频| 国产午夜亚洲精品不卡电影| 免费在线观看亚洲| 一级毛片完整版免费播放一区| 中文字幕亚洲一区| 久久香蕉国产线看免费| 精品日韩亚洲AV无码| 免费福利网站在线观看| 亚洲精品无码你懂的| 又大又硬又爽免费视频| 久久精品免费网站网| 亚洲第一福利视频| 日本妇人成熟免费中文字幕 | 亚洲欧洲自拍拍偷精品 美利坚| 一级毛片免费不卡直观看| 国产日韩亚洲大尺度高清| 中文字幕在线免费观看| 亚洲人成77777在线播放网站不卡 亚洲人成77777在线观看网 | 在线观看AV片永久免费| 国产精品观看在线亚洲人成网| 免费国产成人午夜电影| 精品国产免费一区二区三区香蕉 | 亚洲精品无码专区在线播放| 啊v在线免费观看| 国产va在线观看免费| 午夜在线a亚洲v天堂网2019| 国产成人精品久久亚洲| 伊人久久免费视频| 亚洲AV综合永久无码精品天堂| 中文字幕亚洲综合久久男男| 91精品成人免费国产片| 特级毛片aaaa免费观看| 老司机亚洲精品影院无码| 日韩成全视频观看免费观看高清| 中文在线免费不卡视频| 四虎亚洲精品高清在线观看|