> On Jan 13, 2016, at 8:34 AM, Roberto Bottoni - AfterBit 
> <r.bott...@afterbit.com> wrote:
> 
> Hi,
> CXF add automatically the following "namespaces" to Command_Cryptic and also 
> creates its prefixes (ns6, ns70...)  :
> 
> <ns70:Command_Cryptic
>>> 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<String, String> namespaceMap)
or 
public void setContextualNamespaceMap(Map<String, String> 
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" <sberyoz...@gmail.com>
> To: <users@cxf.apache.org>
> 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 :
>>> 
>>> <soap:Envelope xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/";>
>>>     <soap:Header>
>>>         <wsse:Security
>>> 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">
>>>             <wsse:UsernameToken
>>> wsu:Id="UsernameToken-371dcf1d-2ef6-4e29-8b96-eedd053fdf69">
>>>                 <wsse:Username>MYUSER</wsse:Username>
>>>                 <wsse:Password
>>> Type="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-username-token-profile-1.0#PasswordDigest";>QTh0CuaMLVIUpyLCM8vvobZZg28=</wsse:Password>
>>> 
>>>                 <wsse:Nonce
>>> EncodingType="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-soap-message-security-1.0#Base64Binary";>B2BolkOOPUgz4uXRDQJlJA==</wsse:Nonce>
>>> 
>>>                 <wsu:Created>2016-01-12T15:58:31.142Z</wsu:Created>
>>>             </wsse:UsernameToken>
>>>         </wsse:Security>
>>>         <Action
>>> xmlns="http://www.w3.org/2005/08/addressing";>http://webservices.afterbit.com/HSFREQ_07_3_1A</Action>
>>> 
>>>         <MessageID
>>> xmlns="http://www.w3.org/2005/08/addressing";>urn:uuid:59eeb370-c04c-4457-bd77-b67784c37eab</MessageID>
>>> 
>>>         <To
>>> xmlns="http://www.w3.org/2005/08/addressing";>https://test.webservices.afterbit.com/MYUSER</To>
>>> 
>>>         <ReplyTo xmlns="http://www.w3.org/2005/08/addressing";>
>>> <Address>http://www.w3.org/2005/08/addressing/anonymous</Address>
>>>         </ReplyTo>
>>>         <ns6:AMA_SecurityHostedUser
>>> 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"; >
>>>             <ns6:UserID AgentDutyCode="SS" POS_Type="0"
>>> PseudoCityCode="AAABBB" RequestorType="X"/>
>>>         </ns6:AMA_SecurityHostedUser>
>>>     </soap:Header>
>>>     <soap:Body>
>>>         <ns70:Command_Cryptic
>>> 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"; >
>>>             <ns70:longTextString>
>>>                 <ns70:textStringDetails>Hi</ns70:textStringDetails>
>>>             </ns70:longTextString>
>>>         </ns70:Command_Cryptic>
>>>     </soap:Body>
>>> </soap:Envelope>
>>> 
>>> 
>>> 
>>> and this is what i would want :
>>> 
>>> 
>>> <soap:Envelope xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/";>
>>>     <soap:Header>
>>>         <wsse:Security
>>> 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">
>>>             <wsse:UsernameToken
>>> wsu:Id="UsernameToken-371dcf1d-2ef6-4e29-8b96-eedd053fdf69">
>>>                 <wsse:Username>MYUSER</wsse:Username>
>>>                 <wsse:Password
>>> Type="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-username-token-profile-1.0#PasswordDigest";>QTh0CuaMLVIUpyLCM8vvobZZg28=</wsse:Password>
>>> 
>>>                 <wsse:Nonce
>>> EncodingType="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-soap-message-security-1.0#Base64Binary";>B2BolkOOPUgz4uXRDQJlJA==</wsse:Nonce>
>>> 
>>>                 <wsu:Created>2016-01-12T15:58:31.142Z</wsu:Created>
>>>             </wsse:UsernameToken>
>>>         </wsse:Security>
>>>         <Action
>>> xmlns="http://www.w3.org/2005/08/addressing";>http://webservices.afterbit.com/HSFREQ_07_3_1A</Action>
>>> 
>>>         <MessageID
>>> xmlns="http://www.w3.org/2005/08/addressing";>urn:uuid:59eeb370-c04c-4457-bd77-b67784c37eab</MessageID>
>>> 
>>>         <To
>>> xmlns="http://www.w3.org/2005/08/addressing";>https://test.webservices.afterbit.com/MYUSER</To>
>>> 
>>>         <ReplyTo xmlns="http://www.w3.org/2005/08/addressing";>
>>> <Address>http://www.w3.org/2005/08/addressing/anonymous</Address>
>>>         </ReplyTo>
>>>         <ns6:AMA_SecurityHostedUser
>>> xmlns:ns6="http://xml.afterbit.com/2010/06/Security_v1";>
>>>             <ns6:UserID AgentDutyCode="SS" POS_Type="0"
>>> PseudoCityCode="AAABBB" RequestorType="X"/>
>>>         </ns6:AMA_SecurityHostedUser>
>>>     </soap:Header>
>>>     <soap:Body>
>>>         <ns70:Command_Cryptic>
>>>             <ns70:longTextString>
>>>                 <ns70:textStringDetails>Hi</ns70:textStringDetails>
>>>             </ns70:longTextString>
>>>         </ns70:Command_Cryptic>
>>>     </soap:Body>
>>> </soap:Envelope>
>>> 
>>> 
>>> that is :
>>> 
>>> 1) <ns6:AMA_SecurityHostedUser
>>> 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"; >
>>> becomes :
>>> <ns6:AMA_SecurityHostedUser
>>> xmlns:ns6="http://xml.afterbit.com/2010/06/Security_v1"; >
>>> 2) <ns70:Command_Cryptic
>>> 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"; >
>>> becomes :
>>> <ns70:Command_Cryptic >
>>> 
>>> 
>>> this is my java unsuccessful code :
>>> 
>>> 
>>> Map<String, String> outTransformMap = new HashMap<String, String>();
>>> outTransformMap.put("{http://xml.afterbit.com/HSFREQ_07_3_1A}*";, "*");
>>> outTransformMap.put("{http://xml.afterbit.com/HSFRES_07_3_1A}*";, "*");
>>> outTransformMap.put("{http://xml.afterbit.com/2010/06/Security_v1}*";, "*");
>>> outTransformMap.put("AMA_SecurityHostedUser",
>>> "{http://xml.afterbit.com/2010/06/Security_v1}AMA_SecurityHostedUser";);
>>> org.apache.cxf.interceptor.transform.TransformOutInterceptor
>>> transformOutInterceptor  = new
>>> org.apache.cxf.interceptor.transform.TransformOutInterceptor();
>>> transformOutInterceptor.setOutTransformElements(outTransformMap);
>>> client.getOutInterceptors().add(transformOutInterceptor);
>>> 
>>> Thanks!
>>> 
>>> 
>>> 
>>> 
>>> 
>> 
>> 
>> -- 
>> Sergey Beryozkin
>> 
>> Talend Community Coders
>> http://coders.talend.com/
>> 
> 

-- 
Daniel Kulp
dk...@apache.org - http://dankulp.com/blog
Talend Community Coder - http://coders.talend.com

Reply via email to