001: /*
002: * Copyright 2001-2004 The Apache Software Foundation.
003: *
004: * Licensed under the Apache License, Version 2.0 (the "License");
005: * you may not use this file except in compliance with the License.
006: * You may obtain a copy of the License at
007: *
008: * http://www.apache.org/licenses/LICENSE-2.0
009: *
010: * Unless required by applicable law or agreed to in writing, software
011: * distributed under the License is distributed on an "AS IS" BASIS,
012: * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
013: * See the License for the specific language governing permissions and
014: * limitations under the License.
015: */
016:
017: package samples.bidbuy;
018:
019: import org.apache.axis.client.Call;
020: import org.apache.axis.client.Service;
021: import org.apache.axis.encoding.XMLType;
022: import org.apache.axis.encoding.ser.BeanDeserializerFactory;
023: import org.apache.axis.encoding.ser.BeanSerializerFactory;
024: import org.apache.axis.utils.Options;
025:
026: import javax.xml.namespace.QName;
027: import javax.xml.rpc.ParameterMode;
028: import java.net.URL;
029: import java.util.Calendar;
030:
031: /**
032: * Test Client for the echo interop service. See the main entrypoint
033: * for more details on usage.
034: *
035: * @author Sam Ruby <rubys@us.ibm.com>
036: */
037: public class TestClient {
038:
039: private static Service service = null;
040: private static Call call = null;
041:
042: /**
043: * Test an echo method. Declares success if the response returns
044: * true with an Object.equal comparison with the object to be sent.
045: * @param method name of the method to invoke
046: * @param toSend object of the correct type to be sent
047: */
048: private static void test(String method, Object toSend) {
049:
050: }
051:
052: /**
053: * Main entry point. Tests a variety of echo methods and reports
054: * on their results.
055: *
056: * Arguments are of the form:
057: * -h localhost -p 8080 -s /soap/servlet/rpcrouter
058: */
059: public static void main(String args[]) throws Exception {
060: // set up the call object
061: Options opts = new Options(args);
062: service = new Service();
063: call = (Call) service.createCall();
064: call.setTargetEndpointAddress(new URL(opts.getURL()));
065: call.setUseSOAPAction(true);
066: call.setSOAPActionURI("http://www.soapinterop.org/Bid");
067:
068: // register the PurchaseOrder class
069: QName poqn = new QName("http://www.soapinterop.org/Bid",
070: "PurchaseOrder");
071: Class cls = PurchaseOrder.class;
072: call.registerTypeMapping(cls, poqn,
073: BeanSerializerFactory.class,
074: BeanDeserializerFactory.class);
075:
076: // register the Address class
077: QName aqn = new QName("http://www.soapinterop.org/Bid",
078: "Address");
079: cls = Address.class;
080: call.registerTypeMapping(cls, aqn, BeanSerializerFactory.class,
081: BeanDeserializerFactory.class);
082:
083: // register the LineItem class
084: QName liqn = new QName("http://www.soapinterop.org/Bid",
085: "LineItem");
086: cls = LineItem.class;
087: call.registerTypeMapping(cls, liqn,
088: BeanSerializerFactory.class,
089: BeanDeserializerFactory.class);
090:
091: try {
092: // Default return type based on what we expect
093: call.setOperationName(new QName(
094: "http://www.soapinterop.org/Bid", "Buy"));
095: call.addParameter("PO", poqn, ParameterMode.IN);
096: call.setReturnType(XMLType.XSD_STRING);
097:
098: LineItem[] li = new LineItem[2];
099: li[0] = new LineItem("Tricorder", 1, "2500.95");
100: li[1] = new LineItem("Phasor", 3, "7250.95");
101:
102: PurchaseOrder po = new PurchaseOrder("NCC-1701", Calendar
103: .getInstance(), new Address("Sam Ruby", "Home",
104: "Raleigh", "NC", "27676"), new Address(
105: "Lou Gerstner", "Work", "Armonk", "NY", "15222"),
106: li);
107:
108: // issue the request
109: String receipt = (String) call.invoke(new Object[] { po });
110:
111: System.out.println(receipt);
112: } catch (Exception e) {
113: System.out.println("Buy failed: " + e);
114: throw e;
115: }
116: }
117:
118: }
|