示例#1
0
  @Override
  public Restlet createInboundRoot() {

    String resources = "clap://class/static/todo/";

    Directory directory = new Directory(getContext(), resources);
    directory.setListingAllowed(true);
    directory.setDeeplyAccessible(true);

    /*
    LocalReference localReference = LocalReference.createClapReference(LocalReference.CLAP_THREAD, "/src/com/pmonteiro/fasttrial/ui/");
       CompositeClassLoader compositeCL = new CompositeClassLoader();
       compositeCL.addClassLoader(Thread.currentThread().getContextClassLoader());
       compositeCL.addClassLoader(Router.class.getClassLoader());
       ClassLoaderDirectory dir = new ClassLoaderDirectory(getContext(),localReference,compositeCL);
       */

    Router todoRouter = new Router(this.getContext());

    todoRouter.attach("/web", directory);
    todoRouter.attach("/todos", TodosResource.class);
    todoRouter.attach("/todos/{todoId}", TodoResource.class);
    // todoRouter.attachDefault(TodosResource.class);

    return todoRouter;
  }
  /*
   * (non-Javadoc)
   *
   * @see org.restlet.Application#createInboundRoot()
   */
  @Override
  public Restlet createInboundRoot() {
    // Create a router Restlet that routes each call to a new instance of
    // HelloWorldResource.
    Router router = new Router(getContext());
    router.setDefaultMatchingQuery(false);

    router.attach("/symbol/2525B/{id}", SymbolResource2525B.class);
    router.attach("/symbol", SymbolServlet.class);

    router.attach("/query/2525B/{id}", SymbolQueryResource2525B.class);
    router.attach("/query/2525B/", SymbolQueryResource2525B.class);
    router.attach("/query/2525B", SymbolQueryResource2525B.class);
    router.attach("/graphics", TacticalGraphicsQueryResource2525B.class);
    try {
      Directory dir =
          new Directory(
              getContext(), new Reference(this.getClass().getResource("/static").toURI()));
      dir.setListingAllowed(true);
      dir.setDeeplyAccessible(true);
      router.attachDefault(dir);
    } catch (URISyntaxException e) {
      getLogger().log(Level.SEVERE, "Unable to create a directory browser resource", e);
    }
    return router;
  }
 @Override
 public Restlet createInboundRoot() {
   Router router = new Router();
   router.attach("/test", new TestRangeRestlet());
   router.attach("/testGet", new TestRangeGetRestlet());
   Directory directory =
       new Directory(getContext(), LocalReference.createFileReference(testDir));
   directory.setModifiable(true);
   router.attach("/testPut/", directory);
   return router;
 }
  private static Resource getResource(
      CollectInfo collectInfo, Object restlet, String basePath, ChallengeScheme scheme) {
    Resource resource = new Resource();
    resource.setResourcePath(basePath);

    if (restlet instanceof Directory) {
      Directory directory = (Directory) restlet;
      resource.setName(directory.getName());
      resource.setDescription(directory.getDescription());
    }
    if (restlet instanceof ServerResource) {
      ServerResource serverResource = (ServerResource) restlet;
      resource.setName(serverResource.getName());
      resource.setDescription(serverResource.getDescription());
    }
    if (restlet instanceof DocumentedResource) {
      DocumentedResource documentedServerResource = (DocumentedResource) restlet;
      resource.setSections(documentedServerResource.getSections());
    } else if (collectInfo.isUseSectionNamingPackageStrategy()) {
      String sectionName = restlet.getClass().getPackage().getName();
      resource.getSections().add(sectionName);
    }

    if (StringUtils.isNullOrEmpty(resource.getName())) {
      String name = restlet.getClass().getSimpleName();
      if (name.endsWith(SUFFIX_SERVER_RESOURCE)
          && name.length() > SUFFIX_SERVER_RESOURCE.length()) {
        name = name.substring(0, name.length() - SUFFIX_SERVER_RESOURCE.length());
      }
      if (name.endsWith(SUFFIX_RESOURCE) && name.length() > SUFFIX_RESOURCE.length()) {
        name = name.substring(0, name.length() - SUFFIX_RESOURCE.length());
      }
      resource.setName(name);
    }

    Template template = new Template(basePath);
    for (String variable : template.getVariableNames()) {
      PathVariable pathVariable = new PathVariable();
      pathVariable.setName(variable);
      resource.getPathVariables().add(pathVariable);
    }

    if (scheme != null) {
      resource.setAuthenticationProtocol(scheme.getName());
    }

    return resource;
  }
  @Override
  public Restlet createInboundRoot() {
    // Create a simple password verifier
    MapVerifier verifier = new MapVerifier();
    verifier.getLocalSecrets().put("scott", "tiger".toCharArray());

    // Create a Guard
    ChallengeAuthenticator authenticator =
        new ChallengeAuthenticator(getContext(), ChallengeScheme.HTTP_BASIC, "Tutorial");
    authenticator.setVerifier(verifier);

    // Create a Directory able to return a deep hierarchy of files
    Directory directory = new Directory(getContext(), ROOT_URI);
    directory.setListingAllowed(true);
    authenticator.setNext(directory);
    return authenticator;
  }
  public static void collectResource(
      CollectInfo collectInfo,
      Directory directory,
      String basePath,
      ChallengeScheme scheme,
      List<? extends IntrospectionHelper> introspectionHelper) {
    Resource resource = getResource(collectInfo, directory, basePath, scheme);

    // add operations
    ArrayList<Operation> operations = new ArrayList<>();
    operations.add(getOperationFromMethod(Method.GET));
    if (directory.isModifiable()) {
      operations.add(getOperationFromMethod(Method.DELETE));
      operations.add(getOperationFromMethod(Method.PUT));
    }
    resource.setOperations(operations);

    for (IntrospectionHelper helper : introspectionHelper) {
      helper.processResource(resource, directory.getClass());
    }
    addSectionsForResource(collectInfo, resource);
    collectInfo.addResource(resource);
  }
