posts - 5,  comments - 6,  trackbacks - 0
            2010年1月10日

          Inotify 是文件系統(tǒng)事件監(jiān)控機(jī)制,計(jì)劃包含在即將發(fā)布的 Linux 內(nèi)核中作為 dnotify 的有效替代。dnotify 是較早內(nèi)核支持的文件監(jiān)控機(jī)制。Inotify一種強(qiáng)大的、細(xì)粒度的、異步的機(jī)制,它滿足各種各樣的文件監(jiān)控需要,不僅限于安全和性能。下面讓我們一起學(xué)習(xí)如何安裝 inotify 和如何構(gòu)建一個(gè)示例用戶空間應(yīng)用程序來響應(yīng)文件系統(tǒng)事件。

          1.1同步工具安裝
          1、輸入命令:su root,切換到超級(jí)用戶。
          2、先查看linux的內(nèi)核是否支持inotify,支持inotify的內(nèi)核最小為2.6.13,輸入命令:uname –a。如下圖所示,內(nèi)核為2.6.27,支持inotify:
           
          注:如果內(nèi)核低于2.6.13,請(qǐng)升級(jí)內(nèi)核或重新安裝內(nèi)核版本更高的linux系統(tǒng)。
          3、建立同步ssh信任關(guān)系,輸入命令:cd $HOME,進(jìn)入用戶根目錄。
          輸入命令:ssh-keygen -t rsa (會(huì)出現(xiàn)幾個(gè)提示信息,一直按回車即可)。
          會(huì)在 cd $HOME/.ssh/目錄下生成2個(gè)文件id_rsa、id_rsa.pub。
          輸入命令:cp  id_rsa.pub  authorized_keys,將id_rsa.pub拷貝成authorized_keys。
          將授權(quán)密鑰分發(fā)到iEPG服務(wù)器(192.168.100.101)上,輸入命令:
          scp  ~/.ssh/authorized_keys root@192.168.100.101:/root/.ssh/
          如果有多臺(tái)下載服務(wù)器,每臺(tái)都須運(yùn)行一次上面的密鑰下發(fā)命令。
          4、通過如下命令查看系統(tǒng)是否支持inotify:ll /proc/sys/fs/inotify
          如果有如下輸出,表示系統(tǒng)內(nèi)核已經(jīng)支持inotify:
          total 0
          -rw-r--r-- 1 root root 0 Feb 21 01:15 max_queued_events
          -rw-r--r-- 1 root root 0 Feb 21 01:15 max_user_instances
          -rw-r--r-- 1 root root 0 Feb 21 01:15 max_user_watches
          5、取得軟件包inotify-tools-3.13.tar.gz,放在/tmp下。
          6、輸入命令:tar zvxf inotify-tools-3.13.tar.gz,解壓軟件包。
          7、輸入命令:cd inotify-tools-3.13,進(jìn)入解壓后的目錄。
          8、輸入命令:./configure
          9、輸入命令:make
          10、輸入命令:make install
          11、在系統(tǒng)下執(zhí)行命令:man inotify、 man inotifywait、 man inotifywatch即可得到相應(yīng)的幫助信息,表示inotify安裝成功。
          12、輸入命令:rsync,查看rsync是否安裝。
          rsync一般是系統(tǒng)默認(rèn)安裝,如果沒有安裝就取得軟件包,安裝方法同inotify。

          同步腳本使用
          1、取得syncapps.sh腳本

          #!/bin/sh
              SRC=/root/sys/
              SEND=iEPGService.dat
              PID_FILE=syncapps.pid
              
              function sync_files
              {
                 cat $SEND | while read DST 
                 do
                 rsync -avzq  --delete --exclude '/.version' --exclude '/.bak' $SRC $DST
                 done
                  
              }
              
              function inotify_func
              {
                  inotifywait -mrq -e modify,delete,create ${SRC} | while read D E F;do
                      # echo "$D : $E : $F"
                      sync_files
                  done
              }
              
              function stop
              {
                  pkill inotifywait &>/dev/null && rm -f ${PID_FILE} &> /dev/null
              }
              
              case $1 in
                  stop)
                      echo -n "Stopping sync service"
                      if [ -e ${PID_FILE} ]; then
                          stop
                          echo "Stopped"
                          exit 0
                      else
                          echo "pid file not found"
                          exit 2
                      fi
                      ;;
                  start) 
                      echo -n "Starting sync service"
                      if [ -f ${PID_FILE} ] && ((`ps awux | grep -v grep | grep -c inotifywait`)); then
                          echo " already running: pid file found ($PID_FILE) and an inotifywait process is running"
                          exit 1
                      elif [ -f ${PID_FILE} ]; then
                          echo -n "(stale pid file)"
                      fi                        
                      
                      sync_files
                      inotify_func&
                      
                      pid="$!"
                      ps --ppid $pid -o pid,cmd | grep inotifywait | awk '{print $1}' > ${PID_FILE}
                      
                      echo "Started"
                      ;;
                  restart)
                      $0 stop
                      $0 start
                      exit 0
                      ;;
                  status)
                      echo -n "Getting status for syncer service "
                      pid=`cat ${PID_FILE} 2>/dev/null`
                      if [ -f ${PID_FILE} ] && ((`ps awux | grep -v grep | egrep -c "$pid.*inotifywait"`)); then
                          echo "running (pid $pid)"
                          exit 0
                      elif [ -f ${PID_FILE} ]; then
                          echo "not runing (pid file found $pid)"
                          exit 3
                      elif ((`ps awux | grep -v grep | egrep -c "$pid.*inotifywait"`)); then
                          echo "not running (inotifywait procs found)"
                          exit 4
                      else
                          echo "not running"
                          exit 5
                      fi
                      ;;
                              
                  *)
                      echo "Usage error"
                      echo "Usage: $0 
          <start|stop|restart|status>"
                      ;;
              esac
          2、取得iEPGService.dat腳本。
            root@10.10.80.76:/root/files/
          3、輸入命令:chmod  +x  *.sh,給文件賦可執(zhí)行權(quán)限。
          4、輸入命令:./syncapps.sh start,啟動(dòng)同步工具。
          啟動(dòng)同步工具的輸入命令:./syncapps.sh start
          停止同步工具的輸入命令:./syncapps.sh stop
          重啟同步工具的輸入命令:./syncapps.sh restart
          查看同步工具狀態(tài)的輸入命令:./syncapps.sh status
          link
          posted @ 2010-01-10 20:07 潯陽(yáng)江頭夜送客 閱讀(1386) | 評(píng)論 (0)編輯 收藏

          首先閱讀此文之前,最好閱讀
          http://hi.baidu.com/maml897/blog/item/324bf86369961ed4e6113a5c.html

          http://hi.baidu.com/maml897/blog/item/fa5f0a7e1edef00129388ae2.html

          其次還要知道一點(diǎn)常識(shí),就是我們?cè)谟浭卤镜纫恍┪谋竟ぞ咧?寫的都是字符,沒有誰會(huì)去寫字節(jié)(可以寫字節(jié),但是要用具特殊的編輯器),但是其實(shí),我們的寫的是字符,但磁盤上真實(shí)存儲(chǔ)的是字節(jié)。

          這里就出現(xiàn)了轉(zhuǎn)換的問題,當(dāng)然,這些問題記事本本身會(huì)幫助我們解決。我們打開一個(gè)記事本,然后文件--另存為,你會(huì)發(fā)現(xiàn)有幾種存儲(chǔ)格式供您選擇,
          ANSI格式:就是ascii的格式
          Unicode格式:采用國(guó)際通用的編碼存儲(chǔ)
          Unicode big endian格式:這個(gè)和unicode有點(diǎn)區(qū)別,但我也不明太具體的不同
          UTF-8:采用utf-8存儲(chǔ),看過上面的兩篇文章,你會(huì)十分的了解這里介紹的編碼。Utf-8,是unicode的一種實(shí)現(xiàn)方式。

          例如我們?cè)谟浭卤纠锩孑斎?#8220;連通”兩個(gè)字。

          1.我們另存記事本的時(shí)候,采用unicode存儲(chǔ),那么雖然我們看到的字符還是“連通”,但是其實(shí)存儲(chǔ)在磁盤上的字節(jié) 確實(shí)
          8FDE(連) 901A (通),這個(gè)是規(guī)定的,unicode是國(guó)際上規(guī)定的,給世界上的每個(gè)字符分配的唯一編碼。獲取某個(gè)字符的unicode的方法,可以去網(wǎng)上查找,最簡(jiǎn)單的方法,就是打開word文檔,輸入字符,把光標(biāo)移動(dòng)到字符后面,按alt+x,word會(huì)自動(dòng)把字符轉(zhuǎn)換成unicode編碼,這里呢我們也可以看到,用unicode存儲(chǔ)漢字啊,每個(gè)漢字占用兩個(gè)字節(jié)。

          2.我們另存記事本的時(shí)候,采用utf-8存儲(chǔ),雖然我們看到的字符還是“連通”,但是其實(shí)存儲(chǔ)在磁盤上的字節(jié) 確實(shí)已經(jīng)變化了,這時(shí)候存儲(chǔ)的是
          E8 BF 9E (連)E9 80 9A(通)。這就是utf-8的存儲(chǔ)的編碼,至于utf-8為什么這樣存儲(chǔ),你可以閱讀上面的兩篇文章來了解,可以看到,utf-8使用3個(gè)字節(jié)存儲(chǔ)一個(gè)漢字。

          另外我們還要知道的就是:電腦怎么區(qū)分一個(gè)記事本是用什么存儲(chǔ)的呢?
          換句話說,為什么我用unicode存儲(chǔ)的8FDE(連) 901A (通),電腦就知道這是unicode編碼,從而使用unicode解碼,還原為“連通”呢?電腦又怎么知道E8 BF 9E (連)E9 80 9A(通)這是按照utf-8的存儲(chǔ)方式存儲(chǔ)的呢?

          這里有一點(diǎn)標(biāo)記,就是在存儲(chǔ)字節(jié)的時(shí)候,記事本首先在最前面 標(biāo)明,這個(gè)記事本下面的存儲(chǔ)格式 是utf-8,還是unicode。

          例如,

          1.unicode存儲(chǔ)“連通”。磁盤字節(jié)真實(shí)存儲(chǔ)的其實(shí)是:

          FF FE 8FDE 901A

          前兩個(gè)FF FE是標(biāo)記,告訴電腦,這個(gè)文檔的存儲(chǔ)方式是unicode

          2.utf-8存儲(chǔ)“連通”。磁盤字節(jié)真實(shí)存儲(chǔ)的其實(shí)是:

          EF BB BF E8 BF 9E E9 80 9A

          前三個(gè)EF BB BF 告訴電腦 這個(gè)文檔是utf-8存儲(chǔ)的

          根據(jù)不同編碼的特點(diǎn)和標(biāo)志,對(duì)一個(gè)文本文件判斷編碼方法如下
          1  .  UTF7  所有字節(jié)的內(nèi)容不會(huì)大于127,也就是不大于&HFF
          2  .  UTF8  起始三個(gè)字節(jié)為"0xEF 0xBB 0xBF"
          3  .  UTF-16BE 起始三個(gè)字節(jié)為"0xFE  0xFF"
          4  .  UTF-16LE 起始三個(gè)字節(jié)為"0xFF  0xFE"


          import java.io.BufferedInputStream;
          import java.io.File;
          import java.io.FileInputStream;

          public class FileEncodeReferee
          {
              
          private File file;
              
              
          public FileEncodeReferee(File file)
              
          {
                  
          this.file = file;
              }

              
              
          public FileEncodeReferee(String path)
              
          {
                  file 
          = new File(path);
              }

              
              
          public String getCharset()
              
          {
                  File file 
          = this.file;
                  
                  String charset 
          = "GBK";
                  
          byte[] first3Bytes = new byte[3];
                  BufferedInputStream bis 
          = null;
                  
          try
                  
          {
                      
          //boolean checked = false;
                      bis = new BufferedInputStream(new FileInputStream(file));
                      bis.mark(
          0);
                      
          int read = bis.read(first3Bytes, 03);
                      
          if (read == -1)
                      
          {
                          
          return charset;
                      }

                      
          if (first3Bytes[0== (byte0xFF && first3Bytes[1== (byte0xFE)
                      
          {
                          charset 
          = "UTF-16LE";
                          
          //checked = true;
                      }

                      
          else if (first3Bytes[0== (byte0xFE
                              
          && first3Bytes[1== (byte0xFF)
                      
          {
                          charset 
          = "UTF-16BE";
                          
          //checked = true;
                      }

                      
          else if (first3Bytes[0== (byte0xEF
                              
          && first3Bytes[1== (byte0xBB
                              
          && first3Bytes[2== (byte0xBF)
                      
          {
                          charset 
          = "UTF-8";
                          
          //checked = true;
                      }

                      
          /** */
                      
          /*******************************************************************
                      * bis.reset(); if (!checked) { int loc = 0; while ((read =
                      * bis.read()) != -1) { loc++; if (read >= 0xF0) { break; } if (0x80 <=
                      * read && read <= 0xBF) // 單獨(dú)出現(xiàn)BF以下的,也算是GBK { break; } if (0xC0 <=
                      * read && read <= 0xDF) { read = bis.read(); if (0x80 <= read &&
                      * read <= 0xBF)// 雙字節(jié) (0xC0 - 0xDF) { // (0x80 - 0xBF),也可能在GB編碼內(nèi)
                      * continue; } else { break; } } else if (0xE0 <= read && read <=
                      * 0xEF) { // 也有可能出錯(cuò),但是幾率較小 read = bis.read(); if (0x80 <= read &&
                      * read <= 0xBF) { read = bis.read(); if (0x80 <= read && read <=
                      * 0xBF) { charset = "UTF-8"; break; } else { break; } } else {
                      * break; } } } System.out.println(loc + " " +
                      * Integer.toHexString(read)); }
                      *****************************************************************
          */

                  }

                  
          catch (Exception e)
                  
          {
                      e.printStackTrace();
                  }

                  
          finally
                  
          {
                      
          if (bis != null)
                      
          {
                          
          try
                          
          {
                              bis.close();
                          }

                          
          catch (Exception ex)
                          
          {
                              ex.printStackTrace();
                          }

                      }

                  }

                  
          return charset;
              }

              
              
          public static void main(String[] args)
              
          {
                  FileEncodeReferee fer 
          = new FileEncodeReferee("F://鎖表1.sql");
                  System.out.println(fer.getCharset());
              }

          }

          posted @ 2010-01-10 19:56 潯陽(yáng)江頭夜送客 閱讀(402) | 評(píng)論 (0)編輯 收藏
            2009年10月19日
          在cglib 中 BeanMap的用法

          1.導(dǎo)入cglib-nodep-2.1.3.jar
           
          2.在javaBean 對(duì)象中重寫toString()方法  比如是UserManageVo.Java
           public String toString(){
            return BeanTools.getBeanDesc(UserManageVo.this);
           }
          java 代碼
           1package BeanUtils;
           2
           3import net.sf.cglib.beans.BeanMap;
           4
           5public class BeanTools {
           6    private static String LINE = System.getProperty("line.separator""\r\n");
           7
           8    /**
           9     * 對(duì)象中重寫toString()方法,在打印日志的時(shí)候調(diào)用
          10     * @param obj
          11     * @return
          12     * @return String
          13     */

          14    public static String getBeanDesc(Object obj) {
          15        StringBuffer bf = new StringBuffer();
          16        bf.append(LINE + "{" + LINE + "Class = " + obj.getClass().getName()
          17                + LINE);
          18        BeanMap beanMap = BeanMap.create(obj);
          19        for (Object object : beanMap.keySet()) {
          20            Object value = beanMap.get(object);
          21            if (null != value) {
          22                /**
          23                 * 這是定義對(duì)象的是時(shí)候用到
          24                 */

          25                String className = value.getClass().getName();
          26                if (className.startsWith("test.UserManageEvent")
          27                        || className.startsWith("test.BasicEvent")
          28                        || className.startsWith("test.UserManageVo")) {
          29                    bf.append(object + " = " + getBeanDesc(value) + LINE);
          30                }

          31
          32                /**
          33                 * 這是數(shù)組對(duì)象的是時(shí)候用到
          34                 */

          35                if (className.startsWith("Ltest.UserManageEvent")
          36                        || className.startsWith("Ltest.BasicEvent")
          37                        || className.startsWith("Ltest.UserManageVo")) {
          38                    Object[] objs = (Object[]) value;
          39                    for (int i = 0; i < objs.length; i++{
          40                        bf.append(object + " = " + getBeanDesc(objs[i]) + LINE);
          41                    }

          42                }

          43                
          44                /**
          45                 * 對(duì)String數(shù)組重寫toString()方法
          46                 */

          47                if (className.startsWith("[Ljava.lang.String")) {
          48                    Object[] objs = (Object[]) value;
          49                    for (int i = 0; i < objs.length; i++{
          50                        bf.append(object + "[" + i + "]" + " = " + objs[i]
          51                                + LINE);
          52                    }

          53                }

          54            }

          55            bf.append(object + " = " + value + LINE);
          56        }

          57        bf.append("}");
          58        return bf.toString();
          59    }

          60}

          java代碼
          /Files/yjlongfei/beanUtil.rar
          posted @ 2009-10-19 21:41 潯陽(yáng)江頭夜送客 閱讀(2549) | 評(píng)論 (0)編輯 收藏
          一、簡(jiǎn)介:

                  BeanUtils提供對(duì)Java反射和自省API的包裝。其主要目的是利用反射機(jī)制對(duì)JavaBean的屬性進(jìn)行處理。我們知道,一個(gè)JavaBean通常包含了大量的屬性,很多情況下,對(duì)JavaBean的處理導(dǎo)致大量get/set代碼堆積,增加了代碼長(zhǎng)度和閱讀代碼的難度。

          二、用法:

                  如果你有兩個(gè)具有很多相同屬性的JavaBean,我們對(duì)一個(gè)對(duì)象copy 到另外一個(gè)對(duì)象,可用用下面的方法。

          1. 導(dǎo)入commons-beanutils.jar
          2. 導(dǎo)入commons-logging-1.1.jar
          3. 構(gòu)建UserManageVo , UserManageEvent 對(duì)象 ,這兩個(gè)對(duì)象的屬性相同
          4. 調(diào)用 BeanUtils.copyProperties(UserManageVo, UserManageEvent)
           java 主要代碼

           1import java.lang.reflect.InvocationTargetException;
           2import org.apache.commons.beanutils.BeanUtils;
           3import test.BasicEvent;
           4import test.UserManageEvent;
           5import test.UserManageVo;
           6
           7public class TestCase {
           8    
           9    public static void main(String[] args) {
          10        UserManageEvent event = new UserManageEvent();
          11        event.setName("zhangsan");
          12        event.setUserId("1");
          13        
          14        BasicEvent basicEvt = new BasicEvent();
          15        basicEvt.setEventId("2");
          16        basicEvt.setVersion("version");
          17        
          18        event.setEvent(basicEvt);
          19        UserManageVo vo = new UserManageVo();
          20        try {
          21            BeanUtils.copyProperties(vo, event);
          22            System.out.println(vo.getUserId());
          23            System.out.println(vo.getName());
          24            System.out.println(vo.getEvent());
          25        }
           catch (IllegalAccessException e) {
          26            e.printStackTrace();
          27        }
           catch (InvocationTargetException e) {
          28            e.printStackTrace();
          29        }
           
          30    }

          31}


          java代碼:
          /Files/yjlongfei/test.rar

          posted @ 2009-10-19 21:21 潯陽(yáng)江頭夜送客 閱讀(1173) | 評(píng)論 (0)編輯 收藏
            2009年10月17日

          關(guān)鍵字: webservice

          1. Introduction
          This document will outline the process of developing a JAX-WS web service and deploying it using MyEclipse 6.5 to the internal MyEclipse Tomcat server. The web service used in this tutorial will be a very simple calculator service that provides add, subtract, multiply and divide operations to the caller.

          MyEclipse also supports developing web services using the existing XFire framework from previous MyEclipse releases. For folks needing to develop and deploy WebSphere JAX-RPC or WebSphere JAX-WS web services, please take a look at our MyEclipse Blue Edition of the MyEclipse IDE.

          Additional resources covering web service creation using JAX-RPC, JAX-WS or XFire are included in the Resources section of this document.


          2. System Requirements
          This tutorial was created with MyEclipse 6.5. If you are using another version of MyEclipse (possibly newer), most of these screens and instructions should still be very similar.

          If you are using a newer version of MyEclipse and notice portions of this tutorial looking different than the screens you are seeing, please let us know and we will make sure to resolve any inconsistencies.

          3.新建一個(gè)工程
          開始我們新建一個(gè)Web Service Project工程File->New->Web Service Project(Optional Maven Support)

           
          Note:A JAX-WS web service can also be generated in any existing Java EE 5 web project.

          我們給這個(gè)工程取名為WebServiceProject.注意JAX-WS支持只在javaEE5或更高版本的工程中是可行的。如果你需要使用低版本的工程類型(java1.4或者1.3),那么只能使用XFire Web Service代替JAX-WS。

           

          這里我們使用上面的JAX—WS。
          4.創(chuàng)建服務(wù)類
          服務(wù)類就是一個(gè)普通的java類,負(fù)責(zé)提供我們想要發(fā)布的執(zhí)行方法。這里我們寫一個(gè)簡(jiǎn)單的計(jì)算器類,實(shí)現(xiàn)幾個(gè)典型的計(jì)算器應(yīng)用方法,如加減乘除。
          首先我們先建一個(gè)包,WebServiceProject->src->new->package,取名com.myeclipseide.ws

          讓后我們?cè)谶@個(gè)包下建一個(gè)類,Calculator.java.


          根據(jù)上面提到的,這個(gè)計(jì)算器類實(shí)現(xiàn)計(jì)算器的加減乘除算法,簡(jiǎn)單實(shí)現(xiàn):
          Java代碼

          package com.myeclipseide.ws; 

          public class Calculator 
          public int add(int a, int b) 
          return (a + b); 
          }
           

          public int subtract(int a, int b) 
          return (a - b); 
          }
           

          public int multiply(int a, int b) 
          return (a * b); 
          }
           

          public int divide(int a, int b) 
          return (a / b); 
          }
           
          }
           


          可以看出,這個(gè)類中的方法是非常簡(jiǎn)單的,沒有用到特殊的注釋還有接口,父類之類的東西。
          5.創(chuàng)建一個(gè)Web Service
          在上面的工具條中點(diǎn)擊新建Web Service

          Note:如果沒有的話可以File->New->others->Myeclipse->WebService->webService
          點(diǎn)擊之后出現(xiàn)的屏幕,在Strategy中選擇Bottom-up scenario,因?yàn)槲覀円呀?jīng)建立好了Calculator類而且想根據(jù)它建立JAX-WS服務(wù)。

          下面是創(chuàng)建的最后一個(gè)屏幕,你需要選擇提供webService方法的javaBean,在我們這個(gè)例子中就是我們已經(jīng)建立好的Calculator類。

          填好之后,Myeclipse會(huì)自動(dòng)幫我們填滿其他的項(xiàng),Select Generate WSDL in project and hit Finish.


          點(diǎn)擊完成之后,Myeclipse會(huì)自動(dòng)生成CalculatorDelegate代理類,還有一些必須的JAX-WS描述符,而且會(huì)自動(dòng)在服務(wù)器目錄下的web.xml中配置WebService的一些mappings,方便將webService部署到服務(wù)器中。

          到此web service已經(jīng)建立好了,我們開始部署它然后進(jìn)行測(cè)試。
          6.部署和測(cè)試webService。
          這里我們不使用用Myeclipse自帶的tomcat服務(wù)器,使用自己應(yīng)經(jīng)在電腦中部署好的tomcat5.5。
          在server面板中右擊,選擇configure


          部署自己的tomcat注意選擇jdk要跟項(xiàng)目中的相同。

          現(xiàn)在要向工程中導(dǎo)入JAX-WS的jar包
          在項(xiàng)目名稱上右擊->properties->Add Library->Myeclipse Libraries->最后面的兩個(gè)。

          點(diǎn)擊完成,導(dǎo)入成功。
          Note:Myeclipse自帶的tomcat中有自帶的這兩個(gè)jar包,可以不用導(dǎo)入。

          6.1部署
          在部署好的tomcat服務(wù)器上右擊選擇Add Deployment


          點(diǎn)擊完成。
          6.2測(cè)試
          運(yùn)行tomcat服務(wù)器,在工具欄中點(diǎn)擊launch WebService Explorer

          打開后,點(diǎn)擊右上角的WSDL視圖,可以看到下面的屏幕

          在WSDL URL中填寫路徑:http://localhost:8888/WebServiceProject/CalculatorPort?WSDL
          解釋下路徑組成:
          http://localhost:8888/是服務(wù)器的路徑,我的端口號(hào)是8888,可以根據(jù)自己的更改,一般都是8080。
          /WebServiceProject = We know by default the Web Context-root that is used to deploy(部署) web projects matches the name of the projects. (因?yàn)槲覀儧]有為這個(gè)工程自定義我們的Web Context-root,所以他就是這個(gè)工程的名字)
          /CalculatorPort = As we saw from the last screenshot in Section #5, when our JAX-WS web service was generated, it was bound using a servlet-mapping in the web.xml file to the /CalculatorPort path.
          XML代碼
            

          <servlet>     
              
          <description>JAX-WS endpoint - CalculatorService</description>     
              
          <display-name>CalculatorService</display-name>     
              
          <servlet-name>CalculatorService</servlet-name>     
              
          <servlet-class>     
                  com.sun.xml.ws.transport.http.servlet.WSServlet      
              
          </servlet-class>     
              
          <load-on-startup>1</load-on-startup>     
            
          </servlet>     
            
          <servlet-mapping>     
              
          <servlet-name>CalculatorService</servlet-name>     
              
          <url-pattern>/CalculatorPort</url-pattern>     
            
          </servlet-mapping>    
          <servlet>  
              
          <description>JAX-WS endpoint - CalculatorService</description>  
              
          <display-name>CalculatorService</display-name>  
              
          <servlet-name>CalculatorService</servlet-name>  
              
          <servlet-class>  
                  com.sun.xml.ws.transport.http.servlet.WSServlet   
              
          </servlet-class>  
              
          <load-on-startup>1</load-on-startup>  
            
          </servlet>  
            
          <servlet-mapping>  
              
          <servlet-name>CalculatorService</servlet-name>  
              
          <url-pattern>/CalculatorPort</url-pattern>  
            
          </servlet-mapping>

           WSDL = This is a universal query string argument that can be added to the end of any web service which will tell the web service to return it's full WSDL to the caller. In this case, the WSDL is returned to our Web Services Explorer tool which loads it up, and displays the web services exposed operations to us.
          弄清楚之后,我們開始測(cè)試,比如我們選擇add方法:
          填寫args,點(diǎn)擊go,在status中就會(huì)顯示結(jié)果。  

          結(jié)果是正確的。
          7.創(chuàng)建Webservice Client
          現(xiàn)在我們已經(jīng)部署好Webservice,而且應(yīng)經(jīng)測(cè)試過了,那我們新建一個(gè)Webservice client,來調(diào)用Webservice提供的方法。
          7.1新建一個(gè)java project,給他取個(gè)名字。比如我們叫它ClientofWebService


          在工具條中點(diǎn)擊new Web Service Client

          然后按照以下步驟操作:


          The last step of the web service client creation is to specify either a WSDL File or a WSDL URL for the wizard to retrieve the web service WSDL from. In our case we are using the URL and generate the client into the new package com.myeclipseide.ws.client:

          http://localhost:8888/WebServiceProject/CalculatorPort?WSDL


          點(diǎn)擊Next知道完成。
          可以看到在新建的java project ClientofWebService中,src文件夾下產(chǎn)生了許多的文件,根據(jù)名稱我們大體可以了解其意思,可以打開看一下源代碼,其實(shí)不難理解。比如add文件,就是Calculator類中add方法的兩個(gè)參數(shù)的get和set方法。其他類似。
          我們?cè)谖募A下見一個(gè)類test.java寫一個(gè)main函數(shù)測(cè)試
          Java代碼     

          public static void main(String[] args) {    
              
          /* Create the service instance */    
              CalculatorService service 
          = new CalculatorService();    
              CalculatorDelegate delegate 
          = service.getCalculatorPort();    
            
              
          /* Using the web service, perform the 4 calculations */    
              System.out.println( 
          "1. 3+7=" + delegate.add(37));    
              System.out.println( 
          "2. 12-2=" + delegate.subtract(122));    
              System.out.println( 
          "3. 9*9=" + delegate.multiply(99));    
              System.out.println( 
          "4. 40/2=" + delegate.divide(402));    
          }
             

           運(yùn)行得到如下結(jié)果:
          1. 3+7=10
          2. 12-2=10
          3. 9*9=81
          4. 40/2=20
          測(cè)試完成。

          本文來自CSDN博客,轉(zhuǎn)載請(qǐng)標(biāo)明出處:http://blog.csdn.net/foart/archive/2009/06/21/4287515.aspx

          posted @ 2009-10-17 22:50 潯陽(yáng)江頭夜送客 閱讀(3019) | 評(píng)論 (6)編輯 收藏
          僅列出標(biāo)題  
          <2025年5月>
          27282930123
          45678910
          11121314151617
          18192021222324
          25262728293031
          1234567

          常用鏈接

          留言簿

          隨筆分類

          隨筆檔案

          myeclipse6.5上基于JAX-WS開發(fā)Webservice(中文示例)

          搜索

          •  

          最新評(píng)論

          閱讀排行榜

          評(píng)論排行榜

          主站蜘蛛池模板: 上蔡县| 广州市| 临汾市| 军事| 贡觉县| 阿尔山市| 青龙| 安国市| 尚志市| 柏乡县| 庆云县| 鄂托克旗| 昔阳县| 吴堡县| 金川县| 盘山县| 丹凤县| 沭阳县| 芦山县| 定南县| 庆阳市| 常熟市| 宜宾市| 潞城市| 青冈县| 宜州市| 曲松县| 高碑店市| 绥宁县| 南丹县| 清徐县| 乌审旗| 文登市| 金门县| 安吉县| 泽州县| 祁连县| 贵港市| 聊城市| 大兴区| 雅江县|