diff --git a/LaunchServer/src/main/java/ru/gravit/launchserver/socket/websocket/WebSocketFrameHandler.java b/LaunchServer/src/main/java/ru/gravit/launchserver/socket/websocket/WebSocketFrameHandler.java index 27b6965a..58652cb8 100644 --- a/LaunchServer/src/main/java/ru/gravit/launchserver/socket/websocket/WebSocketFrameHandler.java +++ b/LaunchServer/src/main/java/ru/gravit/launchserver/socket/websocket/WebSocketFrameHandler.java @@ -2,8 +2,6 @@ import com.google.gson.Gson; import com.google.gson.GsonBuilder; -import com.google.gson.JsonObject; -import com.google.gson.stream.JsonReader; import io.netty.buffer.ByteBuf; import io.netty.buffer.ByteBufInputStream; import io.netty.channel.ChannelHandlerContext; @@ -11,14 +9,12 @@ import io.netty.channel.group.ChannelGroup; import io.netty.channel.group.DefaultChannelGroup; import io.netty.handler.codec.http.websocketx.WebSocketFrame; -import io.netty.handler.codec.json.JsonObjectDecoder; import io.netty.util.concurrent.GlobalEventExecutor; import ru.gravit.launchserver.socket.websocket.json.JsonResponse; import ru.gravit.launchserver.socket.websocket.json.JsonResponseAdapter; import ru.gravit.utils.helper.IOHelper; import ru.gravit.utils.helper.LogHelper; -import java.io.BufferedReader; import java.io.InputStreamReader; import java.io.Reader; diff --git a/LaunchServer/src/main/java/ru/gravit/launchserver/socket/websocket/json/EchoResponse.java b/LaunchServer/src/main/java/ru/gravit/launchserver/socket/websocket/json/EchoResponse.java new file mode 100644 index 00000000..d8382d92 --- /dev/null +++ b/LaunchServer/src/main/java/ru/gravit/launchserver/socket/websocket/json/EchoResponse.java @@ -0,0 +1,23 @@ +package ru.gravit.launchserver.socket.websocket.json; + +import io.netty.channel.ChannelHandlerContext; +import io.netty.handler.codec.http.websocketx.WebSocketFrame; +import ru.gravit.utils.helper.LogHelper; + +public class EchoResponse implements JsonResponse { + public final String echo; + + public EchoResponse(String echo) { + this.echo = echo; + } + + @Override + public String getType() { + return "echo"; + } + + @Override + public void execute(ChannelHandlerContext ctx, WebSocketFrame frame) { + LogHelper.info("Echo: %s",echo); + } +} diff --git a/LaunchServer/src/main/java/ru/gravit/launchserver/socket/websocket/json/JsonResponseAdapter.java b/LaunchServer/src/main/java/ru/gravit/launchserver/socket/websocket/json/JsonResponseAdapter.java index 8dadf58e..e3f48525 100644 --- a/LaunchServer/src/main/java/ru/gravit/launchserver/socket/websocket/json/JsonResponseAdapter.java +++ b/LaunchServer/src/main/java/ru/gravit/launchserver/socket/websocket/json/JsonResponseAdapter.java @@ -6,12 +6,15 @@ import java.util.HashMap; public class JsonResponseAdapter implements JsonSerializer, JsonDeserializer { - static HashMap> map = new HashMap<>(); + static HashMap map = new HashMap<>(); private static final String PROP_NAME = "type"; + static { + map.put("echo",EchoResponse.class); + } @Override public JsonResponse deserialize(JsonElement json, Type typeOfT, JsonDeserializationContext context) throws JsonParseException { String typename = json.getAsJsonObject().getAsJsonPrimitive(PROP_NAME).getAsString(); - Class cls = map.get(typename); + Class cls = map.get(typename); return (JsonResponse) context.deserialize(json, cls);