Friday, October 26, 2007

Couple of things about CXF

Here's a couple of things you need to think about when you're using CXF. I have my services working pretty good now. I prefer to work 'code-first' so I wanted to have my wsdl file generated (using java annotations) which in the end was really not a lot of work. Just to get the wsdl exactly right can be a bit tricky.
Anyway it works now and Axis1 and Axis2 client code can handle my services perfectly.

Just a couple of things I ran into...

- In CXF 2.0.2 there is a bug that duplicates the exception declarations in your wsdl file when specifying a target namespace in your exception class like so:
@WebFault(name="WhateverException", targetNamespace="http://exceptions.api.tripolis.com/")

A workaround is to omit the targetNamespace property. It's fixed in 2.0.3 thanx to Daniel Kulp (https://issues.apache.org/jira/browse/CXF-1127)

- I also noticed that Flex apps can't handle an array of items in the response object of a call when they're directly defined inside the object inside the response. For instance I return an array of picklistitems inside the object I return like so:
<xs:element name="keyValuePairs" maxOccurs="unbounded" minOccurs="0" type="tns:KeyValuePair" nillable="true"/>

Apparently the first elemnt in this array is not accessable when trying to iterate over the array. I don't know why but there is a fix for this.
You can wrap the array in a container object like so:
<xs:xs:element name="keyValuePairs" minOccurs="0" type="tns:KeyValuePairContainer"/>

This container just contains the array of KeyValuePair objects. When the client code is generated the container becomes transparent so the client will not see the container and will directly get the array of objects; now it works fine. Other clients (e.g. Axis1 and Axis2) won't notice the change and just keep on working.

No comments: