Search in sources :

Example 1 with Server

use of org.simpleframework.transport.Server in project gradle by gradle.

the class SimpleHttpFileServerFactory method start.

public HttpFileServer start(File contentRoot, int port) {
    Container container = new SimpleFileServerContainer(new FileContext(contentRoot));
    try {
        final Server server = new ContainerServer(container);
        Connection connection = new SocketConnection(server);
        InetSocketAddress address = new InetSocketAddress(port);
        InetSocketAddress usedAddress = (InetSocketAddress) connection.connect(address);
        return new SimpleHttpFileServer(contentRoot, usedAddress.getPort(), new Stoppable() {

            public void stop() {
                try {
                    server.stop();
                } catch (IOException e) {
                    throw new UncheckedIOException(e);
                }
            }
        });
    } catch (IOException e) {
        throw new UncheckedIOException(e);
    }
}
Also used : SimpleFileServerContainer(org.gradle.plugins.javascript.envjs.http.simple.internal.SimpleFileServerContainer) ContainerServer(org.simpleframework.http.core.ContainerServer) Container(org.simpleframework.http.core.Container) SimpleFileServerContainer(org.gradle.plugins.javascript.envjs.http.simple.internal.SimpleFileServerContainer) Server(org.simpleframework.transport.Server) HttpFileServer(org.gradle.plugins.javascript.envjs.http.HttpFileServer) ContainerServer(org.simpleframework.http.core.ContainerServer) SocketConnection(org.simpleframework.transport.connect.SocketConnection) InetSocketAddress(java.net.InetSocketAddress) Connection(org.simpleframework.transport.connect.Connection) SocketConnection(org.simpleframework.transport.connect.SocketConnection) Stoppable(org.gradle.internal.concurrent.Stoppable) UncheckedIOException(org.gradle.api.UncheckedIOException) IOException(java.io.IOException) UncheckedIOException(org.gradle.api.UncheckedIOException) FileContext(org.simpleframework.http.resource.FileContext)

Aggregations

IOException (java.io.IOException)1 InetSocketAddress (java.net.InetSocketAddress)1 UncheckedIOException (org.gradle.api.UncheckedIOException)1 Stoppable (org.gradle.internal.concurrent.Stoppable)1 HttpFileServer (org.gradle.plugins.javascript.envjs.http.HttpFileServer)1 SimpleFileServerContainer (org.gradle.plugins.javascript.envjs.http.simple.internal.SimpleFileServerContainer)1 Container (org.simpleframework.http.core.Container)1 ContainerServer (org.simpleframework.http.core.ContainerServer)1 FileContext (org.simpleframework.http.resource.FileContext)1 Server (org.simpleframework.transport.Server)1 Connection (org.simpleframework.transport.connect.Connection)1 SocketConnection (org.simpleframework.transport.connect.SocketConnection)1