R
Rick Brandt
I am attempting to troubleshoot an XML parsing error that occurs when XML
is submitted to my servlet. The error does not occur when I run the
servlet locally so to debug the problem I was attempting to log the
contents of the InputSource to a file just before attempting the parse. To
that end I added the lines of code below between the asterisk rows.
It appears that the getByteStream() that I run against my InputSource
(xmlIn) renders it useless for passing to the parser. Can an InputSource
only be read through once? Is there no way to reset it before I pass it to
the SAX parser?
public String ProcessHTTPPost(InputSource xmlIn) {
try {
XMLReader parser =
XMLReaderFactory.createXMLReader("org.apache.xerces.parsers.SAXParser");
MBOSaxParser MBOSaxParserInstance = new MBOSaxParser();
parser.setContentHandler(MBOSaxParserInstance);
//*********************************************
BufferedReader br = new BufferedReader(new
InputStreamReader(xmlIn.getByteStream()));
String str = null;
while ((str = br.readLine()) != null)
{
System.out.println(str);
log = new RegMgrLogger(str, false);
}
//*********************************************
parser.parse(xmlIn);
response = MBOSaxParserInstance.mboInstance.returnVal;
}
catch(Exception ex) {
ex.printStackTrace();
response = "ERROR~" + ex.toString();
}
finally {
return response;
}
}
is submitted to my servlet. The error does not occur when I run the
servlet locally so to debug the problem I was attempting to log the
contents of the InputSource to a file just before attempting the parse. To
that end I added the lines of code below between the asterisk rows.
It appears that the getByteStream() that I run against my InputSource
(xmlIn) renders it useless for passing to the parser. Can an InputSource
only be read through once? Is there no way to reset it before I pass it to
the SAX parser?
public String ProcessHTTPPost(InputSource xmlIn) {
try {
XMLReader parser =
XMLReaderFactory.createXMLReader("org.apache.xerces.parsers.SAXParser");
MBOSaxParser MBOSaxParserInstance = new MBOSaxParser();
parser.setContentHandler(MBOSaxParserInstance);
//*********************************************
BufferedReader br = new BufferedReader(new
InputStreamReader(xmlIn.getByteStream()));
String str = null;
while ((str = br.readLine()) != null)
{
System.out.println(str);
log = new RegMgrLogger(str, false);
}
//*********************************************
parser.parse(xmlIn);
response = MBOSaxParserInstance.mboInstance.returnVal;
}
catch(Exception ex) {
ex.printStackTrace();
response = "ERROR~" + ex.toString();
}
finally {
return response;
}
}