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" <[email protected]>
To: <[email protected]>
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.


Reply via email to