FileDocCategorySizeDatePackage
DelayedStockQuote.javaAPI DocApache Axis 1.42925Sat Apr 22 18:56:52 BST 2006samples.jaxm

DelayedStockQuote

public class DelayedStockQuote extends Object

Fields Summary
Constructors Summary
Methods Summary
public java.lang.StringgetStockQuote(java.lang.String tickerSymbol)

        SOAPConnectionFactory scFactory = SOAPConnectionFactory.newInstance();
        SOAPConnection con = scFactory.createConnection();

        MessageFactory factory = MessageFactory.newInstance();
        SOAPMessage message = factory.createMessage();

        SOAPPart soapPart = message.getSOAPPart();
        SOAPEnvelope envelope = soapPart.getEnvelope();

        SOAPHeader header = envelope.getHeader();
        SOAPBody body = envelope.getBody();

        header.detachNode();

        Name bodyName = envelope.createName("getQuote", "n", "urn:xmethods-delayed-quotes");
        SOAPBodyElement gltp = body.addBodyElement(bodyName);

        Name name = envelope.createName("symbol");
        SOAPElement symbol = gltp.addChildElement(name);
        symbol.addTextNode(tickerSymbol);

        URLEndpoint endpoint = new URLEndpoint("http://64.124.140.30/soap");
        SOAPMessage response = con.call(message, endpoint);
        con.close();

        SOAPPart sp = response.getSOAPPart();
        SOAPEnvelope se = sp.getEnvelope();
        SOAPBody sb = se.getBody();
        Iterator it = sb.getChildElements();
        while (it.hasNext()) {
            SOAPBodyElement bodyElement = (SOAPBodyElement) it.next();
            Iterator it2 = bodyElement.getChildElements();
            while (it2.hasNext()) {
                SOAPElement element2 = (SOAPElement) it2.next();
                return element2.getValue();
            }
        }
        return null;
    
public static voidmain(java.lang.String[] args)

        DelayedStockQuote stockQuote = new DelayedStockQuote();
        System.out.print("The last price for SUNW is " + stockQuote.getStockQuote("SUNW"));