org.restlet.routing.Template Java Examples

The following examples show how to use org.restlet.routing.Template. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: ManagerRestApplication.java    From uReplicator with Apache License 2.0 6 votes vote down vote up
@Override
public Restlet createInboundRoot() {
  final Router router = new Router(getContext());
  router.setDefaultMatchingMode(Template.MODE_EQUALS);

  // Topic Servlet
  router.attach("/topics", TopicManagementRestletResource.class);
  router.attach("/topics/", TopicManagementRestletResource.class);
  router.attach("/topics/{topicName}", TopicManagementRestletResource.class);
  router.attach("/topics/{topicName}/", TopicManagementRestletResource.class);

  // Admin Servlet
  router.attach("/admin", AdminRestletResource.class);
  router.attach("/admin/{opt}", AdminRestletResource.class);

  // Health Check Servlet
  router.attach("/health", HealthCheckRestletResource.class);
  router.attach("/health/", HealthCheckRestletResource.class);

  return router;
}
 
Example #2
Source File: RestApiServer.java    From floodlight_with_topoguard with Apache License 2.0 6 votes vote down vote up
@Override
public Restlet createInboundRoot() {
    Router baseRouter = new Router(context);
    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;
}
 
Example #3
Source File: OntopiaRestApplication.java    From ontopia with Apache License 2.0 6 votes vote down vote up
@Override
public Restlet createInboundRoot() {
	// encoding service that allows disabling
	setEncoderService(new OntopiaEncoderService());
	
	Router versions = new Router(getContext());
	versions.setDefaultMatchingMode(Template.MODE_STARTS_WITH);
	versions.setRoutingMode(Router.MODE_BEST_MATCH);
	versions.setName("Ontopia API root router");
	
	versions.attach("/", APIInfoResource.class);
	
	for (APIVersions version : APIVersions.values()) {
		if (isEnabled(version)) {
			logger.info("Exposing API {}", version.getName());
			versions.attach("/" + version.getName(), new OntopiaAPIVersionFilter(getContext(), version.createChain(this), version));
		}
	}

	return versions;
}
 
Example #4
Source File: RestletApplication.java    From uReplicator with Apache License 2.0 5 votes vote down vote up
@Override
public Restlet createInboundRoot() {
  final Router router = new Router(getContext());
  router.setDefaultMatchingMode(Template.MODE_EQUALS);

  // Servlet
  router.attach("/ratelimiter", RateLimiterResource.class);

  return router;
}
 
Example #5
Source File: EntryPointResource.java    From attic-polygene-java with Apache License 2.0 5 votes vote down vote up
private EntryPoint createEntryPoint()
        {
            Map<String, RestLink> entryPoints = new HashMap<>();
            for( Route r : parameters.router().get().getRoutes() )
            {
                if( r instanceof TemplateRoute)
                {
                    TemplateRoute route = (TemplateRoute) r;
                    Template template = route.getTemplate();
                    // Only include patterns that doesn't have variables, and has a proper name.
                    if( template.getVariableNames().isEmpty() && route.getName().indexOf( '>' ) == -1 )
                    {
                        Reference hostRef = parameters.request().get().getOriginalRef();
//                        Reference reference = new Reference( hostRef, template.getPattern() );
                        RestLink link;
                        if( route.getDescription() == null )
                        {
                            link = resourceBuilder.createRestLink( template.getPattern(), hostRef, Method.GET );
                        }
                        else
                        {
                            link = resourceBuilder.createRestLink( template.getPattern(), hostRef, Method.GET, route.getDescription() );
                        }
                        entryPoints.put( route.getName(), link );
                    }
                }
            }
            ValueBuilder<EntryPoint> builder = vbf.newValueBuilder( EntryPoint.class );
            builder.prototype().identity().set( StringIdentity.identityOf( "/" ) );
            builder.prototype().api().set( entryPoints );
            return builder.newInstance();
        }
 
