Here is a complete example without a servlet: Assuming you have created your request and / or response filter, you can add them to the startup code as follows: (Note that the ApiInterceptor class is both a request and a response filter in this example)
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();
lithium
source share