1 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 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 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 } 87 | Popular Tags |