hey,
I put this into C:\Program
Files\Apache\jakarta-tomcat-4.1.31\webapps\axis\WEB-INF\classes\log4j.properties
and deleted simplelog.properties from axis.jar. The bit that follows is the
logging code in my class I want to debug... but I don't see any logs in
C:\Program Files\Apache\jakarta-tomcat-4.1.31\logs, is there another
log4j.properties file that might overload this?
# Log4j configuration file.
# Set root logger level to DEBUG and its only appender to A.
log4j.rootCategory=DEBUG, A
# A is a DailyRollingFileAppender
log4j.appender.A=org.apache.log4j.DailyRollingFileAppender
log4j.appender.A.file=C:\Program
Files\Apache\jakarta-tomcat-4.1.31\logs\wsAxis.log
log4j.appender.A.datePattern='.'yyyy-MM-dd
log4j.appender.A.append=true
log4j.appender.A.layout=org.apache.log4j.PatternLayout
log4j.appender.A.layout.ConversionPattern=%-5p %d{ISO8601} [%t] - %m%n
/*
* 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.Logger;
import org.apache.log4j.BasicConfigurator;
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 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{
logger.debug("============Getting XML
String=====================");
logger.debug("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{
logger.debug("about to head into loop to parse list");
while (flights.hasNext()) {
Flight f = (Flight)flights.next();
addFlightNode(root, f);
}
logger.debug("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{
logger.debug("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 {
// Use a Transformer for String output
TransformerFactory tFactory = TransformerFactory.newInstance();
Transformer transformer = tFactory.newTransformer();
DOMSource source = new DOMSource(xDoc);
StringWriter sw = new StringWriter();
logger.debug("========Hello from transformDOMtoString().");
transformer.transform(source, new StreamResult(sw));
String result = sw.toString();
logger.debug("=======sending back this" + result);
return result;
}catch (TransformerConfigurationException tce) {
throw new XMLException("XMLExcepion in
DOMGetFlightsXMLImpl.transformDOMtoString() " + tce.getMessageAndLocation() );
}catch (TransformerException te) {
throw new XMLException("XMLExcepion in
DOMGetFlightsXMLImpl.transformDOMtoString() " + te.getMessageAndLocation() );
}
}
/**
* 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() );
}
}
}
Quoting Jeff <[EMAIL PROTECTED]>:
> 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:
.......