users@jsr311.java.net

sub resource method matching empty path

From: Reto Bachmann-Gmuer <reto.bachmann_at_trialox.org>
Date: Tue, 26 Jan 2010 16:24:59 +0100

Hi,

According to section 3.7.2 when there is no path left after the path
of the resource class only resource methods but not sub-resource
method may be selected. I think it would be useful to be able to
return another object to handle the request also for the root of the
resource.

For example I would like the following class to delegate any request
to the instance of WidgetResource returned by WidgetResourceFactory:

@Path("")
public class WidgetsResource {

  @Path("{path:.+}")
  public WidgetResource findWidget(@Context UriInfo uriInfo) {
    return new WidgetResourceFactory.getWidgetResourceByUri(uriInfo.getAbsolutePath())
  }

}

public class WidgetResource {

  @GET
  public Widget getDetails() {...}

  @PROPFIND
  public Object() {...}

}


The concrete use case is that in Apache Clerezza we want to redirect
to a Resource Class based on the type of the requested resource in an
underlying RDF model if no regular root resource class could be
located for the specific path. Currently we are doing this with an
explicit call back via a non-standard extension[1] of the jax-rs
implementation, however this is quite odd as for every http method
(including any extension) we need to add a new resource method to the
forwarding class.

I think a slight generalisation of the spec could satisfy our needs,
the minimalist way to achieve this would be to change in section 3.7.2
2 (a) "and go to step 3" to "if M is not empty go to step 3".

I believe such a change would also be useful in other situations, in
fact I've been writing constructs like the following several time:

@Path("widgets")
public class WidgetsResource {

  @GET
  public Widget getRootWidget(@Context UriInfo uriInfo) {
      return getWidget(uriInfo);
  }

  @GET @Path("{path:.+}")
  public Widget getWidget(@Context UriInfo uriInfo) {...}
}

It seems awkward to have to write that extra method for when there is
no path left.

Cheers,
reto


1. http://svn.apache.org/viewvc/incubator/clerezza/trunk/org.apache.clerezza.parent/org.apache.clerezza.jaxrs.extensions/src/main/java/org/apache/clerezza/jaxrs/extensions/RootResourceExecutor.java?view=markup