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

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

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

Router.attachDefault介绍

[英]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.
[中]将资源类作为默认目标附加到此路由器,以便在没有匹配的路由时调用。它实际上设置了一个默认路由,将所有呼叫的得分设置为1.0。

代码示例

代码示例来源: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: 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: 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.gae/org.restlet.ext.platform

public RestletChain add(Restlet restlet) {
  if (first == null) {
    first = restlet;
  }
  if (last != null) {
    if (last instanceof Router) {
      Router router = (Router) last;
      router.attachDefault(restlet);
    } else if (last instanceof Filter) {
      Filter filter = (Filter) last;
      filter.setNext(restlet);
    } else {
      throw new IllegalArgumentException("Could not chain any component after a Restlet");
    }
  }
  last = restlet;
  return this;
}

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

public RestletChain add(Restlet restlet) {
  if (first == null) {
    first = restlet;
  }
  if (last != null) {
    if (last instanceof Router) {
      Router router = (Router) last;
      router.attachDefault(restlet);
    } else if (last instanceof Filter) {
      Filter filter = (Filter) last;
      filter.setNext(restlet);
    } else {
      throw new IllegalArgumentException("Could not chain any component after a Restlet");
    }
  }
  last = restlet;
  return this;
}

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

public RestletChain add(Restlet restlet) {
  if (first == null) {
    first = restlet;
  }
  if (last != null) {
    if (last instanceof Router) {
      Router router = (Router) last;
      router.attachDefault(restlet);
    } else if (last instanceof Filter) {
      Filter filter = (Filter) last;
      filter.setNext(restlet);
    } else {
      throw new IllegalArgumentException("Could not chain any component after a Restlet");
    }
  }
  last = restlet;
  return this;
}

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

/**
 * Attaches a Restlet 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.
 * 
 * In addition to super class behavior, this method will set the context of
 * the target if it is empty by creating a protected context via the
 * {@link Context#createChildContext()} method.
 * 
 * @param defaultTarget
 *            The Restlet to use as the default target.
 * @return The created route.
 */
@Override
public TemplateRoute attachDefault(Restlet defaultTarget) {
  checkContext(defaultTarget);
  return super.attachDefault(defaultTarget);
}

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

public RestletChain add(Restlet restlet) {
  if (first == null) {
    first = restlet;
  }
  if (last != null) {
    if (last instanceof Router) {
      Router router = (Router) last;
      router.attachDefault(restlet);
    } else if (last instanceof Filter) {
      Filter filter = (Filter) last;
      filter.setNext(restlet);
    } else {
      throw new IllegalArgumentException("Could not chain any component after a Restlet");
    }
  }
  last = restlet;
  return this;
}

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

public RestletChain add(Restlet restlet) {
  if (first == null) {
    first = restlet;
  }
  if (last != null) {
    if (last instanceof Router) {
      Router router = (Router) last;
      router.attachDefault(restlet);
    } else if (last instanceof Filter) {
      Filter filter = (Filter) last;
      filter.setNext(restlet);
    } else {
      throw new IllegalArgumentException("Could not chain any component after a Restlet");
    }
  }
  last = restlet;
  return this;
}

代码示例来源: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: 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.ext.osgi

/**
 * Called by OSGi DS to inject the default router provider service
 * 
 * @param routerProvider
 *            the default router provider
 */
public void bindDefaultRouterProvider(RouterProvider routerProvider) {
  defaultRestletProvider = routerProvider;
  if (router != null)
    router.attachDefault(routerProvider.getInboundRoot(router
        .getContext()));
}

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

@Override
 public synchronized Restlet createInboundRoot() {
   Directory directory = new Directory(getContext(), LocalReference.createFileReference("/home/florian/dev/wkspace/myproject/src/main/webapp/public"));
   directory.setListingAllowed(true);
   Router router = new Router(getContext());
   router.attachDefault(new HomeApplication());
   router.attach("/static", directory);
   router.attach("/hello", new HelloWorldApplication());
   return router;
 }

代码示例来源:origin: dice-group/AGDISTIS

/**
   * 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 GetDisambiguation.
    final Router router = new Router(getContext());

    // Defines only one route
    router.attachDefault(GetDisambiguation.class);
    //System.gc();
    return router;
  }
}

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

final Router router = new Router();
router.attachDefault(HttpListener.class);

MySharedObj myobj = MySharedObj.newInstance();

org.restlet.Application myApp = new org.restlet.Application() {
  @Override
  public org.restlet.Restlet createInboundRoot() {
    return router;
  };
};
Component component = new Component();
component.getDefaultHost().attach("/", myApp);

new Server(Protocol.HTTP, port, component).start();

// in a different thread
MySharedObj myobj = MySharedObj.get();
myobj.doStuff()

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

@Override
public TemplateRoute attachDefault(Restlet defaultTarget) {
  if (defaultTarget.getContext() == null) {
    defaultTarget.setContext(getContext().createChildContext());
  }
  return super.attachDefault(defaultTarget);
}

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

Router router = new Router(); // Remove final from this.
 router.attachDefault(HttpListener.class);
 Component component = new Component();
 Context ctx = component.getApplication().getContext().createChildContext(); // Remove final
 ctx.getAttributes().put("mysharedobj", new MySharedObj());
 org.restlet.Application myApp = new org.restlet.Application(ctx) {
   @Override
   public org.restlet.Restlet createInboundRoot() {
     return router;
   };
 };

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

@Override
public Restlet getInboundRoot(Context context) {
  if (router == null) {
    router = createRouter(context);
    for (ResourceProvider resourceProvider : resourceProviders)
      attachResource(resourceProvider);
    for (DirectoryProvider directoryProvider : directoryProviders)
      attachDirectory(directoryProvider);
    if (defaultRestletProvider != null)
      router.attachDefault(defaultRestletProvider
          .getInboundRoot(context));
  }
  Restlet inboundRoot = super.getInboundRoot(context);
  return inboundRoot != null ? inboundRoot : router;
}

代码示例来源: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: 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;
}

相关文章