org.restlet.Application类的使用及代码示例

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

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

Application介绍

[英]Restlet that can be attached to one or more VirtualHosts. Applications are guaranteed to receive calls with their base reference set relatively to the VirtualHost that served them. This class is both a descriptor able to create the root Restlet and the actual Restlet that can be attached to one or more VirtualHost instances.

Applications also have many useful Services associated. They are available as properties that can be eventually overriden:

  • "connectorService" to declare necessary client and server connectors.
  • "decoderService" to automatically decode or decompress request entities.
  • "metadataService" to provide access to metadata and their associated extension names.
  • "rangeService" to automatically exposes ranges of response entities.
  • "statusService" to provide common representations for exception status.
  • "taskService" to run tasks asynchronously.
  • "tunnelService" to tunnel method names or client preferences via query parameters.
    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.
    [中]可以附加到一个或多个VirtualHost的Restlet。应用程序被保证使用其基本引用集(相对于为其提供服务的VirtualHost)来接收呼叫。此类既是一个描述符,能够创建根Restlet,也是一个实际的Restlet,可以附加到一个或多个VirtualHost实例。
    应用程序还具有许多相关的有用服务。它们作为最终可以覆盖的属性提供:
    *“connectorService”声明必要的客户端和服务器连接器。
    *“decoderService”自动解码或解压缩请求实体。
    *“metadataService”提供对元数据及其相关扩展名的访问。
    *“rangeService”自动公开响应实体的范围。
    *“statusService”提供异常状态的通用表示。
    *“taskService”异步运行任务。
    *“tunnelService”通过查询参数来隧道方法名称或客户端首选项。
    并发性注意:此类或其子类的实例可以由多个线程同时调用,因此必须是线程安全的。在成员变量中存储状态时,应该特别小心。

代码示例

代码示例来源:origin: uber/chaperone

public AdminRestletResource() {
 _helixMirrorMakerManager = (HelixMirrorMakerManager) getApplication().getContext()
   .getAttributes().get(HelixMirrorMakerManager.class.toString());
}

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

/**
 * Returns the parent application if it exists, or null.
 * 
 * @return The parent application if it exists, or null.
 */
public Application getApplication() {
  return Application.getCurrent();
}

代码示例来源:origin: uber/chaperone

_component.getClients().add(Protocol.WAR);
final Context applicationContext = _component.getContext().createChildContext();
applicationContext.getAttributes().put(ControllerConf.class.toString(), _config);
applicationContext.getAttributes().put(HelixMirrorMakerManager.class.toString(), _helixMirrorMakerManager);
applicationContext.getAttributes().put(ValidationManager.class.toString(), _validationManager);
_controllerRestApp.setContext(applicationContext);

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

public static Context getCurrentApplicationContext() {
  Application application = Application.getCurrent();
  if (application == null) {
    return null;
  }
  return application.getContext();
}

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

/**
 * Called by OSGi DS to inject the router provider service
 * 
 * @param routerProvider
 *            the router provider service
 */
public void bindRouterProvider(RouterProvider routerProvider) {
  this.routerProvider = routerProvider;
  if (application != null)
    application.setInboundRoot(routerProvider
        .getInboundRoot(application.getContext()));
}

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

application.setContext(parentContext.createChildContext());
  } catch (NoSuchMethodException e) {
    log("[Restlet] ServerServlet couldn't invoke the constructor of the target class. Please check this class has a constructor without parameter. The constructor with a parameter of type Context will be used instead.");
        parentContext.createChildContext());
