Вопрос

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.

Это было полезно?

Решение

It turns out that wrapping the input stream into StreamSource is causing the problem. After dropping it your code becomes:

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);

And it should work now!

Лицензировано под: CC-BY-SA с атрибуция
Не связан с StackOverflow
scroll top