You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@camel.apache.org by "sandesh.naik" <sa...@accenture.com> on 2016/11/04 09:20:42 UTC

how to change default namespace ns1 or ns2 added by Camel to custom namespace

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.

Re: how to change default namespace ns1 or ns2 added by Camel to custom namespace

Posted by "sandesh.naik" <sa...@accenture.com>.
Thanks for replying Zoran

I now think we have the NamespaceConfigurer registered as I can see a debug
message from the configure method appear at app startup and it is also
changing the behaviour of the web service call.

However, in terms of the changed behaviour, not only is the 'ns1' namespace
prefix still not being replaced with 'ser' but the payload of the web
service call appears to be being encoded/encrypted, i.e. -

...
<soap:Body>
    <ns1:quote xmlns:ns1=&quot;https://&lt;domain>/">
        <Request>PD94bWwgdmVyc2lvb
        ...
        AgICAgICAgICA8L1BvbXNSZXF1ZXN0Pg==</Request>
    </ns1:quote>
</soap:Body>
...

Is there some config of CxfEndpointConfigurer/JAXBDataBinding that I need to
specify to stop this?

Also, does CxfEndpointConfigurer/JAXBDataBinding honour the config already
specified in the 'cxf://...' URI?

Thanks again




--
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-tp5789743p5789956.html
Sent from the Camel Development mailing list archive at Nabble.com.

Re: how to change default namespace ns1 or ns2 added by Camel to custom namespace

Posted by Zoran Regvart <zo...@regvart.com>.
Hi Sandesh,

On Tue, Nov 8, 2016 at 11:29 AM, sandesh.naik
<sa...@accenture.com> wrote:
> Thanks Zoran,
>      We tried implementing the changes as suggested by you. But seems like
> they are not working for us.

I've uploaded a sample project based on Spring Boot you can take a
look at it here:
https://github.com/zregvart/cxf-camel-custom-namespace-sample

> Can you let me know how we could determine if we are using JAXB in our
> application.

JAXB is used by default in CXF, you would need to configure other
supported data binding by explicitly setting `dataBinding` parameter
on the endpoint, you're not, so you're using JAXB...

> Can you also please tell how we could add NamespaceConfigurer to our
> application context registry via our implementation of SpringCameContext.
>
> Currently we have created a NamespaceConfigurer as below
[snip]

Thats the exact approach I did in the sample, it should work...

zoran
--
Zoran Regvart

Re: how to change default namespace ns1 or ns2 added by Camel to custom namespace

Posted by "sandesh.naik" <sa...@accenture.com>.
Thanks Zoran,
     We tried implementing the changes as suggested by you. But seems like
they are not working for us.

Can you let me know how we could determine if we are using JAXB in our
application.

Can you also please tell how we could add NamespaceConfigurer to our
application context registry via our implementation of SpringCameContext.

Currently we have created a NamespaceConfigurer as below

public class NamespaceConfigurer implements CxfEndpointConfigurer {

    private static final Logger LOGGER =
LoggerFactory.getLogger(NamespaceConfigurer.class);

    @Override
    public void configure(final AbstractWSDLBasedEndpointFactory
factoryBean) {

        LOGGER.debug("In NamespaceConfigurer.configure");

        final JAXBDataBinding jaxb = new JAXBDataBinding();

        final Map<String, String> namespacePrefixes = new HashMap<>();
        namespacePrefixes.put("https://services.renewals.co.uk/", "ser");
        jaxb.setNamespaceMap(namespacePrefixes);

        factoryBean.setDataBinding(jaxb);
    }
}


Then created a bean in our CamelConfig class as below    

@Bean(name="apadcRemoteNamespaceConfigurer")
    public NamespaceConfigurer apadcRemoteNamespaceConfigurer() {
        return new NamespaceConfigurer();
    }

And then tried calling this in target URI as below

String uri = "cxf://" + url + "?wsdlURL=" + wsdlUrl + "" + 
                "&synchronous=true" + 
                "&dataFormat=" + dataFormat.name() + 
                "&loggingFeatureEnabled=true"; 
        if (dataFormat == DataFormat.PAYLOAD) { 
            uri = uri + "&defaultOperationName=" + operationName; 
        } 
        uri = uri +
"&cxfEndpointConfigurer=#apadcRemoteNamespaceConfigurer";

Please can you help us with the correct approach to create this
functionality.




--
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-tp5789743p5789897.html
Sent from the Camel Development mailing list archive at Nabble.com.

Re: how to change default namespace ns1 or ns2 added by Camel to custom namespace

Posted by Zoran Regvart <zr...@redhat.com>.
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
<sa...@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