Package javarepl.console.rest

Source Code of javarepl.console.rest.RestConsole

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();
        }
    }
}
TOP

Related Classes of javarepl.console.rest.RestConsole

TOP
Copyright © 2018 www.massapi.com. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.