01: /*
02: * Copyright 2001-2004 The Apache Software Foundation.
03: *
04: * Licensed under the Apache License, Version 2.0 (the "License");
05: * you may not use this file except in compliance with the License.
06: * You may obtain a copy of the License at
07: *
08: * http://www.apache.org/licenses/LICENSE-2.0
09: *
10: * Unless required by applicable law or agreed to in writing, software
11: * distributed under the License is distributed on an "AS IS" BASIS,
12: * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13: * See the License for the specific language governing permissions and
14: * limitations under the License.
15: */
16:
17: package samples.misc;
18:
19: import org.apache.axis.client.Call;
20: import org.apache.axis.client.Service;
21: import org.apache.axis.message.SOAPEnvelope;
22: import org.apache.axis.utils.Options;
23:
24: import java.io.ByteArrayInputStream;
25: import java.io.InputStream;
26: import java.net.URL;
27:
28: /**
29: *
30: * @author Doug Davis (dug@us.ibm.com)
31: * @author Glen Daniels (gdaniels@allaire.com)
32: */
33: public class TestClient {
34: public static String msg = "<SOAP-ENV:Envelope "
35: + "xmlns:SOAP-ENV=\"http://schemas.xmlsoap.org/soap/envelope/\" "
36: + "xmlns:soapenc=\"http://schemas.xmlsoap.org/soap/encoding/\" > "
37: + "<SOAP-ENV:Body>\n"
38: + "<echo:Echo xmlns:echo=\"EchoService\">\n"
39: + "<symbol>IBM</symbol>\n" + "</echo:Echo>\n"
40: + "</SOAP-ENV:Body></SOAP-ENV:Envelope>\n";
41:
42: /**
43: * Send a hardcoded message to the server, and print the response.
44: *
45: * @param args the command line arguments (mainly for specifying URL)
46: * @param op an optional service argument, which will be used for
47: * specifying the transport-level service
48: */
49: public static String doTest(String args[], String op)
50: throws Exception {
51: Options opts = new Options(args);
52: String url = opts.getURL();
53: String action = "EchoService";
54:
55: if (op != null)
56: action = op;
57:
58: args = opts.getRemainingArgs();
59: if (args != null)
60: action = args[0];
61:
62: InputStream input = new ByteArrayInputStream(msg.getBytes());
63: Service service = new Service();
64: Call call = (Call) service.createCall();
65: SOAPEnvelope env = new SOAPEnvelope(input);
66:
67: call.setTargetEndpointAddress(new URL(url));
68: if (action != null) {
69: call.setUseSOAPAction(true);
70: call.setSOAPActionURI(action);
71: }
72:
73: System.out.println("Request:\n" + msg);
74:
75: env = call.invoke(env);
76:
77: System.out.println("Response:\n" + env.toString());
78: return (env.toString());
79: }
80:
81: public static void main(String args[]) throws Exception {
82: doTest(args, null);
83: }
84:
85: public static void mainWithService(String args[], String service)
86: throws Exception {
87: doTest(args, service);
88: }
89: }
|