Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/json/15.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Java Restlet:如何在应用程序中使用ClientResource_Java_Json_Restlet_Chunked Encoding - Fatal编程技术网

Java Restlet:如何在应用程序中使用ClientResource

Java Restlet:如何在应用程序中使用ClientResource,java,json,restlet,chunked-encoding,Java,Json,Restlet,Chunked Encoding,我们有一个RESTlet应用程序,它创建一个应用程序对象,然后使用CLAP服务静态文件(通过LocalReference.createClapReference) 现在,我们想通过使用ClientResource#setRe来关闭分块​questEntityBuffering,但我一辈子都不知道在哪里将其集成到我们的RESTlet中。它如何与应用程序和路由器对象相适应 我是否应该创建一个LocalReference.CLAP\u类的子类,并以某种方式将其固定在其中 建议 public stati

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

现在,我们想通过使用
ClientResource#setRe来关闭分块​questEntityBuffering
,但我一辈子都不知道在哪里将其集成到我们的RESTlet中。它如何与
应用程序
和路由器对象相适应

我是否应该创建一个
LocalReference.CLAP\u类的子类
,并以某种方式将其固定在其中

建议

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;
}

目录在引擎盖下使用DirectoryServerResource,它从上下文请求ClientDispatcher。这会自动为您的请求协议(CLAP)选择正确的客户端连接器。我会摆弄这个或上下文参数。