示例#7
0
  public APIRouter(
      @Uses Context context,
      @Structure Module module,
      @Service AuthenticationFilterService filterService,
      @Service AvailabilityService availabilityService)
      throws Exception {
    super(context);
    this.factory = module.objectBuilderFactory();
    this.filterService = filterService;

    Restlet cqr =
        factory.newObjectBuilder(CommandQueryRestlet.class).use(getContext()).newInstance();

    Filter availabilityFilter =
        factory
            .newObjectBuilder(AvailabilityFilter.class)
            .use(getContext(), cqr, availabilityService)
            .newInstance();
    Filter authenticationFilter =
        factory
            .newObjectBuilder(AuthenticationFilter.class)
            .use(getContext(), availabilityFilter, this.filterService)
            .newInstance();
    Filter noCacheFilter = new NoCacheFilter(context, authenticationFilter);
    Filter performanceLoggingFilter = new PerformanceLoggingFilter(context, noCacheFilter);

    attachDefault(new ExtensionMediaTypeFilter(getContext(), performanceLoggingFilter));

    // Events
    attach(
        "/events/domain",
        new ExtensionMediaTypeFilter(
            getContext(), createServerResourceFinder(DomainEventsServerResource.class)),
        Template.MODE_STARTS_WITH);
    attach(
        "/events/application",
        new ExtensionMediaTypeFilter(
            getContext(), createServerResourceFinder(ApplicationEventsServerResource.class)),
        Template.MODE_STARTS_WITH);

    // Admin resources
    Router adminRouter = new Router(getContext());
    adminRouter.attach("/entity", createServerResourceFinder(EntitiesResource.class));
    adminRouter.attach("/entity/{identity}", createServerResourceFinder(EntityResource.class));
    adminRouter.attach(
        "/query",
        new PerformanceLoggingFilter(context, createServerResourceFinder(SPARQLResource.class)),
        Template.MODE_STARTS_WITH);
    adminRouter.attach("/index", createServerResourceFinder(IndexResource.class));
    adminRouter.attach("/console", createServerResourceFinder(ConsoleServerResource.class));
    adminRouter.attach("/search", createServerResourceFinder(SolrSearchServerResource.class));
    adminRouter.attach("/log", LoggingServerResource.class);
    attach("/admin/tools", new ExtensionMediaTypeFilter(getContext(), adminRouter));

    {
      Directory dir = new Directory(getContext(), "clap://thread/static/admin/");
      dir.setIndexName("index.html");
      attach("/admin/", dir);
    }

    {
      Directory dir = new Directory(getContext(), "clap://thread/static/crystal/");
      dir.setIndexName("index.html");
      attach("/statistics/", dir);
    }

    // Version info
    Directory directory = new Directory(getContext(), "clap://thread/static/");
    directory.setListingAllowed(true);
    attach(
        "/static",
        factory
            .newObjectBuilder(AuthenticationFilter.class)
            .use(getContext(), directory, this.filterService)
            .newInstance());
  }