cxf-users mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Sergey Beryozkin" <sbery...@progress.com>
Subject RE: Delegating REST request to sub-resource classes ??
Date Tue, 27 Oct 2009 22:39:04 GMT
Hi

It is 

subresourceLocatorItemHandler() which will do the delegation in this
example, because it is a subresource locator.

This method has only a @Path annotation so it returns an object
(CatalogHandler impl) which will be able to execute a required action...

So if you have 

POST catalogue/123/delete/xyz

Then 'catalogue' will be consumed by CXF servlet,
123/delete will be captured by 

@PathParam("id") and @PathParam("action")

so you can use an "action" to select a handler which will do something
with an item with id "id".

Now that I know for sure you always do POST then you can do

interface CatalogueItemHandler {

    @POST
    @Path("{lastsegment}")  
    public Response handle(@PathParam("lastsegment") String str);
} 

> public class SearchCatalogueItemHandler {
> 
>    SearchCatalogueItemHandler();
>    public Response handle(String lastsegment) {}
> }

'lastsegment' will capture 'xyz'

Cheers, Sergey 

-----Original Message-----
From: vmrm [mailto:rmode@vmware.com] 
Sent: 23 October 2009 21:47
To: users@cxf.apache.org
Subject: Re: Delegating REST request to sub-resource classes ??


Thanks Sergey, for helping, as always.

But, I am confused a bit here as to how the request is going to be
delegated
to any of subresourceclass 
handler.

Do we assume that getItemHandler method will do the delegation? 
If yes, can you please help me understand how? 

And will it handle following requirement ?

The request : 
POST catalogue/123/delete/xyz  HTTP1.1
...headers...
Content-lenght:0

will trigger the method "subresourceLocatorItemHandler" in
"BaseRESTResource" but 

1) how will it call the class DeleteCatalogueItemHandler ?

2) Also, in DeleteCatalogueItemHandler how can I have:: 
@Path ("/section/{someID}")
public CatalogueHandler  deleteFromSection (@PathParam("someID") int
someId)
 {
       return getDeleteStatus ();
}

I hope the questions aren't bothering, but i really want to make this
work
:)


Sergey Beryozkin-2 wrote:
> 
> Hi
> 
> you can have something like
> 
> public class BaseRESTResource {
> 
> @Path("{id}/{action}")
> public CatalogueItemHandler
subresourceLocatorItemHandler(@PathParam("id")
> int id, @PathParam("action") String action) {
>     CatalogueItem item = findItem(id);
>     CatalogueItemHandler handler = getItemHandler(action)
>     handler.setItem(item);
>     return handler;
> }
> 
> }
> 
> interface CatalogueItemHandler {
> 
>    public Response handle();
> }
> 
> public class SearchCatalogueItemHandler {
> 
>    SearchCatalogueItemHandler();
>    @POST
>    public Response handle() {}
> }
> 
> public class DeleteCatalogueItemHandler {
> 
>    DeleteCatalogueItemHandler();
> 
>    @POST
>    public Response handle() {}
> }
> 
> etc
> 
> probably much better options are available; this one assumes it's not
> possible to use DELETE/etc HTTP verbs so you have to use POST 
> in all cases, etc...
> 
> cheers, Sergey
> 
> ----- Original Message ----- 
> From: "vmrm" <rmode@vmware.com>
> To: <users@cxf.apache.org>
> Sent: Friday, October 23, 2009 2:12 PM
> Subject: Delegating REST request to sub-resource classes ??
> 
> 
>>
>> Hi,
>>
>> I am using the NON SPRING CXF-2.2.2 REST implementaion. My web.xml
looks
>> like this:
>>
>> ===================================================================
>> <servlet>
>> <servlet-name>CXFServlet</servlet-name>
>> <display-name>CXF Servlet</display-name>
>> <servlet-class>
>> org.apache.cxf.jaxrs.servlet.CXFNonSpringJaxrsServlet
>> </servlet-class>
>> <init-param>
>>   <param-name>jaxrs.serviceClasses</param-name>
>>   <param-value>
>>     com.rest.BaseRestResourceClass
>>    </param-value>
>> </init-param>
>> <load-on-startup>1</load-on-startup>
>> </servlet>
>> <servlet-mapping>
>>        <servlet-name>CXFServlet</servlet-name>
>>         <url-pattern>/catalogue/*</url-pattern>
>>    </servlet-mapping>
>>
>> ===================================================================
>>
>> Now as shown ablove all requests with URIs like (example):
>>
>> /catalogue/123/add/x
>> /catalogue/314/search/y
>> /catalogue/256/delete/z
>>
>> are delegated to the "BaseRESTResourceClass" and respective methods
are
>> called for different URIs .
>>
>>
>> Problem:  I want to have different resource classes for different
>> patterned
>> URIs like:
>>
>> /catalogue/123/add/*   ---> AddResourceClass
>> /catalogue/123/search/*   ---> SearchResourceClass
>> /catalogue/123/delete/*   ---> DeleteResourceClass
>>
>> Is there a way to do this(delegation) in the BaseRESTResourceClass or
>> otherwise ?
>>
>>
>> P.S: I thought of doing it in the web.xml itself, but, as we know, it
>> doesn't allow the specific patterns like:
>> -----------------------------------------------------------
>> <servlet-mapping>
>>        <servlet-name>Addition_CXFServlet</servlet-name>
>>         <url-pattern>/catalogue/*/add/*</url-pattern>
>>    </servlet-mapping>
>> -----------------------------------------------------------
>>  <servlet-mapping>
>>        <servlet-name>Deletion_CXFServlet</servlet-name>
>>         <url-pattern>/catalogue/*/delete/*</url-pattern>
>>    </servlet-mapping>
>> -----------------------------------------------------------
>>
>>
>> Thanks.
>>
>>
>>
>>
>>
>> -- 
>> View this message in context:
>>
http://www.nabble.com/Delegating-REST-request-to-sub-resource-classes---
-tp26026208p26026208.html
>> Sent from the cxf-user mailing list archive at Nabble.com.
>> 
> 
> 
> 

-- 
View this message in context:
http://www.nabble.com/Delegating-REST-request-to-sub-resource-classes---
-tp26026208p26032996.html
Sent from the cxf-user mailing list archive at Nabble.com.


Mime
View raw message