gson单例化,另外关掉gson html转义功能
This commit is contained in:
@@ -11,6 +11,7 @@ package cn.wildfirechat.push;
|
||||
import cn.wildfirechat.common.IMExceptionEvent;
|
||||
import cn.wildfirechat.proto.ProtoConstants;
|
||||
import com.google.gson.Gson;
|
||||
import com.google.gson.GsonBuilder;
|
||||
import io.moquette.persistence.MemorySessionStore;
|
||||
import io.moquette.server.config.IConfig;
|
||||
import io.moquette.spi.ISessionsStore;
|
||||
@@ -29,7 +30,7 @@ import static win.liyufan.im.HttpUtils.HttpPostType.POST_TYPE_Push;
|
||||
|
||||
public class PushServer {
|
||||
private static final Logger LOG = LoggerFactory.getLogger(PushServer.class);
|
||||
|
||||
protected static final Gson gson = new GsonBuilder().disableHtmlEscaping().create();
|
||||
public interface PushMessageType {
|
||||
int PUSH_MESSAGE_TYPE_NORMAL = 0;
|
||||
int PUSH_MESSAGE_TYPE_VOIP_INVITE = 1;
|
||||
@@ -100,7 +101,7 @@ public class PushServer {
|
||||
url = iOSPushServerUrl;
|
||||
pushMessage.voipDeviceToken = session.getVoipDeviceToken();
|
||||
}
|
||||
HttpUtils.httpJsonPost(url, new Gson().toJson(pushMessage, pushMessage.getClass()), POST_TYPE_Push);
|
||||
HttpUtils.httpJsonPost(url, gson.toJson(pushMessage, pushMessage.getClass()), POST_TYPE_Push);
|
||||
} else {
|
||||
LOG.info("Not mobile platform {}", session.getPlatform());
|
||||
}
|
||||
|
||||
@@ -9,6 +9,7 @@
|
||||
package com.xiaoleilu.loServer.action;
|
||||
|
||||
import com.google.gson.Gson;
|
||||
import com.google.gson.GsonBuilder;
|
||||
import com.xiaoleilu.loServer.RestResult;
|
||||
import com.xiaoleilu.loServer.annotation.RequireAuthentication;
|
||||
import com.xiaoleilu.loServer.handler.Request;
|
||||
@@ -39,7 +40,7 @@ import static io.moquette.BrokerConstants.*;
|
||||
abstract public class Action {
|
||||
public static IMessagesStore messagesStore = null;
|
||||
public static ISessionsStore sessionsStore = null;
|
||||
|
||||
protected static final Gson gson = new GsonBuilder().disableHtmlEscaping().create();
|
||||
public ChannelHandlerContext ctx;
|
||||
|
||||
protected static RateLimiter adminLimiter = null;
|
||||
@@ -129,7 +130,7 @@ abstract public class Action {
|
||||
}
|
||||
|
||||
RestResult result = RestResult.resultOf(errorCode, errorCode.getMsg(), RestResult.resultOf(errorCode));
|
||||
response.setContent(new Gson().toJson(result));
|
||||
response.setContent(gson.toJson(result));
|
||||
response.send();
|
||||
}
|
||||
|
||||
@@ -145,7 +146,7 @@ abstract public class Action {
|
||||
FullHttpRequest fullHttpRequest = (FullHttpRequest) request;
|
||||
byte[] bytes = Utils.readBytesAndRewind(fullHttpRequest.content());
|
||||
String content = new String(bytes, StandardCharsets.UTF_8);//contribute by JiaRG from github
|
||||
Gson gson = new Gson();
|
||||
|
||||
T t = gson.fromJson(content, cls);
|
||||
return t;
|
||||
}
|
||||
@@ -154,6 +155,6 @@ abstract public class Action {
|
||||
|
||||
protected void setResponseContent(RestResult result, Response response) {
|
||||
response.setStatus(HttpResponseStatus.OK);
|
||||
response.setContent(new Gson().toJson(result));
|
||||
response.setContent(gson.toJson(result));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -34,7 +34,7 @@ public class VersionAction extends Action {
|
||||
|
||||
try {
|
||||
|
||||
response.setContent(Utility.formatJson(new Gson().toJson(GitRepositoryState.getGitRepositoryState())));
|
||||
response.setContent(Utility.formatJson(gson.toJson(GitRepositoryState.getGitRepositoryState())));
|
||||
} catch (IOException e) {
|
||||
e.printStackTrace();
|
||||
response.setContent("{\"version\":\"unknown\"}");
|
||||
|
||||
@@ -99,7 +99,7 @@ abstract public class AdminAction extends Action {
|
||||
}
|
||||
|
||||
RestResult result = RestResult.resultOf(errorCode, errorCode.getMsg(), data);
|
||||
response.setContent(new Gson().toJson(result));
|
||||
response.setContent(gson.toJson(result));
|
||||
response.send();
|
||||
}
|
||||
}
|
||||
|
||||
+1
-1
@@ -50,7 +50,7 @@ public class ApplicationGetUserInfoAction extends AdminAction {
|
||||
}
|
||||
|
||||
response.setStatus(HttpResponseStatus.OK);
|
||||
response.setContent(new Gson().toJson(result));
|
||||
response.setContent(gson.toJson(result));
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
@@ -42,7 +42,7 @@ public class BlockUserAction extends AdminAction {
|
||||
response.setStatus(HttpResponseStatus.OK);
|
||||
RestResult result;
|
||||
result = RestResult.resultOf(errorCode);
|
||||
response.setContent(new Gson().toJson(result));
|
||||
response.setContent(gson.toJson(result));
|
||||
|
||||
if (inputUserBlock.getStatus() == 2) {
|
||||
sendApiMessage(null, null, ServerAPIHelper.KICKOFF_USER_REQUEST, inputUserBlock.getUserId().getBytes(), null);
|
||||
|
||||
@@ -36,7 +36,7 @@ public class CheckUserOnlineAction extends AdminAction {
|
||||
InputGetUserInfo inputUserId = getRequestBody(request.getNettyRequest(), InputGetUserInfo.class);
|
||||
if (inputUserId == null || !StringUtil.isNullOrEmpty(inputUserId.getUserId())) {
|
||||
sendApiMessage(response, inputUserId.getUserId(), ServerAPIHelper.CHECK_USER_ONLINE_REQUEST, inputUserId.getUserId().getBytes(), res -> {
|
||||
OutputCheckUserOnline out = new Gson().fromJson(new String(res), OutputCheckUserOnline.class);
|
||||
OutputCheckUserOnline out = gson.fromJson(new String(res), OutputCheckUserOnline.class);
|
||||
return new Result(ErrorCode.ERROR_CODE_SUCCESS, out);
|
||||
});
|
||||
return false;
|
||||
|
||||
@@ -39,7 +39,7 @@ public class CreateChatroomAction extends AdminAction {
|
||||
FullHttpRequest fullHttpRequest = (FullHttpRequest)request.getNettyRequest();
|
||||
byte[] bytes = Utils.readBytesAndRewind(fullHttpRequest.content());
|
||||
String content = new String(bytes);
|
||||
Gson gson = new Gson();
|
||||
|
||||
InputCreateChatroom inputCreateChatroom = gson.fromJson(content, InputCreateChatroom.class);
|
||||
if (inputCreateChatroom != null
|
||||
&& !StringUtil.isNullOrEmpty(inputCreateChatroom.getTitle())) {
|
||||
|
||||
@@ -67,7 +67,7 @@ public class CreateRobotAction extends AdminAction {
|
||||
Utility.printExecption(LOG, e, IMExceptionEvent.EventType.ADMIN_API_Exception);
|
||||
response.setStatus(HttpResponseStatus.OK);
|
||||
RestResult result = RestResult.resultOf(ErrorCode.ERROR_CODE_SERVER_ERROR, e.getMessage());
|
||||
response.setContent(new Gson().toJson(result));
|
||||
response.setContent(gson.toJson(result));
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
@@ -37,7 +37,7 @@ public class DestoryChatroomAction extends AdminAction {
|
||||
FullHttpRequest fullHttpRequest = (FullHttpRequest)request.getNettyRequest();
|
||||
byte[] bytes = Utils.readBytesAndRewind(fullHttpRequest.content());
|
||||
String content = new String(bytes);
|
||||
Gson gson = new Gson();
|
||||
|
||||
InputDestoryChatroom inputDestoryChatroom = gson.fromJson(content, InputDestoryChatroom.class);
|
||||
if (inputDestoryChatroom != null
|
||||
&& !StringUtil.isNullOrEmpty(inputDestoryChatroom.getChatroomId())) {
|
||||
|
||||
+1
-1
@@ -50,7 +50,7 @@ public class ModifyGroupMemberExtraAction extends AdminAction {
|
||||
} else {
|
||||
response.setStatus(HttpResponseStatus.OK);
|
||||
RestResult result = RestResult.resultOf(ErrorCode.INVALID_PARAMETER);
|
||||
response.setContent(new Gson().toJson(result));
|
||||
response.setContent(gson.toJson(result));
|
||||
}
|
||||
}
|
||||
return true;
|
||||
|
||||
+1
-1
@@ -52,7 +52,7 @@ public class ApplicationGetUserInfoAction extends ChannelAction {
|
||||
}
|
||||
|
||||
response.setStatus(HttpResponseStatus.OK);
|
||||
response.setContent(new Gson().toJson(result));
|
||||
response.setContent(gson.toJson(result));
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
@@ -101,7 +101,7 @@ abstract public class ChannelAction extends Action {
|
||||
}
|
||||
|
||||
RestResult result = RestResult.resultOf(errorCode, errorCode.getMsg(), data);
|
||||
response.setContent(new Gson().toJson(result));
|
||||
response.setContent(gson.toJson(result));
|
||||
response.send();
|
||||
}
|
||||
|
||||
@@ -110,7 +110,7 @@ abstract public class ChannelAction extends Action {
|
||||
FullHttpRequest fullHttpRequest = (FullHttpRequest) request;
|
||||
byte[] bytes = Utils.readBytesAndRewind(fullHttpRequest.content());
|
||||
String content = new String(bytes, StandardCharsets.UTF_8);
|
||||
Gson gson = new Gson();
|
||||
|
||||
T t = gson.fromJson(content, cls);
|
||||
return t;
|
||||
}
|
||||
|
||||
+1
-1
@@ -38,7 +38,7 @@ public class SubscriberChannelAction extends ChannelAction {
|
||||
if(input.getSubscribe() > 0 && (channelInfo.getStatus() & ProtoConstants.ChannelState.Channel_State_Mask_Active_Subscribe) == 0) {
|
||||
response.setStatus(HttpResponseStatus.OK);
|
||||
RestResult result = RestResult.resultOf(ErrorCode.ERROR_CODE_NOT_RIGHT);
|
||||
response.setContent(new Gson().toJson(result));
|
||||
response.setContent(gson.toJson(result));
|
||||
return true;
|
||||
}
|
||||
WFCMessage.ListenChannel listenChannel = WFCMessage.ListenChannel.newBuilder().setChannelId(channelInfo.getTargetId()).setListen(input.getSubscribe()).build();
|
||||
|
||||
+1
-1
@@ -52,7 +52,7 @@ public class ApplicationGetUserInfoAction extends RobotAction {
|
||||
}
|
||||
|
||||
response.setStatus(HttpResponseStatus.OK);
|
||||
response.setContent(new Gson().toJson(result));
|
||||
response.setContent(gson.toJson(result));
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
+1
-1
@@ -53,7 +53,7 @@ public class ModifyGroupMemberExtraAction extends RobotAction {
|
||||
} else {
|
||||
response.setStatus(HttpResponseStatus.OK);
|
||||
RestResult result = RestResult.resultOf(ErrorCode.INVALID_PARAMETER);
|
||||
response.setContent(new Gson().toJson(result));
|
||||
response.setContent(gson.toJson(result));
|
||||
}
|
||||
}
|
||||
return true;
|
||||
|
||||
@@ -102,7 +102,7 @@ abstract public class RobotAction extends Action {
|
||||
}
|
||||
|
||||
RestResult result = RestResult.resultOf(errorCode, errorCode.getMsg(), data);
|
||||
response.setContent(new Gson().toJson(result));
|
||||
response.setContent(gson.toJson(result));
|
||||
response.send();
|
||||
}
|
||||
|
||||
@@ -113,7 +113,7 @@ abstract public class RobotAction extends Action {
|
||||
String content = null;
|
||||
try {
|
||||
content = new String(bytes, "UTF-8");
|
||||
Gson gson = new Gson();
|
||||
|
||||
T t = gson.fromJson(content, cls);
|
||||
return t;
|
||||
} catch (UnsupportedEncodingException e) {
|
||||
|
||||
@@ -25,6 +25,7 @@ import io.netty.util.internal.StringUtil;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
import cn.wildfirechat.common.ErrorCode;
|
||||
import win.liyufan.im.GsonUtil;
|
||||
import win.liyufan.im.RateLimiter;
|
||||
import win.liyufan.im.Utility;
|
||||
|
||||
@@ -141,7 +142,7 @@ abstract public class IMHandler<T> {
|
||||
// }
|
||||
|
||||
//json ?
|
||||
return (T)(new Gson().fromJson(new String(bytes), dataCls));
|
||||
return (T)(GsonUtil.gson.fromJson(new String(bytes), dataCls));
|
||||
}
|
||||
|
||||
public static void init(IMessagesStore ms, ISessionsStore ss, MessagesPublisher p, ThreadPoolExecutorWrapper businessExecutor, Server server) {
|
||||
|
||||
@@ -20,10 +20,7 @@ import io.moquette.spi.impl.Qos1PublishHandler;
|
||||
import io.netty.buffer.ByteBuf;
|
||||
import cn.wildfirechat.common.ErrorCode;
|
||||
import io.netty.buffer.Unpooled;
|
||||
import win.liyufan.im.HttpUtils;
|
||||
import win.liyufan.im.IMTopic;
|
||||
import win.liyufan.im.MessageShardingUtil;
|
||||
import win.liyufan.im.Utility;
|
||||
import win.liyufan.im.*;
|
||||
|
||||
import java.util.HashSet;
|
||||
import java.util.Set;
|
||||
@@ -219,7 +216,7 @@ public class SendMessageHandler extends IMHandler<WFCMessage.Message> {
|
||||
if(StringUtil.isNullOrEmpty(content)) {
|
||||
saveAndPublish(fromUser, clientID, finalMsg, requestSourceType);
|
||||
} else {
|
||||
MessagePayload payload = new Gson().fromJson(content, MessagePayload.class);
|
||||
MessagePayload payload = GsonUtil.gson.fromJson(content, MessagePayload.class);
|
||||
if (payload != null && payload.getType() > 0) {
|
||||
WFCMessage.Message newMsg = finalMsg.toBuilder().setContent(payload.toProtoMessageContent()).build();
|
||||
saveAndPublish(fromUser, clientID, newMsg, requestSourceType);
|
||||
|
||||
@@ -1143,7 +1143,7 @@ public class MemoryMessagesStore implements IMessagesStore {
|
||||
event.type = type;
|
||||
m_Server.getCallbackScheduler().execute(() -> {
|
||||
try {
|
||||
HttpUtils.httpJsonPost(mGroupInfoUpdateCallback, new Gson().toJson(event), HttpUtils.HttpPostType.POST_TYPE_Grout_Event_Callback);
|
||||
HttpUtils.httpJsonPost(mGroupInfoUpdateCallback, GsonUtil.gson.toJson(event), HttpUtils.HttpPostType.POST_TYPE_Grout_Event_Callback);
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
Utility.printExecption(LOG, e, EVENT_CALLBACK_Exception);
|
||||
@@ -1162,7 +1162,7 @@ public class MemoryMessagesStore implements IMessagesStore {
|
||||
event.value = value;
|
||||
m_Server.getCallbackScheduler().execute(() -> {
|
||||
try {
|
||||
HttpUtils.httpJsonPost(mGroupMemberUpdateCallback, new Gson().toJson(event), HttpUtils.HttpPostType.POST_TYPE_Grout_Member_Event_Callback);
|
||||
HttpUtils.httpJsonPost(mGroupMemberUpdateCallback, GsonUtil.gson.toJson(event), HttpUtils.HttpPostType.POST_TYPE_Grout_Member_Event_Callback);
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
Utility.printExecption(LOG, e, EVENT_CALLBACK_Exception);
|
||||
@@ -1180,7 +1180,7 @@ public class MemoryMessagesStore implements IMessagesStore {
|
||||
event.value = value;
|
||||
m_Server.getCallbackScheduler().execute(() -> {
|
||||
try {
|
||||
HttpUtils.httpJsonPost(mRelationUpdateCallback, new Gson().toJson(event), HttpUtils.HttpPostType.POST_TYPE_User_Relation_Event_Callback);
|
||||
HttpUtils.httpJsonPost(mRelationUpdateCallback, GsonUtil.gson.toJson(event), HttpUtils.HttpPostType.POST_TYPE_User_Relation_Event_Callback);
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
Utility.printExecption(LOG, e, EVENT_CALLBACK_Exception);
|
||||
@@ -1193,7 +1193,7 @@ public class MemoryMessagesStore implements IMessagesStore {
|
||||
if (!StringUtil.isNullOrEmpty(mUserInfoUpdateCallback)) {
|
||||
m_Server.getCallbackScheduler().execute(() -> {
|
||||
try {
|
||||
HttpUtils.httpJsonPost(mUserInfoUpdateCallback, new Gson().toJson(InputOutputUserInfo.fromPbUser(user)), HttpUtils.HttpPostType.POST_TYPE_User_Info_Event_Callback);
|
||||
HttpUtils.httpJsonPost(mUserInfoUpdateCallback, GsonUtil.gson.toJson(InputOutputUserInfo.fromPbUser(user)), HttpUtils.HttpPostType.POST_TYPE_User_Info_Event_Callback);
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
Utility.printExecption(LOG, e, EVENT_CALLBACK_Exception);
|
||||
@@ -1210,7 +1210,7 @@ public class MemoryMessagesStore implements IMessagesStore {
|
||||
event.type = type;
|
||||
m_Server.getCallbackScheduler().execute(() -> {
|
||||
try {
|
||||
HttpUtils.httpJsonPost(mChannelInfoUpdateCallback, new Gson().toJson(event), HttpUtils.HttpPostType.POST_TYPE_Channel_Info_Event_Callback);
|
||||
HttpUtils.httpJsonPost(mChannelInfoUpdateCallback, GsonUtil.gson.toJson(event), HttpUtils.HttpPostType.POST_TYPE_Channel_Info_Event_Callback);
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
Utility.printExecption(LOG, e, EVENT_CALLBACK_Exception);
|
||||
@@ -1226,7 +1226,7 @@ public class MemoryMessagesStore implements IMessagesStore {
|
||||
event.type = type;
|
||||
m_Server.getCallbackScheduler().execute(() -> {
|
||||
try {
|
||||
HttpUtils.httpJsonPost(mChatroomInfoUpdateCallback, new Gson().toJson(event), HttpUtils.HttpPostType.POST_TYPE_Chatroom_Info_Event_Callback);
|
||||
HttpUtils.httpJsonPost(mChatroomInfoUpdateCallback, GsonUtil.gson.toJson(event), HttpUtils.HttpPostType.POST_TYPE_Chatroom_Info_Event_Callback);
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
Utility.printExecption(LOG, e, EVENT_CALLBACK_Exception);
|
||||
@@ -1244,7 +1244,7 @@ public class MemoryMessagesStore implements IMessagesStore {
|
||||
event.type = type;
|
||||
m_Server.getCallbackScheduler().execute(() -> {
|
||||
try {
|
||||
HttpUtils.httpJsonPost(mChatroomMemberUpdateCallback, new Gson().toJson(event), HttpUtils.HttpPostType.POST_TYPE_Chatroom_Member_Event_Callback);
|
||||
HttpUtils.httpJsonPost(mChatroomMemberUpdateCallback, GsonUtil.gson.toJson(event), HttpUtils.HttpPostType.POST_TYPE_Chatroom_Member_Event_Callback);
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
Utility.printExecption(LOG, e, EVENT_CALLBACK_Exception);
|
||||
@@ -3889,7 +3889,7 @@ public class MemoryMessagesStore implements IMessagesStore {
|
||||
Utility.printExecption(LOG, e);
|
||||
}
|
||||
} else if(modifyType == Modify_Channel_Menu) {
|
||||
OutputGetChannelInfo.OutputMenuList outputMenuButtons = new Gson().fromJson(value, OutputGetChannelInfo.OutputMenuList.class);
|
||||
OutputGetChannelInfo.OutputMenuList outputMenuButtons = GsonUtil.gson.fromJson(value, OutputGetChannelInfo.OutputMenuList.class);
|
||||
if (!outputMenuButtons.isEmpty()) {
|
||||
for (OutputGetChannelInfo.OutputMenu outputMenuButton : outputMenuButtons) {
|
||||
newInfoBuilder.addMenu(outputMenuButton.toPbInfo());
|
||||
|
||||
@@ -35,6 +35,7 @@ import io.moquette.spi.ISessionsStore;
|
||||
import io.netty.buffer.ByteBuf;
|
||||
import io.netty.buffer.Unpooled;
|
||||
import io.netty.handler.codec.mqtt.*;
|
||||
import win.liyufan.im.GsonUtil;
|
||||
import win.liyufan.im.HttpUtils;
|
||||
import win.liyufan.im.IMTopic;
|
||||
|
||||
@@ -188,7 +189,7 @@ public class MessagesPublisher {
|
||||
OutputClient finalOutputClient = outputClient;
|
||||
Server.getServer().getCallbackScheduler().execute(() -> {
|
||||
try {
|
||||
HttpUtils.httpJsonPost(robot.getCallback(), new Gson().toJson(OutputMessageData.fromProtoMessage(finalMsg, finalOutputClient), OutputMessageData.class), HttpUtils.HttpPostType.POST_TYPE_Robot_Message_Callback);
|
||||
HttpUtils.httpJsonPost(robot.getCallback(), GsonUtil.gson.toJson(OutputMessageData.fromProtoMessage(finalMsg, finalOutputClient), OutputMessageData.class), HttpUtils.HttpPostType.POST_TYPE_Robot_Message_Callback);
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
Utility.printExecption(LOG, e, EVENT_CALLBACK_Exception);
|
||||
@@ -616,7 +617,7 @@ public class MessagesPublisher {
|
||||
OutputClient finalOutputClient = outputClient;
|
||||
Server.getServer().getCallbackScheduler().execute(() -> {
|
||||
try {
|
||||
HttpUtils.httpJsonPost(channelInfo.getCallback() + "/message", new Gson().toJson(OutputMessageData.fromProtoMessage(message, finalOutputClient), OutputMessageData.class), HttpUtils.HttpPostType.POST_TYPE_Channel_Message_Callback);
|
||||
HttpUtils.httpJsonPost(channelInfo.getCallback() + "/message", GsonUtil.gson.toJson(OutputMessageData.fromProtoMessage(message, finalOutputClient), OutputMessageData.class), HttpUtils.HttpPostType.POST_TYPE_Channel_Message_Callback);
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
Utility.printExecption(LOG, e, EVENT_CALLBACK_Exception);
|
||||
@@ -669,7 +670,7 @@ public class MessagesPublisher {
|
||||
public void forwardMessage(final WFCMessage.Message message, String forwardUrl, OutputClient outputClient) {
|
||||
Server.getServer().getCallbackScheduler().execute(() -> {
|
||||
try {
|
||||
HttpUtils.httpJsonPost(forwardUrl, new Gson().toJson(OutputMessageData.fromProtoMessage(message, outputClient), OutputMessageData.class), HttpUtils.HttpPostType.POST_TYPE_Forward_Message_Callback);
|
||||
HttpUtils.httpJsonPost(forwardUrl, GsonUtil.gson.toJson(OutputMessageData.fromProtoMessage(message, outputClient), OutputMessageData.class), HttpUtils.HttpPostType.POST_TYPE_Forward_Message_Callback);
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
Utility.printExecption(LOG, e, EVENT_CALLBACK_Exception);
|
||||
@@ -679,7 +680,7 @@ public class MessagesPublisher {
|
||||
|
||||
public void forwardMessageWithCallback(final WFCMessage.Message message, String forwardUrl, HttpUtils.HttpCallback callback) {
|
||||
try {
|
||||
HttpUtils.httpJsonPost(forwardUrl, new Gson().toJson(OutputMessageData.fromProtoMessage(message), OutputMessageData.class), new HttpUtils.HttpCallback() {
|
||||
HttpUtils.httpJsonPost(forwardUrl, GsonUtil.gson.toJson(OutputMessageData.fromProtoMessage(message), OutputMessageData.class), new HttpUtils.HttpCallback() {
|
||||
@Override
|
||||
public void onSuccess(String content) {
|
||||
Server.getServer().getImBusinessScheduler().execute(()->{
|
||||
@@ -707,7 +708,7 @@ public class MessagesPublisher {
|
||||
|
||||
Server.getServer().getCallbackScheduler().execute(() -> {
|
||||
try {
|
||||
HttpUtils.httpJsonPost(channelInfo.getCallback() + "/subscribe", new Gson().toJson(new OutputNotifyChannelSubscribeStatus(user, channelInfo.getTargetId(), listen), OutputNotifyChannelSubscribeStatus.class), HttpUtils.HttpPostType.POST_TYPE_Channel_Subscriber_Event_Callback);
|
||||
HttpUtils.httpJsonPost(channelInfo.getCallback() + "/subscribe", GsonUtil.gson.toJson(new OutputNotifyChannelSubscribeStatus(user, channelInfo.getTargetId(), listen), OutputNotifyChannelSubscribeStatus.class), HttpUtils.HttpPostType.POST_TYPE_Channel_Subscriber_Event_Callback);
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
Utility.printExecption(LOG, e, EVENT_CALLBACK_Exception);
|
||||
|
||||
@@ -43,6 +43,7 @@ import io.netty.handler.codec.mqtt.*;
|
||||
import io.netty.handler.timeout.IdleStateHandler;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
import win.liyufan.im.GsonUtil;
|
||||
import win.liyufan.im.HttpUtils;
|
||||
import win.liyufan.im.IMTopic;
|
||||
import win.liyufan.im.Utility;
|
||||
@@ -264,7 +265,7 @@ public class ProtocolProcessor {
|
||||
if (!StringUtil.isNullOrEmpty(mUserOnlineStatusCallback)) {
|
||||
mServer.getCallbackScheduler().execute(() -> {
|
||||
try {
|
||||
HttpUtils.httpJsonPost(mUserOnlineStatusCallback, new Gson().toJson(new UserOnlineStatus(userId, clientId, platform, status, packageName)), HttpUtils.HttpPostType.POST_TYPE_User_Online_Event_Callback);
|
||||
HttpUtils.httpJsonPost(mUserOnlineStatusCallback, GsonUtil.gson.toJson(new UserOnlineStatus(userId, clientId, platform, status, packageName)), HttpUtils.HttpPostType.POST_TYPE_User_Online_Event_Callback);
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
Utility.printExecption(LOG, e, EVENT_CALLBACK_Exception);
|
||||
|
||||
@@ -57,6 +57,7 @@ import io.netty.handler.codec.mqtt.MqttFixedHeader;
|
||||
import io.netty.handler.codec.mqtt.MqttMessageType;
|
||||
import io.netty.handler.codec.mqtt.MqttPublishMessage;
|
||||
import cn.wildfirechat.common.ErrorCode;
|
||||
import win.liyufan.im.GsonUtil;
|
||||
import win.liyufan.im.IMTopic;
|
||||
import win.liyufan.im.RateLimiter;
|
||||
import win.liyufan.im.Utility;
|
||||
@@ -142,7 +143,7 @@ public class Qos1PublishHandler extends QosPublishHandler {
|
||||
out.addSession(userId, session.getClientID(), session.getPlatform(), status, session.getLastActiveTime());
|
||||
}
|
||||
|
||||
callback.onRouteHandled(new Gson().toJson(out).getBytes());
|
||||
callback.onRouteHandled(GsonUtil.gson.toJson(out).getBytes());
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
@@ -0,0 +1,8 @@
|
||||
package win.liyufan.im;
|
||||
|
||||
import com.google.gson.Gson;
|
||||
import com.google.gson.GsonBuilder;
|
||||
|
||||
public class GsonUtil {
|
||||
public static final Gson gson = new GsonBuilder().disableHtmlEscaping().create();
|
||||
}
|
||||
@@ -98,7 +98,7 @@ public class Utility {
|
||||
if(now - t >= SendExceptionDuration) {
|
||||
for (Map.Entry<String, IMExceptionEvent> entry : exceptionEventHashMap.entrySet()) {
|
||||
if(entry.getValue().count > 0) {
|
||||
String jsonStr = new Gson().toJson(entry.getValue());
|
||||
String jsonStr = GsonUtil.gson.toJson(entry.getValue());
|
||||
Server.getServer().getCallbackScheduler().execute(() -> HttpUtils.httpJsonPost(gMonitorEventAddress, jsonStr, HttpUtils.HttpPostType.POST_TYPE_Server_Exception_Callback));
|
||||
entry.getValue().count = 0;
|
||||
lastSendTime = now;
|
||||
@@ -111,7 +111,7 @@ public class Utility {
|
||||
event.msg = "监控心跳通知";
|
||||
event.call_stack = "别担心!这个是心跳消息,已经有24小时没有出现异常消息了!";
|
||||
event.count = IMExceptionEvent.EventType.HEART_BEAT;
|
||||
String jsonStr = new Gson().toJson(event);
|
||||
String jsonStr = GsonUtil.gson.toJson(event);
|
||||
Server.getServer().getCallbackScheduler().execute(() -> HttpUtils.httpJsonPost(gMonitorEventAddress, jsonStr, HttpUtils.HttpPostType.POST_TYPE_Server_Exception_Callback));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
package cn.wildfirechat.pojos;
|
||||
|
||||
import com.google.gson.Gson;
|
||||
import com.google.gson.GsonBuilder;
|
||||
|
||||
import java.nio.charset.StandardCharsets;
|
||||
import java.util.ArrayList;
|
||||
@@ -47,7 +48,7 @@ public class ArticleContent {
|
||||
MessagePayload payload = new MessagePayload();
|
||||
payload.setType(13);
|
||||
payload.setSearchableContent(top.title);
|
||||
payload.setBase64edData(Base64.getEncoder().encodeToString(new Gson().toJson(this).getBytes(StandardCharsets.UTF_8)));
|
||||
payload.setBase64edData(Base64.getEncoder().encodeToString(new GsonBuilder().disableHtmlEscaping().create().toJson(this).getBytes(StandardCharsets.UTF_8)));
|
||||
return payload;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -11,6 +11,7 @@ package cn.wildfirechat.pojos;
|
||||
import cn.wildfirechat.proto.ProtoConstants;
|
||||
import cn.wildfirechat.proto.WFCMessage;
|
||||
import com.google.gson.Gson;
|
||||
import com.google.gson.GsonBuilder;
|
||||
import com.google.protobuf.ByteString;
|
||||
|
||||
import java.util.List;
|
||||
@@ -89,7 +90,7 @@ public class GroupNotificationBinaryContent {
|
||||
}
|
||||
|
||||
public WFCMessage.MessageContent getGroupNotifyContent(int groupContentType) {
|
||||
return WFCMessage.MessageContent.newBuilder().setType(groupContentType).setData(ByteString.copyFromUtf8(new Gson().toJson(this))).build();
|
||||
return WFCMessage.MessageContent.newBuilder().setType(groupContentType).setData(ByteString.copyFromUtf8(new GsonBuilder().disableHtmlEscaping().create().toJson(this))).build();
|
||||
}
|
||||
|
||||
public WFCMessage.MessageContent getAddGroupNotifyContent() {
|
||||
|
||||
@@ -9,6 +9,7 @@ import cn.wildfirechat.sdk.model.IMResult;
|
||||
import cn.wildfirechat.sdk.utilities.AdminHttpUtils;
|
||||
import cn.wildfirechat.sdk.utilities.RobotHttpUtils;
|
||||
import com.google.gson.Gson;
|
||||
import com.google.gson.GsonBuilder;
|
||||
import io.netty.util.internal.StringUtil;
|
||||
|
||||
|
||||
@@ -1510,7 +1511,7 @@ public class Main {
|
||||
menu21.url = "http://www.sohu.com";
|
||||
menu2.subMenus.add(menu21);
|
||||
|
||||
String menuStr = new Gson().toJson(menus);
|
||||
String menuStr = new GsonBuilder().disableHtmlEscaping().create().toJson(menus);
|
||||
voidIMResult = channelServiceApi.modifyChannelInfo(ProtoConstants.ModifyChannelInfoType.Modify_Channel_Menu, menuStr);
|
||||
if (voidIMResult != null && voidIMResult.getErrorCode() == ErrorCode.ERROR_CODE_SUCCESS) {
|
||||
System.out.println("modify channel menu success");
|
||||
|
||||
@@ -2,6 +2,7 @@ package cn.wildfirechat.sdk.utilities;
|
||||
|
||||
import cn.wildfirechat.sdk.model.IMResult;
|
||||
import com.google.gson.Gson;
|
||||
import com.google.gson.GsonBuilder;
|
||||
import ikidou.reflect.TypeBuilder;
|
||||
import org.apache.commons.codec.digest.DigestUtils;
|
||||
import org.apache.http.HttpResponse;
|
||||
@@ -29,6 +30,7 @@ import java.util.concurrent.TimeUnit;
|
||||
|
||||
public class AdminHttpUtils extends JsonUtils {
|
||||
private static final Logger LOG = LoggerFactory.getLogger(AdminHttpUtils.class);
|
||||
public static final Gson gson = new GsonBuilder().disableHtmlEscaping().create();
|
||||
|
||||
private static String adminUrl;
|
||||
private static String adminSecret;
|
||||
@@ -124,7 +126,7 @@ public class AdminHttpUtils extends JsonUtils {
|
||||
|
||||
String jsonStr = "";
|
||||
if (object != null) {
|
||||
jsonStr = new Gson().toJson(object);
|
||||
jsonStr = gson.toJson(object);
|
||||
}
|
||||
LOG.info("http request content: {}", jsonStr);
|
||||
|
||||
|
||||
@@ -2,6 +2,7 @@ package cn.wildfirechat.sdk.utilities;
|
||||
|
||||
import cn.wildfirechat.sdk.model.IMResult;
|
||||
import com.google.gson.Gson;
|
||||
import com.google.gson.GsonBuilder;
|
||||
import ikidou.reflect.TypeBuilder;
|
||||
import org.apache.commons.codec.digest.DigestUtils;
|
||||
import org.apache.http.HttpResponse;
|
||||
@@ -26,6 +27,7 @@ import java.util.concurrent.TimeUnit;
|
||||
|
||||
public class ChannelHttpUtils extends JsonUtils {
|
||||
private static final Logger LOG = LoggerFactory.getLogger(ChannelHttpUtils.class);
|
||||
public static final Gson gson = new GsonBuilder().disableHtmlEscaping().create();
|
||||
|
||||
private String imurl;
|
||||
private String channelId;
|
||||
@@ -74,7 +76,7 @@ public class ChannelHttpUtils extends JsonUtils {
|
||||
|
||||
String jsonStr = "";
|
||||
if (object != null) {
|
||||
jsonStr = new Gson().toJson(object);
|
||||
jsonStr = gson.toJson(object);
|
||||
}
|
||||
LOG.info("http request content: {}", jsonStr);
|
||||
|
||||
|
||||
@@ -2,16 +2,17 @@ package cn.wildfirechat.sdk.utilities;
|
||||
|
||||
import cn.wildfirechat.sdk.model.IMResult;
|
||||
import com.google.gson.Gson;
|
||||
import com.google.gson.GsonBuilder;
|
||||
import ikidou.reflect.TypeBuilder;
|
||||
|
||||
public class JsonUtils {
|
||||
|
||||
public static final Gson gson = new GsonBuilder().disableHtmlEscaping().create();
|
||||
public static <T> IMResult<T> fromJsonObject(String content, Class<T> clazz) {
|
||||
TypeBuilder builder = TypeBuilder.newInstance(IMResult.class);
|
||||
if (!clazz.equals(Void.class)) {
|
||||
builder.addTypeParam(clazz);
|
||||
}
|
||||
return new Gson().fromJson(content, builder.build());
|
||||
return gson.fromJson(content, builder.build());
|
||||
}
|
||||
|
||||
public static boolean isNullOrEmpty(String str) {
|
||||
|
||||
@@ -2,6 +2,7 @@ package cn.wildfirechat.sdk.utilities;
|
||||
|
||||
import cn.wildfirechat.sdk.model.IMResult;
|
||||
import com.google.gson.Gson;
|
||||
import com.google.gson.GsonBuilder;
|
||||
import ikidou.reflect.TypeBuilder;
|
||||
import io.netty.util.internal.StringUtil;
|
||||
import org.apache.commons.codec.digest.DigestUtils;
|
||||
@@ -27,6 +28,7 @@ import java.util.concurrent.TimeUnit;
|
||||
|
||||
public class RobotHttpUtils extends JsonUtils {
|
||||
private static final Logger LOG = LoggerFactory.getLogger(RobotHttpUtils.class);
|
||||
public static final Gson gson = new GsonBuilder().disableHtmlEscaping().create();
|
||||
|
||||
private final String url;
|
||||
private final String robotId;
|
||||
@@ -75,7 +77,7 @@ public class RobotHttpUtils extends JsonUtils {
|
||||
|
||||
String jsonStr = null;
|
||||
if (object != null) {
|
||||
jsonStr = new Gson().toJson(object);
|
||||
jsonStr = gson.toJson(object);
|
||||
}
|
||||
LOG.info("http request content: {}", jsonStr);
|
||||
|
||||
|
||||
Reference in New Issue
Block a user