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

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

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

    danchaofan

      BlogJava :: 首頁 :: 聯系 :: 聚合  :: 管理
      14 Posts :: 20 Stories :: 3 Comments :: 0 Trackbacks

    #

    本人通過實際項目開發,敘述關于測試的使用和感悟,本人堅持用代碼說話的方式,來講述測試在項目中的真正實際應用,同時也希望大家多多賜教,共同探討,總結更適用的開發經驗,共同分享!
    文章來源:http://dev.csdn.net/author/fuwei2241/cb5b26ad75fa41829d967fbefef3685f.html
    posted @ 2007-03-02 18:30 單炒飯 閱讀(91) | 評論 (0)編輯 收藏

    jdk為1。3版本,沒有replaceAll()方法

    public class Trans {

     /**
      * @param args
      */
     public static void main(String[] args) {
      // TODO Auto-generated method stub

     }
     /**
      *
      * @param sourceString
      * @param toReplaceString
      * @param replaceString
      * @return
      */
     public static String transChar(String sourceString, String toReplaceString,
       String replaceString) {
      String returnString = sourceString;
      int stringLength = 0;
      if (toReplaceString != null) {
       stringLength = toReplaceString.length();
      }

      if (returnString != null && returnString.length() > stringLength) {
       int max = 0;
       String S4 = "";
       //int i = sourceString.length();

       for (int i = 0; i < sourceString.length(); i++) {

        max = i + toReplaceString.length() > sourceString.length() ? sourceString
          .length()
          : i + stringLength;
        String S3 = sourceString.substring(i, max);
        if (!S3.equals(toReplaceString)) {
         S4 += S3.substring(0, 1);
        } else {
         S4 += replaceString;
         i += stringLength - 1;
        }
       }
       returnString = S4;
      }
      return returnString;

     }

    }

    posted @ 2006-02-27 17:30 單炒飯 閱讀(320) | 評論 (2)編輯 收藏

    調用webservice,可以首先根據wsdl文件生成客戶端,或者直接根據地址調用,下面討論直接調用地址的兩種不同方式:axis和Soap,soap方式主要是用在websphere下

    axis方式調用:

     

    import java.util.Date;

    import java.text.DateFormat;

    import org.apache.axis.client.Call;

    import org.apache.axis.client.Service;

    import javax.xml.namespace.QName;

    import java.lang.Integer;

    import javax.xml.rpc.ParameterMode;

     

    public class caClient {

                

           public static void main(String[] args) {

     

                  try {

                         String endpoint = "http://localhost:8080/ca3/services/caSynrochnized?wsdl";

                         Service service = new Service();

                         Call call = (Call) service.createCall();

                         call.setTargetEndpointAddress(endpoint);

                         call.setOperationName("addUser");

                         call.addParameter("userName", org.apache.axis.encoding.XMLType.XSD_DATE,

                                       javax.xml.rpc.ParameterMode.IN);

                         call.setReturnType(org.apache.axis.encoding.XMLType.XSD_STRING);

                         call.setUseSOAPAction(true);

                         call.setSOAPActionURI("http://www.my.com/Rpc");

                         //Integer k = (Integer) call.invoke(new Object[] { i, j });

                         //System.out.println("result is  " + k.toString() + ".");

                         String temp = "測試人員";

                         String result = (String)call.invoke(new Object[]{temp});

                         System.out.println("result is "+result);

                  }

                  catch (Exception e) {

                         System.err.println(e.toString());

                  }

           }

    }

    soap方式調用

    調用java生成的webservice

    import org.apache.soap.util.xml.*;

    import org.apache.soap.*;

    import org.apache.soap.rpc.*;

     

    import java.io.*;

    import java.net.*;

    import java.util.Vector;

     

    public class caService{

           public static String getService(String user) {

           URL url = null;

           try {

               url=new URL("http://192.168.0.100:8080/ca3/services/caSynrochnized");

           } catch (MalformedURLException mue) {

              return mue.getMessage();

             }

                 // This is the main SOAP object

           Call soapCall = new Call();

           // Use SOAP encoding

           soapCall.setEncodingStyleURI(Constants.NS_URI_SOAP_ENC);

           // This is the remote object we're asking for the price

           soapCall.setTargetObjectURI("urn:xmethods-caSynrochnized");

           // This is the name of the method on the above object

           soapCall.setMethodName("getUser");

           // We need to send the ISBN number as an input parameter to the method

           Vector soapParams = new Vector();

     

           // name, type, value, encoding style

           Parameter isbnParam = new Parameter("userName", String.class, user, null);

           soapParams.addElement(isbnParam);

           soapCall.setParams(soapParams);

           try {

              // Invoke the remote method on the object

              Response soapResponse = soapCall.invoke(url,"");

              // Check to see if there is an error, return "N/A"

              if (soapResponse.generatedFault()) {

                  Fault fault = soapResponse.getFault();

                 String f = fault.getFaultString();

                 return f;

              } else {

                 // read result

                 Parameter soapResult = soapResponse.getReturnValue ();

                 // get a string from the result

                 return soapResult.getValue().toString();

              }

           } catch (SOAPException se) {

              return se.getMessage();

           }

        }

    }

    返回一維數組時

    Parameter soapResult = soapResponse.getReturnValue();

    String[] temp = (String[])soapResult.getValue();

     

    調用ASP.Net生成的webservice

    private String HelloWorld(String uri, String u) {

                  try {

                         SOAPMappingRegistry smr = new SOAPMappingRegistry();

                         StringDeserializer sd = new StringDeserializer();

                         ArraySerializer arraySer = new ArraySerializer();

                         BeanSerializer beanSer = new BeanSerializer();

                         smr.mapTypes(Constants.NS_URI_SOAP_ENC, new QName(

                                       "http://tempuri.org/", "HelloWorldResult"), String.class,

                                       null, sd);

                         smr.mapTypes(Constants.NS_URI_SOAP_ENC, new QName(

                                       "http://tempuri.org/", "temp"), String.class,

                                       beanSer, beanSer);

     

                         URL url = new URL(uri);

                         Call call = new Call();

                         call.setSOAPMappingRegistry(smr);

                         call.setTargetObjectURI("urn:xmethods-Service1");

                         call.setMethodName("HelloWorld");

                         call.setEncodingStyleURI(Constants.NS_URI_SOAP_ENC);

     

                         Vector soapParams = new Vector();

                         soapParams.addElement(new Parameter("temp", String.class, u, null));

                         call.setParams(soapParams);

     

                         Response soapResponse = call.invoke(url,"http://tempuri.org/HelloWorld");

     

                         if (soapResponse.generatedFault()) {

                                Fault fault = soapResponse.getFault();

                                System.out.println(fault);

                         } else {

                                Parameter soapResult = soapResponse.getReturnValue();

                                Object obj = soapResult.getValue();

                                System.out.println("===" + obj);

                         }

                  } catch (Exception e) {

                         e.printStackTrace();

                  }

                  return null;

           }
    posted @ 2006-02-27 13:46 單炒飯 閱讀(1081) | 評論 (0)編輯 收藏

    Webservice開發

    1.  發布環境:win2000 Professional + JDK1.4.2_03 + Tomcat5

    2.  下載Axis,解壓縮,將其webapps目錄下的axis拷貝到tomcatwebapps目錄下,進行訪問測試,http://localhost:8080/axis/  出現正常頁面即可。

    3.  下載包含wtpEclipse,解壓縮

    4.  新建動態Web Project,比如ca3,將axis下的jar包導入該項目的編譯環境里,在JavaSource中寫java程序比如caSynrochnized,寫好后,在上面點右鍵,選擇Create Web Service按照默認設置,即可生成Web Service

    tomcat下部署

    5. 生成后,將eclipseca3\.deployables下的ca3目錄拷貝到tomcatwebapps目錄下

    6. 設置axis的環境變量,如下                                                                                    

    a)        AXIS_HOME  E:\Tomcat5.0\webapps\axis

    b)        AXIS_LIB    %AXIS_HOME%\WEB-INF\lib

    c)         Classpath   .;%AXIS_LIB%\axis.jar;%AXIS_LIB%\commons-discovery-0.2.jar;%AXIS_LIB%\commons-logging-1.0.4.jar;%AXIS_LIB%\jaxrpc.jar;%AXIS_LIB%\saaj.jar;%AXIS_LIB%\log4j-1.2.8.jar; %AXIS_LIB%\wsdl4j-1.5.1.jar;

    7. E:\Tomcat 5.0\webapps\ca3\WEB-INF\caSynrochnizedService\com\hshz\ca找到deploy.wsdd文件,在dos命令行狀態下進入上面目錄,運行以下命令進行發布        java org.apache.axis.client.AdminClient deploy.wsdd

    8.  IE中輸入http://localhost:8080/ca3/services可以看到已發布的webservice

    E:\Tomcat 5.0\webapps\ca3\wsdl目錄下找到wsdl文件,最后幾行比如<wsdlsoap:address location="http://localhost:8080/ca3/services/caSynrochnized"/>其中的location才是web Service相互調用的地址,另外localhost改為自己的IP地址。

    Webservice的重新部署

    對于已發布的服務,修改接口后,直接將發布目錄下的wsdl,以及wsddclassesservice文件夾拷貝到tomcat相應目錄下,不用重新發布即可。可先在瀏覽器中輸入地址/services進行查看。

    部署時可能遇到的問題

    1)             dos窗口下執行java org.apache.axis.client.AdminClient deploy.wsdd命令時,出現404錯誤,此時可能你的tomcat服務器沒有啟動,請先啟動tomcat服務器。

    2)             不同系統安裝相同的jdk版本,發布webservice服務時,可能會出現unsupportedVersionException,如果在IE下敲入http://localhost:8080/java-oa/services,發現服務已經發布成功,并且點wsdl鏈接能夠顯示wsdl文件,則此錯誤可以忽略

    3)             如果發現在啟動tomcat時,出現server-config.wsdd文件需要typehandle一類的錯誤,則有可能你的應用下存在gnujaxp.jar,因為這個jar包會與axis所需要的jar包相沖突,將gnujaxp.jar拷貝到common\lib下即可。

    4)             如果webservice中的方法名字或者參數名或者參數數目,更改后需要重新發布webservice

    提供webservice中的程序在方法名,參數不變的情況下,重新編譯后只需要覆蓋原來的類即可。
    posted @ 2006-02-27 13:41 單炒飯 閱讀(1894) | 評論 (1)編輯 收藏

    僅列出標題
    共2頁: 上一頁 1 2 
    主站蜘蛛池模板: 成在线人免费无码高潮喷水| 久久久久久久国产免费看 | 永久免费的网站在线观看| 亚洲天堂中文资源| 99久久人妻精品免费二区| 亚洲视频免费在线看| av免费不卡国产观看| 亚洲日产乱码一二三区别| 国产精品国产午夜免费福利看| 国产精品无码亚洲一区二区三区| 午夜国产羞羞视频免费网站| 未满十八私人高清免费影院| 中文字幕亚洲乱码熟女一区二区| 精品亚洲永久免费精品| 久久亚洲精品中文字幕| 成人免费一级毛片在线播放视频| 激情综合亚洲色婷婷五月 | 国产成人高清精品免费软件| 国产高潮久久免费观看| 亚洲AV日韩AV天堂一区二区三区| 久久久久久精品免费看SSS | 成人毛片免费观看视频| 爱情岛论坛免费视频| 亚洲午夜久久久久久久久久 | 在线观看片免费人成视频播放| 亚洲AV无码一区东京热| 曰批全过程免费视频网址| 久久综合亚洲色hezyo| 国产亚洲成av片在线观看| 日本亚洲免费无线码| 国产午夜亚洲精品不卡免下载| 亚洲AV永久无码精品成人| 国产免费久久精品99re丫y| 菠萝菠萝蜜在线免费视频| 亚洲AV日韩AV高潮无码专区| 成全视频在线观看免费高清动漫视频下载 | 91在线免费视频| 国产精品亚洲精品青青青| 国产亚洲精品精品国产亚洲综合| 三年片在线观看免费大全电影| 亚洲AV无码专区亚洲AV桃|