質問

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