camel-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Zoran Regvart <zregv...@redhat.com>
Subject Re: how to change default namespace ns1 or ns2 added by Camel to custom namespace
Date Fri, 04 Nov 2016 13:04:17 GMT
Hi Sandesh,
you can achieve custom namespace prefixes by customizing the
DataBinding, for instance if you're using JAXB:

final JAXBDataBinding jaxb = new JAXBDataBinding();

final Map<String, String> namespacePrefixes = new HashMap<>();
namespacePrefixes.put("http://example.com/namespace", "examplePrefix");
jaxb.setNamespaceMap(namespacePrefixes);

and configure this DataBinding by implementing CxfEndpointConfigurer
and construct one in configure method, like:

class NamespaceConfigurer implements CxfEndpointConfigurer {

    @Override
    public void configure(final AbstractWSDLBasedEndpointFactory factoryBean) {
        final JAXBDataBinding jaxb = new JAXBDataBinding();

        final Map<String, String> namespacePrefixes = new HashMap<>();
        namespacePrefixes.put("http://example.com/namespace", "examplePrefix");
        jaxb.setNamespaceMap(namespacePrefixes);

        factoryBean.setDataBinding(jaxb);
    }
...
}

Then simply reference this CxfEndpointConfigurer in the
cxfEndpointConfigurer parameter of the CXF component.

But, if the endpoint expects specific namespace prefixes, it might be
that the service you're trying to invoke is not namespace aware, or is
not using a proper XML parser, which could lead to all sorts of
trouble.

zoran

On Fri, Nov 4, 2016 at 10:20 AM, sandesh.naik
<sandesh.pradeep.naik@accenture.com> wrote:
> Hi team,
>      I am looking for a technique which will help me change the default
> namespace (ns1 or ns2) added by Camel to a custom namespace (ser).
>
> Below is our XML.
>
> <soap:Envelope xmlns:soap="http://xxxx/soap/envelope/">
>    <soap:Header>
>       <AuthenticationToken xmlns="http://xxxx">
>          <Username>xxxx</Username>
>          <Password>xxxx</Password>
>       </AuthenticationToken>
>    </soap:Header>
>    <soap:Body>
>       <ns1:quote xmlns:ns1="https://xxxx">
>          <PomsRequest>
>
> I would like to change the namespace (ns1) to (ser), since that is what our
> endpoint is expecting.
>
> We tried changing the target URI from our code using below logic.
>
> String uri = "cxf://" + url + "?wsdlURL=" + wsdlUrl + "" +
>                 "&synchronous=true" +
>                 "&dataFormat=" + dataFormat.name() +
>                 "&loggingFeatureEnabled=true";
>         if (dataFormat == DataFormat.PAYLOAD) {
>             uri = uri + "&defaultOperationName=" + operationName;
>         }
>        * uri = uri +
> "&endpointName='ser:PomsSrvsWSDLSOAP'&serviceName='ser:PomsSrvsWSDL'";*
>
> But it did not do any difference.
>
> Can you let me know, if there is any inbuilt API that can be used to
> customise the namespace.
>
>
>
> --
> View this message in context: http://camel.465427.n5.nabble.com/how-to-change-default-namespace-ns1-or-ns2-added-by-Camel-to-custom-namespace-tp5789743.html
> Sent from the Camel Development mailing list archive at Nabble.com.



-- 
Zoran Regvart
zregvart@redhat.com

Mime
View raw message