Hi Francesco
On 15/10/13 13:07, Francesco Chicchiriccò wrote:
Hi,
I am currently trying to enrich the WADL auto-generated by CXF 2.7.7 in
Syncope.

I currently have these Spring beans defined:

   <bean id="wadlGenerator"
class="org.apache.cxf.jaxrs.model.wadl.WadlGenerator">
     <property name="applicationTitle" value="Apache Syncope
${project.version}"/>
     <property name="namespacePrefix" value="syncope"/>
     <property name="linkJsonToXmlSchema" value="true"/>
     <property name="useJaxbContextForQnames" value="true"/>
     <property name="ignoreMessageWriters" value="true"/>
     <property name="addResourceAndMethodIds" value="true"/>
   </bean>

and

   <jaxrs:server id="restContainer" address="/"
staticSubresourceResolution="true">
       <!-- snip -->
     <jaxrs:providers>
       <ref bean="jaxbProvider"/>
       <ref bean="jsonProvider"/>
       <ref bean="exceptionMapper"/>
       <ref bean="wadlGenerator"/>
     </jaxrs:providers>
   </jaxrs:server>

I am currently testing one of available services that now looks as
follows (showing only a couple of methods for simplicity):

@Path("users")
@Produces({MediaType.APPLICATION_XML, MediaType.APPLICATION_JSON})
@Consumes({MediaType.APPLICATION_XML, MediaType.APPLICATION_JSON})
public interface UserService {

     @GET
     @Path("{userId}")
     @Descriptions(
             @Description(target = DocTarget.METHOD, value = "Returns a
single user matching the provided userId"))
     UserTO read(@PathParam("userId") Long userId);


     @GET
     @XMLName("{http://syncope.apache.org/1.1}users";)
     List<UserTO> list();
}

Now, while the former becomes (in the WADL)

<method name="GET" id="read">
   <doc>Returns a single user matching the provided userId</doc>
   <request/>
   <response>
     <representation mediaType="application/xml" element="syncope1:user"/>
     <representation mediaType="application/json" element="syncope1:user"/>
   </response>
</method>

which is just fine, the latter is instead reported as

<method name="GET" id="list">
   <response>
     <representation mediaType="application/xml" element="syncope1:users"/>
     <representation mediaType="application/json" element="syncope1:user"/>
   </response>
</method>

As you can see, representation/@element is different between JSON and
XML, e.g. for XML the value provided via @XMLName is used, while for
JSON it is reported as if the return type was plain 'UserTO' instead of
'List<UserTO>'.

This is a bug to do with linking JSON reps to XML schemas, I'll have a look; I'm actually experimenting with WADL Generator right now anyway :-)

Without @XMLName, element attribute is not even reported for XML.

Right, I thought that typically we can't be 100% sure what the wrapper name is, the default would be XMLRootElement's local name + "s" - but it is not guaranteed to be precise; however I think may be we can relax it, users can customize with XMLName if the default name calculation does not work

Moreover, I would expect to find something in the <schema> section of
the WADL for '{http://syncope.apache.org/1.1}users', as [1] seems to
suggest.

has UserTO @XmlRootElement attached to it ?

Cheers, Sergey

Any clue?
TIA

Regards.

[1]
http://cxf.apache.org/docs/jaxrs-services-description.html#JAXRSServicesDescription-RepresentingexplicitJAXBcollections




Reply via email to