final Context applicationContext = application.getContext();
    .getInitParameterNames(); enum1.hasMoreElements();) {
  initParam = enum1.nextElement();
  applicationContext.getParameters().add(initParam,
      servletConfig.getInitParameter(initParam));

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

.getDescription()));
if (application.toString().equals(application.getName())) {
  LOGGER.log(Level.WARNING,
      "Please provide a name to your application by overriding its method getName. Used "
  contract.setName(application.getClass().getSimpleName());
} else {
  contract.setName(application.getName());
    application.getInboundRoot(), null /*

代码示例来源:origin: com.noelios.restlet/com.noelios.restlet.ext.servlet

application.setContext(new ServletContextAdapter(this,
        parentContext));
  } catch (NoSuchMethodException e) {
final Context applicationContext = application.getContext();
    .getInitParameterNames(); enum1.hasMoreElements();) {
  initParam = enum1.nextElement();
  applicationContext.getParameters().add(initParam,
      servletConfig.getInitParameter(initParam));
    .getInitParameterNames(); enum1.hasMoreElements();) {
  initParam = enum1.nextElement();
  applicationContext.getParameters().add(initParam,
      getServletContext().getInitParameter(initParam));

代码示例来源:origin: locationtech/geowave

final Context appContext = Application.getCurrent().getContext();
final ExecutorService opPool =
  (ExecutorService) appContext.getAttributes().get("asyncOperationPool");
final ConcurrentHashMap<String, Future> opStatuses =
  (ConcurrentHashMap<String, Future>) appContext.getAttributes().get(
    "asyncOperationStatuses");

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

if (isStopped()) {
  super.start();
  if (getHelper() != null) {
    getHelper().start();
  if (getConnectorService() != null) {
    getConnectorService().start();
  if (getConverterService() != null) {
    getConverterService().start();
  if (getDecoderService() != null) {
    getDecoderService().start();
  if (getMetadataService() != null) {
    getMetadataService().start();
  if (getRangeService() != null) {
    getRangeService().start();
  if (getStatusService() != null) {
    getStatusService().start();
  if (getTaskService() != null) {
    getTaskService().start();
  if (getTunnelService() != null) {
    getTunnelService().start();

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

if (Application.getCurrent() != null
        && !Application.getCurrent().isDebugging()) {
        Context.getCurrentLogger()
            .log(Level.WARNING,
                "The cause of the exception should be null except in debug mode");
      representationObject, variant);
} catch (Exception e) {
  Context.getCurrentLogger().log(
      Level.WARNING,
      "Could not serialize throwable class "

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

public void execute(final Runnable runnable) {
  // Save the thread local variables
  final Application currentApplication = Application.getCurrent();
  final Context currentContext = Context.getCurrent();
  final Integer currentVirtualHost = VirtualHost.getCurrent();
  final Response currentResponse = Response.getCurrent();
  executorService.execute(new Runnable() {
    public void run() {
      // Copy the thread local variables
      Response.setCurrent(currentResponse);
      Context.setCurrent(currentContext);
      VirtualHost.setCurrent(currentVirtualHost);
      Application.setCurrent(currentApplication);
      try {
        // Run the user task
        runnable.run();
      } finally {
        // Reset the thread local variables
        Response.setCurrent(null);
        Context.setCurrent(null);
        VirtualHost.setCurrent(-1);
        Application.setCurrent(null);
      }
    }
  });
}

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

@Override
public synchronized void start()
  throws Exception
{
  setName( polygeneApplication.name() );
  Series<Parameter> parameters = getContext().getParameters();
  String mode = parameters.getFirstValue( "org.apache.polygene.runtime.mode" );
  super.start();
  getLogger().info( "RestApplication successfully started." );
}

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

metadataService = Application.getCurrent().getMetadataService();
StringTokenizer stt = new StringTokenizer(extensions, ".");
while (stt.hasMoreTokens()) {

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

Filter filter = null;
for (Service service : getHelped().getServices()) {
  if (service.isEnabled()) {
            : getContext().createChildContext());
            : getContext().createChildContext());
setInboundNext(getHelped().getInboundRoot());

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

/**
 * Returns the metadata service of the parent application.
 * 
 * @return The metadata service of the parent application.
 */
public MetadataService getMetadataService() {
  return getApplication().getMetadataService();
}

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

@Override
public Representation getRepresentation(Status status, Request request,
    Response response) {
  // Create the data model
  Map<String, String> dataModel = new ConcurrentHashMap<String, String>();
  dataModel.put("applicationName", Application.getCurrent().getName());
  dataModel.put("statusDescription", response.getStatus()
      .getDescription());
  dataModel.put("statusReasonPhrase", response.getStatus()
      .getReasonPhrase());
  // Load the FreeMarker template
  Representation mailFtl = new ClientResource(
      LocalReference.createClapReference(getClass().getPackage())
          + "/MailStatus.ftl").get();
  // Wraps the bean with a FreeMarker representation
  return new TemplateRepresentation(mailFtl, dataModel,
      MediaType.TEXT_HTML);
}

相关文章