Hi
On 22/04/13 15:32, jeff fitzgerald wrote:
I've been playing around with a dynamic service/plugin model that I could
register with CXF that would not require any annotations (based on some of
the docs I read here:
http://cxf.apache.org/docs/jax-rs-advanced-features.html).

I started by defining a Generic Service that had a method per HTTP
operation.

public class GenericService
{
     Response get();
     Response put(Object content);
     Response post(Object content);
     Response delete();
}

Then, I was hoping I could define a list of resources in the model file,
and map each operation within each resource to one of the methods in the
generic service.

<model xmlns="http://cxf.apache.org/jaxrs";>
     <resource name="com.example.GenericService" path="bookstore">
         <operation name="get" verb="GET" path="/books"
produces="application/xml"/>
         <operation name="get" verb="GET" path="/books/{id}">
             <param name="id" type="PATH"/>
         </operation>
     </resource>

Would you like to use the same operation to handle both /books & /books/{id} ? If so then the only (JAX-RS compliant) way to do it is to have a custom regular expression, example,

<resource name="com.example.GenericService" path="bookstore">
 <operation name="get" verb="GET" path="/books/{id:.*}"
            produces="application/xml"/>
</resource>

something like that
     <resource name="com.example.GenericService" path="bank">
         <operation name="get" verb="GET" path="/money"/>
         <operation name="put" verb="PUT" path="/money"
consumes="application/xml">
             <param name="content" type="REQUEST_BODY"/>
         </operation>
     </resource>
</model>

However, I ran into a couple of problems.

Based on the example above, in the bookstore resource, only the second GET
operation is registered; the first one returns 404.

See the comment above...

Also, if I try to
define another resource with a different path but using the same generic
service, the bookstore example above would return 404, and only the bank
endpoint would be available.

I'm guessing the resources are store in some sort of map, and they must be
using the same key (the resource name rather than the path).

Is there any way for me to define a generic resource/service class to
process more than one path?


Do you actually need com.example.GenericService to handle both

GET /bookstore/books
and
GET /bank/money

and moreover, using the same method ? I guess that was just a test, do you have a concrete requirement where something like that is required ?

Thanks, Sergey


Thanks,

Fitz


Reply via email to