org.restlet.routing.Router.getRoutes()方法的使用及代码示例

x33g5p2x  于2022-01-28 转载在 其他  
字(10.4k)|赞(0)|评价(0)|浏览(241)

本文整理了Java中org.restlet.routing.Router.getRoutes方法的一些代码示例,展示了Router.getRoutes的具体用法。这些代码示例主要来源于Github/Stackoverflow/Maven等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Router.getRoutes方法的具体详情如下:
包路径:org.restlet.routing.Router
类名称:Router
方法名:getRoutes

Router.getRoutes介绍

[英]Returns the modifiable list of routes. Creates a new instance if no one has been set.
[中]返回可修改的路由列表。如果未设置任何实例,则创建新实例。

代码示例

代码示例来源:origin: apache/attic-polygene-java

protected void printRoutes( PrintStream out )
{
  router.getRoutes()
     .stream()
     .map( Object::toString )
     .forEach( out::println );
}

代码示例来源:origin: apache/attic-polygene-java

@Override
  public Route findRoute( String name, Router router )
  {
    return router.getRoutes().stream().filter( route -> name.equals( route.getName() ) ).findFirst().orElse( null );
  }
}

代码示例来源:origin: ontopia/ontopia

private void describeRoutes(StringBuilder b, Router router, String path) {
  RouteList routes = router.getRoutes();
  
  b.append("[").append(path).append("] = Router: ").append(router.getName()).append(": ").append(router.getDescription()).append("\n");
  
  for (Route r : routes) {
    if (r instanceof TemplateRoute) {
      describe(b, r.getNext(), path + ((TemplateRoute)r).getTemplate().getPattern());
    }
    
  }
  
}

代码示例来源:origin: org.restlet.osgi/org.restlet

/**
 * Attaches a target Restlet to this router based on a given URI pattern. A
 * new route will be added routing to the target when calls with a URI
 * matching the pattern will be received.
 * 
 * @param pathTemplate
 *            The URI path template that must match the relative part of the
 *            resource URI.
 * @param target
 *            The target Restlet to attach.
 * @param matchingMode
 *            The matching mode.
 * @return The created route.
 */
public TemplateRoute attach(String pathTemplate, Restlet target,
    int matchingMode) {
  TemplateRoute result = createRoute(pathTemplate, target, matchingMode);
  getRoutes().add(result);
  return result;
}

代码示例来源:origin: org.restlet.osgi/org.restlet

/**
 * Detaches the target from this router. All routes routing to this target
 * Restlet are removed from the list of routes and the default route is set
 * to null.
 * 
 * @param targetClass
 *            The target class to detach.
 */
public void detach(Class<?> targetClass) {
  for (int i = getRoutes().size() - 1; i >= 0; i--) {
    Restlet target = getRoutes().get(i).getNext();
    if (target != null
        && Finder.class.isAssignableFrom(target.getClass())) {
      Finder finder = (Finder) target;
      if (finder.getTargetClass().equals(targetClass)) {
        getRoutes().remove(i);
      }
    }
  }
  if (getDefaultRoute() != null) {
    Restlet target = getDefaultRoute().getNext();
    if (target != null
        && Finder.class.isAssignableFrom(target.getClass())) {
      Finder finder = (Finder) target;
      if (finder.getTargetClass().equals(targetClass)) {
        setDefaultRoute(null);
      }
    }
  }
}

代码示例来源:origin: stackoverflow.com

// Example router setup
Router router = Router.router(vertx);
router.route(HttpMethod.GET, "/").handler(routingContext -> {
  routingContext.response().end("Root");
});

router.route(HttpMethod.GET, "/users").handler(routingContext -> {
  routingContext.response().end("Post");
});

router.route(HttpMethod.POST, "/users").handler(routingContext -> {
  routingContext.response().end("Post");
});

// Getting the routes
for (Route r : router.getRoutes()) {
  // Path is public, but methods are not. We change that
  Field f = r.getClass().getDeclaredField("methods");
  f.setAccessible(true);
  Set<HttpMethod> methods = (Set<HttpMethod>) f.get(r);
  System.out.println(methods.toString() + r.getPath());
}

代码示例来源:origin: ontopia/ontopia

