I set up a web services with soap2.2. I want to time the response time on client sides. I wrote a loop to send request 10 times to the Web services. the first one is very long others are very short. if I start program again the result is same, first one is long but others are short.
I attached the program pls help why? Do you have any idea how to do timing for web services? I also time the myrpc.invoke() the result is same first time is long others short. What can cause this problem? some wrong with my program? I knew the webservice use http service. it may have sock connection setup on the first time, but my question is I create new soap connection everytime in the loop,why the time is short after first query and why if I run new program again the first time become very long too. how can http server know it is different program rather than different soap call. Please help!!! ***This is my test program String sName=commandLine.getFlagArg("-serviceName"); GMDQuery g=null; long time=0; for(int i=0;i<10;i++){ try{ //create a class which is for soap query (code is below) g=new GMDQuery(gmdHost,Integer.parseInt(port),soapDir,soapServiceName); Price p=null; long st=System.currentTimeMillis(); //start time p=g.getPrice(sName.trim()); long ft=System.currentTimeMillis(); //finish time time=(ft-st)+time; System.out.println("Done: "+ (ft-st)); System.out.println(p.toString()); }catch(GMDQueryException e){ System.err.println(e.getMessage()); System.exit(2); } }//for ***My query class public class GMDQuery { Call myrpc; String servicePoint; public GMDQuery(String host, int port, String soapDir, String soapServiceName) throws GMDQueryException{ Properties props = new Properties(); servicePoint="http://"+host+":"+String.valueOf(port)+soapDir; System.out.println("Current GMD is on "+servicePoint+"\n"); myrpc = new Call(); myrpc.setTargetObjectURI(soapServiceName); } public Price getPrice(String sName) throws GMDQueryException{ Element QueryPriceRoot=new Element("QUERY-PRICE"); QueryPriceRoot.addContent(new Element("SERVICE_NAME").setText(sName)); Document QueryPrice=new Document(QueryPriceRoot); XMLOutputter outputter=new XMLOutputter(" ",true); String outReq=outputter.outputString(QueryPrice); //for looking at xml message //System.out.println(outReq); myrpc.setMethodName("queryPrice"); String rxml=null; try{ rxml=executeSOAPQuery(outReq); }catch(GMDQueryException e){ throw e; } ...... return new Price(hPrice,sPrice); } private String executeSOAPQuery(String outReq) throws GMDQueryException{ myrpc.setEncodingStyleURI("http://schemas.xmlsoap.org/soap/encoding/"); //Create a URL object, which represents the endpoint URL url=null; try{ url=new URL(servicePoint); }catch(java.net.MalformedURLException e){ throw new GMDQueryException(e.getMessage()); } // Add Parameters if(!outReq.equals("")){ Vector myparams = new Vector(1); myparams.addElement(new Parameter("inputReq", String.class, outReq,null)); myrpc.setParams(myparams); } //Send the SOAP RPC request message using invoke() method Response resp=null; try{ resp=myrpc.invoke(url," "); }catch(org.apache.soap.SOAPException e){ throw new GMDQueryException("connection error"); } //Check the response. Parameter result=null; if(resp.generatedFault()){ //Error Occured Fault fault=resp.getFault(); throw new GMDQueryException("GMD Error:"+fault.getFaultString()); }else { result=resp.getReturnValue(); } return result.getValue().toString(); }