📄 xmlbeansclient.java
字号:
/*
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. The ASF licenses this file
* to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*/
package samples.address.client.xmlbeans;
import java.io.PrintStream;
import samples.address.service.xmlbeans.GetAddDocument;
import samples.address.service.xmlbeans.GetAddResponseDocument;
import samples.address.service.xmlbeans.InsertAddDocument;
final class Timer{
private long startTime;
private long endTime;
public Timer() { reset(); }
public void start() {
System.gc();
startTime = System.currentTimeMillis();
}
public void end() {
System.gc();
endTime = System.currentTimeMillis();
}
public long duration() {
return (endTime - startTime);
}
public void printDuration( PrintStream out ) {
long elapsedTimeInSecond = duration() / 1000;
long remainderInMillis = duration() % 1000;
out.println("\nTotal execution time:"
+ elapsedTimeInSecond + "."
+ remainderInMillis
+ " seconds");
}
public void reset() {
startTime = 0;
endTime = 0;
}
}
public class XMLBEANSClient{
public static void main(java.lang.String args[]){
Timer timer = new Timer();
try{
AddressListStub stub =
new AddressListStub
("http://132.159.172.104:8080/axis2/services/addressList");
timer.start();
for(int i=0;i<1000;i++){
getAdd(stub);
insertAdd(stub);
getAdd(stub);
}
} catch(Exception e){
e.printStackTrace();
System.err.println("\n\n\n");
}
timer.end();
timer.printDuration(System.out);
}
/* fire and forget */
public static void insertAdd(AddressListStub stub){
try{
InsertAddDocument reqDoc = InsertAddDocument.Factory.newInstance();
InsertAddDocument.InsertAdd req = reqDoc.addNewInsertAdd();
req.setName("jack");
req.setPhone("webservice@webservice.com");
stub.insertAdd(reqDoc);
System.err.println("phone insert");
} catch(Exception e){
e.printStackTrace();
System.err.println("\n\n\n");
}
}
/* two way call/receive */
public static void getAdd(AddressListStub stub){
try{
GetAddDocument reqDoc = GetAddDocument.Factory.newInstance();
GetAddDocument.GetAdd req = reqDoc.addNewGetAdd();
req.setName("jack");
GetAddResponseDocument res = stub.getAdd(reqDoc);
System.err.println(res.getGetAddResponse().getReturn());
} catch(Exception e){
e.printStackTrace();
System.err.println("\n\n\n");
}
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -