Can i have a sample JAXM Client that connects to say a Stock Quote Service from XMethods.net?
Created May 7, 2012
Davanum Srinivas Here's a sample JAXM Client that connects to "Delayed Stock Quote" Service from http://www.xmethods.net/. JAXM is part of the Winter JAX Pack that can be downloaded from http://java.sun.com/xml/downloads/javaxmlpack.html.
import javax.xml.soap.*; import javax.xml.messaging.*; import java.io.*; import java.util.*; public class Request { public static void main(String[] args) { try { 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); if(args.length <= 0) symbol.addTextNode("SUNW"); else symbol.addTextNode(args[0]); URLEndpoint endpoint = new URLEndpoint("http://64.39.29.211:9090/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(); String lastPrice = element2.getValue(); System.out.print("The last price is "); System.out.println(lastPrice); } } } catch (Exception ex) { ex.printStackTrace(); } } }