Virtual File Service

The Virtual File Service enables you to create services that publish content using the Kanzi Connect Server built-in HTTP server.

Architecture

VirtualFileService implements the VirtualFile interface and acts as a proxy between Kanzi Connect Server built-in web server (Civet) and user-written virtual file provider.

If you want a service to provide content using HTTP, you must implement VirtualFileProvider interface and register it to the VirtualFileService. This image shows the high-level entities involved.

../_images/httpvirtualfileservice.png

Operation

Kanzi Connect Client that wants to provide content must register itself to handle a specific path within the domain that the Kanzi Connect Server serves. When this requirement is met, all requests made inside that specific path are forwarded to the registered file provider. When provider receives a request to provide a file it can complete the request in these ways:

  • Provide the content directly.

  • Provide the path to a locally accessible file. Kanzi Connect Server internally provides the contents of the file to a Kanzi Connect Client.

  • Provide a URI where the request can be redirected using HTTP redirect.

To use Virtual File Service to publish content using the Kanzi Connect Server built-in HTTP server:

  1. Register a path to the Kanzi Connect Server built-in web server.

    For example, use this code snippet to register the ´´/myhandler´´ path to the Kanzi Connect Server built-in web server

    // Look up the Virtual File Service.
    auto service = getDomain()->getServiceLookup()->lookupLocalService("Connect.CoreService.VirtualFile");
    // Create a local communications channel to the service.
    m_Client = VirtualFileLocalClient::create(dynamic_pointer_cast<VirtualFileManager>(service));
    // Register the /myhandler path to the Kanzi Connect Server built-in web server.
    m_Client->registerPath("http", "/myhandler", this);
    

    Note that this code snippet does not include error handling.

  2. Provide files by responding with content. Returned content contains the requested path.

    For example, use this code snippet to return a text document which contains the word hello when you go to the URI http://localhost:8080/myhandler/hello.

    class MyClass : public VirtualFileProvider {
      ...
    };
    
    void MyClass::provideFile(const string& path, VirtualFileResponseSharedPtr response)
    {
        response->provideAsHttpContent("application/text", (const unsigned char *)path.c_str(), path.length());
    }
    

Interface definition

The interface definition XML file for the Virtual File Service is <KanziConnectInstallation>/SDK/sources/connect/core_services/virtualfile_service/interface/virtualfile_interface.xml.

Fully qualified name for the Virtual File Service is Connect.CoreService.VirtualFile.

Supported platforms

This service is supported on all platforms that Kanzi Connect supports.