org.glassfish.jersey.server
Interface Application.Builder

Enclosing class:
Application

public static interface Application.Builder

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:

  Application.Builder appBuilder = Application.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) { ... }
  }
 


Nested Class Summary
static interface Application.Builder.BoundBuilder
          Represents a supported resource path to which new resource methods and sub-resource locators can be attached.
static interface Application.Builder.ResourceMethodBuilder
          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
 Application.Builder.BoundBuilder bind(String path)
          Bind a new resource to a path within the application.
 Application build()
          Build new application based on the defined resource bindings and provider configuration.
 

Method Detail

bind

Application.Builder.BoundBuilder bind(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

Application build()
Build new application based on the defined resource bindings and provider configuration.

Returns:
new application instance.


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