weblogic
Closed this issue · 10 comments
Used the library in a gwt app. It works in hosted mode but when I deploy it on a weblogic server it doesn't. Any suggestions?
Can you give more details? What does "it doesn't work" mean?
When I call writer.add(reader) an XMLStreamException: Cannot end document
is thrown.
- What version of StAXON are you using?
- Can you post some code snippet?
- Would you please post the exception's stack trace?
1.I'm using staxon-1.1
- public static String toJSon(String str, String prefix) {
Logger logger = Logger.getLogger(Conversion.class);
logger.info("Starting toJson with : " + str);
String json = null;
InputStream input = null;
OutputStream output = new ByteArrayOutputStream();
JsonXMLConfig config = new JsonXMLConfigBuilder().autoArray(true).prettyPrint(true).build();
try {
input = new ByteArrayInputStream(str.getBytes("UTF-8"));
logger.info("Created a inputstream");
XMLEventReader reader = XMLInputFactory.newInstance().createXMLEventReader(input);
JsonXMLOutputFactory outputFactory = new JsonXMLOutputFactory(config);
outputFactory.setProperty(JsonXMLOutputFactory.PROP_NAMESPACE_DECLARATIONS, false);
XMLEventWriter writer = outputFactory.createXMLEventWriter(output);
logger.info("Created a writer");
/*
* Copy events from reader to writer.
*/
writer.add(reader);
logger.info("Added a reader to writer");
reader.close();
writer.flush();
json = output.toString();
json = json.replaceAll(prefix + ":", "");
writer.close();
} catch (UnsupportedEncodingException e) {
logger.info("UnsupportedEncodingException: " + e.getMessage());
} catch (XMLStreamException e) {
logger.info("XMLStreamException: " + e.getMessage());
} catch (FactoryConfigurationError e) {
logger.info("FactoryConfigurationError: " + e.getMessage());
} finally {
/*
* As per StAX specification, XMLEventReader/Writer.close() doesn't
* close the underlying stream.
*/
try {
output.close();
input.close();
} catch (IOException e) {
e.printStackTrace();
}
}
return json;
}
- Stack trace : I'm gonna check if I can get more then "Cannnot end document'
INFO di sep 25 16:50:28.888 2012 XMLStreamException: de.odysseus.staxon.base.AbstractXMLStreamWriter.writeEndDocument(AbstractXMLStreamWriter.java:320)
INFO di sep 25 16:50:28.888 2012 XMLStreamException: de.odysseus.staxon.json.JsonXMLStreamWriter.writeEndDocument(JsonXMLStreamWriter.java:274)
INFO di sep 25 16:50:28.889 2012 XMLStreamException: de.odysseus.staxon.event.SimpleXMLEventWriter.add(SimpleXMLEventWriter.java:57)
INFO di sep 25 16:50:28.889 2012 XMLStreamException: de.odysseus.staxon.event.SimpleXMLEventWriter.add(SimpleXMLEventWriter.java:119)
INFO di sep 25 16:50:28.889 2012 XMLStreamException: nl.tudelft.server.Conversion.toJSon(Conversion.java:131)
INFO di sep 25 16:50:28.890 2012 XMLStreamException: nl.tudelft.server.MyServletContextListener.contextInitialized(MyServletContextListener.java:23)
...
Thanks. This seems to be a bug in WebLogic's StAX implementation. I guess you don't have a XML declaration (<?xml ...>
) in your input, right? The reader does not create a START_DOCUMENT event but an END_DOCUMENT event.
Possible Solutions
- deploy a better StAX implementation, e.g. woodstox (if you deployed BEA's jsr-173-*.jar, get rid of it)
- add an XML declaration to your XML
- add the
START_DOCUMENT
manually like this:
if (!reader.peek().isStartDocument()) { // this should be there, but...
writer.add(XMLEventFactory.newInstance().createStartDocument());
}
Hi,
I do start the document:
// test
String xml = "<ns:persoon xmlns:S="http://schemas.xmlsoap.org/soap/envelope/\" xmlns:ns="http://www.tudelft.nl/enterprise/2.1/\">ns:naamns:achterNaamHeijink/ns:achterNaamns:voorkeurNaamMarcel/ns:voorkeurNaam<ns:r…….
Hi Christoph,
I got it working.
I added woodstoz-core-asl-4.1.4 and stax2-api-3.1.1 to my project
And I told weblogic to use these jars by adding
<prefer-web-inf-classes>true</prefer-web-inf-classes>
to the weblogic.xml
Thanks!
Great!
Anyway, I think I've found the cause now... Using BEA's original StAX implementation (jsr173-1.0-ri.jar
), I replaced the
writer.add(reader);
with
System.out.println(reader.getClass());
while (reader.peek() != null) {
XMLEvent event = reader.nextEvent();
System.out.println(event);
writer.add(event);
}
and got the following output:
class com.bea.xml.stream.XMLEventReaderBase
[Stax Event #7]
[Stax Event #1]
[Stax Event #2]
[Stax Event #8]
[Stax Event #8] <-- Second END_DOCUMENT
That is, the peek()
method reports zombie END_DOCUMENT
events instead of null
(as required by the specification).
Hello @mheijink I know you solved this long time ago, but It would be possible you provide me your solution. I recently ran into the same problem when traying to convert xml to json in OSB.