I've created multiple routes using this code with components:
Component component = new Component();
component.getServers().add(Protocol.HTTP, port);
component.getDefaultHost().attach(pair.uriPattern, pair.restlet);
component.getDefaultHost().attach("/heartbeat", new HeartbeatRestlet());
My heartbeat code works.
But when I use a router as the pair.restlet
above it doesn't work:
Router router = new Router();
Restlet fooHandler = new FooRouter();
Restlet barHandler = new BarRouter();
router.attach("/foo/{fooId}", fooHandler);
router.attach("/bar/{barId1}/{barId2}", barHandler);
The Restlet doc only gives an example of using a router with the Application
class:
public class FirstStepsApplication extends Application {
@Override
public synchronized Restlet createInboundRoot() {
Router router = new Router(getContext());
router.attach("/hello", HelloWorldResource.class);
return router;
}
}
Actually using my router-based code gives the same effect as hitting a nonexistant URL.
So I'm asking:
- Is there any difference between what the router-based approach is supposed to achieve and the Component-based approach?
- Can I get this code to work using the router-based approach? As of now my only solution is to scrap the multiple routers and attach multiple components instead, which requires dealing with more legacy code.