private void list(Map<Restlet, String> all, Restlet restlet, String path) {
  all.put(restlet, path);
  if (restlet instanceof Router) {
    for (Route r : ((Router)restlet).getRoutes()) {
      list(all, r, path + ((TemplateRoute)r).getTemplate().getPattern());
    }
  } else if (restlet instanceof Filter) {
    list(all, ((Filter) restlet).getNext(), path);
  }
}

代码示例来源:origin: org.restlet.jse/org.restlet.ext.platform

/**
   * Completes the list of ResourceInfo instances for the given Router
   * instance.
   * 
   * 
   * @param router
   *            The router to document.
   * @param introspectionHelper
   */
  private static void collectForRouter(CollectInfo collectInfo,
      String basePath, Router router, ChallengeScheme scheme,
      List<? extends IntrospectionHelper> introspectionHelper) {
    for (Route route : router.getRoutes()) {
      collectForRoute(collectInfo, basePath, route, scheme,
          introspectionHelper);
    }

    if (router.getDefaultRoute() != null) {
      collectForRoute(collectInfo, basePath, router.getDefaultRoute(),
          scheme, introspectionHelper);
    }
  }
}

代码示例来源:origin: org.restlet.jee/org.restlet.ext.apispark

/**
   * Completes the list of ResourceInfo instances for the given Router
   * instance.
   * 
   * 
   * @param router
   *            The router to document.
   * @param introspectionHelper
   */
  private static void collectForRouter(CollectInfo collectInfo,
      String basePath, Router router, ChallengeScheme scheme,
      List<? extends IntrospectionHelper> introspectionHelper) {
    for (Route route : router.getRoutes()) {
      collectForRoute(collectInfo, basePath, route, scheme,
          introspectionHelper);
    }

    if (router.getDefaultRoute() != null) {
      collectForRoute(collectInfo, basePath, router.getDefaultRoute(),
          scheme, introspectionHelper);
    }
  }
}

代码示例来源:origin: org.restlet.jee/org.restlet.ext.platform

/**
 * Returns the next application available.
 * 
 * @param current
 *            The current Restlet to inspect.
 * @return The first application available.
 */
private static Application getNextApplication(Restlet current) {
  Application result = null;
  if (current instanceof Application) {
    result = (Application) current;
  } else if (current instanceof Filter) {
    result = getNextApplication(((Filter) current).getNext());
  } else if (current instanceof Router) {
    Router router = (Router) current;
    for (Route route : router.getRoutes()) {
      result = getNextApplication(route.getNext());
      if (result != null) {
        break;
      }
    }
  }
  return result;
}

代码示例来源:origin: org.restlet.gae/org.restlet.ext.platform

/**
   * Completes the list of ResourceInfo instances for the given Router
   * instance.
   * 
   * 
   * @param router
   *            The router to document.
   * @param introspectionHelper
   */
  private static void collectForRouter(CollectInfo collectInfo,
      String basePath, Router router, ChallengeScheme scheme,
      List<? extends IntrospectionHelper> introspectionHelper) {
    for (Route route : router.getRoutes()) {
      collectForRoute(collectInfo, basePath, route, scheme,
          introspectionHelper);
    }

    if (router.getDefaultRoute() != null) {
      collectForRoute(collectInfo, basePath, router.getDefaultRoute(),
          scheme, introspectionHelper);
    }
  }
}

代码示例来源:origin: org.restlet.jee/org.restlet.ext.apispark

/**
 * Returns the next application available.
 * 
 * @param current
 *            The current Restlet to inspect.
 * @return The first application available.
 */
private static Application getNextApplication(Restlet current) {
  Application result = null;
  if (current instanceof Application) {
    result = (Application) current;
  } else if (current instanceof Filter) {
    result = getNextApplication(((Filter) current).getNext());
  } else if (current instanceof Router) {
    Router router = (Router) current;
    for (Route route : router.getRoutes()) {
      result = getNextApplication(route.getNext());
      if (result != null) {
        break;
      }
    }
  }
  return result;
}

代码示例来源:origin: org.restlet.osgi/org.restlet.ext.platform

/**
 * Returns the next application available.
 * 
 * @param current
 *            The current Restlet to inspect.
 * @return The first application available.
 */
private static Application getNextApplication(Restlet current) {
  Application result = null;
  if (current instanceof Application) {
    result = (Application) current;
  } else if (current instanceof Filter) {
    result = getNextApplication(((Filter) current).getNext());
  } else if (current instanceof Router) {
    Router router = (Router) current;
    for (Route route : router.getRoutes()) {
      result = getNextApplication(route.getNext());
      if (result != null) {
        break;
      }
    }
  }
  return result;
}

