All Downloads are FREE. Search and download functionalities are using the official Maven repository.

javarepl.console.rest.RestConsole Maven / Gradle / Ivy

There is a newer version: 431
Show newest version
package javarepl.console.rest;

import com.googlecode.utterlyidle.ServerConfiguration;
import com.googlecode.utterlyidle.httpserver.RestServer;
import javarepl.console.Console;
import javarepl.console.DelegatingConsole;

import static com.googlecode.utterlyidle.BasePath.basePath;
import static com.googlecode.utterlyidle.ServerConfiguration.defaultConfiguration;

public class RestConsole extends DelegatingConsole {
    private final RestServer server;
    private final Integer port;

    public RestConsole(Console console, Integer port) throws Exception {
        super(console);

        ServerConfiguration configuration = defaultConfiguration().port(port);
        RestConsoleApplication application = new RestConsoleApplication(basePath("/"), this);

        this.server = new RestServer(application, configuration);
        this.port = port;
    }

    public final Integer port() {
        return port;
    }

    @Override
    public void shutdown() {
        try {
            server.close();
        } catch (Exception e) {
            throw new RuntimeException(e);
        } finally {
            super.shutdown();
        }
    }
}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy