Discussion:
Custom namespace prefix in JAXB
gquintana
2014-05-21 09:15:26 UTC
Permalink
Hello,

I need to customise the namespace prefix used in outgoing XML HTTP requests.

Outside ServiceMix, the following code does the job:

But once in ServiceMix, it raises an exception:



Obviously, the com.sun.xml.bind.namespacePrefixMapper property is not
supported. What's the appropriate way to do it? Which implementation of JAXB
is used in ServiceMix 5.4.1 / Java 7?

Thanks for your help,
Gerald



--
View this message in context: http://servicemix.396122.n5.nabble.com/Custom-namespace-prefix-in-JAXB-tp5720382.html
Sent from the ServiceMix - User mailing list archive at Nabble.com.
gquintana
2014-05-21 09:24:48 UTC
Permalink
JAXB Bundle versions:

Apache CXF Runtime JAXB DataBinding
org.apache.cxf.cxf-rt-databinding-jaxb
2.6.6
Apache ServiceMix :: Bundles :: jaxb-impl
org.apache.servicemix.bundles.jaxb-impl
2.2.1.1_2
Apache ServiceMix :: Bundles :: jaxb-xjc
org.apache.servicemix.bundles.jaxb-xjc
2.2.1.1_2



--
View this message in context: http://servicemix.396122.n5.nabble.com/Custom-namespace-prefix-in-JAXB-tp5720382p5720383.html
Sent from the ServiceMix - User mailing list archive at Nabble.com.
Cristiano Costantini
2014-05-21 09:30:30 UTC
Permalink
Try adding a package-info.java to the annotated class, and fill in with
something similar to the following

@XmlSchema(namespace = "http://example.org/main-namespace",
elementFormDefault = XmlNsForm.QUALIFIED, xmlns = {
@XmlNs(prefix = "my", namespaceURI = "
http://example.org/main-namespace")
@XmlNs(prefix = "other", namespaceURI = "
http://example.org/other-referred-namespace")
})
package my.package;

import javax.xml.bind.annotation.XmlNs;
import javax.xml.bind.annotation.XmlNsForm;
import javax.xml.bind.annotation.XmlSchema;


consider that @XmlNs is only a "suggestion" and often it is ignored

Cristiano
Post by gquintana
Apache CXF Runtime JAXB DataBinding
org.apache.cxf.cxf-rt-databinding-jaxb
2.6.6
Apache ServiceMix :: Bundles :: jaxb-impl
org.apache.servicemix.bundles.jaxb-impl
2.2.1.1_2
Apache ServiceMix :: Bundles :: jaxb-xjc
org.apache.servicemix.bundles.jaxb-xjc
2.2.1.1_2
--
http://servicemix.396122.n5.nabble.com/Custom-namespace-prefix-in-JAXB-tp5720382p5720383.html
Sent from the ServiceMix - User mailing list archive at Nabble.com.
gquintana
2014-05-21 12:15:44 UTC
Permalink
Thanks for you advice, I tried this solution but:
- I can not make the cxf-xjc-plugin Maven plugin generate the appropriate
package-info.java
- The generated XML contains a "ew:" behind each element and I need to have
it only on the root element.

I recognize the endpoint I am compelled to access sucks.

I tried to marshal un JAXBElement with QName speciying the prefix, but it
doesn't help.

My only option left, is doing search/replace on the generated String
message. This solutions is abominable as well.





--
View this message in context: http://servicemix.396122.n5.nabble.com/Custom-namespace-prefix-in-JAXB-tp5720382p5720385.html
Sent from the ServiceMix - User mailing list archive at Nabble.com.
Cristiano Costantini
2014-05-21 12:31:06 UTC
Permalink
Yes, sorry, my advice is applicable to a Java First approach, where I add
the package-info.java manually
I don't use cxf-xjc-plugin but I write JaxB annotated Java and generate XML
Schemas and WSDL from it...

"- The generated XML contains a "ew:" behind each element and I need to have
it only on the root element."
maybe this depend on the elementFormDefault: if it is QUALIFIED, every
element will use the prefix, try with UNQUALIFIED
Post by gquintana
- I can not make the cxf-xjc-plugin Maven plugin generate the appropriate
package-info.java
- The generated XML contains a "ew:" behind each element and I need to have
it only on the root element.
I recognize the endpoint I am compelled to access sucks.
I tried to marshal un JAXBElement with QName speciying the prefix, but it
doesn't help.
My only option left, is doing search/replace on the generated String
message. This solutions is abominable as well.
--
http://servicemix.396122.n5.nabble.com/Custom-namespace-prefix-in-JAXB-tp5720382p5720385.html
Sent from the ServiceMix - User mailing list archive at Nabble.com.
Loading...