这里是一个完全非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();