Package org.restlet.routing

Examples of org.restlet.routing.Filter


    }

    /** Start hook. */
    @Override
    public synchronized void start() throws Exception {
        Filter filter = null;

        for (Service service : getHelped().getServices()) {
            if (service.isEnabled()) {
                // Attach the service inbound filters
                filter = service
View Full Code Here


        // Let's actually start the component
        if (!success) {
            getHelped().stop();
        } else {
            Filter filter = null;

            for (Service service : getHelped().getServices()) {
                if (service.isEnabled()) {
                    // Attach the service inbound filters
                    filter = service
View Full Code Here

    /**
     * Test Restlet instance attaching/detaching.
     */
    public void testAttachDetachInstance() throws Exception {
        final Filter filter = getFilter();
        assertFalse(filter.hasNext());
        filter.setNext(getRestlet());
        filter.start();
        assertTrue(filter.isStarted());
        assertFalse(filter.isStopped());
        final Request request = getRequest();
        final Response response = getResponse(request);
        filter.handle(request, response);
        assertTrue(filter.hasNext());
        filter.setNext((Restlet) null);
        assertFalse(filter.hasNext());
    }
View Full Code Here

            }
            Class def = getTargetClass(child);
            if (def==null) {
               return;
            }
            Filter childFilter = null;
            try {
               childFilter = createFilter(parentContext,def,child);
            } catch (Exception ex) {
               LOG.log(Level.SEVERE,"Cannot instantiate filter.",ex);
               return;
View Full Code Here

    /**
     * Test not started Filter.
     */
    public void testIllegalStartedState() throws Exception {
        final Filter filter = getFilter();
        filter.setNext(getRestlet());
        assertTrue(filter.hasNext());
        assertFalse(filter.isStarted());
        assertTrue(filter.isStopped());
        final Request request = getRequest();
        final Response response = getResponse(request);
        try {
            filter.handle(request, response);

            if (!filter.isStarted()) {
                fail("Filter handles call without being started");
            }
        } catch (Exception ex) {
            // noop.
        }
View Full Code Here

    /**
     * Test with null target.
     */
    public void testIllegalTarget() throws Exception {
        final Filter filter = getFilter();
        filter.start();
        assertTrue(filter.isStarted());
        assertFalse(filter.isStopped());
        assertFalse(filter.hasNext());
        final Request request = getRequest();
        final Response response = getResponse(request);
        try {
            filter.handle(request, response);
            fail("Filter handles call without a target");
        } catch (Exception ex) {
            // noop.
        }
    }
View Full Code Here

      router.attach("/",UsersResource.class);
      router.attach("/{alias}",UserResource.class);
      router.attach("/{alias}/{facet}",UserResource.class);
      router.attach("/{alias}/{facet}/",UserResource.class);
      router.attach("/{alias}/{facet}/{facet-alias}",UserResource.class);
      Filter dbFilter = new Filter(getContext()) {
         protected int beforeHandle(Request request,Response response)
         {
            request.getAttributes().put(App.DB_ATTR,db);
            return Filter.CONTINUE;
         }
      };
      dbFilter.setNext(router);
      return dbFilter;
     
   }
View Full Code Here

      getContext().getAttributes().put(WebComponent.ATOMOJO_TMP_DIR,context.getAttributes().get(WebComponent.ATOMOJO_TMP_DIR));
   }
  
   @Override
   public Restlet createRoot() {
      Filter attFilter = new Filter(getContext()) {
         protected int beforeHandle(Request request,Response response)
         {
            request.getAttributes().put(App.DB_ATTR,db);
            request.getAttributes().put(App.STORAGE_ATTR,storage);
            request.getAttributes().put(App.RESOURCE_BASE_ATTR,resourceBase);
            return Filter.CONTINUE;
         }
      };
      Router router = new Router(getContext());
      attFilter.setNext(router);
      router.setDefaultMatchingMode(Template.MODE_STARTS_WITH);
      router.attach("/users",new UserApplication(getContext(),db));
      router.attach("/sync",new SyncApplication(getContext(),db,storage));
      router.attach("/backup",BackupResource.class);
      router.attach("/backup.zip",BackupResource.class);
View Full Code Here

   public Restlet createRoot() {
      Router router = new Router(getContext());
      router.setDefaultMatchingMode(Template.MODE_STARTS_WITH);
      router.attach("/",new ClassResourceFinder(getContext(),EditApplication.class.getClassLoader(),EditApplication.class));
      router.attach("/editor/",new ClassResourceFinder(getContext(),ClassResourceFinder.class.getClassLoader(),ClassResourceFinder.class));
      Filter uploadFilter = new Filter(getContext()) {
         protected int beforeHandle(Request request,Response response)
         {
            request.getAttributes().put("app.url", "riap://application/app/");
            return Filter.CONTINUE;
         }
      };
      uploadFilter.setNext(new UploadApplication(getContext(),atomApp));
      router.attach("/upload",uploadFilter);
      router.attach("/app",atomApp);
      Filter guard = new UserGuard(getContext(),ChallengeScheme.HTTP_BASIC,"Atom User",atomApp.getAuthService());
      guard.setNext(router);
      return guard;
   }
View Full Code Here

      realmRouter.attach("/groups/{group-id}/{facet}/",GroupResource.class).getTemplate().setMatchingMode(Template.MODE_EQUALS);
      realmRouter.attach("/groups/{group-id}/{facet}/{facet-id}",GroupResource.class).getTemplate().setMatchingMode(Template.MODE_EQUALS);
      realmRouter.attach("/groups/{group-id}/{facet}/a/{facet-name}",GroupResource.class).getTemplate().setMatchingMode(Template.MODE_EQUALS);
      realmRouter.attach("/groups/{group-id}/{facet}/n/{facet-name}",GroupResource.class).getTemplate().setMatchingMode(Template.MODE_EQUALS);
     
      Filter realmByName = new RealmFilter(getContext(),db);
      mainRouter.attach("/realms/n/{realm-name}",realmByName);
      RealmUserGuard realmByNameGuard = new RealmUserGuard(getContext(),db,null,ChallengeScheme.HTTP_BASIC,"Realm Users",superuser) {
         protected boolean hasRealmSpecific(Request request,RealmUser user)
         {
            // we need to check the group because a user could have realm superuser for another realm
            try {
               Group admin = db.getGroup(user.getRealm(),"admin");
               return user.isMemberOf(admin);
            } catch (SQLException ex) {
               getContext().getLogger().log(Level.SEVERE,"Cannot check role due to database error.",ex);
               return false;
            }
         }
      };
      realmByNameGuard.addPermission(realmSuperuser);
      realmByName.setNext(realmByNameGuard);
      realmByNameGuard.setNext(realmRouter);
     
      Filter realmById = new RealmFilter(getContext(),db);
      mainRouter.attach("/realms/{realm-id}",realmById);
      RealmUserGuard realmByIdGuard = new RealmUserGuard(getContext(),db,null,ChallengeScheme.HTTP_BASIC,"Realm Users",superuser) {
         protected boolean hasRealmSpecific(Request request,RealmUser user)
         {
            try {
               Group admin = db.getGroup(user.getRealm(),"admin");
               return user.isMemberOf(admin);
            } catch (SQLException ex) {
               getContext().getLogger().log(Level.SEVERE,"Cannot check role due to database error.",ex);
               return false;
            }
         }
      };
      realmByIdGuard.addPermission(realmSuperuser);
      realmById.setNext(realmByIdGuard);
      realmByIdGuard.setNext(realmRouter);
     
      UserGuard adminGuard = new UserGuard(getContext(),db,ChallengeScheme.HTTP_BASIC,"users");
      adminGuard.setPermission(superuser);
      mainRouter.attach("/admin",adminGuard);
View Full Code Here

TOP

Related Classes of org.restlet.routing.Filter

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.