Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
package org.jumpserver.chen.framework.console;

import com.alibaba.fastjson.JSON;
import com.google.gson.Gson;
import org.apache.commons.lang3.StringUtils;
import org.jumpserver.chen.framework.console.action.DataViewAction;
import org.jumpserver.chen.framework.console.dataview.DataView;
Expand Down Expand Up @@ -33,6 +33,8 @@ public class DataViewConsole extends AbstractConsole {
private String schema;
private String table;

private static final Gson GSON = new Gson();

public DataViewConsole(Datasource datasource, WebSocketSession ws, String nodeKey) {
super(datasource, ws, nodeKey);
}
Expand Down Expand Up @@ -73,7 +75,7 @@ public void handle(Packet packet) {
switch (packet.getType()) {
case "ping" -> this.getPacketIO().sendPacket("pong", null);
case Packet.TYPE_DATA_VIEW_ACTION -> {
var action = JSON.parseObject(JSON.toJSONString(packet.getData()), DataViewAction.class);
var action = GSON.fromJson(GSON.toJson(packet.getData()), DataViewAction.class);
this.onDataViewAction(action);
}
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
package org.jumpserver.chen.framework.console;

import com.alibaba.druid.sql.parser.ParserException;
import com.alibaba.fastjson.JSON;
import com.google.gson.Gson;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.lang3.StringUtils;
import org.jumpserver.chen.framework.console.action.DataViewAction;
Expand Down Expand Up @@ -48,6 +48,8 @@ public class QueryConsole extends AbstractConsole {
private StateManager<QueryConsoleState> stateManager;
private final Map<String, DataView> dataViews = new HashMap<>();

private static final Gson GSON = new Gson();

public QueryConsole(Datasource datasource, WebSocketSession ws, String nodeKey) {
super(datasource, ws, nodeKey);
this.setTitle(String.format(MessageUtils.get("Query") + "-%d", generateConsoleName()));
Expand Down Expand Up @@ -132,12 +134,12 @@ public void handle(Packet packet) {
}

case Packet.TYPE_QUERY_CONSOLE_ACTION -> {
var action = JSON.parseObject(JSON.toJSONString(packet.getData()), QueryConsoleAction.class);
var action = GSON.fromJson(GSON.toJson(packet.getData()), QueryConsoleAction.class);
this.onAction(action);

}
case Packet.TYPE_DATA_VIEW_ACTION -> {
var action = JSON.parseObject(JSON.toJSONString(packet.getData()), DataViewAction.class);
var action = GSON.fromJson(GSON.toJson(packet.getData()), DataViewAction.class);
this.onDataViewAction(action);
}
default -> log.warn("Unknown packet type {}", packet.getType());
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
package org.jumpserver.chen.framework.ws;

import com.alibaba.fastjson.JSON;
import com.google.gson.Gson;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.lang3.StringUtils;
import org.jumpserver.chen.framework.console.Console;
Expand All @@ -22,6 +22,8 @@
@Slf4j
public class ConsoleWebSocketHandler extends TextWebSocketHandler {

private static final Gson GSON = new Gson();


@Override
public void afterConnectionEstablished(WebSocketSession session) throws Exception {
Expand All @@ -44,7 +46,7 @@ public void handleMessage(WebSocketSession session, WebSocketMessage<?> message)
var token = (String) session.getAttributes().get("token");
SessionManager.setContext(token);

var packet = JSON.parseObject(message.getPayload().toString(), Packet.class);
var packet = GSON.fromJson(message.getPayload().toString(), Packet.class);
if (StringUtils.equals(packet.getType(), Packet.TYPE_CONNECT)) {
onConnectPacket(session, packet);
} else {
Expand All @@ -68,7 +70,7 @@ public void handleMessage(WebSocketSession session, WebSocketMessage<?> message)
}

private void onConnectPacket(WebSocketSession session, Packet packet) {
Connect connect = JSON.parseObject(packet.getData().toString(), Connect.class);
Connect connect = GSON.fromJson(packet.getData().toString(), Connect.class);
Console console = null;
var webSess = SessionManager.getCurrentSession();

Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
package org.jumpserver.chen.framework.ws;

import com.alibaba.fastjson.JSON;
import com.google.gson.Gson;
import lombok.extern.slf4j.Slf4j;
import org.jumpserver.chen.framework.i18n.MessageUtils;
import org.jumpserver.chen.framework.session.Session;
Expand All @@ -17,6 +17,8 @@
@Slf4j
public class SessionWebSocketHandler extends TextWebSocketHandler {

private static final Gson GSON = new Gson();

@Override
public void afterConnectionEstablished(WebSocketSession session) throws Exception {

Expand Down Expand Up @@ -77,7 +79,11 @@ public void handleMessage(WebSocketSession session, WebSocketMessage<?> message)
SessionManager.setContext(token);
var webSession = SessionManager.getCurrentSession();

var packet = JSON.parseObject(message.getPayload().toString(), Packet.class);
var packet = GSON.fromJson(
message.getPayload().toString(),
Packet.class
);

switch (packet.getType()) {
case "ping" -> {
log.debug("receive ping packet from session {}", webSession.getUsername());
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
package org.jumpserver.chen.framework.ws.io;

import com.alibaba.fastjson.JSON;
import com.google.gson.Gson;
import com.google.gson.GsonBuilder;
import lombok.Getter;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.socket.TextMessage;
Expand All @@ -19,10 +19,15 @@ public PacketIO(WebSocketSession ws) {
this.wsSession = ws;
}

private static final Gson GSON = new GsonBuilder()
.setDateFormat("yyyy-MM-dd HH:mm:ss")
.create();

public void sendPacket(Packet packet) {
synchronized (this.wsSession) {
try {
String json = JSON.toJSONStringWithDateFormat(packet, "yyyy-MM-dd HH:mm:ss");

String json = GSON.toJson(packet);
this.wsSession.sendMessage(new TextMessage(json));
} catch (IOException e) {
log.error(e.getMessage());
Expand Down
5 changes: 0 additions & 5 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -52,11 +52,6 @@
<artifactId>lombok</artifactId>
<version>1.18.38</version>
</dependency>
<dependency>
<groupId>com.alibaba</groupId>
<artifactId>fastjson</artifactId>
<version>1.2.83</version>
</dependency>
<dependency>
<groupId>com.google.code.gson</groupId>
<artifactId>gson</artifactId>
Expand Down
Loading