Example #6
Source File: StuffApplication.java    From spring-5-examples with MIT License 4 votes vote down vote up
@Override
public synchronized void start() throws Exception {
  Router router = new Router(getContext());


  Properties props = new Properties();
  props.load(getClass().getResourceAsStream("/velocity.properties"));

  VelocityEngine velocity = new VelocityEngine(props);

  Function<String, Function<Identifier, ? extends Entity>> entityFactory =
      type -> identifier ->
      {
        switch (type) {
          case "task":
            return new Task(identifier);

          case "project":
            return new Project(identifier);
        }

        throw new IllegalArgumentException(type);
      };

  eventStore = new InMemoryEventStore();
  Repository repository = new InMemoryRepository(eventStore, eventStore, entityFactory);

  graphDb = new GraphDatabaseFactory().newEmbeddedDatabase("graphdb");

  InboxModel inboxModel = new Neo4jInboxModel(graphDb);
  eventStore.addInteractionContextSink(inboxModel);

  ObjectMapper mapper = new ObjectMapper();
  mapper.registerModule(new SimpleModule("EventSourcing", new Version(1, 0, 0, null, "eventsourcing", "eventsourcing")).
      addSerializer(InteractionContext.class, new InteractionContextSerializer()).
      addDeserializer(InteractionContext.class, new InteractionContextDeserializer()).setMixInAnnotation(Event.class, JacksonEvent.class)
  );

  File file = new File("events.log").getAbsoluteFile();
  LoggerFactory.getLogger(getClass()).info("Event log:" + file);
  storage = new FileEventStorage(mapper);

  if (file.exists())
    storage.load(file, eventStore);

  storage.save(file, eventStore);

  eventStore.addInteractionContextSink(new LoggingModel(mapper));

  InboxResource inboxResource = new InboxResource(velocity, repository,
      new TaskResource(velocity, repository, inboxModel), inboxModel);
  router.attach("inbox/{task}/{command}", inboxResource);
  router.attach("inbox/{task}/", inboxResource);
  router.attach("inbox/{command}", inboxResource);
  router.attach("inbox/", inboxResource);

  Reference staticContent = new Reference(new File(getClass().getResource("/htdocs/index.html").getFile()).getParentFile().toURI());
  router.attachDefault(new Directory(getContext(), staticContent)).setMatchingMode(Template.MODE_STARTS_WITH);

  setInboundRoot(router);

  super.start();
}
 
Example #7
Source File: ControllerRestApplication.java    From uReplicator with Apache License 2.0 4 votes vote down vote up
@Override
public Restlet createInboundRoot() {
  final Router router = new Router(getContext());
  router.setDefaultMatchingMode(Template.MODE_EQUALS);

  // Topic Servlet
  router.attach("/topics", TopicManagementRestletResource.class);
  router.attach("/topics/", TopicManagementRestletResource.class);
  router.attach("/topics/{topicName}", TopicManagementRestletResource.class);
  router.attach("/topics/{topicName}/", TopicManagementRestletResource.class);

  // Health Check Servlet
  router.attach("/health", HealthCheckRestletResource.class);
  router.attach("/health/", HealthCheckRestletResource.class);

  // Validation Servlet
  router.attach("/validation", ValidationRestletResource.class);
  router.attach("/validation/", ValidationRestletResource.class);
  router.attach("/validation/{option}", ValidationRestletResource.class);
  router.attach("/validation/{option}/", ValidationRestletResource.class);

  // Admin Servlet
  router.attach("/admin", AdminRestletResource.class);
  router.attach("/admin/{opt}", AdminRestletResource.class);

  // MirrorMakerManager Servlet
  router.attach("/instances", MirrorMakerManagerRestletResource.class);
  router.attach("/instances/", MirrorMakerManagerRestletResource.class);
  router.attach("/instances/{instanceName}", MirrorMakerManagerRestletResource.class);
  router.attach("/instances/{instanceName}/", MirrorMakerManagerRestletResource.class);

  router.attach("/offset", TopicParitionOffsetRestletResource.class);
  router.attach("/offset/", TopicParitionOffsetRestletResource.class);
  router.attach("/offset/{topic}/{partition}", TopicParitionOffsetRestletResource.class);
  router.attach("/offset/{topic}/{partition}/", TopicParitionOffsetRestletResource.class);
  router.attach("/noprogress", NoProgressTopicPartitionRestletResource.class);

  // TopicPartition Blacklist Servlet
  router.attach("/blacklist", TopicPartitionBlacklistRestletResource.class);

  return router;
}
 
