문제

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