加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 编程开发 > Java > 正文

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请求.
>要实际能够使用这些已注册的客户端连接器,您需要通过指定要使用的协议来启用它们.例如,如果添加HTTP协议,Restlet将在已注册的能够处理此协议的列表中找到第一个客户端连接器.对于执行HTTP请求,它将使用此连接器.如果没有可用的连接器,它将抛出异常……

在您的情况下,FILE协议的客户端连接器由Restlet核心本身提供,因此它会自动注册.但是您需要明确告诉Restlet您要使用此协议.

希望它能帮到你,蒂埃里

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读