cxf-users mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Sergey Beryozkin <sberyoz...@gmail.com>
Subject Re: WADL generation: linkJsonToXmlSchema & XMLName
Date Thu, 17 Oct 2013 15:55:17 GMT
Hi Francesco,

the JSON to schema link issue is fixed now, it should actually work with 
Produces/Consumes containing application/json only, but there was a bug 
when multiple media types were set.

@XMLName on explicit collections is optional now,

I was not able though to reproduce the issue with a package info being 
not picked up; the schema is generated in such cases too.

The package of UserTO has no packageinfo, have you added it locally ?
One other thing to check is whether a complete JAXBContext has even been 
created, what may've happened is that few types like Response have 
slipped in which would cause JAXBContext creation to fail, that has been 
tightened now too,

Please try the snapshots

Cheers, Sergey

On 15/10/13 16:02, Sergey Beryozkin wrote:
> Hi
> On 15/10/13 13:48, Francesco Chicchiriccò wrote:
>> On 15/10/2013 14:43, Sergey Beryozkin wrote:
>>> 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
>>> :-)
>>
>> Nice coincidence :-)
>> If there is any related issue on JIRA, please report.
>>
> Sure, https://issues.apache.org/jira/browse/CXF-5336
>
> There are few issues there I'd like to address, some of them minor, and
> I tried to catch major ones in the subject
>
>>>> 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
>>
>> Sounds reasonable.
>>
>>>> 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 ?
>>
>> Sure:
>> https://svn.apache.org/repos/asf/syncope/branches/1_1_X/common/src/main/java/org/apache/syncope/common/to/UserTO.java
>>
>>
>>
>> In addition to this, I have also defined some package-info.java with
>> content:
>>
>> @XmlSchema(namespace = "http://syncope.apache.org/1.1")
>> package org.apache.syncope.common.to;
>>
>> and put
>>
>>      <property name="namespacePrefixes">
>>        <map>
>>          <entry key="http://syncope.apache.org/1.1">
>>            <value>syncope</value>
>>          </entry>
>>        </map>
>>      </property>
>>
>> in jaxProvider.
>>
> Looks like it misses on the package info in the explicit collections
> case, though I'm pretty sure it works otherwise.
> Btw, I'm seeing the issues with the generator adding new XSD elements
> into the already generated schema, fixed locally already
>
> Cheers, Sergey
>
> Thanks, Sergey
>
>> Regards.
>>
>>> Cheers, Sergey
>>>
>>>> Any clue?
>>>> TIA
>>>>
>>>> Regards.
>>>>
>>>> [1]
>>>> http://cxf.apache.org/docs/jaxrs-services-description.html#JAXRSServicesDescription-RepresentingexplicitJAXBcollections
>>>>
>>>
>>>
>>
>
>



Mime
View raw message