Any update on this? Or can this not be done using jibx?
Peter
________________________________
From: [EMAIL PROTECTED]
[mailto:[EMAIL PROTECTED] On Behalf Of Black,
Peter (IT)
Sent: Monday, July 09, 2007 2:17 PM
To: jibx-users@lists.sourceforge.net
Subject: Re: [jibx-users] Creating well formed xml with jibx
Let me elaborate.
The following is an example taken from
http://www.ibm.com/developerworks/xml/library/x-tipstx4/
Which has been modified to show my point. It uses stax, and when an
error is thrown
while writing to the stream, I can recover gracefully and send back well
formed xml with
an error element.
public class WriterExample
{
// Namespaces
private static final String GARDENING = "http://com.bdaum.gardening";
private static final String XHTML = "http://www.w3.org/1999/xhtml";
public static void main(String[] args) throws XMLStreamException {
XMLOutputFactory xmlof = XMLOutputFactory.newInstance();
XMLStreamWriter xmlw =
xmlof.createXMLStreamWriter(System.out);
try
{
// Write XML prologue
xmlw.writeStartDocument();
// Write a processing instruction
xmlw.writeProcessingInstruction(
"xml-stylesheet href='catalog.xsl' type='text/xsl'");
// Now start with root element
xmlw.writeStartElement("product");
// Set the namespace definitions to the root element
// Declare the default namespace in the root element
xmlw.writeDefaultNamespace(GARDENING);
// Writing a few attributes
xmlw.writeAttribute("productNumber","3923-1");
xmlw.writeAttribute("name","Nightshadow");
// Different namespace for description element
xmlw.writeStartElement(XHTML,"description");
if(true)
throw new Exception();
xmlw.writeCharacters(
"A tulip of almost black color. \nBlossoms in April & May");
xmlw.writeEndElement();
// Shorthand for empty elements
xmlw.writeEmptyElement("supplier");
xmlw.writeAttribute("name","Floral22");
}
catch(Exception e)
{
xmlw.writeEndElement();
xmlw.writeStartElement(XHTML,"error");
xmlw.writeCharacters("A System Error Occured");
xmlw.writeEndElement();
}
finally
{
xmlw.writeEndDocument();
xmlw.close();
}
}
}
Notice I am throwing an Exception. This would be similar to a
JibxException being thrown during marshalling.
However, I catch this exception, add an error element as the end
element, then call writeEndDocument which
closes all open structures. Can something similar be done with jibx?
instead of sending back xml that is
not well formed?
Peter
Hello,
I am creating a REST style web service and am creating the xml response
using Jibx with StAX as my parser.
However, when a jibxexception is thrown during binding, the client
receives
xml that is not well formed:
<GetQuestionResponse>
<Question id="1">
<Category id="1">
<Name>calculus</Name>
</Category>
<Title>my problem</Title>
<User id="1">
<Username>abstractionz</Username>
</User>
<Problem>this is my problem</Problem>
So to get around this issue I am building the response in memory first,
which I don't want to do.
Then if there is a jibx exception, I clear out what is in memory, and
send
back an error response.
I would like to just keep streaming the xml to the output stream, but at
the
same time I don't want
to be sending the client invalid xml. Has anybody else come across this
issue?
rgds,
Peter
________________________________
NOTICE: If received in error, please destroy and notify sender. Sender
does not intend to waive confidentiality or privilege. Use of this email
is prohibited when received in error.
--------------------------------------------------------
NOTICE: If received in error, please destroy and notify sender. Sender does not
intend to waive confidentiality or privilege. Use of this email is prohibited
when received in error.
-------------------------------------------------------------------------
This SF.net email is sponsored by DB2 Express
Download DB2 Express C - the FREE version of DB2 express and take
control of your XML. No limits. Just data. Click to get it now.
http://sourceforge.net/powerbar/db2/
_______________________________________________
jibx-users mailing list
jibx-users@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/jibx-users