KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > objectweb > celtix > performance > basic_type > client > Client


1 package org.objectweb.celtix.performance.basic_type.client;
2
3 import java.io.File JavaDoc;
4 import java.net.MalformedURLException JavaDoc;
5 import java.util.Iterator JavaDoc;
6 import java.util.List JavaDoc;
7
8 import javax.xml.namespace.QName JavaDoc;
9 import javax.xml.ws.BindingProvider;
10
11 import org.objectweb.celtix.pat.internal.TestCaseBase;
12 import org.objectweb.celtix.pat.internal.TestResult;
13 import org.objectweb.celtix.performance.basic_type.BasicPortType;
14 import org.objectweb.celtix.performance.basic_type.BasicService;
15 import org.objectweb.celtix.performance.basic_type.server.Server;
16  
17 public final class Client extends TestCaseBase {
18     
19     private static final QName JavaDoc SERVICE_NAME
20         = new QName JavaDoc("http://celtix.objectweb.org/performance/basic_type", "BasicService");
21
22     private static int opid;
23     
24     private byte[] inputBase64 = new byte[100 * 1024];
25     private String JavaDoc inputString = new String JavaDoc();
26
27     private final int asciiCount = 1 * 1024;
28     
29     private BasicService ss;
30     private BasicPortType port;
31
32     public Client(String JavaDoc[] args) {
33         super("Base TestCase", args);
34         serviceName = "BasicService";
35         portName = "BasicPortType";
36         operationName = "echoString";
37         amount = 30;
38         wsdlNameSpace = "http://celtix.objectweb.org/performance/basic_type";
39     }
40
41     public void initTestData() {
42         String JavaDoc temp = "abcdefghijklmnopqrstuvwxyz0123456789!@#$%^&*()_+?><[]/0123456789";
43         for (int idx = 0; idx < 4 * packetSize; idx++) {
44             for (int jdx = 0; jdx < 256; jdx++) {
45                 inputBase64[idx * 256 + jdx] = (byte)(jdx - 128);
46             }
47         }
48         for (int i = 0; i < asciiCount / temp.length() * packetSize; i++) {
49             inputString = inputString + temp;
50         }
51     }
52
53     public void printUsage() {
54         System.out.println("Syntax is: Client [-WSDL wsdllocation] operation [-operation args...]");
55         System.out.println(" operation is one of: ");
56         System.out.println(" echoBase64");
57         System.out.println(" echoString");
58     }
59
60     public static void main(String JavaDoc args[]) throws Exception JavaDoc {
61         Client client = new Client(args);
62         client.initialize();
63         if (client.getOperationName().equals("echoString")) {
64             opid = 0;
65         } else {
66             opid = 1;
67         }
68         client.run();
69         List JavaDoc results = client.getTestResults();
70         TestResult testResult = null;
71         for (Iterator JavaDoc iter = results.iterator(); iter.hasNext();) {
72             testResult = (TestResult)iter.next();
73             System.out.println("Throughput " + testResult.getThroughput());
74             System.out.println("AVG Response Time " + testResult.getAvgResponseTime());
75         }
76         System.out.println("Celtix client is going to shutdown!");
77         //System.exit(0);
78
}
79
80     public void doJob() {
81         try {
82             switch(opid) {
83             case 0:
84                 port.echoString(inputString);
85                 break;
86             case 1:
87                 port.echoBase64(inputBase64);
88                 break;
89             default:
90                 port.echoString(inputString);
91             }
92         } catch (Exception JavaDoc e) {
93             e.printStackTrace();
94         }
95     }
96
97     public void getPort() {
98         if (usePipe) {
99             try {
100                 new Server(bus, "pipe://localhost:20000/performance/basic_type/SoapPort");
101             } catch (Exception JavaDoc ex) {
102                 ex.printStackTrace();
103             }
104         }
105         File JavaDoc wsdl = new File JavaDoc(wsdlPath);
106         try {
107             ss = new BasicService(wsdl.toURL(), SERVICE_NAME);
108         } catch (MalformedURLException JavaDoc e) {
109             e.printStackTrace();
110         }
111         port = ss.getSoapHttpPort();
112         if (usePipe) {
113             javax.xml.ws.BindingProvider provider = (javax.xml.ws.BindingProvider)port;
114             provider.getRequestContext().put(provider.ENDPOINT_ADDRESS_PROPERTY,
115                                              "pipe://localhost:20000/performance/basic_type/SoapPort");
116         }
117
118     }
119 }
120  
121
122
123
Popular Tags