cxf-users mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Andreas Bucksteeg" <andreas.buckst...@hybris.de>
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="http://schemas.xmlsoap.org/soap/envelope/">
  <soap:Body>
    <ns1:getBinaryFileResponse xmlns:ns1="http://some.url">
      <GetBinaryFileResult xmlns:ns2="http://www.w3.org/2005/08/addressing/wsdl" xmlns:ns3="
some.url/Schema">
        <file>
        <content>PD94bWwgdmVyc2lvbj0iMS4wIj8+1sCglkYXRlO
G9tYWluPgoJCTxpZD4zMDAwPC9pZD4KCQk8ZG9tYWluY2xhc3NpZD4xPC9kb21haW5jbGFzc2lkPgoJCTxuYW1lPkJhZWNobGk8L25hbWU+Cgk8L2RvbWFpb
j4KPC9kb21haW5zPgo=</content>
          <filename>domain.xml</filename>
          <mimetype>text/xml</mimetype>
          <size>1349</size>
        </file>
        <ns3:resultCode>0</ns3:resultCode>
      </GetBinaryFileResult>
    </ns1:getBinaryFileResponse>
  </soap:Body>
</soap:Envelope>

The following message was generated by the old Axis 1.x implementation:
<?xml version="1.0" encoding="UTF-8"?>
<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:xsd="http://www.w3.org/2001/XMLSchema"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
  <soapenv:Body>
    <ns1:putBinaryFile soapenv:encodingStyle="http://schemas.xmlsoap.org/soap/encoding/"
xmlns:ns1="http://werk-ii.de/soap/comet">
      <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"/>
      </file>
    </ns1:putBinaryFile>
  </soapenv:Body>
</soapenv:Envelope>

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,

Andreas

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 [mailto:freeman.fang@iona.com] 
Gesendet: Montag, 14. Mai 2007 04:03
An: cxf-user@incubator.apache.org
Betreff: Re: Custom serializer / deserializer in cxf?

Hi Andreas,

I believe you can use jax-ws soap protocol handler to do your attachment 
serializer.
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
programatically.

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>();
newHandlerChain.add(sh);
((BindingProvider)port).getBinding().setHandlerChain(newHandlerChain);
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

Freeman


Mime
View raw message