You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@cxf.apache.org by Joe-D Morrison <jo...@db.com> on 2009/03/25 22:46:54 UTC
Simplest way in CXF to customize XML serialization for JAXWS WSDL-first
services?
I'm porting an application from XFire to CXF. The XFire implementation was
a code-first design with a customized serializer for one of the types.
That code obtained a reference to the type registry using this Spring
reference:
xfire.typeMappingRegistry
and then registered a custom type with the default type mapping.
The new CXF implementation is WSDL first, using JAXWS + JAXB. What's the
cleanest way to customize the serialization for one type?
One possibility is to add JAXB customizations to the jaxws:endpoint, i.e.
<bean class="org.apache.cxf.jaxb.JAXBDataBinding">
<property name="contextProperties">
<map>
????
</map>
</property>
</bean>
Another possibility is to switch from JAXB to Aegis.
In either case how do you get access to the type registry from code to add
a mapping? I read everything relevant I could find in the forums and
tried the Aegis solution:
<bean id="aegisDataBinding" class="org.apache.cxf.aegis.databinding
.AegisDatabinding" scope="prototype" />
<jaxws:endpoint ...>
<jaxws:serviceFactory>
<bean class="org.apache.cxf.jaxws
.support.JaxWsServiceFactoryBean">
<property name="dataBinding" ref
="aegisDataBinding" />
</bean>
</jaxws:serviceFactory>
and then added my custom type mapping this way:
dataBinding.getAegisContext().getTypeMapping().register(new
CustomizedType());
but that seemed to result in a completely empty type mapping that couldn't
serialize anything.
Is there any kind of HOWTO for this, the equivalent of this page
http://xfire.codehaus.org/Custom+Types but for CXF instead of XFire?
Thanks for any guidance,
- Joe
--
Joe Morrison, Lab49 Cell +1 (917)
952-2935
http://www.lab49.com Desk +1 (212)
250-8486
---
This communication may contain confidential and/or privileged information.
If you are not the intended recipient (or have received this communication
in error) please notify the sender immediately and destroy this
communication. Any unauthorized copying, disclosure or distribution of the
material in this communication is strictly forbidden.
Deutsche Bank does not render legal or tax advice, and the information
contained in this communication should not be regarded as such.
Re: Simplest way in CXF to customize XML serialization for JAXWS
WSDL-first services?
Posted by Benson Margulies <bi...@gmail.com>.
For Aegis, there is a some information on Confluence, and there are test
cases in the source tree of customization.
On Wed, Mar 25, 2009 at 5:46 PM, Joe-D Morrison <jo...@db.com>wrote:
> I'm porting an application from XFire to CXF. The XFire implementation was
> a code-first design with a customized serializer for one of the types.
> That code obtained a reference to the type registry using this Spring
> reference:
>
> xfire.typeMappingRegistry
>
> and then registered a custom type with the default type mapping.
>
> The new CXF implementation is WSDL first, using JAXWS + JAXB. What's the
> cleanest way to customize the serialization for one type?
>
> One possibility is to add JAXB customizations to the jaxws:endpoint, i.e.
>
> <bean class="org.apache.cxf.jaxb.JAXBDataBinding">
> <property name="contextProperties">
> <map>
> ????
> </map>
> </property>
> </bean>
>
> Another possibility is to switch from JAXB to Aegis.
>
> In either case how do you get access to the type registry from code to add
> a mapping? I read everything relevant I could find in the forums and
> tried the Aegis solution:
>
> <bean id="aegisDataBinding" class="org.apache.cxf.aegis.databinding
> .AegisDatabinding" scope="prototype" />
>
> <jaxws:endpoint ...>
> <jaxws:serviceFactory>
> <bean class="org.apache.cxf.jaxws
> .support.JaxWsServiceFactoryBean">
> <property name="dataBinding" ref
> ="aegisDataBinding" />
> </bean>
> </jaxws:serviceFactory>
>
> and then added my custom type mapping this way:
>
> dataBinding.getAegisContext().getTypeMapping().register(new
> CustomizedType());
>
> but that seemed to result in a completely empty type mapping that couldn't
> serialize anything.
>
> Is there any kind of HOWTO for this, the equivalent of this page
> http://xfire.codehaus.org/Custom+Types but for CXF instead of XFire?
>
> Thanks for any guidance,
> - Joe
>
> --
> Joe Morrison, Lab49 Cell +1 (917)
> 952-2935
> http://www.lab49.com Desk +1 (212)
> 250-8486
>
>
>
> ---
> This communication may contain confidential and/or privileged information.
> If you are not the intended recipient (or have received this communication
> in error) please notify the sender immediately and destroy this
> communication. Any unauthorized copying, disclosure or distribution of the
> material in this communication is strictly forbidden.
>
> Deutsche Bank does not render legal or tax advice, and the information
> contained in this communication should not be regarded as such.
Re: Simplest way in CXF to customize XML serialization for JAXWS WSDL-first services?
Posted by Daniel Kulp <dk...@apache.org>.
If you WANT to go JAXB, Jaxb DOES have @XmlJavaTypeAdapter things that can be
used to "convert" types to other types as part of
serialization/deserialization. Basically, you define a JAXB type that looks
like what you WANT on the wire, and then write an adapter that converts from
what your model wants to/from what you want on the wire. The "normal" use
for this is to map interfaces to concrete implementations, but it could
definitely work for this as well.
Dan
On Wed March 25 2009 5:46:54 pm Joe-D Morrison wrote:
> I'm porting an application from XFire to CXF. The XFire implementation was
> a code-first design with a customized serializer for one of the types.
> That code obtained a reference to the type registry using this Spring
> reference:
>
> xfire.typeMappingRegistry
>
> and then registered a custom type with the default type mapping.
>
> The new CXF implementation is WSDL first, using JAXWS + JAXB. What's the
> cleanest way to customize the serialization for one type?
>
> One possibility is to add JAXB customizations to the jaxws:endpoint, i.e.
>
> <bean class="org.apache.cxf.jaxb.JAXBDataBinding">
> <property name="contextProperties">
> <map>
> ????
> </map>
> </property>
> </bean>
>
> Another possibility is to switch from JAXB to Aegis.
>
> In either case how do you get access to the type registry from code to add
> a mapping? I read everything relevant I could find in the forums and
> tried the Aegis solution:
>
> <bean id="aegisDataBinding" class="org.apache.cxf.aegis.databinding
> .AegisDatabinding" scope="prototype" />
>
> <jaxws:endpoint ...>
> <jaxws:serviceFactory>
> <bean class="org.apache.cxf.jaxws
> .support.JaxWsServiceFactoryBean">
> <property name="dataBinding" ref
> ="aegisDataBinding" />
> </bean>
> </jaxws:serviceFactory>
>
> and then added my custom type mapping this way:
>
> dataBinding.getAegisContext().getTypeMapping().register(new
> CustomizedType());
>
> but that seemed to result in a completely empty type mapping that couldn't
> serialize anything.
>
> Is there any kind of HOWTO for this, the equivalent of this page
> http://xfire.codehaus.org/Custom+Types but for CXF instead of XFire?
>
> Thanks for any guidance,
> - Joe
--
Daniel Kulp
dkulp@apache.org
http://www.dankulp.com/blog