danchaofan

            BlogJava :: 首頁(yè) :: 聯(lián)系 :: 聚合  :: 管理
            14 Posts :: 20 Stories :: 3 Comments :: 0 Trackbacks

          #

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

          jdk為1。3版本,沒(méi)有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 單炒飯 閱讀(321) | 評(píng)論 (2)編輯 收藏

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

          axis方式調(diào)用:

           

          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 = "測(cè)試人員";

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

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

                        }

                        catch (Exception e) {

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

                        }

                 }

          }

          soap方式調(diào)用

          調(diào)用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();

                 }

              }

          }

          返回一維數(shù)組時(shí)

          Parameter soapResult = soapResponse.getReturnValue();

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

           

          調(diào)用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 單炒飯 閱讀(1082) | 評(píng)論 (0)編輯 收藏

          Webservice開(kāi)發(fā)

          1.  發(fā)布環(huán)境:win2000 Professional + JDK1.4.2_03 + Tomcat5

          2.  下載Axis,解壓縮,將其webapps目錄下的axis拷貝到tomcatwebapps目錄下,進(jìn)行訪問(wèn)測(cè)試,http://localhost:8080/axis/  出現(xiàn)正常頁(yè)面即可。

          3.  下載包含wtpEclipse,解壓縮

          4.  新建動(dòng)態(tài)Web Project,比如ca3,將axis下的jar包導(dǎo)入該項(xiàng)目的編譯環(huán)境里,在JavaSource中寫(xiě)java程序比如caSynrochnized,寫(xiě)好后,在上面點(diǎn)右鍵,選擇Create Web Service按照默認(rèn)設(shè)置,即可生成Web Service

          tomcat下部署

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

          6. 設(shè)置axis的環(huán)境變量,如下                                                                                    

          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命令行狀態(tài)下進(jìn)入上面目錄,運(yùn)行以下命令進(jìn)行發(fā)布        java org.apache.axis.client.AdminClient deploy.wsdd

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

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

          Webservice的重新部署

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

          部署時(shí)可能遇到的問(wèn)題

          1)             dos窗口下執(zhí)行java org.apache.axis.client.AdminClient deploy.wsdd命令時(shí),出現(xiàn)404錯(cuò)誤,此時(shí)可能你的tomcat服務(wù)器沒(méi)有啟動(dòng),請(qǐng)先啟動(dòng)tomcat服務(wù)器。

          2)             不同系統(tǒng)安裝相同的jdk版本,發(fā)布webservice服務(wù)時(shí),可能會(huì)出現(xiàn)unsupportedVersionException,如果在IE下敲入http://localhost:8080/java-oa/services,發(fā)現(xiàn)服務(wù)已經(jīng)發(fā)布成功,并且點(diǎn)wsdl鏈接能夠顯示wsdl文件,則此錯(cuò)誤可以忽略

          3)             如果發(fā)現(xiàn)在啟動(dòng)tomcat時(shí),出現(xiàn)server-config.wsdd文件需要typehandle一類的錯(cuò)誤,則有可能你的應(yīng)用下存在gnujaxp.jar,因?yàn)檫@個(gè)jar包會(huì)與axis所需要的jar包相沖突,將gnujaxp.jar拷貝到common\lib下即可。

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

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

          僅列出標(biāo)題
          共2頁(yè): 上一頁(yè) 1 2 
          主站蜘蛛池模板: 宝清县| 宁城县| 肥乡县| 江城| 湟源县| 平原县| 孟村| 巨野县| 工布江达县| 嘉荫县| 靖边县| 临江市| 桐城市| 寿宁县| 龙泉市| 泰兴市| 通辽市| 泰顺县| 阳城县| 霍山县| 东源县| 灵宝市| 芦溪县| 翼城县| 景泰县| 名山县| 长乐市| 台中市| 佛冈县| 柏乡县| 泸溪县| 宁城县| 苍梧县| 乾安县| 团风县| 武山县| 平顺县| 木兰县| 舟山市| 济阳县| 登封市|