axis-java-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Daniel Keltner <dank...@yahoo.com>
Subject Help: java.lang.reflect.InvocationTargetException
Date Fri, 19 Apr 2002 00:13:13 GMT
hi all,

I am running Axis beta 1 under Tomcat 4 on a Linux
Box.

I have a simple java application that has a method
called getResults that takes a String ("cityName"),
uses a SAXParser to parse an xml file, searches for
the element with that city name, and returns a string
with the contents for that city.

This code works fine when I run it from the command
line, but when I tried to place it under Axis and
access it as a web service, it gave me the following
stackTrace:

Exception in thread "main"
java.lang.reflect.InvocationTargetException
        at
org.apache.axis.message.SOAPFaultBuilder.endElement(Unknown
Source)
        at
org.apache.axis.encoding.DeserializationContextImpl.endElement(Unknown
Source)
        at
org.apache.xerces.parsers.SAXParser.endElement(SAXParser.java:1403)
        at
org.apache.xerces.validators.common.XMLValidator.callEndElement(XMLValidator.java:1550)
        at
org.apache.xerces.framework.XMLDocumentScanner$ContentDispatcher.dispatch(XMLDocumentScanner.java:1204)
        at
org.apache.xerces.framework.XMLDocumentScanner.parseSome(XMLDocumentScanner.java:381)
        at
org.apache.xerces.framework.XMLParser.parse(XMLParser.java:1098)
        at
javax.xml.parsers.SAXParser.parse(SAXParser.java:393)
        at
org.apache.axis.encoding.DeserializationContextImpl.parse(Unknown
Source)
        at
org.apache.axis.SOAPPart.getAsSOAPEnvelope(Unknown
Source)
        at org.apache.axis.client.Call.invoke(Unknown
Source)
        at org.apache.axis.client.Call.invoke(Unknown
Source)
        at org.apache.axis.client.Call.invoke(Unknown
Source)
        at org.apache.axis.client.Call.invoke(Unknown
Source)
        at WTClient.main(WTClient.java:40)

My code for the web service (the .jws file) is as
follows:

import org.xml.sax.helpers.DefaultHandler;
import org.xml.sax.ContentHandler;
import org.xml.sax.SAXException;
import org.xml.sax.SAXParseException;
import org.xml.sax.Attributes;
import org.xml.sax.XMLReader;
import org.xml.sax.helpers.XMLReaderFactory;
import org.apache.xerces.parsers.SAXParser;



class WeatherParser {

	private String cityName = "Tucson";
	private String output = "";
    String results;
	StringBuffer buffer = new StringBuffer();

	public void setCityName (String n) {
		this.cityName = n;
	}

	public String getCityName () {
		return this.cityName;
	}

	public void setOutput (String n) {
		this.output = n;
	}

	public static void main(String[] args) {
		new WeatherParser(args);
	}

	WeatherParser (String [] args) {
		if (args.length > 0) {
			setCityName(args[0]);
		}
		output = getResults("");
		System.out.println (output);
	}

	public String getResults (String fileName) {

		try {
			XMLReader parser = new SAXParser();
			parser.setContentHandler(new CH());
			parser.parse("weather.xml");
		}

		catch(Exception e) {
			System.out.println(e);
		}
		results = buffer.toString();
		return results;
	}

	class CH extends DefaultHandler {

		boolean cityNameElementFlag = false;
		boolean currentWeatherFlag = false;
		boolean weekdayFlag = false;
		boolean monthFlag = false;
		boolean dayOfMonthFlag = false;
		boolean precipitationFlag = false;
		boolean conditionsFlag = false;
		boolean highFlag = false;
		boolean lowFlag = false;
		boolean forecastFlag = false;
		boolean cityFoundFlag = false;
		String name = cityName.toUpperCase();
		String weekday;
		String month;
		String dayOfMonth;

		public void startDocument() throws SAXException {
			//System.out.println("cityName = "+name);
		}

