You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@cxf.apache.org by Leith Shabbot <ls...@gmail.com> on 2012/10/16 22:18:59 UTC

Linking the contents in a Response to the WADL

Hi:

I am currently using Apache CXF 2.6.1.  I have a few POJO annotated with
JAXB. Currently just targeting JSON as the format for my REST service. I am
looking at the WADL that gets generated and see the grammars section and
the resources section.  Everything looks good, with the exception that the
type attribute does not refer to one of my types defined in the grammar
section.  For my class that services the request, the operation returns a
Response object and this operation uses the
@ElementClass(response=Echo.class), in which JAXB annotated Echo class
makes up the body of the the response.


Thanks,

Re: Linking the contents in a Response to the WADL

Posted by Sergey Beryozkin <sb...@gmail.com>.
On 17/10/12 15:27, Leith Shabbot wrote:
> I tried the following and I still do not see the type attribute referring
> to my JAXB class.  Am I missing something??  Here is skeleton of my files:
>
> //spring deployment file
> <!-- WadlGenerator configuraiton -->
> <bean id="wadlGenerator"
> class="org.apache.cxf.jaxrs.model.wadl.WadlGenerator">
> <property name="linkJsonToXmlSchema" value="true" />
> </bean>
>
> <!-- Start of Jackson configuration -->
> <bean id="jacksonAnnotationInspector"
> class="com.fasterxml.jackson.databind.introspect.JacksonAnnotationIntrospector"
> />
>
> <bean id="jaxbAnnotationInspector"
> class="com.fasterxml.jackson.module.jaxb.JaxbAnnotationIntrospector" />
>
> <bean id="annotationIntrospector"
> class="com.fasterxml.jackson.databind.AnnotationIntrospector.Pair">
> <constructor-arg ref="jaxbAnnotationInspector" />
> <constructor-arg ref="jacksonAnnotationInspector" />
> </bean>
>
> <bean id="jacksonObjectMapper"
> class="com.fasterxml.jackson.databind.ObjectMapper">
> <property name="annotationIntrospector" ref="annotationIntrospector" />
> </bean>
>
> <bean id="jsonProvider"
> class="com.fasterxml.jackson.jaxrs.json.JacksonJsonProvider">
> <constructor-arg ref="jacksonObjectMapper" />
> </bean>
> <!-- End of Jackson configuration -->
>
> <jaxrs:server id="EchoApi" address="/">
> <jaxrs:serviceBeans>
> <ref bean="echoService" />
> </jaxrs:serviceBeans>
> <jaxrs:providers>
> <ref bean="wadlGenerator" />
> <ref bean="jsonProvider" />
> <ref bean="marshallingExceptionMapper" />
> </jaxrs:providers>
> </jaxrs:server>
>
>
> //echoService
>
> @Path("echo")
> @POST
> @Consumes({ APPLICATION_JSON })
> @Produces({ APPLICATION_JSON })
> @ElementClass(response = Echo.class)
> public Response echo(@Context final MessageContext context, final Echo
> echo) {
>             //some code...
>           }
>
> //Echo class
> @XmlRootElement(name = "echo")
> @XmlAccessorType(XmlAccessType.FIELD)
> @XmlType(propOrder = { "...", "...", "..."" }) //the ... are actual values
> in my real code
> public class Echo {
>     //some code...
> }
>

I've updated my local test with the following:

@PUT
     @Path("books/{bookid}")
     @Description("Update the book")
     @Consumes("application/json")
     @Produces("application/json")
     @ElementClass(response = Book.class)
     public Response addBook(@PathParam("id") int id,
                         @PathParam("bookid") int bookId,
                         @MatrixParam("mid") int matrixId) {
         return null;
     }

And I see a link created - try 2.5.6, I recall there were issues with 
WADLGenerator not 'collecting' class references like Echo if there were 
no direct references to them but only from annotations like ElementClass

Cheers, Sergey

>
> On Wed, Oct 17, 2012 at 4:23 AM, Sergey Beryozkin<sb...@gmail.com>wrote:
>
>> Hi
>>
>> On 16/10/12 21:18, Leith Shabbot wrote:
>>
>>> Hi:
>>>
>>> I am currently using Apache CXF 2.6.1.  I have a few POJO annotated with
>>> JAXB. Currently just targeting JSON as the format for my REST service. I
>>> am
>>> looking at the WADL that gets generated and see the grammars section and
>>> the resources section.  Everything looks good, with the exception that the
>>> type attribute does not refer to one of my types defined in the grammar
>>> section.  For my class that services the request, the operation returns a
>>> Response object and this operation uses the
>>> @ElementClass(response=Echo.**class), in which JAXB annotated Echo class
>>> makes up the body of the the response.
>>>
>>>
>> WADLGenerator has a property "linkJsonToXmlSchema", so if you explicitly
>> register it in jaxrs:providers with this property enabled then it should
>> get json representations linked to the schema.
>>
>> By the way, if you can get a chance, try experimenting with returning a
>> generated WADL in JSON format,
>>
>> Cheers, Sergey
>>
>>
>>> Thanks,
>>>
>>>
>>
>> --
>> Sergey Beryozkin
>>
>> Talend Community Coders
>> http://coders.talend.com/
>>
>> Blog: http://sberyozkin.blogspot.com
>>
>


-- 
Sergey Beryozkin

Talend Community Coders
http://coders.talend.com/

Blog: http://sberyozkin.blogspot.com

Re: Linking the contents in a Response to the WADL

Posted by Leith Shabbot <ls...@gmail.com>.
I tried the following and I still do not see the type attribute referring
to my JAXB class.  Am I missing something??  Here is skeleton of my files:

//spring deployment file
<!-- WadlGenerator configuraiton -->
<bean id="wadlGenerator"
class="org.apache.cxf.jaxrs.model.wadl.WadlGenerator">
<property name="linkJsonToXmlSchema" value="true" />
</bean>

<!-- Start of Jackson configuration -->
<bean id="jacksonAnnotationInspector"
class="com.fasterxml.jackson.databind.introspect.JacksonAnnotationIntrospector"
/>

<bean id="jaxbAnnotationInspector"
class="com.fasterxml.jackson.module.jaxb.JaxbAnnotationIntrospector" />

<bean id="annotationIntrospector"
class="com.fasterxml.jackson.databind.AnnotationIntrospector.Pair">
<constructor-arg ref="jaxbAnnotationInspector" />
<constructor-arg ref="jacksonAnnotationInspector" />
</bean>

<bean id="jacksonObjectMapper"
class="com.fasterxml.jackson.databind.ObjectMapper">
<property name="annotationIntrospector" ref="annotationIntrospector" />
</bean>

<bean id="jsonProvider"
class="com.fasterxml.jackson.jaxrs.json.JacksonJsonProvider">
<constructor-arg ref="jacksonObjectMapper" />
</bean>
<!-- End of Jackson configuration -->

<jaxrs:server id="EchoApi" address="/">
<jaxrs:serviceBeans>
<ref bean="echoService" />
</jaxrs:serviceBeans>
<jaxrs:providers>
<ref bean="wadlGenerator" />
<ref bean="jsonProvider" />
<ref bean="marshallingExceptionMapper" />
</jaxrs:providers>
</jaxrs:server>


//echoService

@Path("echo")
@POST
@Consumes({ APPLICATION_JSON })
@Produces({ APPLICATION_JSON })
@ElementClass(response = Echo.class)
public Response echo(@Context final MessageContext context, final Echo
echo) {
           //some code...
         }

//Echo class
@XmlRootElement(name = "echo")
@XmlAccessorType(XmlAccessType.FIELD)
@XmlType(propOrder = { "...", "...", "..."" }) //the ... are actual values
in my real code
public class Echo {
   //some code...
}


On Wed, Oct 17, 2012 at 4:23 AM, Sergey Beryozkin <sb...@gmail.com>wrote:

> Hi
>
> On 16/10/12 21:18, Leith Shabbot wrote:
>
>> Hi:
>>
>> I am currently using Apache CXF 2.6.1.  I have a few POJO annotated with
>> JAXB. Currently just targeting JSON as the format for my REST service. I
>> am
>> looking at the WADL that gets generated and see the grammars section and
>> the resources section.  Everything looks good, with the exception that the
>> type attribute does not refer to one of my types defined in the grammar
>> section.  For my class that services the request, the operation returns a
>> Response object and this operation uses the
>> @ElementClass(response=Echo.**class), in which JAXB annotated Echo class
>> makes up the body of the the response.
>>
>>
> WADLGenerator has a property "linkJsonToXmlSchema", so if you explicitly
> register it in jaxrs:providers with this property enabled then it should
> get json representations linked to the schema.
>
> By the way, if you can get a chance, try experimenting with returning a
> generated WADL in JSON format,
>
> Cheers, Sergey
>
>
>> Thanks,
>>
>>
>
> --
> Sergey Beryozkin
>
> Talend Community Coders
> http://coders.talend.com/
>
> Blog: http://sberyozkin.blogspot.com
>

Re: Linking the contents in a Response to the WADL

Posted by Sergey Beryozkin <sb...@gmail.com>.
Hi
On 16/10/12 21:18, Leith Shabbot wrote:
> Hi:
>
> I am currently using Apache CXF 2.6.1.  I have a few POJO annotated with
> JAXB. Currently just targeting JSON as the format for my REST service. I am
> looking at the WADL that gets generated and see the grammars section and
> the resources section.  Everything looks good, with the exception that the
> type attribute does not refer to one of my types defined in the grammar
> section.  For my class that services the request, the operation returns a
> Response object and this operation uses the
> @ElementClass(response=Echo.class), in which JAXB annotated Echo class
> makes up the body of the the response.
>

WADLGenerator has a property "linkJsonToXmlSchema", so if you explicitly 
register it in jaxrs:providers with this property enabled then it should 
get json representations linked to the schema.

By the way, if you can get a chance, try experimenting with returning a 
generated WADL in JSON format,

Cheers, Sergey

>
> Thanks,
>


-- 
Sergey Beryozkin

Talend Community Coders
http://coders.talend.com/

Blog: http://sberyozkin.blogspot.com