java – Restlet Protocol.FILE用法
发布时间:2020-12-15 02:12:20 所属栏目:Java 来源:网络整理
导读:我在Restlet站点的 example中有一个关于Protocol.FILE用法的问题 // URI of the root directory.public static final String ROOT_URI = "file:///c:/restlet/docs/api/";[...]// Create a componentComponent component = new Component();component.getSer
我在Restlet站点的
example中有一个关于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添加到客户端连接器列表以提供目录/文件内容? 解决方法
仅仅因为您在ROOT_URI变量中使用此协议;-)关于协议,您需要在创建Restlet组件时显式添加它们.客户端连接器提供了一种使用协议访问资源(本地或远程)的方法.
这里有一些关于幕后发生的事情的更多细节: >在类路径中添加Restlet扩展时,会在引擎中注册一些元素.您可以拥有转换器,服务器连接器,客户端连接器……您可以看到Engine实例上注册的内容: List<ConnectorHelper<Client>> clientConnectors = Engine.getInstance().getRegisteredClients(); for (ConnectorHelper<Client> clientConnector : clientConnectors) { System.out.println(clientConnector); } >关于客户端连接器,它们对应于能够处理特定协议的实体.例如,Jetty扩展提供客户端连接器,以基于Jetty客户端API执行HTTP和HTTPS请求. 在您的情况下,FILE协议的客户端连接器由Restlet核心本身提供,因此它会自动注册.但是您需要明确告诉Restlet您要使用此协议. 希望它能帮到你,蒂埃里 (编辑:李大同) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |