[ 
https://issues.apache.org/jira/browse/AXIS2-5044?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=13034184#comment-13034184
 ] 

Andreas Veithen commented on AXIS2-5044:
----------------------------------------

Strictly speaking this would be a bug in Jettison. In fact, you mention SAX, 
but XMLStreamWriter is specified by the StAX API, which has different semantics 
than SAX. When producing XML, writeStartDocument is used to write the XML 
declaration (see the corresponding Javadoc), and this is optional. If Jettison 
relies on the application code calling writeStartDocument, then this sounds 
like a bug, especially if it throws an NPE instead of a meaningful exception.

Nevertheless, it wouldn't do any harm to add a call to writeStartDocument to 
the axis2-json code. I will look at this later.

PS: The Jettison version used by Axis2 is specified in the parent POM (see 
modules/parent/pom.xml).

> JSONMessageFormatter does not call startDocument on XMLWriter with  Mapped 
> convention
> -------------------------------------------------------------------------------------
>
>                 Key: AXIS2-5044
>                 URL: https://issues.apache.org/jira/browse/AXIS2-5044
>             Project: Axis2
>          Issue Type: Bug
>          Components: modules
>            Reporter: Jean Marc
>   Original Estimate: 5m
>  Remaining Estimate: 5m
>
> When Mapped convention is used, JSONMessageFormatter creates an 
> XMLStreamWriter from Jettison library of type MappedXMLStreamWriter
> and executes the following code
>   XMLStreamWriter jsonWriter = getJSONWriter(bytesOut);
>   element.serializeAndConsume(jsonWriter);
>   jsonWriter.writeEndDocument();
> at 3 places in the class (in getBytes(), getTargetAddress() and writeTo() ).
> In the above code, there is no call to jsonWriter.writeStartDocument().
> This works for Jettison library v1.1 and below because it does not follow the 
> SAX event flow, but Jettison v1.2 and above have been refactored to respect 
> the SAX event chain,
> and the XMLStreamWriter expects the calling serializer to generate a 
> startDocument() event at the beginning. 
> Actually, the axis-json lib 1.5.4 does not specify a Maven version dependency 
> on Jettison so any version should do, but with Jettison v1.2+
> a simple client trying to serialize a OMElement to send a soap message 
> triggers a NPE in Jettison when the last endElement() event is triggered
> because the call to startDocument has never been made.
> Simple solution is to add jsonWriter.writeStartDocument() before calling 
> element.serializeAndConsume().

--
This message is automatically generated by JIRA.
For more information on JIRA, see: http://www.atlassian.com/software/jira

---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to