org.restlet.Application.<init>()方法的使用及代码示例

x33g5p2x  于2022-01-16 转载在 其他  
字(4.1k)|赞(0)|评价(0)|浏览(94)

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

Application.<init>介绍

[英]Constructor. Note this constructor is convenient because you don't have to provide a context like for #Application(Context). Therefore the context will initially be null. It's only when you attach the application to a virtual host via one of its attach*() methods that a proper context will be set.
[中]构造器。注意:这个构造函数很方便,因为您不必像#应用程序(context)那样提供上下文。因此,上下文最初将为null。只有当您通过某个attach*()方法将应用程序附加到虚拟主机时,才会设置正确的上下文。

代码示例

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

/**
 * Called to construct the actual application instance. Extenders will
 * generally override this method.
 * 
 * @param context
 *            the Restlet application context
 * @return the newly constructed application instance
 */
protected Application doCreateApplication(Context context) {
  // FIXME Workaround for a bug in Restlet 2.1M7 - the context should be
  // passed to the Application
  // constructor.
  Application app = new Application();
  app.setContext(context);
  return app;
}

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

/**
 * Returns the parent application. If it wasn't set, it attempts to retrieve
 * the current one via {@link org.restlet.Application#getCurrent()} if it
 * exists, or instantiates a new one as a last resort.
 * 
 * @return The parent application if it exists, or a new one.
 */
public org.restlet.Application getApplication() {
  org.restlet.Application result = this.application;
  if (result == null) {
    result = org.restlet.Application.getCurrent();
    if (result == null) {
      result = new org.restlet.Application(getContext());
    }
    this.application = result;
  }
  return result;
}

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

public static void main(String[] args) throws Exception {
  // Instantiating the Application providing the Range Service
  Application app = new Application();
  // Plug the server resource.
  app.setInboundRoot(HelloServerResource.class);
  // Instantiating the HTTP server and listening on port 8111
  new Server(Protocol.HTTP, 8111, app).start();
}

代码示例来源: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: unchartedsoftware/aperture-tiles

/**
 * Creates the restlet application that will be used to handle all rest calls
 * Takes a map of paths to resource classes
 * <p/>
 * Use the following three lines to access the routing multibinder:
 * TypeLiteral<String> pathType = new TypeLiteral<String>() {};
 * TypeLiteral<Class<? extends ServerResource>> clazzType = new TypeLiteral<Class<? extends ServerResource>>() {};
 * MapBinder<String, Class<? extends ServerResource>> resourceBinder = MapBinder.newMapBinder(binder(), pathType, clazzType);
 * resourceBinder.bind("/my/path").toInstance(MyResource.class);
 */
@Provides
Application createApplication( FinderFactory factory, Map<String, Class<? extends ServerResource>> routes ) {
  Context context = new Context();
  Application application = new Application();
  application.setContext( context );
  Router router = new Router( context );
  // Set binding rules here
  for ( Entry<String, Class<? extends ServerResource>> entry : routes.entrySet() ) {
    final Class<? extends ServerResource> resource = entry.getValue();
    logger.info( "Binding '" + entry.getKey() + "' to " + resource );
    router.attach( entry.getKey(), factory.finder( resource ) );
  }
  application.setInboundRoot( router );
  return application;
}

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

相关文章