router.attach("/users/{user}$", account); router.attach("/users/{user}/orders$", orders); router.attach("/users/{user}/orders/{order}$", order);
router.attach("/users/{user}", account); router.attach("/users/{user}/orders", orders); router.attach("/users/{user}/orders/{order}", order);
    public static void main(String[] args) throws Exception {        // Create a component        Component component = new Component();        component.getServers().add(Protocol.HTTP, 8182);        component.getClients().add(Protocol.FILE);        // Create an application        Application application = new Application(component) {            @Override            public Restlet createRoot() {                // Create a root Router                Router router = new Router(getContext());                // Attach a Guard to secure access to the chained directory                // handler                Guard guard = new Guard(getContext(),                        ChallengeScheme.HTTP_BASIC, "Restlet tutorial");                guard.getAuthorizations().put("scott", "tiger");                router.attach("/docs/", guard);                // Create a Directory able to return a deep hierarchy of Web                // files                Directory directory = new Directory(getContext(), ROOT_URI);                guard.setNext(directory);                // Create the Account Handler                Restlet account = new Restlet() {                    @Override                    public void handle(Request request, Response response) {                        // Print the requested URI path                        String message = "Account of user \""                                + request.getAttributes().get("user") + "\"";                        response.setEntity(message, MediaType.TEXT_PLAIN);                    }                };                // Create the Orders Handler                Restlet orders = new Restlet(getContext()) {                    @Override                    public void handle(Request request, Response response) {                        // Print the user name of the requested orders                        String message = "Orders of user \""                                + request.getAttributes().get("user") + "\"";                        response.setEntity(message, MediaType.TEXT_PLAIN);                    }                };                // Create the Order Handler                Restlet order = new Restlet(getContext()) {                    @Override                    public void handle(Request request, Response response) {                        // Print the user name of the requested orders                        String message = "Order \""                                + request.getAttributes().get("order")                                + "\" for user \""                                + request.getAttributes().get("user") + "\"";                        response.setEntity(message, MediaType.TEXT_PLAIN);                    }                };                // Attach the Handlers to the Router                router.attach("/users/{user}$", account);                router.attach("/users/{user}/orders$", orders);                router.attach("/users/{user}/orders/{order}$", order);                // Return the root router                return router;            }        };        // Attach the application to the component and start it        component.getDefaultHost().attach("", application);        component.start();    }