Skip to main content

Unwanted namespaces added to the payload and duplicated namespace prefixes

Published on: 15/03/2011 Discussion Archived

Dear all, I noted this seems to be a difficult issue to be solved, so I provide some details on this bug and some hints to solve it (partially). There are two different reasons for having duplicated namespace prefixes and unwanted namespace declarations on the payload: 1) JAXB is bugged on the xs:any handling 2) By relying on generated namespace prefixes, and in presence of bug (1), the results will be unpredictable because at any JAXB marshalling there will be more confusion with namespaces (see duplicated namespaces). *** JAXB BUG (1) About JAXB: JAXB instead of ingnoring xs:any content it is adding namespaces to the payload when the payload uses the default namespace. WS-Transfer uses the xsd:Any type which is not supported the right way by JAXB, so why namespaces are added to the payload even if the xsd:Any should not modify at all its content. There are less problems if you transfer an XML instance (payload) without a default namespace (<in:Invoice>...</in:Invoice>) as JAXB will be more happy. I submitted the bug to ORACLE and their answer has been they have too many dependancies and they will not fix the xs:any issue in the short time (maybe never) There is no patch for this unfortunately, but we can just limit damages. PARTIAL WORKAROUND TO (1) For having JAXB using the xs:any better (but not perfectly) it is useful to put the "processContent" attribute to "skip". This change on XSDs is providing a better behavior of JAXB, but anyway it is not solving completely the issue. JAXB *should* not change the xs:any content (payload) at all... but it does. *** Duplicated prefixes BUG (2) ns1....ns(n) prefixes are automatically generated by JAXB during marshalling. In general the most reliable way of handling namespaces is to use DOM 3 Load/Save over other ways. If we use JAXB you need to limit its damages by instructing the marshaller to use specific (predictable) namespace prefixes: com.sun.xml.bind.marshaller.NamespacePrefixMapper mapper = [...your implementation...] marshaller.setProperty("com.sun.xml.bind.namespacePrefixMapper", mapper); NOTE: I used SUN prefix mapper actually but it is an internal class, so it coul dbe better to rewrite it... This step must be done everywhere in LIME and START in a way that every namespace will be using a single prefix (better if standard) If we use LIME + START the bug is bigger as both steps will have JAXB adding issues to our payload also broking the transmission due to duplicated prefixes. Hope this helps Roberto

Operating SystemAll
ComponentAccess Point






Philip HELGER Fri, 09/12/2011 - 16:00

Hi Roberto!

Can you please check, if this is still the case with the latest version?

And if so, it would be great if you could submit a patch, that I'd like to add to out implementation.

// Philip