001: package samples.bidbuy;
002:
003: import org.apache.axis.client.Call;
004: import org.apache.axis.client.Service;
005: import org.apache.axis.encoding.XMLType;
006: import org.apache.axis.encoding.ser.BeanDeserializerFactory;
007: import org.apache.axis.encoding.ser.BeanSerializerFactory;
008:
009: import javax.xml.namespace.QName;
010: import javax.xml.rpc.ParameterMode;
011: import java.math.BigDecimal;
012: import java.net.URL;
013: import java.util.Calendar;
014: import java.util.StringTokenizer;
015: import java.util.Vector;
016:
017: public class v3 implements vInterface {
018: public void register(String registryURL, samples.bidbuy.Service s)
019: throws Exception {
020: try {
021: Service service = new Service();
022: Call call = (Call) service.createCall();
023:
024: call.setTargetEndpointAddress(new URL(registryURL));
025: call.setOperationName(new QName(
026: "http://www.soapinterop.org/Register", "Register"));
027: call.addParameter("ServiceName", XMLType.XSD_STRING,
028: ParameterMode.IN);
029: call.addParameter("ServiceUrl", XMLType.XSD_STRING,
030: ParameterMode.IN);
031: call.addParameter("ServiceType", XMLType.XSD_STRING,
032: ParameterMode.IN);
033: call.addParameter("ServiceWSDL", XMLType.XSD_STRING,
034: ParameterMode.IN);
035:
036: call.invoke(new Object[] { s.getServiceName(),
037: s.getServiceUrl(), s.getServiceType(),
038: s.getServiceWsdl() });
039: } catch (Exception e) {
040: e.printStackTrace();
041: throw e;
042: }
043: }
044:
045: public void unregister(String registryURL, String name)
046: throws Exception {
047: try {
048: Service service = new Service();
049: Call call = (Call) service.createCall();
050:
051: call.setTargetEndpointAddress(new URL(registryURL));
052: call.setOperationName(new QName(
053: "http://www.soapinterop.org/Unregister",
054: "Unregister"));
055: call.addParameter("ServiceName", XMLType.XSD_STRING,
056: ParameterMode.IN);
057: call.invoke(new Object[] { name });
058: } catch (Exception e) {
059: e.printStackTrace();
060: throw e;
061: }
062: }
063:
064: public Boolean ping(String serverURL) throws Exception {
065: try {
066: Service service = new Service();
067: Call call = (Call) service.createCall();
068:
069: call.setTargetEndpointAddress(new URL(serverURL));
070: call.setUseSOAPAction(true);
071: call.setSOAPActionURI("http://www.soapinterop.org/Ping");
072: call.setOperationName(new QName(
073: "http://www.soapinterop.org/Bid", "Ping"));
074: call.invoke((Object[]) null);
075: return (new Boolean(true));
076: } catch (Exception e) {
077: e.printStackTrace();
078: throw e;
079: }
080: }
081:
082: public Vector lookupAsString(String registryURL) throws Exception {
083: try {
084: Service service = new Service();
085: Call call = (Call) service.createCall();
086:
087: call.setTargetEndpointAddress(new URL(registryURL));
088: call.setUseSOAPAction(true);
089: call
090: .setSOAPActionURI("http://www.soapinterop.org/LookupAsString");
091: call.setOperationName(new QName(
092: "http://www.soapinterop.org/Registry",
093: "LookupAsString"));
094: call.addParameter("ServiceType", XMLType.XSD_STRING,
095: ParameterMode.IN);
096: call.setReturnType(XMLType.XSD_DOUBLE);
097:
098: String res = (String) call.invoke(new Object[] { "Bid" });
099:
100: if (res == null)
101: return (null);
102: StringTokenizer lineParser = new StringTokenizer(res, "\n");
103:
104: Vector services = new Vector();
105: while (lineParser.hasMoreTokens()) {
106: String line = (String) lineParser.nextElement();
107: StringTokenizer wordParser = new StringTokenizer(line,
108: "\t");
109: samples.bidbuy.Service s = null;
110:
111: for (int i = 0; wordParser.hasMoreTokens() && i < 4; i++)
112: switch (i) {
113: case 0:
114: s = new samples.bidbuy.Service();
115: if (services == null)
116: services = new Vector();
117: services.add(s);
118: s.setServiceName((String) wordParser
119: .nextToken());
120: break;
121: case 1:
122: s
123: .setServiceUrl((String) wordParser
124: .nextToken());
125: break;
126: case 2:
127: s.setServiceType((String) wordParser
128: .nextToken());
129: break;
130: case 3:
131: s.setServiceWsdl((String) wordParser
132: .nextToken());
133: break;
134: }
135: }
136: return (services);
137: } catch (Exception e) {
138: e.printStackTrace();
139: throw e;
140: }
141: }
142:
143: public double requestForQuote(String serverURL) throws Exception {
144: try {
145:
146: Service service = new Service();
147: Call call = (Call) service.createCall();
148:
149: call.setTargetEndpointAddress(new URL(serverURL));
150: call
151: .setOperationName(new QName(
152: "http://www.soapinterop.org/Bid",
153: "RequestForQuote"));
154: call.setReturnType(XMLType.XSD_DOUBLE);
155: call.setUseSOAPAction(true);
156: call
157: .setSOAPActionURI("http://www.soapinterop.org/RequestForQuote");
158: call.addParameter("ProductName", XMLType.XSD_STRING,
159: ParameterMode.IN);
160: call.addParameter("Quantity", XMLType.XSD_INT,
161: ParameterMode.IN);
162: Object r = call.invoke(new Object[] { "widget",
163: new Integer(10) });
164:
165: /*
166: sd.addOutputParam("RequestForQuoteResult",
167: SOAPTypeMappingRegistry.XSD_DOUBLE);
168: sd.addOutputParam("Result",
169: SOAPTypeMappingRegistry.XSD_DOUBLE);
170: sd.addOutputParam("return",
171: SOAPTypeMappingRegistry.XSD_DOUBLE);
172: */
173:
174: // ??? if ( r instanceof Float ) r = ((Float)r).toString();
175: if (r instanceof String)
176: r = new Double((String) r);
177: Double res = (Double) r;
178: return (res.doubleValue());
179: } catch (Exception e) {
180: e.printStackTrace();
181: throw e;
182: }
183: }
184:
185: public String simpleBuy(String serverURL, int quantity)
186: throws Exception {
187: try {
188: Service service = new Service();
189: Call call = (Call) service.createCall();
190:
191: call.setTargetEndpointAddress(new URL(serverURL));
192: call.setUseSOAPAction(true);
193: call
194: .setSOAPActionURI("http://www.soapinterop.org/SimpleBuy");
195: call.setOperationName(new QName(
196: "http://www.soapinterop.org/Bid", "SimpleBuy"));
197: call.setReturnType(XMLType.XSD_STRING);
198: call.addParameter("Address", XMLType.XSD_STRING,
199: ParameterMode.IN);
200: call.addParameter("ProductName", XMLType.XSD_STRING,
201: ParameterMode.IN);
202: call.addParameter("Quantity", XMLType.XSD_INT,
203: ParameterMode.IN);
204:
205: String res = (String) call.invoke(new Object[] {
206: "123 Main St.", "Widget", new Integer(quantity) });
207:
208: /* sd.addOutputParam("SimpleBuyResult",
209: SOAPTypeMappingRegistry.XSD_STRING);
210: sd.addOutputParam("Result",
211: SOAPTypeMappingRegistry.XSD_STRING);
212: sd.addOutputParam("return",
213: SOAPTypeMappingRegistry.XSD_STRING); */
214:
215: return (res);
216: } catch (Exception e) {
217: e.printStackTrace();
218: throw e;
219: }
220: }
221:
222: public String buy(String serverURL, int quantity, int numItems,
223: double price) throws Exception {
224: try {
225: int i;
226:
227: Service service = new Service();
228: Call call = (Call) service.createCall();
229:
230: call.setTargetEndpointAddress(new URL(serverURL));
231: call.setUseSOAPAction(true);
232: call.setSOAPActionURI("http://www.soapinterop.org/Buy");
233: call.setReturnType(XMLType.XSD_STRING);
234:
235: /* sd.addOutputParam("BuyResult",
236: SOAPTypeMappingRegistry.XSD_STRING);
237: sd.addOutputParam("Result",
238: SOAPTypeMappingRegistry.XSD_STRING);
239: sd.addOutputParam("return",
240: SOAPTypeMappingRegistry.XSD_STRING); */
241:
242: // register the PurchaseOrder class
243: QName poqn = new QName("http://www.soapinterop.org/Bid",
244: "PurchaseOrder");
245: Class cls = PurchaseOrder.class;
246: call.registerTypeMapping(cls, poqn,
247: BeanSerializerFactory.class,
248: BeanDeserializerFactory.class);
249:
250: // register the Address class
251: QName aqn = new QName("http://www.soapinterop.org/Bid",
252: "Address");
253: cls = Address.class;
254: call.registerTypeMapping(cls, aqn,
255: BeanSerializerFactory.class,
256: BeanDeserializerFactory.class);
257:
258: // register the LineItem class
259: QName liqn = new QName("http://www.soapinterop.org/Bid",
260: "LineItem");
261: cls = LineItem.class;
262: call.registerTypeMapping(cls, liqn,
263: BeanSerializerFactory.class,
264: BeanDeserializerFactory.class);
265:
266: LineItem[] lineItems = new LineItem[numItems];
267:
268: for (i = 0; i < numItems; i++)
269: lineItems[i] = new LineItem("Widget" + i, quantity,
270: new BigDecimal(price));
271:
272: PurchaseOrder po = new PurchaseOrder("PO1", Calendar
273: .getInstance(), new Address("Mr Big",
274: "40 Wildwood Lane", "Weston", "CT", "06883"),
275: new Address("Mr Big's Dad", "40 Wildwood Lane",
276: "Weston", "CT", "06883"), lineItems);
277:
278: call.addParameter("PO", poqn, ParameterMode.IN);
279: call.setOperationName(new QName(
280: "http://www.soapinterop.org/Bid", "Buy"));
281:
282: String res = (String) call.invoke(new Object[] { po });
283:
284: return (res);
285: } catch (Exception e) {
286: e.printStackTrace();
287: throw e;
288: }
289: }
290:
291: }
|