Details
Description
I am using custom out interceptor, which make xsl transformation to serialize some elements as CDATA, my code was inspired by org.apache.cxf.feature.transform.XSLTOutInterceptor.
But if I set property com.ctc.wstx.returnNullForDefaultNamespace=true, the I've got an NPE. This property is required to fix some other issues with xml generation (without it I've got empty namespaces xmlns="" in some cases).
The code bellow is the minimum example of NPE, using org.apache.cxf.staxutils.StaxSource.
Exception in thread "main" java.lang.NullPointerException: Cannot invoke "String.equals(Object)" because "prefix" is null at net.sf.saxon.event.ReceivingContentHandler.startPrefixMapping(ReceivingContentHandler.java:300) at org.apache.cxf.staxutils.StaxSource.parse(StaxSource.java:145) at org.apache.cxf.staxutils.StaxSource.parse(StaxSource.java:259) at net.sf.saxon.resource.ActiveSAXSource.deliver(ActiveSAXSource.java:192) at net.sf.saxon.event.Sender.send(Sender.java:104) at net.sf.saxon.jaxp.IdentityTransformer.transform(IdentityTransformer.java:364)
package test; import com.ctc.wstx.stax.WstxInputFactory; import org.apache.cxf.staxutils.StaxSource; import javax.xml.transform.OutputKeys; import javax.xml.transform.Source; import javax.xml.transform.Transformer; import javax.xml.transform.TransformerFactory; import javax.xml.transform.stax.StAXSource; import javax.xml.transform.stream.StreamResult; import java.io.ByteArrayInputStream; import java.io.StringWriter; import java.nio.charset.StandardCharsets; public class NpeTest { public static void main(String[] args) throws Exception { String bodyXml = "<?xml version=\"1.0\"?>\n" + "<soap:Envelope xmlns:soap=\"http://schemas.xmlsoap.org/soap/envelope/\">\n" + " <soap:Body>\n" + " <testReq xmlns=\"http://test.com/test\">\n" + " <reqBody><<<<<</reqBody>\n" + " </testReq>\n" + " </soap:Body>\n" + "</soap:Envelope>\n"; System.setProperty("com.ctc.wstx.returnNullForDefaultNamespace", "true"); WstxInputFactory factory = new WstxInputFactory(); Source beforeSource = new StaxSource(factory.createXMLStreamReader(new ByteArrayInputStream(bodyXml.getBytes(StandardCharsets.UTF_8)))); // Source beforeSource = new StAXSource(factory.createXMLStreamReader(new ByteArrayInputStream(bodyXml.getBytes(StandardCharsets.UTF_8)))); System.out.println(save(beforeSource)); } public static String save(Source beforeSource) throws Exception { StringWriter writer = new StringWriter(); StreamResult result = new StreamResult(writer); TransformerFactory tf = TransformerFactory.newInstance(); Transformer transformer = tf.newTransformer(); transformer.setOutputProperty(OutputKeys.INDENT, "yes"); transformer.setOutputProperty(OutputKeys.STANDALONE, "yes"); transformer.setOutputProperty(OutputKeys.CDATA_SECTION_ELEMENTS, "Q{http://test.com/test}reqBody"); transformer.setOutputProperty("{http://xml.apache.org/xslt}indent-amount", "4"); transformer.transform(beforeSource, result); return writer.toString(); } }
The stacktrace from my project is:
java.lang.NullPointerException at net.sf.saxon.event.ReceivingContentHandler.startPrefixMapping(ReceivingContentHandler.java:301) at org.apache.cxf.staxutils.StaxSource.parse(StaxSource.java:145) at org.apache.cxf.staxutils.StaxSource.parse(StaxSource.java:259) at net.sf.saxon.resource.ActiveSAXSource.deliver(ActiveSAXSource.java:190) at net.sf.saxon.event.Sender.send(Sender.java:105) at net.sf.saxon.jaxp.IdentityTransformer.transform(IdentityTransformer.java:364) at org.apache.cxf.feature.transform.XSLTUtils.transform(XSLTUtils.java:57) at org.apache.cxf.feature.transform.XSLTOutInterceptor$XSLTCachedOutputStreamCallback.onClose(XSLTOutInterceptor.java:165) at org.apache.cxf.io.CachedOutputStream.close(CachedOutputStream.java:219) at org.apache.cxf.transport.AbstractConduit.close(AbstractConduit.java:56) at org.apache.cxf.transport.http.HTTPConduit.close(HTTPConduit.java:688) at org.apache.cxf.interceptor.MessageSenderInterceptor$MessageSenderEndingInterceptor.handleMessage(MessageSenderInterceptor.java:63) at org.apache.cxf.phase.PhaseInterceptorChain.doIntercept(PhaseInterceptorChain.java:307) at org.apache.cxf.endpoint.ClientImpl.doInvoke(ClientImpl.java:530) at org.apache.cxf.endpoint.ClientImpl.invoke(ClientImpl.java:441) at org.apache.cxf.endpoint.ClientImpl.invoke(ClientImpl.java:356) at org.apache.cxf.endpoint.ClientImpl.invoke(ClientImpl.java:314) at org.apache.cxf.frontend.ClientProxy.invokeSync(ClientProxy.java:96) at org.apache.cxf.jaxws.JaxWsClientProxy.invoke(JaxWsClientProxy.java:140)
Attachments
Attachments
Issue Links
- links to