Pages

11 November 2012

javax.xml.stream.XMLStreamException: Underlying stream encoding problem

While examining apache axiom to basically create an XML document, a weird exception is raised from serialize method. Serializing to System.out streams is problem-free; on the other hand, serializing to xml file is not. Since, the project's "text file encoding" is Cp1254 and it conflicts with the defined character encoding defined in OMDocument. Change it as i did it in screenshot at bottom of this post.

Let me explain what below code is about. It creates and an instance of OMFactory to create other OM supported XML parts: elements, attributes, namespaces and document to build an XML file programmatically with AXIOM. Then, set some xml metadata attributes and serialize it to System.out and output.xml file. 


javax.xml.stream.XMLStreamException: Underlying stream encoding 'Cp1254' and input paramter for writeStartDocument() method 'UTF-8' do not match.
 at com.sun.xml.internal.stream.writers.XMLStreamWriterImpl.writeStartDocument(Unknown Source)
 at org.apache.axiom.util.stax.wrapper.XMLStreamWriterWrapper.writeStartDocument(XMLStreamWriterWrapper.java:157)
 at org.apache.axiom.util.stax.dialect.SJSXPStreamWriterWrapper.writeStartDocument(SJSXPStreamWriterWrapper.java:36)
 at org.apache.axiom.om.impl.llom.OMDocumentImplUtil.internalSerialize(OMDocumentImplUtil.java:56)
 at org.apache.axiom.om.impl.llom.OMDocumentImpl.internalSerialize(OMDocumentImpl.java:327)
 at org.apache.axiom.om.impl.llom.OMDocumentImpl.internalSerialize(OMDocumentImpl.java:322)
 at org.apache.axiom.om.impl.llom.OMSerializableImpl.serialize(OMSerializableImpl.java:120)
 at org.apache.axiom.om.impl.llom.OMSerializableImpl.serialize(OMSerializableImpl.java:108)
 at org.apache.axiom.om.impl.llom.OMSerializableImpl.serialize(OMSerializableImpl.java:136)
 at com.oguzhan.blog.axis2.axiom.AxiomProgrammatically2.main(AxiomProgrammatically2.java:48)


Change text file encoding from Project>Properties>Resource

Thank you for reading!

No comments:

Post a Comment

Thx for reading! Comments are appreciated...