代码示例来源:origin: org.restlet.osgi/org.restlet

/**
 * Detaches the target from this router. All routes routing to this target
 * Restlet are removed from the list of routes and the default route is set
 * to null.
 * 
 * @param target
 *            The target Restlet to detach.
 */
public void detach(Restlet target) {
  getRoutes().removeAll(target);
  if ((getDefaultRoute() != null)
      && (getDefaultRoute().getNext() == target)) {
    setDefaultRoute(null);
  }
}

代码示例来源:origin: org.restlet.jee/org.restlet.ext.platform

/**
   * Completes the list of ResourceInfo instances for the given Router
   * instance.
   * 
   * 
   * @param router
   *            The router to document.
   * @param introspectionHelper
   */
  private static void collectForRouter(CollectInfo collectInfo,
      String basePath, Router router, ChallengeScheme scheme,
      List<? extends IntrospectionHelper> introspectionHelper) {
    for (Route route : router.getRoutes()) {
      collectForRoute(collectInfo, basePath, route, scheme,
          introspectionHelper);
    }

    if (router.getDefaultRoute() != null) {
      collectForRoute(collectInfo, basePath, router.getDefaultRoute(),
          scheme, introspectionHelper);
    }
  }
}

代码示例来源:origin: org.restlet.osgi/org.restlet.ext.platform

/**
   * Completes the list of ResourceInfo instances for the given Router
   * instance.
   * 
   * 
   * @param router
   *            The router to document.
   * @param introspectionHelper
   */
  private static void collectForRouter(CollectInfo collectInfo,
      String basePath, Router router, ChallengeScheme scheme,
      List<? extends IntrospectionHelper> introspectionHelper) {
    for (Route route : router.getRoutes()) {
      collectForRoute(collectInfo, basePath, route, scheme,
          introspectionHelper);
    }

    if (router.getDefaultRoute() != null) {
      collectForRoute(collectInfo, basePath, router.getDefaultRoute(),
          scheme, introspectionHelper);
    }
  }
}

代码示例来源:origin: org.restlet.jse/org.restlet.ext.platform

/**
 * Returns the next application available.
 * 
 * @param current
 *            The current Restlet to inspect.
 * @return The first application available.
 */
private static Application getNextApplication(Restlet current) {
  Application result = null;
  if (current instanceof Application) {
    result = (Application) current;
  } else if (current instanceof Filter) {
    result = getNextApplication(((Filter) current).getNext());
  } else if (current instanceof Router) {
    Router router = (Router) current;
    for (Route route : router.getRoutes()) {
      result = getNextApplication(route.getNext());
      if (result != null) {
        break;
      }
    }
  }
  return result;
}

代码示例来源:origin: org.restlet.gae/org.restlet.ext.platform

/**
 * Returns the next application available.
 * 
 * @param current
 *            The current Restlet to inspect.
 * @return The first application available.
 */
private static Application getNextApplication(Restlet current) {
  Application result = null;
  if (current instanceof Application) {
    result = (Application) current;
  } else if (current instanceof Filter) {
    result = getNextApplication(((Filter) current).getNext());
  } else if (current instanceof Router) {
    Router router = (Router) current;
    for (Route route : router.getRoutes()) {
      result = getNextApplication(route.getNext());
      if (result != null) {
        break;
      }
    }
  }
  return result;
}

代码示例来源:origin: org.restlet.osgi/org.restlet

/**
 * Stops the filter and the attached routes.
 */
@Override
public synchronized void stop() throws Exception {
  if (isStarted()) {
    // Must be invoked as a first step
    super.stop();
    if (getDefaultRoute() != null) {
      getDefaultRoute().stop();
    }
    for (Route route : getRoutes()) {
      route.stop();
    }
  }
}

代码示例来源:origin: org.restlet.osgi/org.restlet

/**
 * Starts the filter and the attached routes.
 */
@Override
public synchronized void start() throws Exception {
  if (isStopped()) {
    for (Route route : getRoutes()) {
      route.start();
    }
    if (getDefaultRoute() != null) {
      getDefaultRoute().start();
    }
    // Must be invoked as a last step
    super.start();
  }
}

相关文章