| 1 |
/* |
| 2 |
* Copyright 2001-2004 The Apache Software Foundation. |
| 3 |
* |
| 4 |
* Licensed under the Apache License, Version 2.0 (the "License"); |
| 5 |
* you may not use this file except in compliance with the License. |
| 6 |
* You may obtain a copy of the License at |
| 7 |
* |
| 8 |
* http://www.apache.org/licenses/LICENSE-2.0 |
| 9 |
* |
| 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 |
* |
| 31 |
* @author Doug Davis ([email protected]) |
| 32 |
* @author Glen Daniels ([email protected]) |
| 33 |
*/ |
| 34 |
public class TestClient { |
| 35 |
public static String msg = "<SOAP-ENV:Envelope " + |
| 36 |
"xmlns:SOAP-ENV=\"http://schemas.xmlsoap.org/soap/envelope/\" " + |
| 37 |
"xmlns:soapenc=\"http://schemas.xmlsoap.org/soap/encoding/\" > " + |
| 38 |
"<SOAP-ENV:Body>\n" + |
| 39 |
"<echo:Echo xmlns:echo=\"EchoService\">\n" + |
| 40 |
"<symbol>IBM</symbol>\n" + |
| 41 |
"</echo:Echo>\n" + |
| 42 |
"</SOAP-ENV:Body></SOAP-ENV:Envelope>\n"; |
| 43 |
|
| 44 |
/** |
| 45 |
* Send a hardcoded message to the server, and print the response. |
| 46 |
* |
| 47 |
* @param args the command line arguments (mainly for specifying URL) |
| 48 |
* @param op an optional service argument, which will be used for |
| 49 |
* specifying the transport-level service |
| 50 |
*/ |
| 51 |
public static String doTest (String args[], String op) throws Exception { |
| 52 |
Options opts = new Options( args ); |
| 53 |
String url = opts.getURL(); |
| 54 |
String action = "EchoService" ; |
| 55 |
|
| 56 |
if (op != null) action = op; |
| 57 |
|
| 58 |
args = opts.getRemainingArgs(); |
| 59 |
if ( args != null ) action = args[0]; |
| 60 |
|
| 61 |
InputStream input = new ByteArrayInputStream(msg.getBytes()); |
| 62 |
Service service = new Service(); |
| 63 |
Call call = (Call) service.createCall(); |
| 64 |
SOAPEnvelope env = new SOAPEnvelope(input); |
| 65 |
|
| 66 |
call.setTargetEndpointAddress( new URL(url) ); |
| 67 |
if (action != null) { |
| 68 |
call.setUseSOAPAction( true ); |
| 69 |
call.setSOAPActionURI( action ); |
| 70 |
} |
| 71 |
|
| 72 |
System.out.println( "Request:\n" + msg ); |
| 73 |
|
| 74 |
env = call.invoke( env ); |
| 75 |
|
| 76 |
System.out.println( "Response:\n" + env.toString() ); |
| 77 |
return( env.toString() ); |
| 78 |
} |
| 79 |
|
| 80 |
public static void main(String args[]) throws Exception{ |
| 81 |
doTest(args, null); |
| 82 |
} |
| 83 |
public static void mainWithService(String args[], String service) throws Exception{ |
| 84 |
doTest(args, service); |
| 85 |
} |
| 86 |
} |