facebook

Debugging web services

  1. MyEclipse Archived
  2.  > 
  3. Web Services
Viewing 2 posts - 1 through 2 (of 2 total)
  • Author
    Posts
  • #271491 Reply

    jadeite1000
    Member

    Hi:

    I am using MyEclipse 5.5, Axis 1.4 and Tomcat 5.
    I started Tomcat 5 from MyEclipse 5.5

    I 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&#8221;;
    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&#8221;;
    public static final String VALIDATION =
    http://xml.org/sax/features/validation&#8221;;
    public static final String SCHEMA_VALIDATION =
    http://apache.org/xml/features/validation/schema&#8221;;
    public static final String SCHEMA_FULL_CHECKING =
    http://apache.org/xml/features/validation/schema-full-checking&#8221;;

    }

    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.

    #271500 Reply

    Loyal Water
    Member

    MyEclipse’s web service support is based entirely around the XFire framework. Sorry about that.

Viewing 2 posts - 1 through 2 (of 2 total)
Reply To: Debugging web services

You must be logged in to post in the forum log in