Using Restlet Protocol.FILE

I have a question about using Protocol.FILEin this example from the Restlet site

// 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 is it necessary to add Protocol.FILEto the list of client connectors to serve the contents of a directory / file?

+4
source share
1 answer

Just because you use this protocol in a variable ROOT_URI;-) As for the protocols, you need to explicitly add them when creating the Restlet component. Client connectors provide a way to use protocols to access resources (local or remote).

Here are some more details about what is happening under the hood:

  • Restlet . , , ,... , Engine:

    List<ConnectorHelper<Client>> clientConnectors
            = Engine.getInstance().getRegisteredClients();
    for (ConnectorHelper<Client> clientConnector : clientConnectors) {
        System.out.println(clientConnector);
    }
    
  • , , . , Jetty HTTP HTTPS- API- Jetty.

  • , , , . , HTTP, Restlet , . HTTP . , ...

FILE , . Restlet, .

, , Thierry

0

Source: https://habr.com/ru/post/1622607/


All Articles