Restlet:如何将ClientResource与Application一起使用

时间:2014-01-29 17:23:02

标签: java json restlet chunked-encoding

我们有一个RESTlet应用程序,它创建一个Application对象,然后使用CLAP来提供静态文件(通过LocalReference.createClapReference

现在,我们想通过使用ClientResource#setRe​questEntityBuffering来关闭分块,但我不能在我的生活中找出将它集成到我们的RESTlet中的位置。它如何适应Application和Router对象?

我应该创建LocalReference.CLAP_CLASS的子类并以某种方式将其粘贴在那里吗?

建议?

public static void createRestServer(ApplicationContext appCtx, String propertiesPath) throws Exception {

  // Create a component
  Component component = new Component();
  component.getServers().add(Protocol.HTTP, 8081);
  component.getClients().add(Protocol.FILE);
  component.getClients().add(Protocol.CLAP);

  Context context = component.getContext().createChildContext();
  RestServer application = new RestServer(context);

  application.getContext().getParameters().add("useForwardedForHeader", "true");

  application.getContext().getAttributes().put("appCtx", appCtx);
  application.getContext().getAttributes().put("file", propertiesPath);

  // Attach the application to the component and start it
  component.getDefaultHost().attach(application);
  component.start();
}

private RestServer(Context context) {
  super(context);
}

public synchronized Restlet createInboundRoot() {
  Router router = new Router(getContext());

  // we then have a bunch of these
  router.attach("/accounts/{accountId}", AccountFetcher.class); //LIST Account level
  // blah blah blah

  // finally some stuff for static files:
  //
  Directory directory = new Directory(getContext(),
     LocalReference.createClapReference(LocalReference.CLAP_CLASS, "/"));
  directory.setIndexName("index.html");
  router.attach("/", directory);

  return router;
}

0 个答案:

没有答案