Force cxf to generate DataHandler instead of byte[] for MTOM attachment

968 views Asked by At

I have to implement SOAP-Calls using MTOM-Attachments. The WSDL is provided by an external Partner so I can't / don't want to modify it.

I used to generate the Client using axis2 and adb but I would much rather use CXF and JAXB because the generated code looks so much cleaner.

Sadly the WSDL defines the attachment element as follows:

<xsd:element name="documentBinary" type="xsd:base64Binary" />

Which makes CXF (Wsdl2Java) generate the following field:

@XmlValue
protected byte[] documentBinary;

This will lead to the attachment beeing inlined in the SOAP-Message and the SOAP-Service will reject it.

Axis 2 used to generate a field of type DataHandler using the same .xsd and .wsdl files.

I know that i Can change the definition to

<xsd:element name="documentBinary" type="xsd:base64Binary" xmime:expectedContentTypes="*/*">

which will generate the proper code:

@XmlElement(required = true)
@XmlMimeType("*/*")
protected DataHandler documentBinary;

Is there a way to force CXF to generate the second outcome without touching the WSDL (would rather not, as its provided by a third party). Maybe by using a JAXB/JAXWS-Bindings File?

0

There are 0 answers