/** * Sets the inbound root Resource class. * * @param inboundRootClass * The inbound root Resource class. */ public synchronized void setInboundRoot( Class<? extends ServerResource> inboundRootClass) { setInboundRoot(createFinder(inboundRootClass)); }
@Override public Application createApplication(Context context) { application = doCreateApplication(context); if (routerProvider != null) application.setInboundRoot(routerProvider.getInboundRoot(context)); return application; }
/** * Called by OSGi DS to inject the router provider service * * @param routerProvider * the router provider service */ public void bindRouterProvider(RouterProvider routerProvider) { this.routerProvider = routerProvider; if (application != null) application.setInboundRoot(routerProvider .getInboundRoot(application.getContext())); }
public static void main(String[] args) throws Exception { // Instantiating the Application providing the Range Service Application app = new Application(); // Plug the server resource. app.setInboundRoot(HelloServerResource.class); // Instantiating the HTTP server and listening on port 8111 new Server(Protocol.HTTP, 8111, app).start(); }
/** * Creates the restlet application that will be used to handle all rest calls * Takes a map of paths to resource classes * <p/> * Use the following three lines to access the routing multibinder: * TypeLiteral<String> pathType = new TypeLiteral<String>() {}; * TypeLiteral<Class<? extends ServerResource>> clazzType = new TypeLiteral<Class<? extends ServerResource>>() {}; * MapBinder<String, Class<? extends ServerResource>> resourceBinder = MapBinder.newMapBinder(binder(), pathType, clazzType); * resourceBinder.bind("/my/path").toInstance(MyResource.class); */ @Provides Application createApplication( FinderFactory factory, Map<String, Class<? extends ServerResource>> routes ) { Context context = new Context(); Application application = new Application(); application.setContext( context ); Router router = new Router( context ); // Set binding rules here for ( Entry<String, Class<? extends ServerResource>> entry : routes.entrySet() ) { final Class<? extends ServerResource> resource = entry.getValue(); logger.info( "Binding '" + entry.getKey() + "' to " + resource ); router.attach( entry.getKey(), factory.finder( resource ) ); } application.setInboundRoot( router ); return application; }