How to package static files needed by my Android Restlet server?

286 views Asked by At

I'm using Restlet 2.3.2.

I'm building an Android Activity running a Servlet Server. I would like to package some files (the keystore and the static web files directory) with the resulting APK and make them accessible to Restlet.

Right now, I put those files in /storage/sdcard0. Here is the code that actually works with the files located at that place :

Server server = component.getServers().add(org.restlet.data.Protocol.HTTPS, port);
component.getClients().add(org.restlet.data.Protocol.FILE);

Series<Parameter> parameters = server.getContext().getParameters();
parameters.add("sslContextFactory", "org.restlet.engine.ssl.DefaultSslContextFactory");
parameters.add("keyStorePath", "/storage/sdcard0/ssl/keystore");
parameters.add("keyStorePassword", "password");
parameters.add("keyPassword", "password");
parameters.add("keyStoreType", "BKS");

parameters.add("keyManagerAlgorithm", KeyManagerFactory.getDefaultAlgorithm());

// Create an application
Application application = new Application() {
    @Override
    public Restlet createInboundRoot() {
        return new Directory(getContext(), "/storage/sdcard0/www/");
    }
};

component.getDefaultHost().attach("/static", application);

I'd like to package these files by putting them in res/rawor assets in my Android project, but I don't know how to make them accessible to my web server once moved.

1

There are 1 answers

1
Thierry Boileau On

you can change the Directory root url and use the clap protocol (that leverages the classloader):

component.getClients().add(org.restlet.data.Protocol.CLAP);

// Create an application
Application application = new Application() {
    @Override
    public Restlet createInboundRoot() {
        return new Directory(getContext(), "clap://class/assets/");
    }
};

I've not tested exactly your code, I hope it will work for you.