這裏是一個完全非servlet的例子: 假設你已經創建了您的請求和/或響應濾波器(S),你可以將它們添加你的啓動代碼如下: (請注意ApiInterceptor類既是一個請求,在這個例子中的響應過濾器)
final URI BASE_URI = UriBuilder.fromUri("http://localhost/").port(9999).build();
System.out.println("Investigating Api services...");
ResourceConfig rc = new PackagesResourceConfig(
"path.to.your.resource.objects");
System.out.println("Registering interceptors...");
rc.getProperties().put(ResourceConfig.PROPERTY_CONTAINER_REQUEST_FILTERS, ApiInterceptor.class.getName());
rc.getProperties().put(ResourceConfig.PROPERTY_CONTAINER_RESPONSE_FILTERS, ApiInterceptor.class.getName());
Debug.print("Starting grizzly...");
GrizzlyServerFactory.createHttpServer(BASE_URI, rc);
Debug.print("The app started @", BASE_URI.toString());
Debug.print("Enjoy!");
System.in.read();