java.lang.reflect.InvocationTargetException

Discussions

XML & Web services: java.lang.reflect.InvocationTargetException

  1. java.lang.reflect.InvocationTargetException (1 messages)

    Hi All: I am using Tomcat 5.5, Axis 1.4, and myEclipse 5.5. I am new to java web services and Axis. I am trying an example from the book "Beginning Java Web Services" by Henry Bequet. This is the Stock Quote example on Chapter 3 page 113. When I tried the following url:http://localhost:8080/axis/ It gives me a list of web services deployed. There is a link: List -View the list of deployed Web Services Here is the source code for StockCore.java: [QUOTE] package com.wrox.jws.stockcore; import org.w3c.dom.Document; import org.w3c.dom.Element; import org.w3c.dom.Attr; import org.w3c.dom.NodeList; import org.apache.xerces.parsers.DOMParser; import org.xml.sax.InputSource; public class StockCore { 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)); DOMParser domParser = new DOMParser(); domParser.parse(in); doc = domParser.getDocument(); System.out.println("New"); } public static void main(String args[]) throws Exception { if(args.length != 1) { System.out.println("Usage: java dom.StockCore "); System.exit(0); } StockCore stockCore = new StockCore(); System.out.println("The ask price for " + args[0] + " is " + stockCore.getQuote(args[0])); } public String getQuote(String symbol) throws Exception { 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"); } } return""; } [/QUOTE] Here is the client code that calls the method getQuote in the StockCore.java class. I passed the parameter "IBM" to the StockQuote class below: [QUOTE] 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" + " "); 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(); } } } [/QUOTE] Before I ran the client code that calls the web service. I needed to tell Axis that StockQuote is a valid web service. This is done with the help of a deployment descriptor and the Axis AdminClient(make sure that Tomcat is running before launching these commands). Here is the value of the StockQuote.wsdd: [QUOTE] [/QUOTE] Here is the command I ran: C:\Beginning_JWS_Examples\Chp03\StockQuote\src>java org.apache.axis.client.AdminClient ..\StockQuote.wsdd Processing file ..\StockQuote.wsdd Done processing Here is the error message I get when I called the client code StockQuote.java : StockQuote.main: java.lang.reflect.InvocationTargetException AxisFault faultCode: {http://schemas.xmlsoap.org/soap/envelope/}Server.userException faultSubcode: faultString: java.lang.reflect.InvocationTargetException faultActor: faultNode: faultDetail: {http://xml.apache.org/axis/}hostname:albertlam java.lang.reflect.InvocationTargetException at org.apache.axis.message.SOAPFaultBuilder.createFault(SOAPFaultBuilder.java:222) at org.apache.axis.message.SOAPFaultBuilder.endElement(SOAPFaultBuilder.java:129) at org.apache.axis.encoding.DeserializationContext.endElement(DeserializationContext.java:1087) at org.apache.xerces.parsers.AbstractSAXParser.endElement(Unknown Source) at org.apache.xerces.impl.XMLNSDocumentScannerImpl.scanEndElement(Unknown Source) at org.apache.xerces.impl.XMLDocumentFragmentScannerImpl$FragmentContentDispatcher.dispatch(Unknown Source) at org.apache.xerces.impl.XMLDocumentFragmentScannerImpl.scanDocument(Unknown Source) at org.apache.xerces.parsers.XML11Configuration.parse(Unknown Source) at org.apache.xerces.parsers.XML11Configuration.parse(Unknown Source) at org.apache.xerces.parsers.XMLParser.parse(Unknown Source) at org.apache.xerces.parsers.AbstractSAXParser.parse(Unknown Source) at org.apache.xerces.jaxp.SAXParserImpl$JAXPSAXParser.parse(Unknown Source) at org.apache.xerces.jaxp.SAXParserImpl.parse(Unknown Source) at org.apache.axis.encoding.DeserializationContext.parse(DeserializationContext.java:227) at org.apache.axis.SOAPPart.getAsSOAPEnvelope(SOAPPart.java:696) at org.apache.axis.Message.getSOAPEnvelope(Message.java:435) at org.apache.axis.handlers.soap.MustUnderstandChecker.invoke(MustUnderstandChecker.java:62) at org.apache.axis.client.AxisClient.invoke(AxisClient.java:206) at org.apache.axis.client.Call.invokeEngine(Call.java:2784) at org.apache.axis.client.Call.invoke(Call.java:2767) at org.apache.axis.client.Call.invoke(Call.java:2443) at org.apache.axis.client.Call.invoke(Call.java:2366) at org.apache.axis.client.Call.invoke(Call.java:1812) at com.wrox.jws.stockquote.StockQuote.main(StockQuote.java:45) Any hint would be greatly appreciated. Yours, Frustrated.
  2. Is your problem solved ? Please let me know as even i have a similar problem. Thanks