Restlet - trouble attaching Resource class with Router

后端 未结 1 2061
粉色の甜心
粉色の甜心 2021-01-21 05:55

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,

1条回答
  •  -上瘾入骨i
    2021-01-21 06:15

    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();
    }
    

    0 讨论(0)
提交回复
热议问题