cxf-users mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Andreas Bucksteeg" <>
Subject WG: Custom serializer / deserializer in cxf?
Date Fri, 08 Jun 2007 17:04:51 GMT
Hi Freeman, 

I have been assigned to another project for the last three weeks or so, therefore I had no
time to solve my implementation probs... 

I have played a little and I think I know how to solve my problem by using handler, but I
think that it would not be very efficient... 

Currently my cxf service implementation is returning the follwing soap message:

<?xml version="1.0" encoding="UTF-8"?>
<soap:Envelope xmlns:soap="">
    <ns1:getBinaryFileResponse xmlns:ns1="http://some.url">
      <GetBinaryFileResult xmlns:ns2="" xmlns:ns3="

The following message was generated by the old Axis 1.x implementation:
<?xml version="1.0" encoding="UTF-8"?>
<soapenv:Envelope xmlns:soapenv="" xmlns:xsd=""
    <ns1:putBinaryFile soapenv:encodingStyle=""
      <sessionId xsi:type="xsd:string">s6278514638240</sessionId>
      <fileId xsi:type="xsd:string">actions.xml</fileId>
      <file xsi:type="ns2:CometBinary" xmlns:ns2="some.url">
        <filename xsi:type="xsd:string">actions.xml</filename>
        <mimetype xsi:type="xsd:string">text/xml</mimetype>
        <size xsi:type="xsd:int">5965</size>
        <content href="cid:FB5BAE5C8AF988A00C7DC5269937F707"/>

As I mentioned before, the content of the tag <file> should not be embedded, it should
be send as an attachment and the tag should just reference to it using the attribute href
and the Content ID. 

I could use the Handler to modify the outgoing message (extract the <content> body,
remove it from the message, create a attachment from the extracted body of <content>
and use the ContentID of the attachment to add the href="cid:xyz" attribute to the <content>
tag in the message. But this does not look like the right approach, as in my opinion the message
should be created in the right format. 

So I am looking for a way to hook into the serialization process of <file> instances
 (as File is actually a Java class with the properties content, filename, mimetype, size)
to created the message directly in the needed format. Actually I would only need to override
the default serialization for the content property...

Regards from Munich,


P.S. Keep in mind that I can not change the expected message format since the client is a
third party tool, which I can not modify....

-----Urspr√ľngliche Nachricht-----
Von: Freeman Fang [] 
Gesendet: Montag, 14. Mai 2007 04:03
Betreff: Re: Custom serializer / deserializer in cxf?

Hi Andreas,

I believe you can use jax-ws soap protocol handler to do your attachment 
The client could use a SOAP protocol handler(SWAClientHandler) which 
reads several attachments from file or just like your code shows, from 
the data source, and appends
them to the outbound SOAP request using SAAJ API. This handler is specified

The server code registers a handler using the @HandlerChain annotation
within the service implementation class. In this case, SWAServerHandler
is SOAPHandler that checks and saves attachments on
inbound requests.

Attachment is client handler and server handler shows how to 
serialize/dserialize your attachment.
The client handler shows how to read attachment from file and you need 
change to read from data source in your case.
Also you need add code like
SWAClientHandler sh = new SWAClientHandler();
List<Handler> newHandlerChain = new ArrayList<Handler>();
in your client mainline to register client handler and add annotation like
@HandlerChain(file = "../common/swa_handlers.xml", name = 
"SWAHandlerChain") in your serviceImpl code to register server handler.

You can see cxf handlers sample to get more idea how jax-ws handler works.
Thanks very much


View raw message