As I mentioned a few threads back, set up logging and you should see the root cause of the problem.
Jeff ----- Original Message ----- From: "James Taylor" <[EMAIL PROTECTED]> To: <[email protected]> Sent: Thursday, June 02, 2005 4:30 PM Subject: Re: really anoying problem I think its happening somewhere around DOMGetFlightsXMLImpl.transformDOMtoString(Document) call, but cant figure out why??!! Quoting James Taylor <[EMAIL PROTECTED]>: > Hey folks, > apologies for sending such a long mail, I've this web service > that keeps throwing this really annoying > java.lang.reflect.InvocationTargetException and would really appreciate it if > someone could help me put my finger on whats going wrong cause I'm at my wits > end. This is the error I keep getting back: > > HTTP/1.1 500 Internal Server Error > Set-Cookie: JSESSIONID=AD9B5C8B6BB70316879AE7CF8219794E; Path=/axis > Content-Type: text/xml;charset=utf-8 > Date: Thu, 02 Jun 2005 19:39:10 GMT > Server: Apache-Coyote/1.1 > Connection: close > > <soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" > xmlns:xsd="http://www.w3.org/2001/XMLSchema" > xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"><soapenv:Body><soapenv :Fault><faultcode>soapenv:Server.userException</faultcode><faultstring>java. lang.reflect.InvocationTargetException</faultstring><detail><ns1:hostname > xmlns:ns1="http://xml.apache.org/axis/">taylorjw</ns1:hostname></detail></so apenv:Fault></soapenv:Body></soapenv:Envelope> > > ...the web service takes a list of flights in the form and makes an xml > string > out of them using DOM. I know the xml stuff works on its own but I think > thats > where the error is somehow happening but I cant for the life of me figure out > where. The code for the web service is > > package flightCompany.rpcservice; > > import java.util.Iterator; > import java.util.LinkedList; > > import flightCompany.xmlHelper.DOMGetFlightsXMLImpl; > import flightCompany.xmlHelper.GetFlightsXMLIF; > import flightCompany.model.Flight; > > /** > * A JAX-RPC Web service that takes a date and returns a xml String of > flights > * available on that date. > * Created on 11-May-2005 > * @author James Taylor > * @version 1.1 > */ > > public class FlightInfoService implements FlightInfoServiceIF{ > > /** > * returns as string representation of a list of available flights. > * @param date date of flights to search for. > * @return xml String of available flights > * @throws ava.rmi.RemoteException > */ > public String getFlights(String date) throws java.rmi.RemoteException{ > Flight f = new Flight(); > Flight fl = new Flight(); > LinkedList flights = new LinkedList(); > flights.add( f ); > flights.add( fl ); > // Instantiate the XMLHelper > GetFlightsXMLIF xmlHelper = new DOMGetFlightsXMLImpl(); > System.out.println("about to convert to string"); > //turn list to xml > String result = xmlHelper.getFlightListAsXMLString( flights.iterator() > ); > System.out.println("Got me xml shit"); > return result; > } > > > } > > ....the code for a flight object is your ordinary bean kinda stuff > > /* > * Created on 11-May-2005 > */ > package flightCompany.model; > > > > /** > * Data model of a FlightInfo table entry, mapping the database model and the > xml we receive. > * @author James Taylor > * @version 1.1 > */ > public class Flight{ > private int flightNum; > private String sourceAirport; > private String destAirport; > private String flightDate; > private int seatsAvailible; > private int seatPrice; > private String numberOfSeatsToBook; > private int bookingNumber; > > /** > * Default constructor used in xml mapping, it just initialises and creates > instance variables > */ > public Flight() { > this.sourceAirport = ""; > this.destAirport = ""; > this.flightDate = ""; > this.seatPrice = 0; > this.seatsAvailible = 0; > this.flightNum = 0; > this.numberOfSeatsToBook = ""; > bookingNumber = 0; > } > > /** > * constructor used to map the database model > * @param ID flight id > * @param src source airport > * @param dest destination airport > * @param date date of flight > * @param seatsAv number of seats available > * @param price price of a seat > */ > public Flight(int ID, String src, String dest, String date, int seatsAv, int > price) { > flightNum = ID; > sourceAirport = src; > destAirport = dest; > flightDate = date; > seatsAvailible = seatsAv; > seatPrice = price; > this.numberOfSeatsToBook = ""; > bookingNumber = 0; > } > > public void setNumberOfSeatsToBook(String n){ numberOfSeatsToBook = n; } > public String getNumberOfSeatsToBook(){ return numberOfSeatsToBook; } > > public void setFlightNum(int n){ flightNum = n; } > public int getFlightNum(){ return flightNum; } > > public void setSourceAirport(String src){ sourceAirport = src; } > public String getSourceAirport(){ return sourceAirport; } > > public void setDestAirport(String src){ destAirport = src; } > public String getDestAirport(){ return destAirport; } > > public void setFlightDate(String src){ flightDate = src; } > public String getFlightDate(){ return flightDate; } > > public void setSeatsAvailible(int n){ seatsAvailible = n; } > public int getSeatsAvailible(){ return seatsAvailible; } > > public void setSeatPrice(int n){ seatPrice = n; } > public int getSeatPrice(){ return seatPrice; } > > public void setBookingNumber(int n){ bookingNumber = n; } > public int getBookingNumber(){ return bookingNumber; } > > public void print() { > System.out.println("Flight num : " +flightNum); > System.out.println("\nLeaving : "+sourceAirport); > System.out.println("\nArriving in : " +destAirport); > System.out.println("\nDate : "+flightDate); > System.out.println("\nAvailable seats : "+seatsAvailible); > System.out.println( "\nSeat price : "+ seatPrice ); > System.out.println( "\nNo of seats requested : " +numberOfSeatsToBook ); > System.out.println( "\nBooking no : "+bookingNumber ); > } > > public String toString(){ > StringBuffer sb = new StringBuffer(); > sb.append( "Flight num : " ); > sb.append( String.valueOf( flightNum ) ); > sb.append( "\nLeaving : " ); > sb.append( sourceAirport ); > sb.append( "\nArriving in : " ); > sb.append( destAirport ); > sb.append( "\nDate : " ); > sb.append( flightDate ); > sb.append( "\nAvailable seats: " ); > sb.append( String.valueOf( seatsAvailible ) ); > sb.append("\nSeat price : "); > sb.append( String.valueOf( seatPrice ) ); > sb.append( "\nNo of seats requested : " ); > sb.append( numberOfSeatsToBook ); > sb.append( "\nBooking no : " ); > sb.append( String.valueOf(bookingNumber) ); > sb.trimToSize(); > return sb.toString(); > } > } > > ...and the code for the DOM xml class is as follows, follwed by the xml error > class and the client code I'm using. This class is the crux of my problem I > think, but it runs on its own fine. > > /* > * Created on 10-5-2005 > */ > > package flightCompany.xmlHelper; > > import org.w3c.dom.Document; > import org.w3c.dom.Element; > import org.w3c.dom.Node; > > > > import javax.xml.transform.dom.DOMSource; > import javax.xml.parsers.DocumentBuilder; > import javax.xml.parsers.DocumentBuilderFactory; > import javax.xml.parsers.ParserConfigurationException; > import javax.xml.transform.TransformerFactory; > import javax.xml.transform.TransformerException; > import javax.xml.transform.TransformerConfigurationException; > import javax.xml.transform.Transformer; > import javax.xml.transform.stream.StreamResult; > > > import java.io.StringWriter; > import java.util.Iterator; > import java.util.LinkedList; > > import flightCompany.exceptions.XMLException; > import flightCompany.model.*; > > > /** > * This helper provides XML & XML String object mapping the DAO methods and > the > * database model to xml. > * @author James Taylor > * @version 1.2 > */ > > public class DOMGetFlightsXMLImpl { > > private Document doc; > private Element root; > > > /** > * Instantiate class members by creating a DOM document and a root tag > element for it. > * using a root tag. > * @param rootTagName root tag for document > * @throws throws XMLException > */ > protected void createXMLDocument(String rootTagName) throws > XMLException{ > > DocumentBuilderFactory factory = > DocumentBuilderFactory.newInstance(); > try { > factory.setNamespaceAware(true); > DocumentBuilder builder = factory.newDocumentBuilder(); > doc = builder.newDocument(); > root = doc.createElementNS("FlightList.xsd", rootTagName); > //add root tag > doc.appendChild(root); > } catch (ParserConfigurationException e) { > throw new XMLException("XMLExcepion in > DOMGetFlightsXMLImpl.createXMLDocument() " + e.getMessage() ); > } > } > > /* > * Given a list of flight objects this returns a xml string representation > of > them > * @param flights list of flights to put in xml form > * @throws XMLException > */ > public String getFlightListAsXMLString(Iterator flights){ > try{ > System.out.println("============Getting XML > String====================="); > System.out.println("Creating xml dom doc"); > createXMLDocument("FlightList"); > }catch( XMLException xmle ){ > String result = "<Error> Error creating the xml document "+ > xmle.getMessage() +" </Error>"; > System.out.println( result); > return result; > } > if (!flights.hasNext() ) > return "<Result> Couldn't find any flights to parse into xml</Result>"; > try{ > System.out.println("about to head into loop to parse list"); > while (flights.hasNext()) { > Flight f = (Flight)flights.next(); > addFlightNode(root, f); > } > System.out.println("left the loop"); > }catch( Exception e ){ > String result = "<Error> Error making adding nodes to the xml doc "+ > e.getMessage() +" </Error>"; > System.out.println( result); > return result; > } > try{ > System.out.println("About to turn dom to string"); > return transformDOMtoString(doc); > }catch( XMLException xmle ){ > String result = "<Error> Error making string representation on xml doc "+ > xmle.getMessage() +" </Error>"; > System.out.println( result); > return result; > } > } > > /** > * Add XML data mapping from Flight objs to XML by populating the DOM > document > object > * @param parent root tag > * @param f flight object to be parsed to xml > * @throws XMLException > */ > protected void addFlightNode(Node parent, Flight f) throws XMLException{ > try{ > //add <Flight> element > Element flElem = doc.createElement("Flight"); > parent.appendChild(flElem); > > // Make <FlightNum> element and add it > Element elem = doc.createElement( "FlightNum" ); > elem.appendChild(doc.createTextNode( String.valueOf( > f.getFlightNum() ) > )); > flElem.appendChild(elem); > > > // Make <SourceAirport> element and add it > elem = doc.createElement("SourceAirport"); > elem.appendChild(doc.createTextNode( f.getSourceAirport() )); > flElem.appendChild(elem); > > // Make <DestAirport> element and add it > elem = doc.createElement( "DestAirport" ); > elem.appendChild(doc.createTextNode( f.getDestAirport() )); > flElem.appendChild(elem); > > // Make <FlightDate> element and add it > elem = doc.createElement( "FlightDate" ); > elem.appendChild(doc.createTextNode( f.getFlightDate() )); > flElem.appendChild(elem); > > //Make <SeatsAvailible> element and add it > elem = doc.createElement( "SeatsAvailible" ); > elem.appendChild(doc.createTextNode( String.valueOf( > f.getSeatsAvailible() ) )); > flElem.appendChild(elem); > > //Make <SeatsAvailible> element and add it > elem = doc.createElement( "SeatPrice" ); > elem.appendChild(doc.createTextNode( String.valueOf( > f.getSeatPrice() ) > )); > flElem.appendChild(elem); > }catch (Exception e) { > throw new XMLException("XMLExcepion in > DOMGetFlightsXMLImpl.addFlightNode() " + e.getMessage() ); > } > } > > > > /** > * > * @param xDoc Dom document object to convert to a string > * @return a string representation of a DOM document object > * @throws XMLException > */ > protected String transformDOMtoString(Document xDoc) throws XMLException{ > try { > // Use a Transformer for String output > TransformerFactory tFactory = TransformerFactory.newInstance(); > Transformer transformer = tFactory.newTransformer(); > DOMSource source = new DOMSource(xDoc); > StringWriter sw = new StringWriter(); > transformer.transform(source, new StreamResult(sw)); > return sw.toString(); > }catch (TransformerConfigurationException tce) { > throw new XMLException("XMLExcepion in > DOMGetFlightsXMLImpl.transformDOMtoString() " + tce.getMessageAndLocation() > ); > }catch (TransformerException te) { > throw new XMLException("XMLExcepion in > DOMGetFlightsXMLImpl.transformDOMtoString() " + te.getMessage() ); > } > } > > > /** > * Just to test the imlementation > */ > public static void main(String[] arg) { > DOMGetFlightsXMLImpl helper = new DOMGetFlightsXMLImpl(); > try{ > LinkedList flights = new LinkedList(); > Flight f = new Flight(); > Flight fl = new Flight(); > flights.add( f ); > flights.add( fl ); > Iterator iter = flights.iterator(); > System.out.println(helper.getFlightListAsXMLString(iter) ); > } > catch ( Exception saxe ){ > throw new XMLException("Error in parsing xml"+ saxe.getMessage() ); > } > } > } > > /* > * Created on 15-05-2005 > */ > > > package flightCompany.exceptions; > > /** > * > * @author James Taylor > * @version 1.1 > */ > > public class XMLException extends RuntimeException { > > /** > * Constructor > * @param str a string that explains what the exception condition is > */ > public XMLException (String str) { > super(str); > } > > /** > * Default constructor. Takes no arguments > */ > public XMLException () { > super(); > > } > > public String toString() > { > return "XMLException: "+super.toString(); > } > } > > > package flightCompany.rpcservice.client; > > import org.apache.axis.AxisFault; > import java.net.URL; > > /** > * A client that uses the Dynamic Proxy method to communicate with a Web > service > * using JAX-RPC. > * @author James Taylor > * @version 1.1 > */ > > public class FlightCompanyClient { > > // helper class - To fetch the ACME Catalog information > > public String getFlightsFromWSService(String date) throws Exception { > String REMOTE_ENDPOINT_URL = > "http://localhost:7070/axis/services/flightservice"; > String namespace = "flightservice"; > String portName = "FlightInfoServiceIF"; > String servicename = "flightservice"; > > //make a service > FlightInfoServiceIFService service = new > FlightInfoServiceIFServiceLocator(); > //get a stub to the service > FlightInfoServiceIF flightSvc = service.getflightservice( new URL( > REMOTE_ENDPOINT_URL )); > > //make a call > return flightSvc.getFlights(date); > } > > public static void main(String args[]) { > try { > String date = "2005-05-23"; > FlightCompanyClient fclient = new FlightCompanyClient(); > String flights = fclient.getFlightsFromWSService( date ); > System.out.println("Avasilable flights: " + flights); > } > catch( Exception e ) { > if ( e instanceof AxisFault ) { > System.err.println( ((AxisFault)e).dumpToString() ); > } else > e.printStackTrace(); > } > } > > } > > -- > Between the question and the answer lies free will > -- Between the question and the answer lies free will
