Package org.restlet.routing

Examples of org.restlet.routing.Router


            for (Server server : conf.getServers()) {
               LOG.info("Server: "+server.getProtocol()+" at "+server.getAddress()+":"+server.getPort());
               for (Host host : server.getHosts().values()) {
                  LOG.info("Host: "+host.getName());
                  Context context = new Context();
                  Router router = new Router(context);
                  host.attach(router);
               }
            }
         } catch (Exception ex) {
            ex.printStackTrace();
View Full Code Here


      }
     
      public Router createRouter(Context parentContext,Element routerConf) {
         Context routerContext = hasParametersOrAttributes(routerConf) ? createContext(parentContext,routerConf) : parentContext;
         Router router = new Router(routerContext);
         router.setDefaultMatchingMode(Template.MODE_STARTS_WITH);
         String method = routerConf.getAttributeValue("method");
         if ("best".equals(method)) {
            router.setRoutingMode(Router.MODE_BEST_MATCH);
         } else if ("first".equals(method)) {
            router.setRoutingMode(Router.MODE_FIRST_MATCH);
         } else if ("last".equals(method)) {
            router.setRoutingMode(Router.MODE_LAST_MATCH);
         } else if ("next".equals(method)) {
            router.setRoutingMode(Router.MODE_NEXT_MATCH);
         } else if ("random".equals(method)) {
            router.setRoutingMode(Router.MODE_RANDOM_MATCH);
         }
         String matching = routerConf.getAttributeValue("matching");
         if ("starts-with".equals(matching)) {
            router.setDefaultMatchingMode(Template.MODE_STARTS_WITH);
         } else if ("equals".equals(matching)) {
            router.setDefaultMatchingMode(Template.MODE_EQUALS);
         }
         Iterator<Element> elements = routerConf.getElementChildren();
         while (elements.hasNext()) {
            attach(router,elements.next(),false);
         }
View Full Code Here

     * Creates a root Restlet that will receive all incoming calls.
     */
    @Override
    public synchronized Restlet createInboundRoot() {
        // Create a router Restlet that defines routes.
        Router router = new Router(getContext());

        // Defines a route for the resource "list of items"
        router.attach("/items", ItemsResource.class);
        // Defines a route for the resource "item"
        //router.attach("/items/{itemName}", ItemResource.class);

        return router;
    }
View Full Code Here

        getRoles().add(user);
    }

    @Override
    public Restlet createInboundRoot() {
        Router root = new Router();

        // Attach test 1
        ChallengeAuthenticator authenticator = new ChallengeAuthenticator(
                getContext(), ChallengeScheme.HTTP_BASIC, "saas");
        authenticator.setNext(new HelloWorldRestlet());
        root.attach("/test1", authenticator);

        // Attach test 2
        Authorizer authorizer = Authorizer.ALWAYS;
        authorizer.setNext(new HelloWorldRestlet());
        root.attach("/test2", authorizer);

        // Attach test 3
        authorizer = Authorizer.NEVER;
        authorizer.setNext(new HelloWorldRestlet());
        root.attach("/test3", authorizer);

        // Attach test 4
        RoleAuthorizer roleAuthorizer = new RoleAuthorizer();
        roleAuthorizer.getAuthorizedRoles().add(getRole("admin"));
        roleAuthorizer.setNext(new HelloWorldRestlet());

        authenticator = new ChallengeAuthenticator(getContext(),
                ChallengeScheme.HTTP_BASIC, "saas");
        authenticator.setNext(roleAuthorizer);
        root.attach("/test4", authenticator);

        // Attach test 5
        roleAuthorizer = new RoleAuthorizer();
        roleAuthorizer.getForbiddenRoles().add(getRole("admin"));
        roleAuthorizer.setNext(new HelloWorldRestlet());

        authenticator = new ChallengeAuthenticator(getContext(),
                ChallengeScheme.HTTP_BASIC, "saas");
        authenticator.setNext(roleAuthorizer);
        root.attach("/test5", authenticator);

        return root;
    }
View Full Code Here

                + File.separator + "restbook.dbo");
    }

    @Override
    public Restlet createInboundRoot() {
        final Router router = new Router(getContext());

        // Add a route for user resources
        router.attach("/users/{username}", UserResource.class);

        // Add a route for user's bookmarks resources
        router.attach("/users/{username}/bookmarks", BookmarksResource.class);

        // Add a route for bookmark resources
        final TemplateRoute uriRoute = router.attach(
                "/users/{username}/bookmarks/{URI}", BookmarkResource.class);
        uriRoute.getTemplate().getVariables().put("URI",
                new Variable(Variable.TYPE_URI_ALL));

        return router;
View Full Code Here

    @Override
    protected Application createApplication(Component component) {
        final Application application = new Application() {
            @Override
            public Restlet createInboundRoot() {
                final Router router = new Router(getContext());
                router.attach("/test", GetTestResource.class);
                return router;
            }
        };

        return application;
View Full Code Here

    private int port;

    private static class MyApplication extends Application {
        @Override
        public Restlet createInboundRoot() {
            Router router = new Router(getContext());

            DigestAuthenticator da = new DigestAuthenticator(getContext(),
                    "TestRealm", "mySecretServerKey");
            MapVerifier mapVerifier = new MapVerifier();
            mapVerifier.getLocalSecrets().put("scott", "tiger".toCharArray());
            da.setWrappedVerifier(mapVerifier);

            Restlet restlet = new Restlet(getContext()) {
                @Override
                public void handle(Request request, Response response) {
                    response.setEntity("hello, world", MediaType.TEXT_PLAIN);
                }
            };
            da.setNext(restlet);
            router.attach("/", da);
            return router;
        }
View Full Code Here

    @Override
    protected Application createApplication(Component component) {
        final Application application = new Application() {
            @Override
            public Restlet createInboundRoot() {
                final Router router = new Router(getContext());
                router.attach("/test", GetTestResource.class);
                return router;
            }
        };

        return application;
View Full Code Here

    @Override
    protected Application createApplication(Component component) {
        final Application application = new Application() {
            @Override
            public Restlet createInboundRoot() {
                final Router router = new Router(getContext());
                router.attach("/test", PutTestResource.class);
                return router;
            }
        };

        return application;
View Full Code Here

        component.getClients().add(Protocol.RIAP);

        Application app = new Application() {
            @Override
            public Restlet createInboundRoot() {
                Router router = new Router(getContext());
                router.attach("/testA", new Restlet(getContext()) {

                    @Override
                    public void handle(Request request, Response response) {
                        response.setEntity("hello, world", MediaType.TEXT_PLAIN);
                    }

                });
                router.attach("/testB", new Restlet(getContext()) {
                    public void handle(Request request, Response response) {
                        ClientResource resource = new ClientResource(
                                "riap://component/app/testA");
                        try {
                            response.setEntity(resource.get().getText(),
View Full Code Here

TOP

Related Classes of org.restlet.routing.Router

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.