java – Restlet Protocol. File usage
I have an example about protocol in the restlet site Problems with file usage
// 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();
Why do I need to add protocol Add file to the client connector list to provide directory / file content?
Solution
Just because you're in root_ Use this protocol in URI variables; -) For protocols, you need to explicitly add restlet components when you create them The client connector provides a way to access resources (local or remote) using a protocol
Here are some more details about what happened behind the scenes:
>When restlet extension is added to the classpath, some elements will be registered in the engine You can have converters, server connectors, client connectors... You can see the contents registered on the engine instance:
List<ConnectorHelper<Client>> clientConnectors = Engine.getInstance().getRegisteredClients(); for (ConnectorHelper<Client> clientConnector : clientConnectors) { System.out.println(clientConnector); }
>With regard to client connectors, they correspond to entities that can handle specific protocols For example, the jetty extension provides a client connector to execute HTTP and HTTPS requests based on the jetty client API. > To actually use these registered client connectors, you need to enable them by specifying the protocol to use For example, if you add an HTTP protocol, restlet will find the first client connector in the list of registered that can handle this protocol It will use this connector for executing HTTP requests If no connector is available, it throws an exception
In your case, the client connector of the file protocol is provided by the restlet core itself, so it will be registered automatically However, you need to clearly tell restlet that you want to use this agreement
I hope it can help you, Thierry