You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@cxf.apache.org by "Vjacheslav V. Borisov" <sl...@gmail.com> on 2016/04/25 09:48:56 UTC
WADL with references - java code generation
Hi!
Trying to generate code from WADL with references
http://cxf.apache.org/docs/jaxrs-services-description.html#JAXRSServicesDescription-
WADLwithreferences
I am getting strange results
1.
@Path("/books")
public interface BooksResource {
}
2.
@Path("/bookstore/{id}")
public interface BookstoreIdResource {
@GET
@Produces("application/xml")
Book get(@PathParam("id") String id);
}
Why (1) public interface BooksResource is empty?
Shouldn't it contain method that returns subresource instance ?
Why (2) contains Book get(..) method,
Shouldn't it also contain method that returns subresource instance ?
Re: WADL with references - java code generation
Posted by "Vjacheslav V. Borisov" <sl...@gmail.com>.
Yes, with <resource path="/books/bookstore/{id}" type="#bookResource"/>
It generates both interfaces with Book get(@PathParam("id") String id);
But no subresource
Result I am tried to achive with resource_type is equal to this wadl with
ids:
<resources base="http://localhost:8080/">
<resource path="/bookstore">
<resource path="/{id}" type="#bookResource"
id="pkg.BookSubResource"/>
</resource>
<resource path="/books">
<resource path="/bookstore/{id}" type="#bookResource"
id="pkg.BookSubResource">
<param name="id" style="template"/>
<method name="GET">
<response>
<representation mediaType="application/xml" />
</response>
</method>
</resource>
</resource>
</resources>
It contains two resources with same id="pkg.BookSubResource" and it
generates desired result
1. @Path("/bookstore")
public interface BookstoreResource {
@Path("/{id}")
BookSubResource getBookSubResource();
}
2. @Path("/books")
public interface BooksResource {
@Path("/bookstore/{id}")
BookSubResource getBookSubResource(@PathParam("id") String id);
}
3. public interface BookSubResource {
@GET
@Produces("application/xml")
Book get();
}
Where (1) and (2) are using (3) subresource. In WADL this is achived with
duplicating id="pkg.BookSubResource" on different resources,
and ony one is containing "subresource" methods.
This is undocumented, but working feature. Hoewer, reading documentation I
was thinking that this should be described using
resource_type record, so this is why I am posted my question.
2016-04-25 13:27 GMT+04:00 Sergey Beryozkin <sb...@gmail.com>:
> Hi
> On 25/04/16 08:48, Vjacheslav V. Borisov wrote:
>
>> Hi!
>>
>> Trying to generate code from WADL with references
>>
>> http://cxf.apache.org/docs/jaxrs-services-description.html#JAXRSServicesDescription-
>> WADLwithreferences
>>
>>
>> I am getting strange results
>> 1.
>> @Path("/books")
>> public interface BooksResource {
>>
>> }
>>
>> 2.
>>
>> @Path("/bookstore/{id}")
>> public interface BookstoreIdResource {
>>
>> @GET
>> @Produces("application/xml")
>> Book get(@PathParam("id") String id);
>>
>> }
>>
>>
>> Why (1) public interface BooksResource is empty?
>> Shouldn't it contain method that returns subresource instance ?
>>
>
> The fact that example shows one resource enclosing another one does not
> mean the enclosed one needs to be generated as a JAX-RS subresource class
> (this is only possible to do with adding id attributes to WADL that can be
> understood by CXF, ids being class names),
>
> it is equivalent to a commented code in that example, however the fact the
> interface is empty is a problem, can you please try the commented out
> fragment instead ?
>
>
>> Why (2) contains Book get(..) method,
>> Shouldn't it also contain method that returns subresource instance ?
>>
>> Not sure I understand this question.
> <resource path="/bookstore/{id}" type="#bookResource"/>
>
> refers to a resource fragment where a GET method is defined
>
> Cheers, Sergey
>
> --
> Sergey Beryozkin
>
> Talend Community Coders
> http://coders.talend.com/
>
Re: WADL with references - java code generation
Posted by Sergey Beryozkin <sb...@gmail.com>.
Hi
On 25/04/16 08:48, Vjacheslav V. Borisov wrote:
> Hi!
>
> Trying to generate code from WADL with references
> http://cxf.apache.org/docs/jaxrs-services-description.html#JAXRSServicesDescription-
> WADLwithreferences
>
>
> I am getting strange results
> 1.
> @Path("/books")
> public interface BooksResource {
>
> }
>
> 2.
>
> @Path("/bookstore/{id}")
> public interface BookstoreIdResource {
>
> @GET
> @Produces("application/xml")
> Book get(@PathParam("id") String id);
>
> }
>
>
> Why (1) public interface BooksResource is empty?
> Shouldn't it contain method that returns subresource instance ?
The fact that example shows one resource enclosing another one does not
mean the enclosed one needs to be generated as a JAX-RS subresource
class (this is only possible to do with adding id attributes to WADL
that can be understood by CXF, ids being class names),
it is equivalent to a commented code in that example, however the fact
the interface is empty is a problem, can you please try the commented
out fragment instead ?
>
> Why (2) contains Book get(..) method,
> Shouldn't it also contain method that returns subresource instance ?
>
Not sure I understand this question.
<resource path="/bookstore/{id}" type="#bookResource"/>
refers to a resource fragment where a GET method is defined
Cheers, Sergey
--
Sergey Beryozkin
Talend Community Coders
http://coders.talend.com/