我有一个关于Restlet站点Protocol.FILE在这个示例中的使用的问题。
// URI of the root directory.
public static final String ROOT_URI = "file:///c:/restlet/docs/api/";
[...]
// Create a component
Component component = new Component();
component.getServers().add(Protocol.HTTP, 8182);
component.getClients().add(Protocol.FILE);
// Create an application
Application application = new Application() {
@Override
public Restlet createInboundRoot() {
return new Directory(getContext(), ROOT_URI);
}
};
// Attach the application to the component and start it
component.getDefaultHost().attach(application);
component.start();为什么需要将Protocol.FILE添加到客户端连接器列表中以提供目录/文件内容?
发布于 2016-01-03 19:43:53
仅仅因为您在ROOT_URI变量中使用了该协议;-)关于协议,在创建Restlet组件时需要显式地添加它们。客户端连接器提供了使用协议访问资源(本地或远程)的方法。
下面是关于引擎盖下面发生的事情的更多细节:
Engine本身的实例上注册了什么:
List clientConnectors = Engine.getInstance().getRegisteredClients();for (ConnectorHelper clientConnector : clientConnectors) { System.out.println(clientConnector);}HTTP协议,Restlet将在已注册连接器列表中找到能够处理该协议的第一个客户端连接器。对于执行HTTP请求,它将使用此连接器。如果没有可用的连接器,它会抛出一个异常.在您的例子中,FILE协议的客户端连接器是由Restlet本身提供的,因此它是自动注册的。但是您需要显式地告诉Restlet您想要使用这个协议。
希望它能帮到你,蒂埃里
https://stackoverflow.com/questions/34577075
复制相似问题