Prototyping with Restlet 2.1.0, Java SE version, I am having trouble mapping ServerResource classes to urls. I\'ve tried quite a few variations using the Router.attach method,
Finally found the solution by turning on the logging (FINE). I saw this log message:
By default, an application should be attached to a parent component in order to let application's outbound root handle calls properly.
I don't totally understand what it meant (maybe I have to read docs start to finish?). Attaching the application to a VirtualHost fixed the problem:
public static void main(String[] args) throws Exception {
final Router router = new Router();
router.attach("/hello", FirstServerResource.class);
router.attach("/json", Json.class);
router.attachDefault(Default.class);
Application myApp = new Application() {
@Override
public org.restlet.Restlet createInboundRoot() {
router.setContext(getContext());
return router;
};
};
Component component = new Component();
component.getDefaultHost().attach("/test", myApp);
new Server(Protocol.HTTP, 8182, component).start();
}