Java Restlet:如何在应用程序中使用ClientResource
我们有一个RESTlet应用程序,它创建一个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
应用程序
对象,然后使用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)选择正确的客户端连接器。我会摆弄这个或上下文参数。