org.glassfish.jersey.server.model
Interface ResourceBuilder


public interface ResourceBuilder

TODO fix javadoc. Jersey application builder that provides programmatic API for creating server-side JAX-RS / Jersey applications. The programmatic API complements the annotation-based resource API defined by JAX-RS.

A typical use case for the programmatic resource binding API is demonstrated by the following example:

  JerseyApplication.Builder appBuilder = JerseyApplication.builder();

  appBuilder.bind("a")
     .method("GET").to(new Inflector<Request, Response>() {
          @Override
          public Response apply(Request data) {
              // ...GET "/a" request method processing
          }
      })
      .method("HEAD", "OPTIONS").to(new Inflector<Request, Response>() {
          @Override
          public Response apply(Request data) {
              // ...HEAD & OPTIONS "/a" request methods processing
          }
      });
  appBuilder
     .bind("b")
         .method("GET").to(new Inflector<Request, Response>() {
              @Override
              public Response apply(Request data) {
                  // ...GET "/b" request method processing
              }
          })
          .subPath("c")
             .method("GET").to(new Inflector<Request, Response>() {
                  @Override
                  public Response apply(Request data) {
                      // ...GET "/b/c" request method processing
                  }
              });

  appBuilder.build();
The application built in the example above is equivalent to an application that contains the following annotation-based resources:
  @Path("a")
  public class ResourceA {

      @GET
      public Response get(Request request) { ... }

      @OPTIONS @HEAD
      public Response optionsAndHead(Request request) { ... }
  }

  @Path("b")
  public class ResourceB {

      @GET
      public Response getB(Request request) { ... }

      @Path("c")
      @GET
      public Response getBC(Request request) { ... }
  }
 

Author:
Marek Potociar (marek.potociar at oracle.com)

Nested Class Summary
static interface ResourceBuilder.BoundResourceBuilder
          Represents a supported resource path to which new resource methods and sub-resource locators can be attached.
static interface ResourceBuilder.ResourceMethodBuilder
          Jersey application builder used for binding a new resource method to an Inflector<Request, Response> responsible for processing requests targeted at the bound path and the particular method(s).
 
Method Summary
 Set<Resource> build()
          Build new set of programmatically defined resource bindings.
 ResourceBuilder.BoundResourceBuilder path(String path)
          Bind a new resource to a path within the application.
 

Method Detail

path

ResourceBuilder.BoundResourceBuilder path(String path)
Bind a new resource to a path within the application. The method is an entry point to the Jersey application builder fluent programmatic resource binding API. It is equivalent to placing @Path annotation on an annotation-based resource class. See the application builder example for more information.

When invoked, the application builder creates a new bound resource builder that is bound to the supplied path, relative to the base application URI.

Parameters:
path - resource path relative to the base application URI.
Returns:
resource builder bound to the path.

build

Set<Resource> build()
Build new set of programmatically defined resource bindings.

Returns:
new set of programmatically defined resource class models.


Copyright © 2007-2012 Oracle Corporation. All Rights Reserved. Use is subject to license terms.