You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@cxf.apache.org by sireesh <ki...@gmail.com> on 2012/09/05 19:23:18 UTC
Remove namespace prefixes in JAX-RS
Hi,
The REST service I'm talking to doesn't like prefixes in the request xml.
But, it needs the namespace declaration.
The following request is consumed by the REST service
<AuthenticateRequest xmlns="my.namespace">
<Header xmlns="my.namespace.Core">value
</Header>
</AuthenticateRequest>
But, the request xml being generated by CXF contains namespace prefixes.
<ns3:AuthenticateRequest xmlns:ns2="my.namespace.Core"
xmlns:ns3="my.namespace">
<ns2:Header xmlns="my.namespace.Core">value
</ns2:Header>
</ns3:AuthenticateRequest>
Can someone please help me how I can remove the prefixes from the marshalled
xml.
I tried using TransformOutInterceptor, dropping the elements as below, but
it doesn't work.
List<String> dropElements = Collections.singletonList("*");
transformOutInterceptor.setOutDropElements(dropElements);
final ClientConfiguration config =
WebClient.getConfig(authenticationClient);
config.getOutInterceptors().add(transformOutInterceptor);
Thanks,
Sireesh
--
View this message in context: http://cxf.547215.n5.nabble.com/Remove-namespace-prefixes-in-JAX-RS-tp5713618.html
Sent from the cxf-user mailing list archive at Nabble.com.
Re: Remove namespace prefixes in JAX-RS
Posted by sireesh <ki...@gmail.com>.
Hi Sergey,
I tried upgrading to cxf 2.5 and use the defaultNamespace. It didn't work,
the namespaces aren't being generated but the prefixes are getting
generated.
I managed to fix my issue use a custom PhaseInterceptor and a
DelegatingXMLStreamWriter.
I had to override two methods from DelegatingXMLStreamWriter
i) writeStartElement - where I removed the prefix before calling the super
method and added an attribute with xmlns:uri
ii) writeNamespace - doing nothing and returning, so that prefixes are not
written.
Thank you very much for your suggestion about using the custom writer.
Thanks,
Kiran Sireesh
--
View this message in context: http://cxf.547215.n5.nabble.com/Remove-namespace-prefixes-in-JAX-RS-tp5713618p5713683.html
Sent from the cxf-user mailing list archive at Nabble.com.
Re: Remove namespace prefixes in JAX-RS
Posted by Sergey Beryozkin <sb...@gmail.com>.
On 06/09/12 14:59, sireesh wrote:
> Hi Sergey,
>
> Thank you for that tip.
> I've extended TransformOutInterceptor to override
> createTransformWriterIfNeeded method and planning
> to use a custom DelegatingXMLStreamWriter to customize the marhsalling so
> that I can remove the namespace.
> Couldn't find any examples when I googled.
> Please let me know if you have any suggestions.
Please check how TransformOutInterceptor itself uses outDefaultNamespace
propery, that might help
Cheers, Sergey
>
> Thanks,
> Kiran
>
>
>
> --
> View this message in context: http://cxf.547215.n5.nabble.com/Remove-namespace-prefixes-in-JAX-RS-tp5713618p5713654.html
> Sent from the cxf-user mailing list archive at Nabble.com.
--
Sergey Beryozkin
Talend Community Coders
http://coders.talend.com/
Blog: http://sberyozkin.blogspot.com
Re: Remove namespace prefixes in JAX-RS
Posted by sireesh <ki...@gmail.com>.
Hi Sergey,
Thank you for that tip.
I've extended TransformOutInterceptor to override
createTransformWriterIfNeeded method and planning
to use a custom DelegatingXMLStreamWriter to customize the marhsalling so
that I can remove the namespace.
Couldn't find any examples when I googled.
Please let me know if you have any suggestions.
Thanks,
Kiran
--
View this message in context: http://cxf.547215.n5.nabble.com/Remove-namespace-prefixes-in-JAX-RS-tp5713618p5713654.html
Sent from the cxf-user mailing list archive at Nabble.com.
Re: Remove namespace prefixes in JAX-RS
Posted by Sergey Beryozkin <sb...@gmail.com>.
Hi
On 06/09/12 12:03, sireesh wrote:
> Hi Sergey,
> Thank you very much for your quick response and help.
>
> I tried to set the property you have mentioned. I realized that I'm using
> 2.4.1 and it's
> not present in that version.
>
> Is there an alternate way of handling this, using any custom mapping handler
> or marshaller.
> If so, can you please let me know.
>
Not really sure, may be you can create custom XMLStreamWriter and
register it on the message from custom out CXF interceptor. This writer
will work directly with JAXB
Cheers, Sergey
> Thanks,
> Kiran Sireesh
>
>
>
> --
> View this message in context: http://cxf.547215.n5.nabble.com/Remove-namespace-prefixes-in-JAX-RS-tp5713618p5713647.html
> Sent from the cxf-user mailing list archive at Nabble.com.
Re: Remove namespace prefixes in JAX-RS
Posted by sireesh <ki...@gmail.com>.
Hi Sergey,
Thank you very much for your quick response and help.
I tried to set the property you have mentioned. I realized that I'm using
2.4.1 and it's
not present in that version.
Is there an alternate way of handling this, using any custom mapping handler
or marshaller.
If so, can you please let me know.
Thanks,
Kiran Sireesh
--
View this message in context: http://cxf.547215.n5.nabble.com/Remove-namespace-prefixes-in-JAX-RS-tp5713618p5713647.html
Sent from the cxf-user mailing list archive at Nabble.com.
Re: Remove namespace prefixes in JAX-RS
Posted by Sergey Beryozkin <sb...@gmail.com>.
Hi Kiran
On 06/09/12 11:21, sireesh wrote:
> Hi Sergey,
> Thank you for your suggestion.
> I tried using 'outTransformElements' as below:
>
> outTransformMap.put("{my.namespace.Core}*", "*");
>
> This completely removes the namespace as well as the prefix. But, I would
> like to have namespaces but without any prefixes like:
> <AuthenticateRequest xmlns="my.namespace">
> <Header xmlns="my.namespace.Core">value
> </Header>
> </AuthenticateRequest>
>
This is partially supported with an 'outDefaultNamespace' property, but
it can only be used to handle a single namespace, if, given the example
above, it is only 'my.namespace.Core', then it should work.
Alternatively, assuming it's always "my.namespace" and
"my.namespace.Core" then you can just get two TransformOutInterceptors,
a hack but should work.
Guess we can support 'outDefaultNamespace' containing multiple namespaces...
Cheers, Sergey
> Thanks,
> Kiran Sireesh
>
>
>
> --
> View this message in context: http://cxf.547215.n5.nabble.com/Remove-namespace-prefixes-in-JAX-RS-tp5713618p5713645.html
> Sent from the cxf-user mailing list archive at Nabble.com.
Re: Remove namespace prefixes in JAX-RS
Posted by sireesh <ki...@gmail.com>.
Hi Sergey,
Thank you for your suggestion.
I tried using 'outTransformElements' as below:
outTransformMap.put("{my.namespace.Core}*", "*");
This completely removes the namespace as well as the prefix. But, I would
like to have namespaces but without any prefixes like:
<AuthenticateRequest xmlns="my.namespace">
<Header xmlns="my.namespace.Core">value
</Header>
</AuthenticateRequest>
Thanks,
Kiran Sireesh
--
View this message in context: http://cxf.547215.n5.nabble.com/Remove-namespace-prefixes-in-JAX-RS-tp5713618p5713645.html
Sent from the cxf-user mailing list archive at Nabble.com.
Re: Remove namespace prefixes in JAX-RS
Posted by Sergey Beryozkin <sb...@gmail.com>.
Hi
On 05/09/12 18:23, sireesh wrote:
> Hi,
> The REST service I'm talking to doesn't like prefixes in the request xml.
> But, it needs the namespace declaration.
>
> The following request is consumed by the REST service
> <AuthenticateRequest xmlns="my.namespace">
> <Header xmlns="my.namespace.Core">value
> </Header>
> </AuthenticateRequest>
>
> But, the request xml being generated by CXF contains namespace prefixes.
>
> <ns3:AuthenticateRequest xmlns:ns2="my.namespace.Core"
> xmlns:ns3="my.namespace">
> <ns2:Header xmlns="my.namespace.Core">value
> </ns2:Header>
> </ns3:AuthenticateRequest>
>
> Can someone please help me how I can remove the prefixes from the marshalled
> xml.
>
> I tried using TransformOutInterceptor, dropping the elements as below, but
> it doesn't work.
> List<String> dropElements = Collections.singletonList("*");
> transformOutInterceptor.setOutDropElements(dropElements);
> final ClientConfiguration config =
> WebClient.getConfig(authenticationClient);
> config.getOutInterceptors().add(transformOutInterceptor);
>
dropElements is for dropping the actual elements, try
'outTransformElements', ex:
{http://mynamespace}MyElement:MyElement
Cheers, Sergey
> Thanks,
> Sireesh
>
>
>
> --
> View this message in context: http://cxf.547215.n5.nabble.com/Remove-namespace-prefixes-in-JAX-RS-tp5713618.html
> Sent from the cxf-user mailing list archive at Nabble.com.
--
Sergey Beryozkin
Talend Community Coders
http://coders.talend.com/
Blog: http://sberyozkin.blogspot.com