I have a similar requirement which is to remove unused namespaces from SOAP
message dynamically.
As Daniel indicated " JAXB adds namespaces prefixes on the root for every
namespace it knows about so it doesn't have to do it later"
JAXB adds namespace prefixes based on service xml schema.
A real SOAP message normally does not contains every xml element defined by
schema because optional XML element does not show up if it does not have data.
Therefore the namespaces of unused xml elements in the message are not needed.
I have a web service having 250+ namespace (huge isn't it?). The SOAP message
contains 250+ line namespace prefix regardless how many elements being used in
SOAP message.
To reduce a SOAP message size, I am looking for a way to dynamically remove
unused namespace prefix based on the xml elements used in the SOAP message.
Since each SOAP message uses different set of elements, unused namespaces are
different accordingly.
What I did in AXIS world is to add a handler to find out unused namespace and
remove them.
Is there way I can do it in CXF JAXB?
Thanks
Ed
-Original Message-
From: Daniel Kulp [mailto:dk...@apache.org]
Sent: Thursday, January 14, 2016 2:33 PM
To: users@cxf.apache.org; Roberto Bottoni - AfterBit
Subject: Re: CXF remove some namespaces
> On Jan 13, 2016, at 8:34 AM, Roberto Bottoni - AfterBit
> wrote:
>
> Hi,
> CXF add automatically the following "namespaces" to Command_Cryptic and also
> creates its prefixes (ns6, ns70...) :
>
> >> xmlns:ns6="http://xml.afterbit.com/2010/06/Security_v1;
>>> xmlns:ns70="http://xml.afterbit.com/HSFREQ_07_3_1A;
>>> xmlns:ns71="http://xml.afterbit.com/HSFRES_07_3_1A; >
>
> and i cannot find why (and how) CXF add those namespaces
> for instance my package-info.java file is :
This is a JAXB thing. JAXB adds namespaces prefixes on the root for every
namespace it knows about so it doesn't have to do it later.
Unfortunately, it's also not easy to "change" that behavior. CXF's JAXB data
binding has two maps on it that can be used to adjust some of the namespaces.
One or both might be modifiable to test this.If you grab the DataBinding
object out of the client, you should be able to call either:
void setNamespaceMap(Map namespaceMap) or public void
setContextualNamespaceMap(Map contextualNamespaceMap)
to put in a map of URI to prefix. I know they allow complete control over
what the prefixes that are used (instead of ns6, ns7, etc...), but I also
believe that if they are specified, JAXB doesn't output all of them up front.
Not 100% sure on that though.
Dan
> @javax.xml.bind.annotation.XmlSchema(namespace =
> "http://xml.afterbit.com/HSFREQ_07_3_1A;, elementFormDefault =
> javax.xml.bind.annotation.XmlNsForm.QUALIFIED)
> package com.afterbit.xml.hsfreq_07_3_1a;
>
> maybe some other CXF configuration has to be done?
>
>
>
>
> - Original Message - From: "Sergey Beryozkin"
>
> To:
> Sent: Wednesday, January 13, 2016 1:07 PM
> Subject: Re: CXF remove some namespaces
>
>
>> Hi
>>
>> It looks like you'd like to optimize (remove possibly redundant
>> prefixes) as opposed to change the namespaces, the transformation
>> feature does not do it, perhaps you can use XSLT feature to drop
>> namespaces prefixes
>>
>> Cheers, Sergey
>> On 12/01/16 16:34, r.bott...@afterbit.com wrote:
>>> Hi,
>>> i use CXF 3.14
>>> i would like to remove some namespaces for some elements and
>>> preserve other..
>>>
>>> the original XML is like that :
>>>
>>> http://schemas.xmlsoap.org/soap/envelope/;>
>>>
>>> >> xmlns:wsse="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-secext-1.0.xsd;
>>> xmlns:wsu="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-utility-1.0.xsd;
>>> soap:mustUnderstand="1">
>>> >> wsu:Id="UsernameToken-371dcf1d-2ef6-4e29-8b96-eedd053fdf69">
>>> MYUSER
>>> >> Type="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-userna
>>> me-token-profile-1.0#PasswordDigest">QTh0CuaMLVIUpyLCM8vvobZZg28=>> sse:Password>
>>>
>>> >> EncodingType="http://docs.oasis-open.org/wss/2004/01/oasis-200401-ws
>>> s-soap-message-security-1.0#Base64Binary">B2BolkOOPUgz4uXRDQJlJA==>> wsse:Nonce>
>>>
>>> 2016-01-12T15:58:31.142Z
>>>
>>>
>>> >> xmlns="http://www.w3.org/2005/08/addressing;>http://webservices.afte
>>> rbit.com/HSFREQ_07_3_1A
>>>
>>> >> xmlns="http://www.w3.org/2005/08/addressing;>urn:uuid:59eeb370-c04c-
>>> 4457-bd77-b67784c37eab
>>>
>>> >> xmlns="http://www.w3.org/2005/08/addressing;>https://test.webservice
>>> s.afterbit.com/MYUSER
>>>
>>> http://www.w3.org/2005/08/addressing;>
>>> http://www.w3.org/2005/08/addressing/anonymous
>>>
>>> >>