- This topic has 1 reply, 2 voices, and was last updated 17 years, 5 months ago by Loyal Water.
-
AuthorPosts
-
jadeite1000MemberHi:
I am using MyEclipse 5.5, Axis 1.4 and Tomcat 5.
I started Tomcat 5 from MyEclipse 5.5I ran the following client code:
package com.wrox.jws.stockquote;
import org.apache.axis.client.Call;
import org.apache.axis.client.Service;
import org.apache.axis.encoding.XMLType;
import org.apache.axis.utils.Options;import javax.xml.rpc.ParameterMode;
import javax.xml.namespace.QName;import com.wrox.jws.stockcore.StockCore;
public class StockQuote {
public String getQuote(String ticker) throws Exception {
StockCore stockcore = new StockCore();
return stockcore.getQuote(ticker);
}public static void main(String [] args) {
final String methodName = “StockQuote.main”;try {
if(args.length != 1) {
System.err.println(“StockQuote Client”);
System.err.println(
“Usage: java com.wrox.jws.stockquote.StockQuote” +
” <ticker-symbol>”);
System.err.println(
“Example: java com.wrox.jws.stockquote.StockQuote sunw”);
System.exit(1);
}// Replace the following URL with what is suitable for
// your environment http://localhost:8080/axis/servlet/AxisServlet
String endpointURL = “http://localhost:8080/axis/servlet/AxisServlet”;
Service service = new Service();
Call call = (Call)service.createCall();call.setTargetEndpointAddress(new java.net.URL(endpointURL));
call.setOperationName(new QName(“StockQuote”, “getQuote”));
call.addParameter(“ticker”, XMLType.XSD_STRING, ParameterMode.IN);
call.setReturnType(org.apache.axis.encoding.XMLType.XSD_STRING);String ret = (String)call.invoke(new Object[] { args[0] });
System.out.println(“The value of ” + args[0]
+ ” is: ” + ret);} catch (Exception exception) {
System.err.println(methodName + “: ” + exception.toString());
exception.printStackTrace();
}
}
}Here is my web services code: I placed a breakpoint on getQuote function.
Here is my code:
package com.wrox.jws.stockcore.schema;
import org.w3c.dom.Document;
import org.w3c.dom.Element;
import org.w3c.dom.Attr;
import org.w3c.dom.NodeList;import javax.xml.parsers.SAXParser;
import javax.xml.parsers.SAXParserFactory;
import org.xml.sax.XMLReader;import org.xml.sax.InputSource;
import org.apache.xerces.dom.DocumentImpl;public class StockCore {
private static interface FeatureId {
public static final String NAMESPACES =
“http://xml.org/sax/features/namespaces”;
public static final String VALIDATION =
“http://xml.org/sax/features/validation”;
public static final String SCHEMA_VALIDATION =
“http://apache.org/xml/features/validation/schema”;
public static final String SCHEMA_FULL_CHECKING =
“http://apache.org/xml/features/validation/schema-full-checking”;}
private static final String STOCK_FILE = “stock_quote.xml”;
private Document doc;
public Document getDocument() { return doc; }public StockCore() throws Exception {
InputSource in =
new InputSource(
getClass().getClassLoader().getResourceAsStream(STOCK_FILE));SAXParser saxParser = SAXParserFactory.newInstance().newSAXParser();
XMLReader reader = saxParser.getXMLReader();reader.setFeature(FeatureId.NAMESPACES, true);
reader.setFeature(FeatureId.VALIDATION, true);
reader.setFeature(FeatureId.SCHEMA_VALIDATION, true);
reader.setFeature(FeatureId.SCHEMA_FULL_CHECKING, true);StockCoreHandler handler = new StockCoreHandler();
reader.setContentHandler(handler);
reader.setErrorHandler(handler);reader.parse(in);
doc = handler.getDocument();}
public String getQuote(String symbol)
{
try
{Element root = doc.getDocumentElement();
NodeList stockList = root.getElementsByTagName(“stock_quote”);for(int i = 0;i < stockList.getLength();i++) {
Element stockQuoteEl = (Element)stockList.item(i);
Element symbolEl =
(Element)stockQuoteEl.getElementsByTagName(“symbol”).item(0);
if(!symbolEl.getFirstChild().getNodeValue().equals(symbol))
continue;NodeList priceList = stockQuoteEl.getElementsByTagName(“price”);
for(int j = 0;j < priceList.getLength(); j++) {
Element priceEl = (Element)priceList.item(0);
if(priceEl.getAttribute(“type”).equals(“ask”))
return priceEl.getAttribute(“value”);}
}
}
catch(Exception e)
{
System.out.println(“Inside getQuote:”+e.getMessage());
}
return “”;}
public static void main(String args[]) throws Exception {
if(args.length != 1) {
System.out.println(“Usage: java dom.StockCore <symbol>”);
System.exit(0);
}StockCore stockCore = new StockCore();
System.out.println(“The ask price for ” + args[0] + ” is ” +
stockCore.getQuote(args[0]));}
Why does myEclipse doesn’t stop at the breakpoint for the getQuote function?
Yours,
Frustrated.
Loyal WaterMemberMyEclipse’s web service support is based entirely around the XFire framework. Sorry about that.
-
AuthorPosts