Package org.restlet.routing

Examples of org.restlet.routing.Filter


  
   @Override
   public Restlet createRoot() {  
      Router router = new Router(getContext());
      router.setDefaultMatchingMode(Template.MODE_STARTS_WITH);
      Filter guard = new UserGuard(getContext(),ChallengeScheme.HTTP_BASIC,"Atom User",auth);
      guard.setNext(router);
     
      Redirector byId = new IdRedirector(getContext(),this,atomDB,RESOURCE_BASE);
      router.attach("/id/",byId);
     
      ProtocolByPathFinder byPath = new ProtocolByPathFinder(getContext(),this,RESOURCE_BASE,app,atomDB,storage);
View Full Code Here


   public Restlet createRoot() {
      Router router = new Router(getContext());
      router.setDefaultMatchingMode(Template.MODE_STARTS_WITH);
      final String base = getContext().getParameters().getFirstValue("app.url");
      getLogger().info("app.url="+base);
      Filter requireAuth = new Filter(getContext()) {
         protected int beforeHandle(Request request,Response response)
         {
            Cookie cookie = request.getCookies().getFirst("I");
            if (request.getChallengeResponse()==null || cookie==null) {
               String baseURL = base;
               if (baseURL==null) {
                  Object o = request.getAttributes().get("app.url");
                  if (o!=null) {
                     baseURL = o.toString();
                  } else {
                     getLogger().severe("app.url missing.");
                     response.setStatus(Status.CLIENT_ERROR_UNAUTHORIZED);
                     return Filter.STOP;
                  }
               }
               Reference appRef = new Reference(baseURL);
               getLogger().info("Checking APP authentication proxy to "+appRef);
               Client client = new Client(getContext().createChildContext(),appRef.getSchemeProtocol());
               client.getContext().getAttributes().put("hostnameVerifier", org.apache.commons.ssl.HostnameVerifier.DEFAULT);
               Request appRequest = new Request(Method.GET,appRef);
               if (request.getChallengeResponse()!=null) {
                  appRequest.setChallengeResponse(request.getChallengeResponse());
               }
               Response appResponse = client.handle(appRequest);
               if (appResponse.getStatus().isSuccess()) {
                  return Filter.CONTINUE;
               } else if (appResponse.getChallengeRequests().size()>0) {
                  Form headers = (Form)appResponse.getAttributes().get("org.request.http.headers");
                  response.setStatus(appResponse.getStatus());
                  response.setEntity(appResponse.getEntity());
                  response.setChallengeRequests(appResponse.getChallengeRequests());
                  response.getAttributes().put("org.request.http.headers", headers);
                  response.setCookieSettings(appResponse.getCookieSettings());
                  return Filter.STOP;
               } else {
                  response.setStatus(Status.CLIENT_ERROR_UNAUTHORIZED);
                  return Filter.STOP;
               }
            } else {
               return Filter.CONTINUE;
            }
         }
      };
      requireAuth.setNext(router);
      router.attach("/",new ClassResourceFinder(getContext(),EditApplication.class.getClassLoader(),EditApplication.class));
      router.attach("/upload",new UploadApplication(getContext()));
      router.attach("/app/",new APPProxy(getContext()));
      return requireAuth;
   }
View Full Code Here

            baseRouter.setDefaultMatchingMode(Template.MODE_STARTS_WITH);
            for (RestletRoutable rr : restlets) {
                baseRouter.attach(rr.basePath(), rr.getRestlet(context));
            }

            Filter slashFilter = new Filter() {           
                @Override
                protected int beforeHandle(Request request, Response response) {
                    Reference ref = request.getResourceRef();
                    String originalPath = ref.getPath();
                    if (originalPath.contains("//"))
                    {
                        String newPath = originalPath.replaceAll("/+", "/");
                        ref.setPath(newPath);
                    }
                    return Filter.CONTINUE;
                }

            };
            slashFilter.setNext(baseRouter);
           
            return slashFilter;
        }
View Full Code Here

            baseRouter.setDefaultMatchingMode(Template.MODE_STARTS_WITH);
            for (org.flowforwarding.warp.jcontroller.restapi.RestletRoutable rr : restlets) {
                baseRouter.attach(rr.basePath(), rr.getRestlet(context));
            }

            Filter slashFilter = new Filter() {           
                @Override
                protected int beforeHandle(Request request, Response response) {
                    Reference ref = request.getResourceRef();
                    String originalPath = ref.getPath();
                    if (originalPath.contains("//"))
                    {
                        String newPath = originalPath.replaceAll("/+", "/");
                        ref.setPath(newPath);
                    }
                    return Filter.CONTINUE;
                }

            };
            slashFilter.setNext(baseRouter);
           
            return slashFilter;
        }
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.