W
writeameer
Sorry for the dumb question but I need help. The following is a copy
of Request.java from JavaEETutorial.pdf form the java website.
Except, instead of using an imaginary web site that didn't work
(wombat.ztrade.com), I tried to use a real one (webserviceX.net). I
get a java.util.NoSuchElementException.
Help Please !
import javax.xml.soap.*;
import javax.xml.namespace.QName;
import org.w3c.dom.NodeList;
import java.util.Iterator;
import java.net.URL;
public class Request {
public static void main(String[] args) {
try {
SOAPConnectionFactory soapConnectionFactory =
SOAPConnectionFactory.newInstance();
SOAPConnection connection =
soapConnectionFactory.createConnection();
MessageFactory factory = MessageFactory.newInstance();
SOAPMessage message = factory.createMessage();
SOAPHeader header = message.getSOAPHeader();
SOAPBody body = message.getSOAPBody();
header.detachNode();
QName bodyName = new QName("http://www.webserviceX.NET/",
"GetQuote","m");
SOAPBodyElement bodyElement = body.addBodyElement(bodyName);
QName name = new QName("symbol");
SOAPElement symbol = bodyElement.addChildElement(name);
symbol.addTextNode("SUNW");
URL endpoint = new URL ("http://www.webservicex.net/
stockquote.asmx");
SOAPMessage response = connection.call(message, endpoint);
connection.close();
SOAPBody soapBody = response.getSOAPBody();
Iterator iterator = soapBody.getChildElements(bodyName);
bodyElement = (SOAPBodyElement)iterator.next();
String lastPrice = bodyElement.getValue();
System.out.print("The last price for SUNW is ");
System.out.println(lastPrice);
}
catch (Exception ex) {
ex.printStackTrace();
}
}
}
of Request.java from JavaEETutorial.pdf form the java website.
Except, instead of using an imaginary web site that didn't work
(wombat.ztrade.com), I tried to use a real one (webserviceX.net). I
get a java.util.NoSuchElementException.
Help Please !
import javax.xml.soap.*;
import javax.xml.namespace.QName;
import org.w3c.dom.NodeList;
import java.util.Iterator;
import java.net.URL;
public class Request {
public static void main(String[] args) {
try {
SOAPConnectionFactory soapConnectionFactory =
SOAPConnectionFactory.newInstance();
SOAPConnection connection =
soapConnectionFactory.createConnection();
MessageFactory factory = MessageFactory.newInstance();
SOAPMessage message = factory.createMessage();
SOAPHeader header = message.getSOAPHeader();
SOAPBody body = message.getSOAPBody();
header.detachNode();
QName bodyName = new QName("http://www.webserviceX.NET/",
"GetQuote","m");
SOAPBodyElement bodyElement = body.addBodyElement(bodyName);
QName name = new QName("symbol");
SOAPElement symbol = bodyElement.addChildElement(name);
symbol.addTextNode("SUNW");
URL endpoint = new URL ("http://www.webservicex.net/
stockquote.asmx");
SOAPMessage response = connection.call(message, endpoint);
connection.close();
SOAPBody soapBody = response.getSOAPBody();
Iterator iterator = soapBody.getChildElements(bodyName);
bodyElement = (SOAPBodyElement)iterator.next();
String lastPrice = bodyElement.getValue();
System.out.print("The last price for SUNW is ");
System.out.println(lastPrice);
}
catch (Exception ex) {
ex.printStackTrace();
}
}
}