I have a library created which uses jaxb to marshal/unmarshal an xml payload related to web service calls (no json). These calls work perfectly in my library. Once I pull it into a larger project, the calls to setProperty() fail with the following exception.
javax.xml.bind.PropertyException: name: com.sun.xml.internal.bind.xmlHeaders value: <?xml version="1.0" encoding="UTF-8"?>
anyone have any ideas what is going on here? My searches have all come up as wild goose chases. Here's the method in question:
public String serializeXML() throws JAXBException, UnsupportedEncodingException {
JAXBContext context = JAXBContext.newInstance(MPICRequest.class);
Marshaller marshaller = context.createMarshaller();
marshaller.setProperty(Marshaller.JAXB_FORMATTED_OUTPUT, Boolean.TRUE);
marshaller.setProperty("com.sun.xml.internal.bind.xmlHeaders", "<?xml version=\"1.0\" encoding=\"UTF-8\"?>");
marshaller.setProperty("com.sun.xml.internal.bind.xmlHeaders", "<!DOCTYPE xgdquery SYSTEM \"xgdquery.dtd\">");
ByteArrayOutputStream byteStream = new ByteArrayOutputStream();
marshaller.marshal(this, byteStream);
return new String(byteStream.toByteArray());
}
xmlHeaders
I've seen both 'com.sun.xml.internal.bin.xmlHeaders' and 'com.sun.xml.bind.xmlHeaders' in various document and blogs. Both options throw an exception, but each in a different project.
com.sun.xml.internal.. throws an exception in my consuming jar when method executed as larger problem space:
javax.xml.bind.PropertyException: name: com.sun.xml.internal.bind.xmlHeaders value: <?xml version="1.0" encoding="UTF-8"?>
com.sun.xml.. throws an exception in my library jar when method executed in isolation:
javax.xml.bind.PropertyException: name: com.sun.xml.bind.xmlHeaders value: <?xml version="1.0" encoding="UTF-8"?>
JAXB Libraries
The JAXBContext differs between the two jars during run time. I've tried to force the JAXB library via maven dependency:
<dependency>
<groupId>javax.xml.bind</groupId>
<artifactId>jaxb-api</artifactId>
<version>2.2.3</version>
</dependency>
In the case of the consuming project here's the JAXBContext:
jar:file:/private/tmp/hadoop-usr/nm-local-dir/usercache/usr/appcache/application_1502287345977_0001/filecache/10/porter-samza-0.4.14-dist.tar.gz/lib/jaxb-impl-2.2.3-1.jar!/com/sun/xml/bind/v2/runtime/JAXBContextImpl.class Build-Id: 2.2.3
In the case of my reusable library the context is (completely ignoring my jaxb-api:2.2.3 dependency):
jar:file:/Library/Java/JavaVirtualMachines/jdk1.8.0_121.jdk/Contents/Home/jre/lib/rt.jar!/com/sun/xml/internal/bind/v2/runtime/JAXBContextImpl.class Build-Id: 1.8.0_121