Example #8
Source File: RestAdminApplication.java    From helix with Apache License 2.0 4 votes vote down vote up
@Override
public Restlet createInboundRoot() {
  Router router = new Router(getContext());
  router.setDefaultMatchingMode(Template.MODE_EQUALS);
  router.attach("/clusters", ClustersResource.class);
  router.attach("/clusters/{clusterName}", ClusterResource.class);
  router.attach("/clusters/{clusterName}/resourceGroups", ResourceGroupsResource.class);
  router.attach("/clusters/{clusterName}/resourceGroups/{resourceName}",
      ResourceGroupResource.class);
  router.attach("/clusters/{clusterName}/workflows", WorkflowsResource.class);
  router.attach("/clusters/{clusterName}/jobQueues", JobQueuesResource.class);
  router.attach("/clusters/{clusterName}/jobQueues/{jobQueue}", JobQueueResource.class);
  router.attach("/clusters/{clusterName}/jobQueues/{jobQueue}/{job}", JobResource.class);
  router.attach("/clusters/{clusterName}/instances", InstancesResource.class);
  router.attach("/clusters/{clusterName}/instances/{instanceName}", InstanceResource.class);
  router.attach("/clusters/{clusterName}/instances/{instanceName}/currentState/{resourceName}",
      CurrentStateResource.class);
  router.attach("/clusters/{clusterName}/instances/{instanceName}/statusUpdate/{resourceName}",
      StatusUpdateResource.class);
  router.attach("/clusters/{clusterName}/instances/{instanceName}/errors/{resourceName}",
      ErrorResource.class);
  router.attach("/clusters/{clusterName}/instances/{instanceName}/currentState",
      CurrentStatesResource.class);
  router.attach("/clusters/{clusterName}/instances/{instanceName}/statusUpdate",
      StatusUpdatesResource.class);
  router.attach("/clusters/{clusterName}/instances/{instanceName}/errors", ErrorsResource.class);
  router.attach("/clusters/{clusterName}/resourceGroups/{resourceName}/idealState",
      IdealStateResource.class);
  router.attach("/clusters/{clusterName}/resourceGroups/{resourceName}/externalView",
      ExternalViewResource.class);
  router.attach("/clusters/{clusterName}/StateModelDefs/{modelName}", StateModelResource.class);
  router.attach("/clusters/{clusterName}/StateModelDefs", StateModelsResource.class);
  router.attach("/clusters/{clusterName}/SchedulerTasks", SchedulerTasksResource.class);
  router.attach("/clusters/{clusterName}/Controller", ControllerResource.class);
  router.attach("/clusters/{clusterName}/Controller/statusUpdates/{MessageType}/{MessageId}",
      ControllerStatusUpdateResource.class);
  router.attach("/clusters/{clusterName}/configs", ConfigResource.class);
  router.attach("/clusters/{clusterName}/configs/{scope}", ConfigResource.class);
  router.attach("/clusters/{clusterName}/configs/{scope}/{scopeKey1}", ConfigResource.class);
  router.attach("/clusters/{clusterName}/configs/{scope}/{scopeKey1}/{scopeKey2}",
      ConfigResource.class);
  router.attach("/clusters/{clusterName}/constraints/{constraintType}", ConstraintResource.class);
  router.attach("/clusters/{clusterName}/constraints/{constraintType}/{constraintId}",
      ConstraintResource.class);
  router.attach("/zkPath", ZkPathResource.class).setMatchingMode(Template.MODE_STARTS_WITH);
  router.attach("/zkChild", ZkChildResource.class).setMatchingMode(Template.MODE_STARTS_WITH);

  Restlet mainpage = new Restlet() {
    @Override
    public void handle(Request request, Response response) {
      StringBuilder stringBuilder = new StringBuilder();
      stringBuilder.append("<html>");
      stringBuilder.append("<head><title>Restlet Cluster Management page</title></head>");
      stringBuilder.append("<body bgcolor=white>");
      stringBuilder.append("<table border=\"0\">");
      stringBuilder.append("<tr>");
      stringBuilder.append("<td>");
      stringBuilder.append("<h1>Rest cluster management interface V1</h1>");
      stringBuilder.append("</td>");
      stringBuilder.append("</tr>");
      stringBuilder.append("</table>");
      stringBuilder.append("</body>");
      stringBuilder.append("</html>");
      response.setEntity(new StringRepresentation(stringBuilder.toString(), MediaType.TEXT_HTML));
    }
  };
  router.attach("", mainpage);
  return router;
}
 
Example #9
Source File: StatisticServer.java    From open-rmbt with Apache License 2.0 3 votes vote down vote up
/**
 * The Restlet instance that will call the correct resource depending up on
 * URL mapped to it.
 * 
 * @return -- The resource Restlet mapped to the URL.
 */
@Override
public Restlet createInboundRoot()
{
    
    final Router router = new Router(getContext());
    
    router.attach("/version", VersionResource.class);
    
    router.attach("/statistics", StatisticsResource.class);

    router.attach("/export/netztest-opendata-{year}-{month}.", ExportResource.class, Template.MODE_STARTS_WITH);
    router.attach("/export/netztest-opendata_hours-{hours}.", ExportResource.class, Template.MODE_STARTS_WITH);
    router.attach("/export", ExportResource.class, Template.MODE_STARTS_WITH);
    
    router.attach("/{lang}/{open_test_uuid}/{size}.png", ImageExport.class);
    
    // administrative resources (access restrictions might be applied to /admin/ 

    router.attach("/opentests/histogram", HistogramResource.class);
    router.attach("/opentests/statistics", OpenTestStatisticsResource.class);
    //router.attach("/opentests/histogra{histogram}", OpenTestSearchResource.class);
    
    router.attach("/opentests/search", at.alladin.rmbt.statisticServer.opendata.OpenTestSearchResource.class, Template.MODE_STARTS_WITH);
    //router.attach("/opentests/search", OpenTestSearchResource.class, Template.MODE_STARTS_WITH);
    
    router.attach("/opentests/choices", ChoicesResource.class, Template.MODE_STARTS_WITH);
    router.attach("/opentests", at.alladin.rmbt.statisticServer.opendata.OpenTestSearchResource.class);        
    
    router.attach("/opentests/O{open_test_uuid}", OpenTestResource.class);
    
    router.attach("/admin/usage", UsageResource.class);
    router.attach("/admin/usageJSON", UsageJSONResource.class);
                    
    return router;
}