本文整理了Java中org.restlet.routing.Router
类的一些代码示例,展示了Router
类的具体用法。这些代码示例主要来源于Github
/Stackoverflow
/Maven
等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Router
类的具体详情如下:
包路径:org.restlet.routing.Router
类名称:Router
[英]Restlet routing calls to one of the attached routes. Each route can compute an affinity score for each call depending on various criteria. The attach() method allow the creation of routes based on URI patterns matching the beginning of a the resource reference's remaining part.
In addition, several routing modes are supported, implementing various algorithms:
Note that for routes using URI patterns will update the resource reference's base reference during the routing if they are selected. It is also important to know that the routing is very strict about path separators in your URI patterns. Finally, you can modify the list of routes while handling incoming calls as the delegation code is ensured to be thread-safe.
Concurrency note: instances of this class or its subclasses can be invoked by several threads at the same time and therefore must be thread-safe. You should be especially careful when storing state in member variables.
[中]Restlet路由调用一个附加的路由。每个路由都可以根据不同的标准计算每个呼叫的亲和力分数。attach()方法允许基于URI模式创建路由,该模式匹配资源引用的剩余部分的开头。
此外,支持多种路由模式,实现各种算法:
*最佳匹配
*第一个匹配(默认)
*最后一场比赛
*随机匹配
*循环赛
*习俗
请注意,对于使用URI模式的路由,如果选择了它们,则在路由期间将更新资源引用的基本引用。知道路由对于URI模式中的路径分隔符非常严格也很重要。最后,您可以在处理传入呼叫时修改路由列表,因为委派代码可以确保线程安全。
并发性注意:这个类或其子类的实例可以由多个线程同时调用,因此必须是线程安全的。在成员变量中存储状态时,应该特别小心。
代码示例来源:origin: stackoverflow.com
public synchronized Restlet createInboundRoot()
{
Router router = new Router();
router.attach("/helloworld",HelloWorldResource.class);
router.attach("/hello",HelloWorldResource1.class);
Filter fil1 = filterObj();
fil1.setNext(router);
return fil1;
}
代码示例来源: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.jse/org.restlet.example
/**
* Creates a root Restlet that will receive all incoming calls.
*/
@Override
public Restlet createInboundRoot() {
// Create a router Restlet that routes each call to a
// new instance of HelloWorldResource.
Router router = new Router(getContext());
// Defines only one route
router.attachDefault(HelloWorldResource.class);
return router;
}
代码示例来源:origin: uber/chaperone
@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);
return router;
}
}
代码示例来源:origin: org.restlet.osgi/org.restlet
/**
* Attaches a Resource class to this router as the default target to invoke
* when no route matches. It actually sets a default route that scores all
* calls to 1.0.
*
* @param defaultTargetClass
* The target Resource class to attach.
* @return The created route.
*/
public TemplateRoute attachDefault(
Class<? extends ServerResource> defaultTargetClass) {
return attachDefault(createFinder(defaultTargetClass));
}
代码示例来源:origin: locationtech/geowave
@Override
public synchronized Restlet createInboundRoot() {
// Create a router Restlet and map all the resources
final Router router = new Router(getContext());
// set context attributes that resources may need access to here
getContext().getAttributes().put("availableRoutes", availableRoutes);
getContext().getAttributes().put("asyncOperationPool", asyncOperationPool);
getContext().getAttributes().put("asyncOperationStatuses", asyncOperationStatuses);
// actual mapping here
router.attachDefault(MainResource.class);
router.attach("/api", SwaggerResource.class);
router.attach("/v0/fileupload", FileUploadResource.class);
router.attach("/v0/operation_status", AsyncOperationStatusResource.class);
attachApiRoutes(router);
return router;
}
代码示例来源:origin: stackoverflow.com
public class ContactsApplication extends Application {
public Restlet createInboundRoot() {
Router router = new Router(getContext());
router.attach("/contacts/", ContactsServerResource.class);
router.attach("/contacts/{contactId}", ContactServerResource.class);
return router;
}
}
代码示例来源:origin: stackoverflow.com
require([
"app",
"router",
],
function(app, Router) {
app.router = new Router();
Backbone.history.start({ pushState: true, root: app.root });
});
代码示例来源:origin: stackoverflow.com
@Override
public Restlet createInboundRoot() {
Router router = new Router( getContext() );
router.attachDefault( TestActionResource.class );
router.attach( "http://localhost:8111/echo", EchoResource.class );
return router;
}
代码示例来源:origin: bioinformatics-ua/dicoogle
this.internalRouter = new Router(getContext());
this.internalRouter.setDefaultMatchingQuery(false);
internalRouter.attach("/dim", RestDimResource.class);//search resource
internalRouter.attach("/file", RestFileResource.class);//file download resource
internalRouter.attach("/dump", RestDumpResource.class);//dump resource
internalRouter.attach("/tags", RestTagsResource.class);//list of avalilable tags resource
internalRouter.attach("/wado", RestWADOResource.class);
internalRouter.attach("/img", RestDcmImageResource.class);
internalRouter.attach("/examTime", ExamTimeResource.class);
internalRouter.attach("/doIndex", ForceIndexing.class);
internalRouter.getRoutes());
return internalRouter;
代码示例来源:origin: stackoverflow.com
public static void main(String[] args) throws Exception {
final Router router = new Router();
router.attach("/hello", FirstServerResource.class);
router.attach("/json", Json.class);
router.attachDefault(Default.class);
Application myApp = new Application() {
@Override
public org.restlet.Restlet createInboundRoot() {
router.setContext(getContext());
return router;
};
};
Component component = new Component();
component.getDefaultHost().attach("/test", myApp);
new Server(Protocol.HTTP, 8182, component).start();
}
代码示例来源:origin: com.github.ansell.oas/oas-webservice-impl
final Router router = new Router(this.getContext());
router.attach(annotationCreatePath, BulkUpdateAnnotationResourceImpl.class);
router.attach(bulkFetchAnnotationsPath, BulkFetchAnnotationResourceImpl.class);
router.attach(bulkDeleteAnnotationsPath, BulkDeleteAnnotationResourceImpl.class);
router.attach(annotationByIdPath, AnnotationByIdResourceImpl.class);
router.attach(annotationsByObjectTypePath, AnnotationsByAnnotatedObjectTypeResourceImpl.class);
router.attach(annotationsByObjectUriPath, AnnotationsByAnnotatedObjectUriResourceImpl.class);
router.attach(annotationsByOntologyTermPath, AnnotationsByOntologyTermUriResourceImpl.class);
router.attach(annotationsCountByOntologyTermUriPath, AnnotationCountsByOntologyTermUriResourceImpl.class);
router.attach(annotationsCountByAnnotatedObjectUriPath, AnnotationCountsByAnnotatedObjectUriResourceImpl.class);
router.attach(ontologyManagerUploadPath, CreateOntologyResourceImpl.class);
router.attach(ontologyManagerDeletePath, DeleteOntologyResourceImpl.class);
router.attach(ontologyManager, OntologyManagerResourceImpl.class);
router.attach(setCurrentVersion, SetCurrentOntologyResourceImpl.class);
router.attach(ontologyBrowser, OntologyBrowserResourceImpl.class);
代码示例来源: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: apache/attic-polygene-java
protected void printRoutes( PrintStream out )
{
router.getRoutes()
.stream()
.map( Object::toString )
.forEach( out::println );
}
代码示例来源:origin: stackoverflow.com
Router router = new Router(getContext());
router.attachDefault(DefaultResource.class);
RestServicesInit.attachResources(router);
JsonpFilter jsonpFilter = new JsonpFilter(getContext());
**authenticator.setNext(jsonpFilter);
jsonpFilter.setNext(router);**
// Get hold of JSONConverter and enable ISO-date format by default
List<ConverterHelper> registeredConverters = Engine.getInstance().getRegisteredConverters();
for(ConverterHelper helper : registeredConverters) {
if(helper instanceof JacksonConverter) {
JacksonConverter jacksonConverter = (JacksonConverter) helper;
jacksonConverter.getObjectMapper().configure(SerializationConfig.Feature.WRITE_DATES_AS_TIMESTAMPS, false);
}
}
**return authenticator;**
代码示例来源:origin: org.restlet.osgi/org.restlet
for (int i = 0; (result == null) && (i < getMaxAttempts()); i++) {
if (i > 0) {
Thread.sleep(getRetryDelay());
} catch (InterruptedException e) {
switch (getRoutingMode()) {
case MODE_BEST_MATCH:
result = getRoutes().getBest(request, response,
getRequiredScore());
break;
result = getRoutes().getFirst(request, response,
getRequiredScore());
break;
result = getRoutes().getLast(request, response,
getRequiredScore());
break;
result = getRoutes().getNext(request, response,
getRequiredScore());
break;
result = getRoutes().getRandom(request, response,
getRequiredScore());
break;
result = getCustom(request, response);
代码示例来源: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();
}
}
代码示例来源: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.ext.osgi
/**
* Called by OSGi DS to inject the default resource provider service
*
* @param resourceProvider
* the default resource provider
*/
public void bindDefaultResourceProvider(ResourceProvider resourceProvider) {
defaultRestletProvider = resourceProvider;
if (router != null)
router.attachDefault(resourceProvider.getInboundRoot(router
.getContext()));
}
代码示例来源:origin: org.restlet.osgi/org.restlet
@Override
public Restlet getNext(Request request, Response response) {
Restlet result = super.getNext(request, response);
if (result == null) {
getLogger()
.warning(
"The protocol used by this request is not declared in the list of client connectors. ("
+ request.getResourceRef()
.getSchemeProtocol()
+ "). In case you are using an instance of the Component class, check its \"clients\" property.");
}
return result;
}
内容来源于网络,如有侵权,请联系作者删除!