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