14 years ago
Question about Java client code for SOAP
Wow, I'm convinced SoapUI will make a nice mock for a web server that I must hit (and is still being created by someone else).
I haven't done much web programming and all they can tell me is "we're using SOAP."
Questions:
1. Does SoapUI generate any stubs or starter code that would help me get started on the client code?
2. Is Soap so standardized that client code should be some kind of no brainer?
3. Is the following code somewhat close to what I should do? I include the link to oracle as well as the code they give, which is not too long.
http://docs.oracle.com/javaee/5/tutorial/doc/bnbis.html
TIA,
BE
===================================
I haven't done much web programming and all they can tell me is "we're using SOAP."
Questions:
1. Does SoapUI generate any stubs or starter code that would help me get started on the client code?
2. Is Soap so standardized that client code should be some kind of no brainer?
3. Is the following code somewhat close to what I should do? I include the link to oracle as well as the code they give, which is not too long.
http://docs.oracle.com/javaee/5/tutorial/doc/bnbis.html
TIA,
BE
import javax.xml.soap.*;
import javax.xml.namespace.QName;
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://wombat.ztrade.com",
"GetLastTradePrice", "m");
SOAPBodyElement bodyElement = body.addBodyElement(bodyName);
QName name = new QName("symbol");
SOAPElement symbol = bodyElement.addChildElement(name);
symbol.addTextNode("SUNW");
URL endpoint = new URL("http://wombat.ztrade.com/quotes");
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();
}
}
}
===================================