FileDocCategorySizeDatePackage
GetQuote.javaAPI DocApache Axis 1.43979Sat Apr 22 18:56:52 BST 2006samples.transport.tcp

GetQuote

public class GetQuote extends Object
author
Doug Davis (dug@us.ibm.com.com)

Fields Summary
public String
symbol
Constructors Summary
public GetQuote()

    
Methods Summary
public floatgetQuote(java.lang.String[] args)

        Call.addTransportPackage("samples.transport");
        Call.setTransportForProtocol("tcp", TCPTransport.class);
        
        Options opts = new Options( args );
        
        args = opts.getRemainingArgs();
        
        if ( args == null ) {
            System.err.println( "Usage: GetQuote <symbol>" );
            System.exit(1);
        }
        
        String namespace = "urn:xmltoday-delayed-quotes";
        symbol = args[0] ;

        EngineConfiguration defaultConfig =
            (new DefaultEngineConfigurationFactory()).
            getClientEngineConfig();
        SimpleProvider config = new SimpleProvider(defaultConfig);
        SimpleTargetedChain c = new SimpleTargetedChain(new TCPSender());
        config.deployTransport("tcp", c);

        Service service = new Service(config);
        Call call = (Call)service.createCall();
        
        call.setTransport(new TCPTransport());
        
        call.setTargetEndpointAddress( new URL(opts.getURL()) );
        call.setOperationName( new QName("urn:xmltoday-delayed-quotes", "getQuote") );
        call.addParameter( "symbol", XMLType.XSD_STRING, ParameterMode.IN );
        call.setReturnType( XMLType.XSD_FLOAT );
        
        // TESTING HACK BY ROBJ
        if (symbol.equals("XXX_noaction")) {
            symbol = "XXX";
        }
        
        call.setUsername( opts.getUser() );
        call.setPassword( opts.getPassword() );
        
        // useful option for profiling - perhaps we should remove before
        // shipping?
        String countOption = opts.isValueSet('c");
        int count=1;
        if ( countOption != null) {
            count=Integer.valueOf(countOption).intValue();
            System.out.println("Iterating " + count + " times");
        }
        
        Float res = new Float(0.0F);
        for (int i=0; i<count; i++) {
            Object ret = call.invoke(new Object[] {symbol} );
            if (ret instanceof String) {
                System.out.println("Received problem response from server: "+ret);
                throw new AxisFault("", (String)ret, null, null);
            }
            res = (Float) ret;
        }
        
        return res.floatValue();
    
public static voidmain(java.lang.String[] args)

        try {
            GetQuote gq = new GetQuote();
            float val = gq.getQuote(args);
            // args array gets side-effected
            System.out.println(gq.symbol + ": " + val);
        }
        catch( Exception e ) {
            e.printStackTrace();
        }