Пример #1
0
  private Restlet createServerResourceFinder(
      Class<? extends ServerResource> resource, boolean secure) {
    ResourceFinder finder = factory.newObject(ResourceFinder.class);
    finder.setTargetClass(resource);

    if (secure) {
      return factory
          .newObjectBuilder(AuthenticationFilter.class)
          .use(getContext(), finder, this.filterService)
          .newInstance();
    } else return finder;
  }
Пример #2
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());
  }