1 package samples.bidbuy ; 2 3 import org.apache.axis.client.Call; 4 import org.apache.axis.client.Service; 5 import org.apache.axis.encoding.XMLType; 6 import org.apache.axis.encoding.ser.BeanDeserializerFactory; 7 import org.apache.axis.encoding.ser.BeanSerializerFactory; 8 9 import javax.xml.namespace.QName ; 10 import javax.xml.rpc.ParameterMode ; 11 import java.math.BigDecimal ; 12 import java.net.URL ; 13 import java.util.Calendar ; 14 import java.util.StringTokenizer ; 15 import java.util.Vector ; 16 17 public class v3 implements vInterface { 18 public void register(String registryURL, samples.bidbuy.Service s) 19 throws Exception { 20 try { 21 Service service = new Service(); 22 Call call = (Call) service.createCall(); 23 24 call.setTargetEndpointAddress( new URL (registryURL) ); 25 call.setOperationName( new QName ("http://www.soapinterop.org/Register", "Register" )); 26 call.addParameter("ServiceName", XMLType.XSD_STRING, ParameterMode.IN); 27 call.addParameter("ServiceUrl", XMLType.XSD_STRING, ParameterMode.IN); 28 call.addParameter("ServiceType", XMLType.XSD_STRING, ParameterMode.IN); 29 call.addParameter("ServiceWSDL", XMLType.XSD_STRING, ParameterMode.IN); 30 31 call.invoke( new Object [] { s.getServiceName(), s.getServiceUrl(), 32 s.getServiceType(), s.getServiceWsdl() } ); 33 } 34 catch( Exception e ) { 35 e.printStackTrace(); 36 throw e ; 37 } 38 } 39 40 public void unregister(String registryURL, String name) throws Exception { 41 try { 42 Service service = new Service(); 43 Call call = (Call) service.createCall(); 44 45 call.setTargetEndpointAddress( new URL (registryURL) ); 46 call.setOperationName( new QName ("http://www.soapinterop.org/Unregister", "Unregister" )); 47 call.addParameter( "ServiceName", XMLType.XSD_STRING, ParameterMode.IN); 48 call.invoke( new Object [] { name } ); 49 } 50 catch( Exception e ) { 51 e.printStackTrace(); 52 throw e ; 53 } 54 } 55 56 public Boolean ping(String serverURL) throws Exception { 57 try { 58 Service service = new Service(); 59 Call call = (Call) service.createCall(); 60 61 call.setTargetEndpointAddress( new URL (serverURL) ); 62 call.setUseSOAPAction( true ); 63 call.setSOAPActionURI( "http://www.soapinterop.org/Ping" ); 64 call.setOperationName( new QName ("http://www.soapinterop.org/Bid", "Ping" )); 65 call.invoke( (Object []) null ); 66 return( new Boolean (true) ); 67 } 68 catch( Exception e ) { 69 e.printStackTrace(); 70 throw e ; 71 } 72 } 73 74 public Vector lookupAsString(String registryURL) throws Exception 75 { 76 try { 77 Service service = new Service(); 78 Call call = (Call) service.createCall(); 79 80 call.setTargetEndpointAddress( new URL (registryURL) ); 81 call.setUseSOAPAction( true ); 82 call.setSOAPActionURI( "http://www.soapinterop.org/LookupAsString" ); 83 call.setOperationName( new QName ("http://www.soapinterop.org/Registry", "LookupAsString" )); 84 call.addParameter( "ServiceType", XMLType.XSD_STRING, ParameterMode.IN); 85 call.setReturnType( XMLType.XSD_DOUBLE ); 86 87 String res= (String ) call.invoke( new Object [] { "Bid" } ); 88 89 if ( res == null ) return( null ); 90 StringTokenizer lineParser = new StringTokenizer ( res, "\n" ); 91 92 Vector services = new Vector (); 93 while ( lineParser.hasMoreTokens() ) { 94 String line = (String ) lineParser.nextElement(); 95 StringTokenizer wordParser = new StringTokenizer ( line, "\t" ); 96 samples.bidbuy.Service s = null ; 97 98 for ( int i = 0 ; wordParser.hasMoreTokens() && i < 4 ; i++ ) 99 switch(i) { 100 case 0 : s = new samples.bidbuy.Service(); 101 if ( services == null ) services = new Vector (); 102 services.add( s ); 103 s.setServiceName( (String ) wordParser.nextToken()); 104 break ; 105 case 1 : s.setServiceUrl( (String ) wordParser.nextToken()); 106 break ; 107 case 2 : s.setServiceType( (String ) wordParser.nextToken()); 108 break ; 109 case 3 : s.setServiceWsdl( (String ) wordParser.nextToken()); 110 break ; 111 } 112 } 113 return( services ); 114 } 115 catch( Exception e ) { 116 e.printStackTrace(); 117 throw e ; 118 } 119 } 120 121 public double requestForQuote(String serverURL) throws Exception { 122 try { 123 124 Service service = new Service(); 125 Call call = (Call) service.createCall(); 126 127 call.setTargetEndpointAddress( new URL (serverURL) ); 128 call.setOperationName(new QName ("http://www.soapinterop.org/Bid", "RequestForQuote") ); 129 call.setReturnType( XMLType.XSD_DOUBLE ); 130 call.setUseSOAPAction( true ); 131 call.setSOAPActionURI( "http://www.soapinterop.org/RequestForQuote" ); 132 call.addParameter( "ProductName", XMLType.XSD_STRING, ParameterMode.IN); 133 call.addParameter( "Quantity", XMLType.XSD_INT, ParameterMode.IN); 134 Object r = call.invoke( new Object [] { "widget", new Integer (10) } ); 135 136 144 145 if ( r instanceof String ) r = new Double ((String ) r); 147 Double res = (Double ) r ; 148 return( res.doubleValue() ); 149 } 150 catch( Exception e ) { 151 e.printStackTrace(); 152 throw e ; 153 } 154 } 155 156 public String simpleBuy(String serverURL, int quantity ) throws Exception { 157 try { 158 Service service = new Service(); 159 Call call = (Call) service.createCall(); 160 161 call.setTargetEndpointAddress( new URL (serverURL) ); 162 call.setUseSOAPAction( true ); 163 call.setSOAPActionURI( "http://www.soapinterop.org/SimpleBuy" ); 164 call.setOperationName( new QName ("http://www.soapinterop.org/Bid", "SimpleBuy") ); 165 call.setReturnType( XMLType.XSD_STRING ); 166 call.addParameter( "Address", XMLType.XSD_STRING, ParameterMode.IN ); 167 call.addParameter( "ProductName", XMLType.XSD_STRING, ParameterMode.IN); 168 call.addParameter( "Quantity", XMLType.XSD_INT, ParameterMode.IN ); 169 170 String res = (String ) call.invoke(new Object [] { "123 Main St.", 171 "Widget", 172 new Integer (quantity)}); 173 174 180 181 return( res ); 182 } 183 catch( Exception e ) { 184 e.printStackTrace(); 185 throw e ; 186 } 187 } 188 189 public String buy(String serverURL, int quantity, int numItems, double price) 190 throws Exception 191 { 192 try { 193 int i ; 194 195 Service service = new Service(); 196 Call call = (Call) service.createCall(); 197 198 call.setTargetEndpointAddress( new URL (serverURL) ); 199 call.setUseSOAPAction( true ); 200 call.setSOAPActionURI( "http://www.soapinterop.org/Buy" ); 201 call.setReturnType( XMLType.XSD_STRING ); 202 203 209 210 211 QName poqn = new QName ("http://www.soapinterop.org/Bid", "PurchaseOrder"); 213 Class cls = PurchaseOrder.class; 214 call.registerTypeMapping(cls, poqn, BeanSerializerFactory.class, BeanDeserializerFactory.class); 215 216 QName aqn = new QName ("http://www.soapinterop.org/Bid", "Address"); 218 cls = Address.class; 219 call.registerTypeMapping(cls, aqn, BeanSerializerFactory.class, BeanDeserializerFactory.class); 220 221 QName liqn = new QName ("http://www.soapinterop.org/Bid", "LineItem"); 223 cls = LineItem.class; 224 call.registerTypeMapping(cls, liqn, BeanSerializerFactory.class, BeanDeserializerFactory.class); 225 226 LineItem[] lineItems = new LineItem[numItems]; 227 228 229 for ( i = 0 ; i < numItems ; i++ ) 230 lineItems[i] = new LineItem("Widget"+i,quantity,new BigDecimal (price)); 231 232 PurchaseOrder po = new PurchaseOrder( "PO1", 233 Calendar.getInstance(), 234 new Address("Mr Big", 235 "40 Wildwood Lane", 236 "Weston", 237 "CT", 238 "06883"), 239 new Address("Mr Big's Dad", 240 "40 Wildwood Lane", 241 "Weston", 242 "CT", 243 "06883"), 244 lineItems ); 245 246 call.addParameter( "PO", poqn, ParameterMode.IN ); 247 call.setOperationName( new QName ("http://www.soapinterop.org/Bid", "Buy") ); 248 249 String res = (String ) call.invoke( new Object [] { po } ); 250 251 return( res ); 252 } 253 catch( Exception e ) { 254 e.printStackTrace(); 255 throw e ; 256 } 257 } 258 259 } 260 261 | Popular Tags |