		public void endDocument() throws SAXException {}

		public void startElement(String nameSpaceURI, String
localName, String rawName, Attributes atts)
			throws SAXException {
				if (localName.equals("CITY_NAME")) {
					cityNameElementFlag = true;
					//System.out.println("Found a CITY_NAME tag");
				} else if ( localName.equals("CURRENT_WEATHER") )
{
					if (cityFoundFlag) {
						buffer.append(" Latest weather for ");
					}
					currentWeatherFlag = true;					
				} else if ( localName.equals("WEEKDAY") ) {
					weekdayFlag = true;
				} else if ( localName.equals("MONTH") ) {
					monthFlag = true;
				} else if ( localName.equals("DAYOFMONTH") ) {
					dayOfMonthFlag = true;
				} else if ( localName.equals("PRECIPITATION") ) {
					precipitationFlag = true;
				} else if ( localName.equals("HIGH") ) {
					highFlag = true;
				} else if ( localName.equals("LOW") ) {
					lowFlag = true;
				} else if ( localName.equals("CONDITIONS") ) {
					conditionsFlag = true;
				} else if ( localName.equals("FORECAST") ) {
					if (cityFoundFlag) {
						buffer.append(" Forecasted weather for ");
					}
					forecastFlag = true;
				}
		}

		public void endElement(String nameSpaceURI, String
localName, String rawName)
			throws SAXException {
				if ( localName.equals("CITY_NAME") ) {
					cityNameElementFlag = false;
				} else if ( localName.equals("CITY") ) {
					cityFoundFlag = false;
				} else if ( localName.equals("CURRENT_WEATHER") )
{
					currentWeatherFlag = false;
				} else if ( localName.equals("WEEKDAY") ) {
					if (cityFoundFlag) {
						buffer.append(weekday + " ");
					}
					weekdayFlag = false;
				} else if ( localName.equals("MONTH") ) {
					if (cityFoundFlag) {
						buffer.append(month + ", ");
					}
					monthFlag = false;
				} else if ( localName.equals("DAYOFMONTH") ) {
					if (cityFoundFlag) {
						buffer.append(dayOfMonth + "\n");
					}
					dayOfMonthFlag = false;
				} else if ( localName.equals("PRECIPITATION") ) {
					precipitationFlag = false;
				} else if ( localName.equals("HIGH") ) {
					highFlag = false;
				} else if ( localName.equals("LOW") ) {
					lowFlag = false;
				} else if ( localName.equals("CONDITIONS") ) {
					conditionsFlag = false;
				} else if ( localName.equals("FORECAST") ) {
					forecastFlag = false;
				}
					
		}

		public void characters(char[] ch, int start, int
length) throws SAXException {
			String text = new String(ch,start,length);

			if (cityNameElementFlag) {
				//System.out.println("City name = "+text);
				if (text.indexOf(name) > -1) {
					cityFoundFlag = true;
					//System.out.println("Found city:"+name);
					buffer.append("Weather for the city of
"+text+"\n");
				}
			} else if (weekdayFlag) {
				weekday = text;
			} else if (monthFlag) {
				month = text;
			} else if (dayOfMonthFlag) {
				dayOfMonth = text;
			}  

			if (cityFoundFlag) {
				if (precipitationFlag) {
					buffer.append("  - precipitation: "+text+" (last
24 hours)\n");
				} else if (highFlag) {
					buffer.append("  - high: "+text+"F\n");
				} else if (lowFlag) {
					buffer.append("  - low: "+text+"F\n");
				} else if (conditionsFlag) {
					buffer.append("  - conditions: "+text+"\n");
				}
			}
		}
	}
}

Anyone have any ideas why it won't run as a web
service?

Thanks for any help.

__________________________________________________
Do You Yahoo!?
Yahoo! Tax Center - online filing with TurboTax
http://taxes.yahoo.com/

Mime
View raw message