Hey people,
for the moment as I'm inept to logging I'm using simple
System.out.println to debug to Tomcat's console - as I have the liberty of
testing locally - and have changed the class that is wrecking my head to the
below listing. I've been trying to work this out for about 2 full days and am
stuck, which is when we really have to learn and the open window looks really
appealling.. bet you wish i'd just jump!!
You see when I run the class from the main method I get the following
output -
run:
[echo] run task. Running flightCompany.xmlHelper.DOMGetFlightsXMLImpl...
[java] ============Getting XML String=====================
[java] Creating xml dom doc
[java] about to head into loop to parse list
[java] left the loop so we have added nodes to dom
[java] About to turn dom to string
[java] ========Hello from transformDOMtoString().
[java] got TransformerFactory...
[java] got Transformer...
[java] Got DOMSource...
[java] Got StringWriter...
[java] transformed dom...
[java] =======sending back this<?xml version="1.0"
encoding="UTF-8"?><FlightList
xmlns="FlightList.xsd"><Flight><FlightNum>0</FlightNum><SourceAirport></So
urceAirport><DestAirport></DestAirport><FlightDate></FlightDate><SeatsAvailible>
0</SeatsAvailible><SeatPrice>0</SeatPrice></Flight><Flight><FlightNum>0</FlightN
um><SourceAirport></SourceAirport><DestAirport></DestAirport><FlightDate></Fligh
tDate><SeatsAvailible>0</SeatsAvailible><SeatPrice>0</SeatPrice></Flight></Fligh
tList>
[java] <?xml version="1.0" encoding="UTF-8"?><FlightList xmlns="FlightList.
xsd"><Flight><FlightNum>0</FlightNum><SourceAirport></SourceAirport><DestAirport
></DestAirport><FlightDate></FlightDate><SeatsAvailible>0</SeatsAvailible><SeatP
rice>0</SeatPrice></Flight><Flight><FlightNum>0</FlightNum><SourceAirport></Sour
ceAirport><DestAirport></DestAirport><FlightDate></FlightDate><SeatsAvailible>0<
/SeatsAvailible><SeatPrice>0</SeatPrice></Flight></FlightList>
[echo] Done...
BUILD SUCCESSFUL
Total time: 3 seconds
.... This is what I want to send back to the service requester. But, and a
horrible but that I cant figure out why, when I implement the code as a web
service and run the client code the debug statements to tomcat's console seems
to indicate that it hangs around the
DOMGetFlightsXMLImpl.transformDOMtoString(Document) method at this line (171)
TransformerFactory tFactory = TransformerFactory.newInstance();
This is what the console looks like -
03-Jun-2005 03:13:42 org.apache.coyote.http11.Http11Protocol init
INFO: Initializing Coyote HTTP/1.1 on http-8080
Starting service Tomcat-Standalone
Apache Tomcat/4.1.31
03-Jun-2005 03:13:43 org.apache.struts.util.PropertyMessageResources <init>
INFO: Initializing, config='org.apache.struts.util.LocalStrings', returnNull=tru
e
03-Jun-2005 03:13:43 org.apache.struts.util.PropertyMessageResources <init>
INFO: Initializing, config='org.apache.struts.action.ActionResources', returnNul
l=true
03-Jun-2005 03:13:43 org.apache.struts.util.PropertyMessageResources <init>
INFO: Initializing, config='org.apache.webapp.admin.ApplicationResources', retur
nNull=true
03-Jun-2005 03:13:46 org.apache.coyote.http11.Http11Protocol start
INFO: Starting Coyote HTTP/1.1 on http-8080
03-Jun-2005 03:13:46 org.apache.jk.common.ChannelSocket init
INFO: JK2: ajp13 listening on /0.0.0.0:8009
03-Jun-2005 03:13:46 org.apache.jk.server.JkMain start
INFO: Jk running ID=0 time=0/30 config=C:\Program Files\Apache\jakarta-tomcat-4
.1.31\conf\jk2.properties
====================================
about to convert to string
============Getting XML String=====================
Creating xml dom doc
about to head into loop to parse list
left the loop so we have added nodes to dom
About to turn dom to string
========Hello from transformDOMtoString().
/*
* Created on 10-5-2005
*/
package flightCompany.xmlHelper;
import org.w3c.dom.Document;
import org.w3c.dom.Element;
import org.w3c.dom.Node;
//Import log4j classes.
import org.apache.log4j.HTMLLayout;
import org.apache.log4j.Level;
import org.apache.log4j.Logger;
import org.apache.log4j.BasicConfigurator;
import org.apache.log4j.WriterAppender;
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.FileOutputStream;
import java.io.StringWriter;
import java.util.Iterator;
import java.util.LinkedList;
import flightCompany.exceptions.XMLException;
import flightCompany.model.Flight;
/**
* 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 implements GetFlightsXMLIF{
//logger
static Logger logger = Logger.getLogger(DOMGetFlightsXMLImpl.class);
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 so we have added nodes to
dom");
}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 to convert to a string
* @return a string representation of a DOM document object
* @throws XMLException
*/
protected String transformDOMtoString(Document xDoc) throws
XMLException {
try {
System.out.println("========Hello from
transformDOMtoString().");
// Use a Transformer for String output
TransformerFactory tFactory = TransformerFactory.newInstance();
System.out.println("got TransformerFactory...");
Transformer transformer = tFactory.newTransformer();
System.out.println("got Transformer...");
DOMSource source = new DOMSource(xDoc);
System.out.println("Got DOMSource...");
StringWriter sw = new StringWriter();
System.out.println("Got StringWriter...");
transformer.transform(source, new StreamResult(sw));
System.out.println("transformed dom...");
String result = sw.toString();
System.out.println("=======sending back this" + result);
return result;
}catch (TransformerConfigurationException tce) {
System.out.println("TransformerConfigurationException");
throw new XMLException("XMLExcepion in
DOMGetFlightsXMLImpl.transformDOMtoString() " + tce.getMessageAndLocation() );
}catch (TransformerException te) {
System.out.println("TransformerException");
throw new XMLException("XMLExcepion in
DOMGetFlightsXMLImpl.transformDOMtoString() " + te.getMessageAndLocation() );
}
}
/**
* Just to test the imlementation
*
public static void main(String[] arg) {
try{
DOMGetFlightsXMLImpl helper = new
DOMGetFlightsXMLImpl();
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()
);
}
}
**/
}
Quoting James Taylor <[EMAIL PROTECTED]>:
> 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></soapenv: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
> >
>