2

I am trying to create some xml content in my web application. For that i have used JAXB.

JAXBContext jaxbContext = JAXBContext.newInstance(QueryRequest.class);

        XMLInputFactory xif = XMLInputFactory.newInstance();
        xif.setProperty(XMLInputFactory.IS_NAMESPACE_AWARE, false);
        StreamSource source = new StreamSource(new ByteArrayInputStream(
                queryRequestXml.getBytes()));

        XMLStreamReader xsr = xif.createXMLStreamReader(source);

        Unmarshaller jaxbUnmarshaller = jaxbContext.createUnmarshaller();

        QueryRequest queryRequest = (QueryRequest) jaxbUnmarshaller
                .unmarshal(xsr);

The problem i am facing is that in JBOSS,Tomcat it works fine.But as soon as i move my application to Weblogic i get xif.createXMLStreamReader(source); as null.

Any idea on how to get this fixed.

4

1 回答 1

1

事实证明,将输入流包装到StreamSource是导致问题的原因。删除它后,您的代码变为:

JAXBContext jaxbContext = JAXBContext.newInstance(QueryRequest.class);
XMLInputFactory xif = XMLInputFactory.newInstance();
xif.setProperty(XMLInputFactory.IS_NAMESPACE_AWARE, false);
InputStream source = new ByteArrayInputStream(queryRequestXml.getBytes());
XMLStreamReader xsr = xif.createXMLStreamReader(source);

它现在应该可以工作了!

于 2014-04-08T10:23:46.897 回答