From fb7ac489625c87e6a96c47336d9059b4e5d8b522 Mon Sep 17 00:00:00 2001 From: Gravit Date: Tue, 2 Oct 2018 19:29:47 +0700 Subject: [PATCH] =?UTF-8?q?FileServerHandler=20=D0=B8=D1=81=D0=BF=D0=BE?= =?UTF-8?q?=D0=BB=D1=8C=D0=B7=D0=BE=D0=B2=D0=B0=D0=BD=D0=B8=D0=B5?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../command/basic/TestCommand.java | 2 +- .../fileserver/FileInitializer.java | 42 ------------------- .../socket/NettyServerSocketHandler.java | 3 +- 3 files changed, 3 insertions(+), 44 deletions(-) delete mode 100644 LaunchServer/src/main/java/ru/gravit/launchserver/fileserver/FileInitializer.java diff --git a/LaunchServer/src/main/java/ru/gravit/launchserver/command/basic/TestCommand.java b/LaunchServer/src/main/java/ru/gravit/launchserver/command/basic/TestCommand.java index 30972bed..edb653fa 100644 --- a/LaunchServer/src/main/java/ru/gravit/launchserver/command/basic/TestCommand.java +++ b/LaunchServer/src/main/java/ru/gravit/launchserver/command/basic/TestCommand.java @@ -28,7 +28,7 @@ public void invoke(String... args) throws Exception { if (handler == null) handler = new NettyServerSocketHandler(server); if (args[0].equals("start")) { - CommonHelper.newThread("Netty Server",true,handler); + CommonHelper.newThread("Netty Server",true,handler).start(); } if (args[0].equals("stop")) { handler.close(); diff --git a/LaunchServer/src/main/java/ru/gravit/launchserver/fileserver/FileInitializer.java b/LaunchServer/src/main/java/ru/gravit/launchserver/fileserver/FileInitializer.java deleted file mode 100644 index 8aa9ea0d..00000000 --- a/LaunchServer/src/main/java/ru/gravit/launchserver/fileserver/FileInitializer.java +++ /dev/null @@ -1,42 +0,0 @@ -package ru.gravit.launchserver.fileserver; - -import java.io.File; - -import io.netty.channel.ChannelInitializer; -import io.netty.channel.ChannelPipeline; -import io.netty.channel.socket.SocketChannel; -import io.netty.handler.codec.http.HttpObjectAggregator; -import io.netty.handler.codec.http.HttpServerCodec; -import io.netty.handler.ssl.SslContext; -import io.netty.handler.stream.ChunkedWriteHandler; - -public class FileInitializer extends ChannelInitializer { - - private final SslContext sslCtx; - private final File base; - private final boolean outDirs; - - public FileInitializer(SslContext sslCtx, File base, boolean outDirs) { - this.sslCtx = sslCtx; - this.base = base; - this.outDirs = outDirs; - } - - public FileInitializer(File base, boolean outDirs) { - this.sslCtx = null; - this.base = base; - this.outDirs = outDirs; - } - - @Override - public void initChannel(SocketChannel ch) { - ChannelPipeline pipeline = ch.pipeline(); - if (sslCtx != null) { - pipeline.addLast(sslCtx.newHandler(ch.alloc())); - } - pipeline.addLast(new HttpServerCodec()); - pipeline.addLast(new HttpObjectAggregator(65536)); - pipeline.addLast(new ChunkedWriteHandler()); - pipeline.addLast(new FileServerHandler(base, outDirs)); - } -} diff --git a/LaunchServer/src/main/java/ru/gravit/launchserver/socket/NettyServerSocketHandler.java b/LaunchServer/src/main/java/ru/gravit/launchserver/socket/NettyServerSocketHandler.java index fb289908..11922c3c 100644 --- a/LaunchServer/src/main/java/ru/gravit/launchserver/socket/NettyServerSocketHandler.java +++ b/LaunchServer/src/main/java/ru/gravit/launchserver/socket/NettyServerSocketHandler.java @@ -19,6 +19,7 @@ import ru.gravit.launcher.ssl.LauncherKeyStore; import ru.gravit.launcher.ssl.LauncherTrustManager; import ru.gravit.launchserver.LaunchServer; +import ru.gravit.launchserver.fileserver.FileServerHandler; import ru.gravit.launchserver.response.Response; import ru.gravit.launchserver.socket.websocket.WebSocketFrameHandler; import ru.gravit.launchserver.socket.websocket.WebSocketIndexPageHandler; @@ -142,7 +143,7 @@ public void initChannel(NioSocketChannel ch) { pipeline.addLast(new HttpObjectAggregator(65536)); pipeline.addLast(new WebSocketServerCompressionHandler()); pipeline.addLast(new WebSocketServerProtocolHandler(WEBSOCKET_PATH, null, true)); - pipeline.addLast(new WebSocketIndexPageHandler(WEBSOCKET_PATH)); + pipeline.addLast(new FileServerHandler(LaunchServer.server.updatesDir,true)); pipeline.addLast(new WebSocketFrameHandler()); } });