Java Reference
In-Depth Information
try {
String fullDate = getEl(node, "Date")+" "+getEl(node, "Time");
fullDate = fullDate.replace("pm", " pm").replace("am", " am");
timestamp = new SimpleDateFormat("M/d/y K:m a",
Locale.ENGLISH).parse(fullDate);
} catch (ParseException e) {
e.printStackTrace();
timestamp = new Date();
}
return new Stock(symbol, name,
last, open, high, low,
volume, timestamp, marketCap,
previousClose, change,
percentageChange, annRangeLow,
annRangeHigh, earns, pe);
}
private static String getEl(Element node, String n) {
return node.getElementsByTagName(n).item(0).getTextContent();
}
}
3.
Also define another helper class, called StockServiceClient , which will communicate with the
SOAP service, like so:
package withoutwsdlobjectoriented;
import javax.xml.namespace.QName;
import javax.xml.soap.MessageFactory;
import javax.xml.soap.MimeHeaders;
import javax.xml.soap.SOAPBody;
import javax.xml.soap.SOAPBodyElement;
import javax.xml.soap.SOAPConnection;
import javax.xml.soap.SOAPConnectionFactory;
import javax.xml.soap.SOAPElement;
import javax.xml.soap.SOAPException;
import javax.xml.soap.SOAPMessage;
public class StockServiceClient {
private final static String SERVICE_HOST = " http://www.webserviceX.NET/";
private final static String SERVICE_METHOD = "GetQuote";
private final static String SERVICE_ENDPOINT = "stockquote.asmx";
public static SOAPMessage getStockQuote(String stockSymbol) {
SOAPConnection soapConnection = null;
try {
SOAPConnectionFactory soapConnectionFactory =
SOAPConnectionFactory.newInstance();
soapConnection =
soapConnectionFactory.createConnection();
SOAPMessage soapResponse = soapConnection.call(
Search WWH ::




Custom Search