From b0fe3fd57fe1094b9a35982caae3632f47c87118 Mon Sep 17 00:00:00 2001 From: imhao183 Date: Mon, 24 May 2021 10:31:09 +0800 Subject: [PATCH] =?UTF-8?q?=E8=A7=A3=E5=86=B3=E7=9F=AD=E9=93=BE=E6=8E=A5?= =?UTF-8?q?=E5=93=8D=E5=BA=94=E9=94=99=E4=B9=B1=E9=97=AE=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../java/com/xiaoleilu/loServer/action/Action.java | 10 ++++------ .../xiaoleilu/loServer/action/CheckTokenAction.java | 2 +- .../loServer/action/DefaultIndexAction.java | 2 +- .../com/xiaoleilu/loServer/action/FileAction.java | 2 +- .../java/com/xiaoleilu/loServer/action/IMAction.java | 2 +- .../xiaoleilu/loServer/action/NotFoundAction.java | 2 +- .../com/xiaoleilu/loServer/action/RouteAction.java | 2 +- .../loServer/action/UnknownErrorAction.java | 2 +- .../xiaoleilu/loServer/action/UploadFileAction.java | 2 +- .../com/xiaoleilu/loServer/action/VersionAction.java | 2 +- .../action/admin/AddFriendRequestAction.java | 5 +++-- .../loServer/action/admin/AddGroupMemberAction.java | 7 ++++--- .../xiaoleilu/loServer/action/admin/AdminAction.java | 10 +++++----- .../loServer/action/admin/AliasGetAction.java | 4 ++-- .../loServer/action/admin/AliasPutAction.java | 4 ++-- .../loServer/action/admin/BlacklistAction.java | 7 ++++--- .../loServer/action/admin/BlacklistGetAction.java | 4 ++-- .../loServer/action/admin/BlockUserAction.java | 7 ++++--- .../action/admin/BroadcastMessageAction.java | 7 ++++--- .../loServer/action/admin/CheckUserOnlineAction.java | 5 +++-- .../loServer/action/admin/CreateChannelAction.java | 7 ++++--- .../loServer/action/admin/CreateChatroomAction.java | 6 +++--- .../loServer/action/admin/CreateGroupAction.java | 7 ++++--- .../loServer/action/admin/CreateRobotAction.java | 6 +++--- .../loServer/action/admin/CreateUserAction.java | 8 ++++---- .../loServer/action/admin/DestoryChatroomAction.java | 6 +++--- .../loServer/action/admin/DestroyUserAction.java | 7 ++++--- .../loServer/action/admin/DismissGroupAction.java | 7 ++++--- .../loServer/action/admin/FriendRelationAction.java | 7 ++++--- .../action/admin/FriendRelationGetAction.java | 4 ++-- .../loServer/action/admin/GetChatroomInfoAction.java | 6 +++--- .../action/admin/GetChatroomMembersAction.java | 6 +++--- .../loServer/action/admin/GetGroupInfoAction.java | 6 +++--- .../loServer/action/admin/GetGroupMembersAction.java | 6 +++--- .../loServer/action/admin/GetIMTokenAction.java | 5 +++-- .../action/admin/GetSystemSettingAction.java | 6 +++--- .../loServer/action/admin/GetUserAction.java | 6 +++--- .../action/admin/GetUserBlockListAction.java | 4 ++-- .../action/admin/GetUserBlockStatusAction.java | 6 +++--- .../loServer/action/admin/GetUserGroupsAction.java | 6 +++--- .../action/admin/KickoffGroupMemberAction.java | 7 ++++--- .../action/admin/KickoffUserClientAction.java | 4 ++-- .../loServer/action/admin/ModifyGroupInfoAction.java | 7 ++++--- .../action/admin/ModifyGroupMemberAliasAction.java | 7 ++++--- .../action/admin/MulticastMessageAction.java | 7 ++++--- .../action/admin/PutSystemSettingAction.java | 6 +++--- .../loServer/action/admin/QuitGroupMemberAction.java | 7 ++++--- .../loServer/action/admin/RecallMessageAction.java | 7 ++++--- .../action/admin/RecallMultiCastMessageAction.java | 7 ++++--- .../loServer/action/admin/RelationGetAction.java | 4 ++-- .../loServer/action/admin/SendMessageAction.java | 7 ++++--- .../action/admin/SensitiveWordAddAction.java | 4 ++-- .../action/admin/SensitiveWordDeleteAction.java | 4 ++-- .../action/admin/SensitiveWordQueryAction.java | 2 +- .../loServer/action/admin/SetGroupManagerAction.java | 7 ++++--- .../loServer/action/admin/TransferGroupAction.java | 7 ++++--- .../loServer/action/admin/UpdateUserAction.java | 6 +++--- .../loServer/action/channel/ChannelAction.java | 12 ++++++------ .../loServer/action/channel/GetChannelAction.java | 4 ++-- .../action/channel/GetChannelSubscribersAction.java | 4 ++-- .../loServer/action/channel/GetUserAction.java | 6 +++--- .../action/channel/ModifyChannelProfileAction.java | 10 +++++----- .../loServer/action/channel/SendMessageAction.java | 12 ++++++------ .../action/channel/SubscriberChannelAction.java | 11 ++++++----- .../loServer/action/robot/AddGroupMemberAction.java | 10 +++++----- .../loServer/action/robot/CreateGroupAction.java | 10 +++++----- .../loServer/action/robot/DeleteCallbackAction.java | 4 ++-- .../loServer/action/robot/DismissGroupAction.java | 10 +++++----- .../loServer/action/robot/GetCallbackAction.java | 4 ++-- .../loServer/action/robot/GetGroupInfoAction.java | 6 +++--- .../loServer/action/robot/GetGroupMembersAction.java | 6 +++--- .../loServer/action/robot/GetUserAction.java | 6 +++--- .../action/robot/KickoffGroupMemberAction.java | 10 +++++----- .../loServer/action/robot/ModifyGroupInfoAction.java | 10 +++++----- .../action/robot/ModifyGroupMemberAliasAction.java | 10 +++++----- .../loServer/action/robot/QuitGroupMemberAction.java | 10 +++++----- .../xiaoleilu/loServer/action/robot/RobotAction.java | 8 ++++---- .../loServer/action/robot/SendMessageAction.java | 10 +++++----- .../loServer/action/robot/SetCallbackAction.java | 6 +++--- .../loServer/action/robot/TransferGroupAction.java | 10 +++++----- .../loServer/action/robot/UpdateProfileAction.java | 4 ++-- .../xiaoleilu/loServer/handler/ActionHandler.java | 5 ++--- 82 files changed, 264 insertions(+), 244 deletions(-) diff --git a/broker/src/main/java/com/xiaoleilu/loServer/action/Action.java b/broker/src/main/java/com/xiaoleilu/loServer/action/Action.java index ee37e42ae..bb36da53f 100755 --- a/broker/src/main/java/com/xiaoleilu/loServer/action/Action.java +++ b/broker/src/main/java/com/xiaoleilu/loServer/action/Action.java @@ -38,8 +38,6 @@ abstract public class Action { public static ISessionsStore sessionsStore = null; public ChannelHandlerContext ctx; - public Response response; - protected class Result { Object data; ErrorCode errorCode; @@ -73,7 +71,7 @@ public ErrorCode preAction(Request request, Response response) { return ERROR_CODE_SUCCESS; } - public boolean doAction(Request request) { + public boolean doAction(Request request, Response response) { ErrorCode errorCode = preAction(request, response); boolean isSync = true; if (errorCode == ErrorCode.ERROR_CODE_SUCCESS) { @@ -89,7 +87,7 @@ public boolean doAction(Request request) { // throw e; // } // } else { - isSync = action(request); + isSync = action(request, response); // } } else { response.setStatus(HttpResponseStatus.OK); @@ -107,7 +105,7 @@ public boolean doAction(Request request) { public boolean isTransactionAction() { return false; } - abstract public boolean action(Request request); + abstract public boolean action(Request request, Response response); protected T getRequestBody(HttpRequest request, Class cls) { if (request instanceof FullHttpRequest) { @@ -121,7 +119,7 @@ protected T getRequestBody(HttpRequest request, Class cls) { return null; } - protected void setResponseContent(RestResult result) { + protected void setResponseContent(RestResult result, Response response) { response.setStatus(HttpResponseStatus.OK); response.setContent(new Gson().toJson(result)); } diff --git a/broker/src/main/java/com/xiaoleilu/loServer/action/CheckTokenAction.java b/broker/src/main/java/com/xiaoleilu/loServer/action/CheckTokenAction.java index 1da8d5d0a..837c34323 100755 --- a/broker/src/main/java/com/xiaoleilu/loServer/action/CheckTokenAction.java +++ b/broker/src/main/java/com/xiaoleilu/loServer/action/CheckTokenAction.java @@ -29,7 +29,7 @@ public class CheckTokenAction extends Action { private final RateLimiter mLimitCounter = new RateLimiter(10, 1); @Override - public boolean action(Request request) { + public boolean action(Request request, Response response) { if (request.getNettyRequest() instanceof FullHttpRequest) { response.setStatus(HttpResponseStatus.OK); String userId = request.getParam("userId"); diff --git a/broker/src/main/java/com/xiaoleilu/loServer/action/DefaultIndexAction.java b/broker/src/main/java/com/xiaoleilu/loServer/action/DefaultIndexAction.java index d1c7b6861..3ba2fbfc4 100755 --- a/broker/src/main/java/com/xiaoleilu/loServer/action/DefaultIndexAction.java +++ b/broker/src/main/java/com/xiaoleilu/loServer/action/DefaultIndexAction.java @@ -12,7 +12,7 @@ */ public class DefaultIndexAction extends Action{ @Override - public boolean action(Request request) { + public boolean action(Request request, Response response) { response.setContent("Welcome to LoServer."); return true; } diff --git a/broker/src/main/java/com/xiaoleilu/loServer/action/FileAction.java b/broker/src/main/java/com/xiaoleilu/loServer/action/FileAction.java index 0caa425e1..949400898 100755 --- a/broker/src/main/java/com/xiaoleilu/loServer/action/FileAction.java +++ b/broker/src/main/java/com/xiaoleilu/loServer/action/FileAction.java @@ -34,7 +34,7 @@ public class FileAction extends Action { private static final org.slf4j.Logger Logger = LoggerFactory.getLogger(FileAction.class); @Override - public boolean action(Request request) { + public boolean action(Request request, Response response) { response.setHeader("Access-Control-Allow-Origin", "*"); if (false == Request.METHOD_GET.equalsIgnoreCase(request.getMethod())) { response.sendError(HttpResponseStatus.METHOD_NOT_ALLOWED, "Please use GET method to request file!"); diff --git a/broker/src/main/java/com/xiaoleilu/loServer/action/IMAction.java b/broker/src/main/java/com/xiaoleilu/loServer/action/IMAction.java index cb20cee3f..67e70b42b 100755 --- a/broker/src/main/java/com/xiaoleilu/loServer/action/IMAction.java +++ b/broker/src/main/java/com/xiaoleilu/loServer/action/IMAction.java @@ -34,7 +34,7 @@ public class IMAction extends Action { @Override - public boolean action(Request request) { + public boolean action(Request request, Response response) { if (request.getNettyRequest() instanceof FullHttpRequest) { FullHttpRequest fullHttpRequest = (FullHttpRequest)request.getNettyRequest(); diff --git a/broker/src/main/java/com/xiaoleilu/loServer/action/NotFoundAction.java b/broker/src/main/java/com/xiaoleilu/loServer/action/NotFoundAction.java index 95d22345a..607facf96 100755 --- a/broker/src/main/java/com/xiaoleilu/loServer/action/NotFoundAction.java +++ b/broker/src/main/java/com/xiaoleilu/loServer/action/NotFoundAction.java @@ -27,7 +27,7 @@ public class NotFoundAction extends Action{ private final static String TEMPLATE_ERROR = "LoServer - Error report

HTTP Status {} - {}


{}


LoServer

"; @Override - public boolean action(Request request) { + public boolean action(Request request, Response response) { response.sendError(HttpResponseStatus.NOT_FOUND, "404 Not found!"); return true; } diff --git a/broker/src/main/java/com/xiaoleilu/loServer/action/RouteAction.java b/broker/src/main/java/com/xiaoleilu/loServer/action/RouteAction.java index 6c2f92937..d551be6f7 100755 --- a/broker/src/main/java/com/xiaoleilu/loServer/action/RouteAction.java +++ b/broker/src/main/java/com/xiaoleilu/loServer/action/RouteAction.java @@ -36,7 +36,7 @@ public class RouteAction extends Action { private static final Logger LOG = LoggerFactory.getLogger(RouteAction.class); @Override - public boolean action(Request request) { + public boolean action(Request request, Response response) { if (request.getNettyRequest() instanceof FullHttpRequest) { response.setContentType("application/octet-stream"); diff --git a/broker/src/main/java/com/xiaoleilu/loServer/action/UnknownErrorAction.java b/broker/src/main/java/com/xiaoleilu/loServer/action/UnknownErrorAction.java index 6e23c872d..d0eaf1093 100755 --- a/broker/src/main/java/com/xiaoleilu/loServer/action/UnknownErrorAction.java +++ b/broker/src/main/java/com/xiaoleilu/loServer/action/UnknownErrorAction.java @@ -27,7 +27,7 @@ public class UnknownErrorAction extends Action{ private final static String TEMPLATE_ERROR = "LoServer - Error report

HTTP Status {} - {}


{}


LoServer

"; @Override - public boolean action(Request request) { + public boolean action(Request request, Response response) { response.setStatus(HttpResponseStatus.INTERNAL_SERVER_ERROR); return true; } diff --git a/broker/src/main/java/com/xiaoleilu/loServer/action/UploadFileAction.java b/broker/src/main/java/com/xiaoleilu/loServer/action/UploadFileAction.java index 691a74404..9933d8918 100755 --- a/broker/src/main/java/com/xiaoleilu/loServer/action/UploadFileAction.java +++ b/broker/src/main/java/com/xiaoleilu/loServer/action/UploadFileAction.java @@ -73,7 +73,7 @@ public static int validateToken(String token) throws InvalidateTokenExecption { } @Override - public boolean action(Request r) { + public boolean action(Request r, Response response) { if (r.getNettyRequest() instanceof FullHttpRequest) { FullHttpRequest request = (FullHttpRequest) r.getNettyRequest(); diff --git a/broker/src/main/java/com/xiaoleilu/loServer/action/VersionAction.java b/broker/src/main/java/com/xiaoleilu/loServer/action/VersionAction.java index 840de0411..bce1a08c3 100755 --- a/broker/src/main/java/com/xiaoleilu/loServer/action/VersionAction.java +++ b/broker/src/main/java/com/xiaoleilu/loServer/action/VersionAction.java @@ -28,7 +28,7 @@ public class VersionAction extends Action { @Override - public boolean action(Request request) { + public boolean action(Request request, Response response) { if (request.getNettyRequest() instanceof FullHttpRequest) { response.setStatus(HttpResponseStatus.OK); diff --git a/broker/src/main/java/com/xiaoleilu/loServer/action/admin/AddFriendRequestAction.java b/broker/src/main/java/com/xiaoleilu/loServer/action/admin/AddFriendRequestAction.java index cf5cde491..34e953e9c 100755 --- a/broker/src/main/java/com/xiaoleilu/loServer/action/admin/AddFriendRequestAction.java +++ b/broker/src/main/java/com/xiaoleilu/loServer/action/admin/AddFriendRequestAction.java @@ -16,6 +16,7 @@ import com.xiaoleilu.loServer.annotation.HttpMethod; import com.xiaoleilu.loServer.annotation.Route; import com.xiaoleilu.loServer.handler.Request; +import com.xiaoleilu.loServer.handler.Response; import io.netty.buffer.ByteBuf; import io.netty.buffer.Unpooled; import io.netty.handler.codec.http.FullHttpRequest; @@ -31,7 +32,7 @@ public boolean isTransactionAction() { } @Override - public boolean action(Request request) { + public boolean action(Request request, Response response) { if (request.getNettyRequest() instanceof FullHttpRequest) { InputAddFriendRequest input = getRequestBody(request.getNettyRequest(), InputAddFriendRequest.class); @@ -41,7 +42,7 @@ public boolean action(Request request) { } WFCMessage.AddFriendRequest addFriendRequest = WFCMessage.AddFriendRequest.newBuilder().setReason(input.getReason()).setTargetUid(input.getFriendUid()).build(); - sendApiMessage(input.getUserId(), IMTopic.AddFriendRequestTopic, addFriendRequest.toByteArray(), result -> { + sendApiMessage(response, input.getUserId(), IMTopic.AddFriendRequestTopic, addFriendRequest.toByteArray(), result -> { ByteBuf byteBuf = Unpooled.buffer(); byteBuf.writeBytes(result); ErrorCode errorCode = ErrorCode.fromCode(byteBuf.readByte()); diff --git a/broker/src/main/java/com/xiaoleilu/loServer/action/admin/AddGroupMemberAction.java b/broker/src/main/java/com/xiaoleilu/loServer/action/admin/AddGroupMemberAction.java index c4116d38c..2e0a33e59 100755 --- a/broker/src/main/java/com/xiaoleilu/loServer/action/admin/AddGroupMemberAction.java +++ b/broker/src/main/java/com/xiaoleilu/loServer/action/admin/AddGroupMemberAction.java @@ -16,6 +16,7 @@ import com.xiaoleilu.loServer.annotation.Route; import com.xiaoleilu.loServer.handler.Request; import cn.wildfirechat.pojos.InputAddGroupMember; +import com.xiaoleilu.loServer.handler.Response; import io.netty.buffer.ByteBuf; import io.netty.buffer.Unpooled; import io.netty.handler.codec.http.FullHttpRequest; @@ -33,11 +34,11 @@ public boolean isTransactionAction() { } @Override - public boolean action(Request request) { + public boolean action(Request request, Response response) { if (request.getNettyRequest() instanceof FullHttpRequest) { InputAddGroupMember inputAddGroupMember = getRequestBody(request.getNettyRequest(), InputAddGroupMember.class); if (inputAddGroupMember.isValide()) { - sendApiMessage(inputAddGroupMember.getOperator(), IMTopic.AddGroupMemberTopic, inputAddGroupMember.toProtoGroupRequest().toByteArray(), result -> { + sendApiMessage(response, inputAddGroupMember.getOperator(), IMTopic.AddGroupMemberTopic, inputAddGroupMember.toProtoGroupRequest().toByteArray(), result -> { ByteBuf byteBuf = Unpooled.buffer(); byteBuf.writeBytes(result); ErrorCode errorCode = ErrorCode.fromCode(byteBuf.readByte()); @@ -45,7 +46,7 @@ public boolean action(Request request) { }); return false; } else { - setResponseContent(RestResult.resultOf(ErrorCode.INVALID_PARAMETER)); + setResponseContent(RestResult.resultOf(ErrorCode.INVALID_PARAMETER), response); } } return true; diff --git a/broker/src/main/java/com/xiaoleilu/loServer/action/admin/AdminAction.java b/broker/src/main/java/com/xiaoleilu/loServer/action/admin/AdminAction.java index a240c50d0..8be9f376d 100644 --- a/broker/src/main/java/com/xiaoleilu/loServer/action/admin/AdminAction.java +++ b/broker/src/main/java/com/xiaoleilu/loServer/action/admin/AdminAction.java @@ -92,15 +92,15 @@ protected void sendResponse(Response response, ErrorCode errorCode, Object data) response.setContent(new Gson().toJson(result)); response.send(); } - protected void sendApiMessage(String fromUser, String topic, byte[] message, ApiCallback callback) { - sendApiMessage(fromUser, null, topic, message, callback, false); + protected void sendApiMessage(Response response, String fromUser, String topic, byte[] message, ApiCallback callback) { + sendApiMessage(response, fromUser, null, topic, message, callback, false); } - protected void sendApiMessage(String fromUser, String topic, byte[] message, ApiCallback callback, boolean noAdmin) { - sendApiMessage(fromUser, null, topic, message, callback, noAdmin); + protected void sendApiMessage(Response response, String fromUser, String topic, byte[] message, ApiCallback callback, boolean noAdmin) { + sendApiMessage(response, fromUser, null, topic, message, callback, noAdmin); } - protected void sendApiMessage(String fromUser, String clientId, String topic, byte[] message, ApiCallback callback, boolean noAdmin) { + protected void sendApiMessage(Response response, String fromUser, String clientId, String topic, byte[] message, ApiCallback callback, boolean noAdmin) { ServerAPIHelper.sendRequest(fromUser, clientId, topic, message, new ServerAPIHelper.Callback() { @Override public void onSuccess(byte[] result) { diff --git a/broker/src/main/java/com/xiaoleilu/loServer/action/admin/AliasGetAction.java b/broker/src/main/java/com/xiaoleilu/loServer/action/admin/AliasGetAction.java index 5b2911d19..b5a50ad8d 100755 --- a/broker/src/main/java/com/xiaoleilu/loServer/action/admin/AliasGetAction.java +++ b/broker/src/main/java/com/xiaoleilu/loServer/action/admin/AliasGetAction.java @@ -37,7 +37,7 @@ public boolean isTransactionAction() { } @Override - public boolean action(Request request) { + public boolean action(Request request, Response response) { if (request.getNettyRequest() instanceof FullHttpRequest) { InputGetAlias input = getRequestBody(request.getNettyRequest(), InputGetAlias.class); List dataList = messagesStore.getFriendList(input.getOperator(), null, 0); @@ -51,7 +51,7 @@ public boolean action(Request request) { } } - setResponseContent(RestResult.ok(out)); + setResponseContent(RestResult.ok(out), response); } return true; } diff --git a/broker/src/main/java/com/xiaoleilu/loServer/action/admin/AliasPutAction.java b/broker/src/main/java/com/xiaoleilu/loServer/action/admin/AliasPutAction.java index eae113e3c..ba0781c50 100755 --- a/broker/src/main/java/com/xiaoleilu/loServer/action/admin/AliasPutAction.java +++ b/broker/src/main/java/com/xiaoleilu/loServer/action/admin/AliasPutAction.java @@ -36,11 +36,11 @@ public boolean isTransactionAction() { } @Override - public boolean action(Request request) { + public boolean action(Request request, Response response) { if (request.getNettyRequest() instanceof FullHttpRequest) { InputUpdateAlias input = getRequestBody(request.getNettyRequest(), InputUpdateAlias.class); ErrorCode errorCode = messagesStore.setFriendAliasRequest(input.getOperator(), input.getTargetId(), input.getAlias(), new long[1]); - setResponseContent(RestResult.resultOf(errorCode)); + setResponseContent(RestResult.resultOf(errorCode), response); } return true; } diff --git a/broker/src/main/java/com/xiaoleilu/loServer/action/admin/BlacklistAction.java b/broker/src/main/java/com/xiaoleilu/loServer/action/admin/BlacklistAction.java index a23ed8e78..7b8a5897f 100755 --- a/broker/src/main/java/com/xiaoleilu/loServer/action/admin/BlacklistAction.java +++ b/broker/src/main/java/com/xiaoleilu/loServer/action/admin/BlacklistAction.java @@ -17,6 +17,7 @@ import com.xiaoleilu.loServer.annotation.HttpMethod; import com.xiaoleilu.loServer.annotation.Route; import com.xiaoleilu.loServer.handler.Request; +import com.xiaoleilu.loServer.handler.Response; import io.netty.buffer.ByteBuf; import io.netty.buffer.Unpooled; import io.netty.handler.codec.http.FullHttpRequest; @@ -34,7 +35,7 @@ public boolean isTransactionAction() { } @Override - public boolean action(Request request) { + public boolean action(Request request, Response response) { if (request.getNettyRequest() instanceof FullHttpRequest) { InputBlacklistRequest inputData = getRequestBody(request.getNettyRequest(), InputBlacklistRequest.class); if (inputData != null @@ -42,7 +43,7 @@ public boolean action(Request request) { && !StringUtil.isNullOrEmpty(inputData.getTargetUid()) ) { WFCMessage.BlackUserRequest friendRequest = WFCMessage.BlackUserRequest.newBuilder().setUid(inputData.getTargetUid()).setStatus(inputData.getStatus()).build(); - sendApiMessage(inputData.getUserId(), IMTopic.BlackListUserTopic, friendRequest.toByteArray(), result -> { + sendApiMessage(response, inputData.getUserId(), IMTopic.BlackListUserTopic, friendRequest.toByteArray(), result -> { ByteBuf byteBuf = Unpooled.buffer(); byteBuf.writeBytes(result); ErrorCode errorCode = ErrorCode.fromCode(byteBuf.readByte()); @@ -50,7 +51,7 @@ public boolean action(Request request) { }); return false; } else { - setResponseContent(RestResult.resultOf(ErrorCode.INVALID_PARAMETER)); + setResponseContent(RestResult.resultOf(ErrorCode.INVALID_PARAMETER), response); } } diff --git a/broker/src/main/java/com/xiaoleilu/loServer/action/admin/BlacklistGetAction.java b/broker/src/main/java/com/xiaoleilu/loServer/action/admin/BlacklistGetAction.java index 679e7338b..8276eee78 100755 --- a/broker/src/main/java/com/xiaoleilu/loServer/action/admin/BlacklistGetAction.java +++ b/broker/src/main/java/com/xiaoleilu/loServer/action/admin/BlacklistGetAction.java @@ -35,7 +35,7 @@ public boolean isTransactionAction() { } @Override - public boolean action(Request request) { + public boolean action(Request request, Response response) { if (request.getNettyRequest() instanceof FullHttpRequest) { InputUserId inputGetFriendList = getRequestBody(request.getNettyRequest(), InputUserId.class); List dataList = messagesStore.getFriendList(inputGetFriendList.getUserId(), null, 0); @@ -45,7 +45,7 @@ public boolean action(Request request) { list.add(data.getFriendUid()); } } - setResponseContent(RestResult.ok(new OutputStringList(list))); + setResponseContent(RestResult.ok(new OutputStringList(list)), response); } return true; } diff --git a/broker/src/main/java/com/xiaoleilu/loServer/action/admin/BlockUserAction.java b/broker/src/main/java/com/xiaoleilu/loServer/action/admin/BlockUserAction.java index 13b2b6dd4..c8ff5ee0f 100755 --- a/broker/src/main/java/com/xiaoleilu/loServer/action/admin/BlockUserAction.java +++ b/broker/src/main/java/com/xiaoleilu/loServer/action/admin/BlockUserAction.java @@ -15,6 +15,7 @@ import com.xiaoleilu.loServer.annotation.Route; import com.xiaoleilu.loServer.handler.Request; import cn.wildfirechat.pojos.InputOutputUserBlockStatus; +import com.xiaoleilu.loServer.handler.Response; import io.moquette.persistence.ServerAPIHelper; import io.netty.handler.codec.http.FullHttpRequest; import io.netty.handler.codec.http.HttpResponseStatus; @@ -31,7 +32,7 @@ public boolean isTransactionAction() { } @Override - public boolean action(Request request) { + public boolean action(Request request, Response response) { if (request.getNettyRequest() instanceof FullHttpRequest) { InputOutputUserBlockStatus inputUserBlock = getRequestBody(request.getNettyRequest(), InputOutputUserBlockStatus.class); if (inputUserBlock != null @@ -44,12 +45,12 @@ public boolean action(Request request) { response.setContent(new Gson().toJson(result)); if (inputUserBlock.getStatus() == 2) { - sendApiMessage(null, ServerAPIHelper.KICKOFF_USER_REQUEST, inputUserBlock.getUserId().getBytes(), null); + sendApiMessage(response, null, ServerAPIHelper.KICKOFF_USER_REQUEST, inputUserBlock.getUserId().getBytes(), null); } sendResponse(response, ErrorCode.ERROR_CODE_SUCCESS, null); } else { - setResponseContent(RestResult.resultOf(ErrorCode.INVALID_PARAMETER)); + setResponseContent(RestResult.resultOf(ErrorCode.INVALID_PARAMETER), response); } } diff --git a/broker/src/main/java/com/xiaoleilu/loServer/action/admin/BroadcastMessageAction.java b/broker/src/main/java/com/xiaoleilu/loServer/action/admin/BroadcastMessageAction.java index e1ff6bc17..2c168024a 100755 --- a/broker/src/main/java/com/xiaoleilu/loServer/action/admin/BroadcastMessageAction.java +++ b/broker/src/main/java/com/xiaoleilu/loServer/action/admin/BroadcastMessageAction.java @@ -19,6 +19,7 @@ import com.xiaoleilu.loServer.annotation.HttpMethod; import com.xiaoleilu.loServer.annotation.Route; import com.xiaoleilu.loServer.handler.Request; +import com.xiaoleilu.loServer.handler.Response; import io.netty.buffer.ByteBuf; import io.netty.buffer.Unpooled; import io.netty.handler.codec.http.FullHttpRequest; @@ -35,11 +36,11 @@ public boolean isTransactionAction() { } @Override - public boolean action(Request request) { + public boolean action(Request request, Response response) { if (request.getNettyRequest() instanceof FullHttpRequest) { BroadMessageData sendMessageData = getRequestBody(request.getNettyRequest(), BroadMessageData.class); if (BroadMessageData.isValide(sendMessageData) && !StringUtil.isNullOrEmpty(sendMessageData.getSender())) { - sendApiMessage(sendMessageData.getSender(), IMTopic.BroadcastMessageTopic, sendMessageData.toProtoMessage().toByteArray(), result -> { + sendApiMessage(response, sendMessageData.getSender(), IMTopic.BroadcastMessageTopic, sendMessageData.toProtoMessage().toByteArray(), result -> { ByteBuf byteBuf = Unpooled.buffer(); byteBuf.writeBytes(result); ErrorCode errorCode = ErrorCode.fromCode(byteBuf.readByte()); @@ -53,7 +54,7 @@ public boolean action(Request request) { }); return false; } else { - setResponseContent(RestResult.resultOf(ErrorCode.INVALID_PARAMETER)); + setResponseContent(RestResult.resultOf(ErrorCode.INVALID_PARAMETER), response); } } return true; diff --git a/broker/src/main/java/com/xiaoleilu/loServer/action/admin/CheckUserOnlineAction.java b/broker/src/main/java/com/xiaoleilu/loServer/action/admin/CheckUserOnlineAction.java index 5b63a1954..da893ed23 100755 --- a/broker/src/main/java/com/xiaoleilu/loServer/action/admin/CheckUserOnlineAction.java +++ b/broker/src/main/java/com/xiaoleilu/loServer/action/admin/CheckUserOnlineAction.java @@ -15,6 +15,7 @@ import com.xiaoleilu.loServer.annotation.Route; import com.xiaoleilu.loServer.handler.Request; import cn.wildfirechat.pojos.InputGetUserInfo; +import com.xiaoleilu.loServer.handler.Response; import io.moquette.persistence.ServerAPIHelper; import io.netty.handler.codec.http.FullHttpRequest; import io.netty.util.internal.StringUtil; @@ -30,11 +31,11 @@ public boolean isTransactionAction() { } @Override - public boolean action(Request request) { + public boolean action(Request request, Response response) { if (request.getNettyRequest() instanceof FullHttpRequest) { InputGetUserInfo inputUserId = getRequestBody(request.getNettyRequest(), InputGetUserInfo.class); if (inputUserId == null || !StringUtil.isNullOrEmpty(inputUserId.getUserId())) { - sendApiMessage(inputUserId.getUserId(), ServerAPIHelper.CHECK_USER_ONLINE_REQUEST, inputUserId.getUserId().getBytes(), res -> { + sendApiMessage(response, inputUserId.getUserId(), ServerAPIHelper.CHECK_USER_ONLINE_REQUEST, inputUserId.getUserId().getBytes(), res -> { OutputCheckUserOnline out = new Gson().fromJson(new String(res), OutputCheckUserOnline.class); return new Result(ErrorCode.ERROR_CODE_SUCCESS, out); }); diff --git a/broker/src/main/java/com/xiaoleilu/loServer/action/admin/CreateChannelAction.java b/broker/src/main/java/com/xiaoleilu/loServer/action/admin/CreateChannelAction.java index 2d017a83b..a6c8cde9c 100755 --- a/broker/src/main/java/com/xiaoleilu/loServer/action/admin/CreateChannelAction.java +++ b/broker/src/main/java/com/xiaoleilu/loServer/action/admin/CreateChannelAction.java @@ -16,6 +16,7 @@ import com.xiaoleilu.loServer.annotation.HttpMethod; import com.xiaoleilu.loServer.annotation.Route; import com.xiaoleilu.loServer.handler.Request; +import com.xiaoleilu.loServer.handler.Response; import io.netty.buffer.ByteBuf; import io.netty.buffer.Unpooled; import io.netty.handler.codec.http.FullHttpRequest; @@ -33,7 +34,7 @@ public boolean isTransactionAction() { } @Override - public boolean action(Request request) { + public boolean action(Request request, Response response) { if (request.getNettyRequest() instanceof FullHttpRequest) { InputCreateChannel inputCreateChannel = getRequestBody(request.getNettyRequest(), InputCreateChannel.class); if (inputCreateChannel != null @@ -45,7 +46,7 @@ public boolean action(Request request) { inputCreateChannel.setTargetId(messagesStore.getShortUUID()); } - sendApiMessage(inputCreateChannel.getOwner(), IMTopic.CreateChannelTopic, inputCreateChannel.toProtoChannelInfo().toByteArray(), result -> { + sendApiMessage(response, inputCreateChannel.getOwner(), IMTopic.CreateChannelTopic, inputCreateChannel.toProtoChannelInfo().toByteArray(), result -> { ByteBuf byteBuf = Unpooled.buffer(); byteBuf.writeBytes(result); ErrorCode errorCode = ErrorCode.fromCode(byteBuf.readByte()); @@ -60,7 +61,7 @@ public boolean action(Request request) { }); return false; } else { - setResponseContent(RestResult.resultOf(ErrorCode.INVALID_PARAMETER)); + setResponseContent(RestResult.resultOf(ErrorCode.INVALID_PARAMETER), response); } } diff --git a/broker/src/main/java/com/xiaoleilu/loServer/action/admin/CreateChatroomAction.java b/broker/src/main/java/com/xiaoleilu/loServer/action/admin/CreateChatroomAction.java index bc88688aa..6e7fc0965 100755 --- a/broker/src/main/java/com/xiaoleilu/loServer/action/admin/CreateChatroomAction.java +++ b/broker/src/main/java/com/xiaoleilu/loServer/action/admin/CreateChatroomAction.java @@ -34,7 +34,7 @@ public boolean isTransactionAction() { } @Override - public boolean action(Request request) { + public boolean action(Request request, Response response) { if (request.getNettyRequest() instanceof FullHttpRequest) { FullHttpRequest fullHttpRequest = (FullHttpRequest)request.getNettyRequest(); byte[] bytes = Utils.readBytesAndRewind(fullHttpRequest.content()); @@ -54,9 +54,9 @@ public boolean action(Request request) { WFCMessage.ChatroomInfo info = inputCreateChatroom.toChatroomInfo(); messagesStore.createChatroom(inputCreateChatroom.getChatroomId(), info); - setResponseContent(RestResult.ok(new OutputCreateChatroom(inputCreateChatroom.getChatroomId()))); + setResponseContent(RestResult.ok(new OutputCreateChatroom(inputCreateChatroom.getChatroomId())), response); } else { - setResponseContent(RestResult.resultOf(ErrorCode.INVALID_PARAMETER)); + setResponseContent(RestResult.resultOf(ErrorCode.INVALID_PARAMETER), response); } } diff --git a/broker/src/main/java/com/xiaoleilu/loServer/action/admin/CreateGroupAction.java b/broker/src/main/java/com/xiaoleilu/loServer/action/admin/CreateGroupAction.java index 5de641b21..3158cdfea 100755 --- a/broker/src/main/java/com/xiaoleilu/loServer/action/admin/CreateGroupAction.java +++ b/broker/src/main/java/com/xiaoleilu/loServer/action/admin/CreateGroupAction.java @@ -17,6 +17,7 @@ import com.xiaoleilu.loServer.handler.Request; import cn.wildfirechat.pojos.InputCreateGroup; import cn.wildfirechat.pojos.OutputCreateGroupResult; +import com.xiaoleilu.loServer.handler.Response; import io.netty.buffer.ByteBuf; import io.netty.buffer.Unpooled; import io.netty.handler.codec.http.FullHttpRequest; @@ -34,11 +35,11 @@ public boolean isTransactionAction() { } @Override - public boolean action(Request request) { + public boolean action(Request request, Response response) { if (request.getNettyRequest() instanceof FullHttpRequest) { InputCreateGroup inputCreateGroup = getRequestBody(request.getNettyRequest(), InputCreateGroup.class); if (inputCreateGroup.isValide()) { - sendApiMessage(inputCreateGroup.getOperator(), IMTopic.CreateGroupTopic, inputCreateGroup.toProtoGroupRequest().toByteArray(), result -> { + sendApiMessage(response, inputCreateGroup.getOperator(), IMTopic.CreateGroupTopic, inputCreateGroup.toProtoGroupRequest().toByteArray(), result -> { ByteBuf byteBuf = Unpooled.buffer(); byteBuf.writeBytes(result); ErrorCode errorCode = ErrorCode.fromCode(byteBuf.readByte()); @@ -53,7 +54,7 @@ public boolean action(Request request) { }); return false; } else { - setResponseContent(RestResult.resultOf(ErrorCode.INVALID_PARAMETER)); + setResponseContent(RestResult.resultOf(ErrorCode.INVALID_PARAMETER), response); } } return true; diff --git a/broker/src/main/java/com/xiaoleilu/loServer/action/admin/CreateRobotAction.java b/broker/src/main/java/com/xiaoleilu/loServer/action/admin/CreateRobotAction.java index b8442b761..219dbcd02 100755 --- a/broker/src/main/java/com/xiaoleilu/loServer/action/admin/CreateRobotAction.java +++ b/broker/src/main/java/com/xiaoleilu/loServer/action/admin/CreateRobotAction.java @@ -39,7 +39,7 @@ public boolean isTransactionAction() { } @Override - public boolean action(Request request) { + public boolean action(Request request, Response response) { if (request.getNettyRequest() instanceof FullHttpRequest) { InputCreateRobot inputCreateRobot = getRequestBody(request.getNettyRequest(), InputCreateRobot.class); if (inputCreateRobot != null @@ -79,9 +79,9 @@ public boolean action(Request request) { inputCreateRobot.setSecret(UUIDGenerator.getUUID()); } messagesStore.addRobot(inputCreateRobot.toRobot()); - setResponseContent(RestResult.ok(new OutputCreateRobot(inputCreateRobot.getUserId(), inputCreateRobot.getSecret()))); + setResponseContent(RestResult.ok(new OutputCreateRobot(inputCreateRobot.getUserId(), inputCreateRobot.getSecret())), response); } else { - setResponseContent(RestResult.resultOf(ErrorCode.INVALID_PARAMETER)); + setResponseContent(RestResult.resultOf(ErrorCode.INVALID_PARAMETER), response); } } diff --git a/broker/src/main/java/com/xiaoleilu/loServer/action/admin/CreateUserAction.java b/broker/src/main/java/com/xiaoleilu/loServer/action/admin/CreateUserAction.java index 869b0551b..39b1b51ce 100755 --- a/broker/src/main/java/com/xiaoleilu/loServer/action/admin/CreateUserAction.java +++ b/broker/src/main/java/com/xiaoleilu/loServer/action/admin/CreateUserAction.java @@ -40,7 +40,7 @@ public boolean isTransactionAction() { } @Override - public boolean action(Request request) { + public boolean action(Request request, Response response) { if (request.getNettyRequest() instanceof FullHttpRequest) { InputOutputUserInfo inputCreateUser = getRequestBody(request.getNettyRequest(), InputOutputUserInfo.class); if (inputCreateUser != null @@ -89,13 +89,13 @@ public boolean action(Request request) { } catch (Exception e) { e.printStackTrace(); Utility.printExecption(LOG, e, IMExceptionEvent.EventType.ADMIN_API_Exception); - setResponseContent(RestResult.resultOf(ErrorCode.ERROR_CODE_SERVER_ERROR, e.getMessage())); + setResponseContent(RestResult.resultOf(ErrorCode.ERROR_CODE_SERVER_ERROR, e.getMessage()), response); return true; } - setResponseContent(RestResult.ok(new OutputCreateUser(inputCreateUser.getUserId(), inputCreateUser.getName()))); + setResponseContent(RestResult.ok(new OutputCreateUser(inputCreateUser.getUserId(), inputCreateUser.getName())), response); } else { - setResponseContent(RestResult.resultOf(ErrorCode.INVALID_PARAMETER)); + setResponseContent(RestResult.resultOf(ErrorCode.INVALID_PARAMETER), response); } } diff --git a/broker/src/main/java/com/xiaoleilu/loServer/action/admin/DestoryChatroomAction.java b/broker/src/main/java/com/xiaoleilu/loServer/action/admin/DestoryChatroomAction.java index 8c40c7bdb..bce700b5c 100755 --- a/broker/src/main/java/com/xiaoleilu/loServer/action/admin/DestoryChatroomAction.java +++ b/broker/src/main/java/com/xiaoleilu/loServer/action/admin/DestoryChatroomAction.java @@ -32,7 +32,7 @@ public boolean isTransactionAction() { } @Override - public boolean action(Request request) { + public boolean action(Request request, Response response) { if (request.getNettyRequest() instanceof FullHttpRequest) { FullHttpRequest fullHttpRequest = (FullHttpRequest)request.getNettyRequest(); byte[] bytes = Utils.readBytesAndRewind(fullHttpRequest.content()); @@ -42,9 +42,9 @@ public boolean action(Request request) { if (inputDestoryChatroom != null && !StringUtil.isNullOrEmpty(inputDestoryChatroom.getChatroomId())) { messagesStore.destoryChatroom(inputDestoryChatroom.getChatroomId()); - setResponseContent(RestResult.ok()); + setResponseContent(RestResult.ok(), response); } else { - setResponseContent(RestResult.resultOf(ErrorCode.INVALID_PARAMETER)); + setResponseContent(RestResult.resultOf(ErrorCode.INVALID_PARAMETER), response); } } diff --git a/broker/src/main/java/com/xiaoleilu/loServer/action/admin/DestroyUserAction.java b/broker/src/main/java/com/xiaoleilu/loServer/action/admin/DestroyUserAction.java index d473d8672..38709e391 100755 --- a/broker/src/main/java/com/xiaoleilu/loServer/action/admin/DestroyUserAction.java +++ b/broker/src/main/java/com/xiaoleilu/loServer/action/admin/DestroyUserAction.java @@ -17,6 +17,7 @@ import com.xiaoleilu.loServer.annotation.HttpMethod; import com.xiaoleilu.loServer.annotation.Route; import com.xiaoleilu.loServer.handler.Request; +import com.xiaoleilu.loServer.handler.Response; import io.netty.handler.codec.http.FullHttpRequest; import io.netty.handler.codec.http.HttpResponseStatus; import io.netty.util.internal.StringUtil; @@ -34,20 +35,20 @@ public boolean isTransactionAction() { } @Override - public boolean action(Request request) { + public boolean action(Request request, Response response) { if (request.getNettyRequest() instanceof FullHttpRequest) { InputDestroyUser inputDestroyUser = getRequestBody(request.getNettyRequest(), InputDestroyUser.class); if (inputDestroyUser != null && !StringUtil.isNullOrEmpty(inputDestroyUser.getUserId())) { WFCMessage.IDBuf idBuf = WFCMessage.IDBuf.newBuilder().setId(inputDestroyUser.getUserId()).build(); - sendApiMessage(inputDestroyUser.getUserId(), IMTopic.DestroyUserTopic, idBuf.toByteArray(), result -> { + sendApiMessage(response, inputDestroyUser.getUserId(), IMTopic.DestroyUserTopic, idBuf.toByteArray(), result -> { ErrorCode errorCode1 = ErrorCode.fromCode(result[0]); return new Result(errorCode1); }); return false; } else { - setResponseContent(RestResult.resultOf(ErrorCode.INVALID_PARAMETER)); + setResponseContent(RestResult.resultOf(ErrorCode.INVALID_PARAMETER), response); } } diff --git a/broker/src/main/java/com/xiaoleilu/loServer/action/admin/DismissGroupAction.java b/broker/src/main/java/com/xiaoleilu/loServer/action/admin/DismissGroupAction.java index c59b39fc8..7a0fadc73 100755 --- a/broker/src/main/java/com/xiaoleilu/loServer/action/admin/DismissGroupAction.java +++ b/broker/src/main/java/com/xiaoleilu/loServer/action/admin/DismissGroupAction.java @@ -16,6 +16,7 @@ import com.xiaoleilu.loServer.annotation.Route; import com.xiaoleilu.loServer.handler.Request; import cn.wildfirechat.pojos.InputDismissGroup; +import com.xiaoleilu.loServer.handler.Response; import io.netty.buffer.ByteBuf; import io.netty.buffer.Unpooled; import io.netty.handler.codec.http.FullHttpRequest; @@ -33,11 +34,11 @@ public boolean isTransactionAction() { } @Override - public boolean action(Request request) { + public boolean action(Request request, Response response) { if (request.getNettyRequest() instanceof FullHttpRequest) { InputDismissGroup inputDismissGroup = getRequestBody(request.getNettyRequest(), InputDismissGroup.class); if (inputDismissGroup.isValide()) { - sendApiMessage(inputDismissGroup.getOperator(), IMTopic.DismissGroupTopic, inputDismissGroup.toProtoGroupRequest().toByteArray(), result -> { + sendApiMessage(response, inputDismissGroup.getOperator(), IMTopic.DismissGroupTopic, inputDismissGroup.toProtoGroupRequest().toByteArray(), result -> { ByteBuf byteBuf = Unpooled.buffer(); byteBuf.writeBytes(result); ErrorCode errorCode = ErrorCode.fromCode(byteBuf.readByte()); @@ -45,7 +46,7 @@ public boolean action(Request request) { }); return false; } else { - setResponseContent(RestResult.resultOf(ErrorCode.INVALID_PARAMETER)); + setResponseContent(RestResult.resultOf(ErrorCode.INVALID_PARAMETER), response); } } return true; diff --git a/broker/src/main/java/com/xiaoleilu/loServer/action/admin/FriendRelationAction.java b/broker/src/main/java/com/xiaoleilu/loServer/action/admin/FriendRelationAction.java index 231398d49..0473ca2b7 100755 --- a/broker/src/main/java/com/xiaoleilu/loServer/action/admin/FriendRelationAction.java +++ b/broker/src/main/java/com/xiaoleilu/loServer/action/admin/FriendRelationAction.java @@ -16,6 +16,7 @@ import com.xiaoleilu.loServer.annotation.Route; import com.xiaoleilu.loServer.handler.Request; import cn.wildfirechat.pojos.InputUpdateFriendStatusRequest; +import com.xiaoleilu.loServer.handler.Response; import io.netty.buffer.ByteBuf; import io.netty.buffer.Unpooled; import io.netty.handler.codec.http.FullHttpRequest; @@ -34,7 +35,7 @@ public boolean isTransactionAction() { } @Override - public boolean action(Request request) { + public boolean action(Request request, Response response) { if (request.getNettyRequest() instanceof FullHttpRequest) { InputUpdateFriendStatusRequest friendAdd = getRequestBody(request.getNettyRequest(), InputUpdateFriendStatusRequest.class); if (friendAdd != null @@ -45,7 +46,7 @@ public boolean action(Request request) { if (!StringUtil.isNullOrEmpty(friendAdd.getExtra())) { friendRequestBuilder = friendRequestBuilder.setExtra(friendAdd.getExtra()); } - sendApiMessage(friendAdd.getUserId(), IMTopic.HandleFriendRequestTopic, friendRequestBuilder.build().toByteArray(), result -> { + sendApiMessage(response, friendAdd.getUserId(), IMTopic.HandleFriendRequestTopic, friendRequestBuilder.build().toByteArray(), result -> { ByteBuf byteBuf = Unpooled.buffer(); byteBuf.writeBytes(result); ErrorCode errorCode = ErrorCode.fromCode(byteBuf.readByte()); @@ -53,7 +54,7 @@ public boolean action(Request request) { }); return false; } else { - setResponseContent(RestResult.resultOf(ErrorCode.INVALID_PARAMETER)); + setResponseContent(RestResult.resultOf(ErrorCode.INVALID_PARAMETER), response); } } diff --git a/broker/src/main/java/com/xiaoleilu/loServer/action/admin/FriendRelationGetAction.java b/broker/src/main/java/com/xiaoleilu/loServer/action/admin/FriendRelationGetAction.java index 17ca505d0..da0150123 100755 --- a/broker/src/main/java/com/xiaoleilu/loServer/action/admin/FriendRelationGetAction.java +++ b/broker/src/main/java/com/xiaoleilu/loServer/action/admin/FriendRelationGetAction.java @@ -36,7 +36,7 @@ public boolean isTransactionAction() { } @Override - public boolean action(Request request) { + public boolean action(Request request, Response response) { if (request.getNettyRequest() instanceof FullHttpRequest) { InputUserId inputGetFriendList = getRequestBody(request.getNettyRequest(), InputUserId.class); List dataList = messagesStore.getFriendList(inputGetFriendList.getUserId(), null, 0); @@ -47,7 +47,7 @@ public boolean action(Request request) { list.add(data.getFriendUid()); } } - setResponseContent(RestResult.ok(new OutputStringList(list))); + setResponseContent(RestResult.ok(new OutputStringList(list)), response); } return true; } diff --git a/broker/src/main/java/com/xiaoleilu/loServer/action/admin/GetChatroomInfoAction.java b/broker/src/main/java/com/xiaoleilu/loServer/action/admin/GetChatroomInfoAction.java index c48e1b73d..80ba204db 100755 --- a/broker/src/main/java/com/xiaoleilu/loServer/action/admin/GetChatroomInfoAction.java +++ b/broker/src/main/java/com/xiaoleilu/loServer/action/admin/GetChatroomInfoAction.java @@ -32,7 +32,7 @@ public boolean isTransactionAction() { } @Override - public boolean action(Request request) { + public boolean action(Request request, Response response) { if (request.getNettyRequest() instanceof FullHttpRequest) { InputGetChatroomInfo getChatroomInfo = getRequestBody(request.getNettyRequest(), InputGetChatroomInfo.class); String chatroomid = getChatroomInfo.getChatroomId(); @@ -46,9 +46,9 @@ public boolean action(Request request) { } else { result = RestResult.resultOf(ErrorCode.ERROR_CODE_NOT_EXIST); } - setResponseContent(result); + setResponseContent(result, response); } else { - setResponseContent(RestResult.resultOf(ErrorCode.INVALID_PARAMETER)); + setResponseContent(RestResult.resultOf(ErrorCode.INVALID_PARAMETER), response); } } diff --git a/broker/src/main/java/com/xiaoleilu/loServer/action/admin/GetChatroomMembersAction.java b/broker/src/main/java/com/xiaoleilu/loServer/action/admin/GetChatroomMembersAction.java index ea5385b6d..3ac2de3ec 100755 --- a/broker/src/main/java/com/xiaoleilu/loServer/action/admin/GetChatroomMembersAction.java +++ b/broker/src/main/java/com/xiaoleilu/loServer/action/admin/GetChatroomMembersAction.java @@ -39,7 +39,7 @@ public boolean isTransactionAction() { } @Override - public boolean action(Request request) { + public boolean action(Request request, Response response) { if (request.getNettyRequest() instanceof FullHttpRequest) { InputGetChatroomInfo getChatroomInfo = getRequestBody(request.getNettyRequest(), InputGetChatroomInfo.class); String chatroomid = getChatroomInfo.getChatroomId(); @@ -58,9 +58,9 @@ public boolean action(Request request) { } else { result = RestResult.resultOf(ErrorCode.ERROR_CODE_NOT_EXIST); } - setResponseContent(result); + setResponseContent(result, response); } else { - setResponseContent(RestResult.resultOf(ErrorCode.INVALID_PARAMETER)); + setResponseContent(RestResult.resultOf(ErrorCode.INVALID_PARAMETER), response); } } diff --git a/broker/src/main/java/com/xiaoleilu/loServer/action/admin/GetGroupInfoAction.java b/broker/src/main/java/com/xiaoleilu/loServer/action/admin/GetGroupInfoAction.java index f833c20a5..e1282896a 100755 --- a/broker/src/main/java/com/xiaoleilu/loServer/action/admin/GetGroupInfoAction.java +++ b/broker/src/main/java/com/xiaoleilu/loServer/action/admin/GetGroupInfoAction.java @@ -35,7 +35,7 @@ public boolean isTransactionAction() { } @Override - public boolean action(Request request) { + public boolean action(Request request, Response response) { if (request.getNettyRequest() instanceof FullHttpRequest) { InputGetGroup inputGetGroup = getRequestBody(request.getNettyRequest(), InputGetGroup.class); if (inputGetGroup != null @@ -59,9 +59,9 @@ public boolean action(Request request) { pojoGroupInfo.setSearchable(groupInfo.getSearchable()); result = RestResult.ok(pojoGroupInfo); } - setResponseContent(result); + setResponseContent(result, response); } else { - setResponseContent(RestResult.resultOf(ErrorCode.INVALID_PARAMETER)); + setResponseContent(RestResult.resultOf(ErrorCode.INVALID_PARAMETER), response); } } diff --git a/broker/src/main/java/com/xiaoleilu/loServer/action/admin/GetGroupMembersAction.java b/broker/src/main/java/com/xiaoleilu/loServer/action/admin/GetGroupMembersAction.java index 438d053d0..e71c8ae5e 100755 --- a/broker/src/main/java/com/xiaoleilu/loServer/action/admin/GetGroupMembersAction.java +++ b/broker/src/main/java/com/xiaoleilu/loServer/action/admin/GetGroupMembersAction.java @@ -39,7 +39,7 @@ public boolean isTransactionAction() { } @Override - public boolean action(Request request) { + public boolean action(Request request, Response response) { if (request.getNettyRequest() instanceof FullHttpRequest) { InputGetGroup inputGetGroup = getRequestBody(request.getNettyRequest(), InputGetGroup.class); if (inputGetGroup != null @@ -68,9 +68,9 @@ public boolean action(Request request) { result = RestResult.ok(out); } - setResponseContent(result); + setResponseContent(result, response); } else { - setResponseContent(RestResult.resultOf(ErrorCode.INVALID_PARAMETER)); + setResponseContent(RestResult.resultOf(ErrorCode.INVALID_PARAMETER), response); } } diff --git a/broker/src/main/java/com/xiaoleilu/loServer/action/admin/GetIMTokenAction.java b/broker/src/main/java/com/xiaoleilu/loServer/action/admin/GetIMTokenAction.java index 8accc0390..ab791e353 100755 --- a/broker/src/main/java/com/xiaoleilu/loServer/action/admin/GetIMTokenAction.java +++ b/broker/src/main/java/com/xiaoleilu/loServer/action/admin/GetIMTokenAction.java @@ -15,6 +15,7 @@ import com.xiaoleilu.loServer.handler.Request; import cn.wildfirechat.pojos.InputGetToken; import cn.wildfirechat.pojos.OutputGetIMTokenData; +import com.xiaoleilu.loServer.handler.Response; import io.netty.handler.codec.http.FullHttpRequest; import cn.wildfirechat.common.ErrorCode; import win.liyufan.im.IMTopic; @@ -31,14 +32,14 @@ public boolean isTransactionAction() { } @Override - public boolean action(Request request) { + public boolean action(Request request, Response response) { if (request.getNettyRequest() instanceof FullHttpRequest) { InputGetToken input = getRequestBody(request.getNettyRequest(), InputGetToken.class); String userId = input.getUserId(); WFCMessage.GetTokenRequest getTokenRequest = WFCMessage.GetTokenRequest.newBuilder().setUserId(userId).setClientId(input.getClientId()).setPlatform(input.getPlatform() == null ? 0 : input.getPlatform()).build(); - sendApiMessage(userId, input.getClientId(), IMTopic.GetTokenTopic, getTokenRequest.toByteArray(), result -> { + sendApiMessage(response, userId, input.getClientId(), IMTopic.GetTokenTopic, getTokenRequest.toByteArray(), result -> { ErrorCode errorCode1 = ErrorCode.fromCode(result[0]); if (errorCode1 == ErrorCode.ERROR_CODE_SUCCESS) { //ba errorcode qudiao diff --git a/broker/src/main/java/com/xiaoleilu/loServer/action/admin/GetSystemSettingAction.java b/broker/src/main/java/com/xiaoleilu/loServer/action/admin/GetSystemSettingAction.java index b070ccd3b..36bc846a8 100755 --- a/broker/src/main/java/com/xiaoleilu/loServer/action/admin/GetSystemSettingAction.java +++ b/broker/src/main/java/com/xiaoleilu/loServer/action/admin/GetSystemSettingAction.java @@ -34,7 +34,7 @@ public boolean isTransactionAction() { } @Override - public boolean action(Request request) { + public boolean action(Request request, Response response) { if (request.getNettyRequest() instanceof FullHttpRequest) { SystemSettingPojo inputUserId = getRequestBody(request.getNettyRequest(), SystemSettingPojo.class); if (inputUserId != null) { @@ -47,9 +47,9 @@ public boolean action(Request request) { result = RestResult.ok(output); } - setResponseContent(result); + setResponseContent(result, response); } else { - setResponseContent(RestResult.resultOf(ErrorCode.INVALID_PARAMETER)); + setResponseContent(RestResult.resultOf(ErrorCode.INVALID_PARAMETER), response); } } diff --git a/broker/src/main/java/com/xiaoleilu/loServer/action/admin/GetUserAction.java b/broker/src/main/java/com/xiaoleilu/loServer/action/admin/GetUserAction.java index ff0af32e1..b5189df77 100755 --- a/broker/src/main/java/com/xiaoleilu/loServer/action/admin/GetUserAction.java +++ b/broker/src/main/java/com/xiaoleilu/loServer/action/admin/GetUserAction.java @@ -33,7 +33,7 @@ public boolean isTransactionAction() { } @Override - public boolean action(Request request) { + public boolean action(Request request, Response response) { if (request.getNettyRequest() instanceof FullHttpRequest) { InputGetUserInfo inputUserId = getRequestBody(request.getNettyRequest(), InputGetUserInfo.class); if (inputUserId != null @@ -55,9 +55,9 @@ public boolean action(Request request) { result = RestResult.ok(InputOutputUserInfo.fromPbUser(user)); } - setResponseContent(result); + setResponseContent(result, response); } else { - setResponseContent(RestResult.resultOf(ErrorCode.INVALID_PARAMETER)); + setResponseContent(RestResult.resultOf(ErrorCode.INVALID_PARAMETER), response); } } diff --git a/broker/src/main/java/com/xiaoleilu/loServer/action/admin/GetUserBlockListAction.java b/broker/src/main/java/com/xiaoleilu/loServer/action/admin/GetUserBlockListAction.java index 9e58284fa..150e7f32d 100755 --- a/broker/src/main/java/com/xiaoleilu/loServer/action/admin/GetUserBlockListAction.java +++ b/broker/src/main/java/com/xiaoleilu/loServer/action/admin/GetUserBlockListAction.java @@ -29,12 +29,12 @@ public boolean isTransactionAction() { } @Override - public boolean action(Request request) { + public boolean action(Request request, Response response) { if (request.getNettyRequest() instanceof FullHttpRequest) { OutputUserBlockStatusList list = new OutputUserBlockStatusList(); list.setStatusList(messagesStore.getUserStatusList()); RestResult result = RestResult.ok(list); - setResponseContent(result); + setResponseContent(result, response); } return true; } diff --git a/broker/src/main/java/com/xiaoleilu/loServer/action/admin/GetUserBlockStatusAction.java b/broker/src/main/java/com/xiaoleilu/loServer/action/admin/GetUserBlockStatusAction.java index 33471df9e..d3c4eb177 100755 --- a/broker/src/main/java/com/xiaoleilu/loServer/action/admin/GetUserBlockStatusAction.java +++ b/broker/src/main/java/com/xiaoleilu/loServer/action/admin/GetUserBlockStatusAction.java @@ -32,16 +32,16 @@ public boolean isTransactionAction() { } @Override - public boolean action(Request request) { + public boolean action(Request request, Response response) { if (request.getNettyRequest() instanceof FullHttpRequest) { InputGetUserInfo inputUserId = getRequestBody(request.getNettyRequest(), InputGetUserInfo.class); if (inputUserId != null && !StringUtil.isNullOrEmpty(inputUserId.getUserId())) { int status = messagesStore.getUserStatus(inputUserId.getUserId()); - setResponseContent(RestResult.ok(new OutputUserStatus(status))); + setResponseContent(RestResult.ok(new OutputUserStatus(status)), response); } else { - setResponseContent(RestResult.resultOf(ErrorCode.INVALID_PARAMETER)); + setResponseContent(RestResult.resultOf(ErrorCode.INVALID_PARAMETER), response); } } diff --git a/broker/src/main/java/com/xiaoleilu/loServer/action/admin/GetUserGroupsAction.java b/broker/src/main/java/com/xiaoleilu/loServer/action/admin/GetUserGroupsAction.java index 17852264e..a38731eb7 100755 --- a/broker/src/main/java/com/xiaoleilu/loServer/action/admin/GetUserGroupsAction.java +++ b/broker/src/main/java/com/xiaoleilu/loServer/action/admin/GetUserGroupsAction.java @@ -38,7 +38,7 @@ public boolean isTransactionAction() { } @Override - public boolean action(Request request) { + public boolean action(Request request, Response response) { if (request.getNettyRequest() instanceof FullHttpRequest) { InputUserId inputUserId = getRequestBody(request.getNettyRequest(), InputUserId.class); if (inputUserId != null @@ -48,9 +48,9 @@ public boolean action(Request request) { OutputGroupIds outputGroupIds = new OutputGroupIds(); outputGroupIds.setGroupIds(new ArrayList<>(groupIds)); RestResult result = RestResult.ok(outputGroupIds); - setResponseContent(result); + setResponseContent(result, response); } else { - setResponseContent(RestResult.resultOf(ErrorCode.INVALID_PARAMETER)); + setResponseContent(RestResult.resultOf(ErrorCode.INVALID_PARAMETER), response); } } diff --git a/broker/src/main/java/com/xiaoleilu/loServer/action/admin/KickoffGroupMemberAction.java b/broker/src/main/java/com/xiaoleilu/loServer/action/admin/KickoffGroupMemberAction.java index 472bc450b..dbc5f6fef 100755 --- a/broker/src/main/java/com/xiaoleilu/loServer/action/admin/KickoffGroupMemberAction.java +++ b/broker/src/main/java/com/xiaoleilu/loServer/action/admin/KickoffGroupMemberAction.java @@ -16,6 +16,7 @@ import com.xiaoleilu.loServer.annotation.Route; import com.xiaoleilu.loServer.handler.Request; import cn.wildfirechat.pojos.InputKickoffGroupMember; +import com.xiaoleilu.loServer.handler.Response; import io.netty.buffer.ByteBuf; import io.netty.buffer.Unpooled; import io.netty.handler.codec.http.FullHttpRequest; @@ -33,11 +34,11 @@ public boolean isTransactionAction() { } @Override - public boolean action(Request request) { + public boolean action(Request request, Response response) { if (request.getNettyRequest() instanceof FullHttpRequest) { InputKickoffGroupMember inputKickoffGroupMember = getRequestBody(request.getNettyRequest(), InputKickoffGroupMember.class); if (inputKickoffGroupMember.isValide()) { - sendApiMessage(inputKickoffGroupMember.getOperator(), IMTopic.KickoffGroupMemberTopic, inputKickoffGroupMember.toProtoGroupRequest().toByteArray(), result -> { + sendApiMessage(response, inputKickoffGroupMember.getOperator(), IMTopic.KickoffGroupMemberTopic, inputKickoffGroupMember.toProtoGroupRequest().toByteArray(), result -> { ByteBuf byteBuf = Unpooled.buffer(); byteBuf.writeBytes(result); ErrorCode errorCode = ErrorCode.fromCode(byteBuf.readByte()); @@ -45,7 +46,7 @@ public boolean action(Request request) { }); return false; } else { - setResponseContent(RestResult.resultOf(ErrorCode.INVALID_PARAMETER)); + setResponseContent(RestResult.resultOf(ErrorCode.INVALID_PARAMETER), response); } } return true; diff --git a/broker/src/main/java/com/xiaoleilu/loServer/action/admin/KickoffUserClientAction.java b/broker/src/main/java/com/xiaoleilu/loServer/action/admin/KickoffUserClientAction.java index 390af1e11..1473fa82e 100755 --- a/broker/src/main/java/com/xiaoleilu/loServer/action/admin/KickoffUserClientAction.java +++ b/broker/src/main/java/com/xiaoleilu/loServer/action/admin/KickoffUserClientAction.java @@ -31,14 +31,14 @@ public boolean isTransactionAction() { } @Override - public boolean action(Request request) { + public boolean action(Request request, Response response) { if (request.getNettyRequest() instanceof FullHttpRequest) { StringPairPojo pojo = getRequestBody(request.getNettyRequest(), StringPairPojo.class); if (pojo != null && !StringUtil.isNullOrEmpty(pojo.getFirst())) { sessionsStore.kickoffUserClient(pojo.getFirst(), pojo.getSecond()); sendResponse(response, ErrorCode.ERROR_CODE_SUCCESS, null); } else { - setResponseContent(RestResult.resultOf(ErrorCode.INVALID_PARAMETER)); + setResponseContent(RestResult.resultOf(ErrorCode.INVALID_PARAMETER), response); } } diff --git a/broker/src/main/java/com/xiaoleilu/loServer/action/admin/ModifyGroupInfoAction.java b/broker/src/main/java/com/xiaoleilu/loServer/action/admin/ModifyGroupInfoAction.java index 14d02443d..607ced23c 100755 --- a/broker/src/main/java/com/xiaoleilu/loServer/action/admin/ModifyGroupInfoAction.java +++ b/broker/src/main/java/com/xiaoleilu/loServer/action/admin/ModifyGroupInfoAction.java @@ -17,6 +17,7 @@ import com.xiaoleilu.loServer.annotation.HttpMethod; import com.xiaoleilu.loServer.annotation.Route; import com.xiaoleilu.loServer.handler.Request; +import com.xiaoleilu.loServer.handler.Response; import io.netty.buffer.ByteBuf; import io.netty.buffer.Unpooled; import io.netty.handler.codec.http.FullHttpRequest; @@ -33,11 +34,11 @@ public boolean isTransactionAction() { } @Override - public boolean action(Request request) { + public boolean action(Request request, Response response) { if (request.getNettyRequest() instanceof FullHttpRequest) { InputModifyGroupInfo inputAddGroupMember = getRequestBody(request.getNettyRequest(), InputModifyGroupInfo.class); if (inputAddGroupMember.isValide()) { - sendApiMessage(inputAddGroupMember.getOperator(), IMTopic.ModifyGroupInfoTopic, inputAddGroupMember.toProtoGroupRequest().toByteArray(), result -> { + sendApiMessage(response, inputAddGroupMember.getOperator(), IMTopic.ModifyGroupInfoTopic, inputAddGroupMember.toProtoGroupRequest().toByteArray(), result -> { ByteBuf byteBuf = Unpooled.buffer(); byteBuf.writeBytes(result); ErrorCode errorCode = ErrorCode.fromCode(byteBuf.readByte()); @@ -45,7 +46,7 @@ public boolean action(Request request) { }); return false; } else { - setResponseContent(RestResult.resultOf(ErrorCode.INVALID_PARAMETER)); + setResponseContent(RestResult.resultOf(ErrorCode.INVALID_PARAMETER), response); } } return true; diff --git a/broker/src/main/java/com/xiaoleilu/loServer/action/admin/ModifyGroupMemberAliasAction.java b/broker/src/main/java/com/xiaoleilu/loServer/action/admin/ModifyGroupMemberAliasAction.java index da45b32cd..ea4a65660 100755 --- a/broker/src/main/java/com/xiaoleilu/loServer/action/admin/ModifyGroupMemberAliasAction.java +++ b/broker/src/main/java/com/xiaoleilu/loServer/action/admin/ModifyGroupMemberAliasAction.java @@ -17,6 +17,7 @@ import com.xiaoleilu.loServer.annotation.HttpMethod; import com.xiaoleilu.loServer.annotation.Route; import com.xiaoleilu.loServer.handler.Request; +import com.xiaoleilu.loServer.handler.Response; import io.netty.buffer.ByteBuf; import io.netty.buffer.Unpooled; import io.netty.handler.codec.http.FullHttpRequest; @@ -33,11 +34,11 @@ public boolean isTransactionAction() { } @Override - public boolean action(Request request) { + public boolean action(Request request, Response response) { if (request.getNettyRequest() instanceof FullHttpRequest) { InputSetGroupMemberAlias inputSetGroupMemberAlias = getRequestBody(request.getNettyRequest(), InputSetGroupMemberAlias.class); if (inputSetGroupMemberAlias.isValide()) { - sendApiMessage(inputSetGroupMemberAlias.getOperator(), IMTopic.ModifyGroupMemberAliasTopic, inputSetGroupMemberAlias.toProtoGroupRequest().toByteArray(), result -> { + sendApiMessage(response, inputSetGroupMemberAlias.getOperator(), IMTopic.ModifyGroupMemberAliasTopic, inputSetGroupMemberAlias.toProtoGroupRequest().toByteArray(), result -> { ByteBuf byteBuf = Unpooled.buffer(); byteBuf.writeBytes(result); ErrorCode errorCode = ErrorCode.fromCode(byteBuf.readByte()); @@ -45,7 +46,7 @@ public boolean action(Request request) { }); return false; } else { - setResponseContent(RestResult.resultOf(ErrorCode.INVALID_PARAMETER)); + setResponseContent(RestResult.resultOf(ErrorCode.INVALID_PARAMETER), response); } } return true; diff --git a/broker/src/main/java/com/xiaoleilu/loServer/action/admin/MulticastMessageAction.java b/broker/src/main/java/com/xiaoleilu/loServer/action/admin/MulticastMessageAction.java index 15f1e31a3..6e6454cf1 100755 --- a/broker/src/main/java/com/xiaoleilu/loServer/action/admin/MulticastMessageAction.java +++ b/broker/src/main/java/com/xiaoleilu/loServer/action/admin/MulticastMessageAction.java @@ -18,6 +18,7 @@ import com.xiaoleilu.loServer.annotation.HttpMethod; import com.xiaoleilu.loServer.annotation.Route; import com.xiaoleilu.loServer.handler.Request; +import com.xiaoleilu.loServer.handler.Response; import io.netty.buffer.ByteBuf; import io.netty.buffer.Unpooled; import io.netty.handler.codec.http.FullHttpRequest; @@ -34,11 +35,11 @@ public boolean isTransactionAction() { } @Override - public boolean action(Request request) { + public boolean action(Request request, Response response) { if (request.getNettyRequest() instanceof FullHttpRequest) { MulticastMessageData sendMessageData = getRequestBody(request.getNettyRequest(), MulticastMessageData.class); if (MulticastMessageData.isValide(sendMessageData)) { - sendApiMessage(sendMessageData.getSender(), IMTopic.MultiCastMessageTopic, sendMessageData.toProtoMessage().toByteArray(), result -> { + sendApiMessage(response, sendMessageData.getSender(), IMTopic.MultiCastMessageTopic, sendMessageData.toProtoMessage().toByteArray(), result -> { ByteBuf byteBuf = Unpooled.buffer(); byteBuf.writeBytes(result); ErrorCode errorCode = ErrorCode.fromCode(byteBuf.readByte()); @@ -52,7 +53,7 @@ public boolean action(Request request) { }); return false; } else { - setResponseContent(RestResult.resultOf(ErrorCode.INVALID_PARAMETER)); + setResponseContent(RestResult.resultOf(ErrorCode.INVALID_PARAMETER), response); } } return true; diff --git a/broker/src/main/java/com/xiaoleilu/loServer/action/admin/PutSystemSettingAction.java b/broker/src/main/java/com/xiaoleilu/loServer/action/admin/PutSystemSettingAction.java index c5957bd44..b59b8d54f 100755 --- a/broker/src/main/java/com/xiaoleilu/loServer/action/admin/PutSystemSettingAction.java +++ b/broker/src/main/java/com/xiaoleilu/loServer/action/admin/PutSystemSettingAction.java @@ -34,7 +34,7 @@ public boolean isTransactionAction() { } @Override - public boolean action(Request request) { + public boolean action(Request request, Response response) { if (request.getNettyRequest() instanceof FullHttpRequest) { SystemSettingPojo inputUserId = getRequestBody(request.getNettyRequest(), SystemSettingPojo.class); if (inputUserId != null @@ -47,9 +47,9 @@ public boolean action(Request request) { } else { result = RestResult.ok(); } - setResponseContent(result); + setResponseContent(result, response); } else { - setResponseContent(RestResult.resultOf(ErrorCode.INVALID_PARAMETER)); + setResponseContent(RestResult.resultOf(ErrorCode.INVALID_PARAMETER), response); } } diff --git a/broker/src/main/java/com/xiaoleilu/loServer/action/admin/QuitGroupMemberAction.java b/broker/src/main/java/com/xiaoleilu/loServer/action/admin/QuitGroupMemberAction.java index 7e983aa92..97e381109 100755 --- a/broker/src/main/java/com/xiaoleilu/loServer/action/admin/QuitGroupMemberAction.java +++ b/broker/src/main/java/com/xiaoleilu/loServer/action/admin/QuitGroupMemberAction.java @@ -17,6 +17,7 @@ import com.xiaoleilu.loServer.annotation.HttpMethod; import com.xiaoleilu.loServer.annotation.Route; import com.xiaoleilu.loServer.handler.Request; +import com.xiaoleilu.loServer.handler.Response; import io.netty.buffer.ByteBuf; import io.netty.buffer.Unpooled; import io.netty.handler.codec.http.FullHttpRequest; @@ -33,11 +34,11 @@ public boolean isTransactionAction() { } @Override - public boolean action(Request request) { + public boolean action(Request request, Response response) { if (request.getNettyRequest() instanceof FullHttpRequest) { InputQuitGroup inputQuitGroup = getRequestBody(request.getNettyRequest(), InputQuitGroup.class); if (inputQuitGroup.isValide()) { - sendApiMessage(inputQuitGroup.getOperator(), IMTopic.QuitGroupTopic, inputQuitGroup.toProtoGroupRequest().toByteArray(), result -> { + sendApiMessage(response, inputQuitGroup.getOperator(), IMTopic.QuitGroupTopic, inputQuitGroup.toProtoGroupRequest().toByteArray(), result -> { ByteBuf byteBuf = Unpooled.buffer(); byteBuf.writeBytes(result); ErrorCode errorCode = ErrorCode.fromCode(byteBuf.readByte()); @@ -45,7 +46,7 @@ public boolean action(Request request) { }); return false; } else { - setResponseContent(RestResult.resultOf(ErrorCode.INVALID_PARAMETER)); + setResponseContent(RestResult.resultOf(ErrorCode.INVALID_PARAMETER), response); } } return true; diff --git a/broker/src/main/java/com/xiaoleilu/loServer/action/admin/RecallMessageAction.java b/broker/src/main/java/com/xiaoleilu/loServer/action/admin/RecallMessageAction.java index 71d418bdd..5ae2c4578 100755 --- a/broker/src/main/java/com/xiaoleilu/loServer/action/admin/RecallMessageAction.java +++ b/broker/src/main/java/com/xiaoleilu/loServer/action/admin/RecallMessageAction.java @@ -16,6 +16,7 @@ import com.xiaoleilu.loServer.annotation.Route; import com.xiaoleilu.loServer.handler.Request; import cn.wildfirechat.pojos.RecallMessageData; +import com.xiaoleilu.loServer.handler.Response; import io.netty.buffer.ByteBuf; import io.netty.buffer.Unpooled; import io.netty.handler.codec.http.FullHttpRequest; @@ -34,13 +35,13 @@ public boolean isTransactionAction() { } @Override - public boolean action(Request request) { + public boolean action(Request request, Response response) { if (request.getNettyRequest() instanceof FullHttpRequest) { RecallMessageData recallMessageData = getRequestBody(request.getNettyRequest(), RecallMessageData.class); if (recallMessageData != null && !StringUtil.isNullOrEmpty(recallMessageData.getOperator())) { WFCMessage.INT64Buf idBuf = WFCMessage.INT64Buf.newBuilder().setId(recallMessageData.getMessageUid()).build(); - sendApiMessage(recallMessageData.getOperator(), IMTopic.RecallMessageTopic, idBuf.toByteArray(), result -> { + sendApiMessage(response, recallMessageData.getOperator(), IMTopic.RecallMessageTopic, idBuf.toByteArray(), result -> { ByteBuf byteBuf = Unpooled.buffer(); byteBuf.writeBytes(result); ErrorCode errorCode = ErrorCode.fromCode(byteBuf.readByte()); @@ -48,7 +49,7 @@ public boolean action(Request request) { }); return false; } else { - setResponseContent(RestResult.resultOf(ErrorCode.INVALID_PARAMETER)); + setResponseContent(RestResult.resultOf(ErrorCode.INVALID_PARAMETER), response); } } return true; diff --git a/broker/src/main/java/com/xiaoleilu/loServer/action/admin/RecallMultiCastMessageAction.java b/broker/src/main/java/com/xiaoleilu/loServer/action/admin/RecallMultiCastMessageAction.java index 9ab7cbd23..6de535e66 100755 --- a/broker/src/main/java/com/xiaoleilu/loServer/action/admin/RecallMultiCastMessageAction.java +++ b/broker/src/main/java/com/xiaoleilu/loServer/action/admin/RecallMultiCastMessageAction.java @@ -17,6 +17,7 @@ import com.xiaoleilu.loServer.annotation.HttpMethod; import com.xiaoleilu.loServer.annotation.Route; import com.xiaoleilu.loServer.handler.Request; +import com.xiaoleilu.loServer.handler.Response; import io.netty.buffer.ByteBuf; import io.netty.buffer.Unpooled; import io.netty.handler.codec.http.FullHttpRequest; @@ -34,13 +35,13 @@ public boolean isTransactionAction() { } @Override - public boolean action(Request request) { + public boolean action(Request request, Response response) { if (request.getNettyRequest() instanceof FullHttpRequest) { RecallMultiCastMessageData recallMessageData = getRequestBody(request.getNettyRequest(), RecallMultiCastMessageData.class); if (recallMessageData != null && !StringUtil.isNullOrEmpty(recallMessageData.operator)) { WFCMessage.RecallMultiCastMessageRequest recallRequest = WFCMessage.RecallMultiCastMessageRequest.newBuilder().setMessageId(recallMessageData.messageUid).addAllReceiver(recallMessageData.receivers).build(); - sendApiMessage(recallMessageData.operator, IMTopic.RecallMultiCastMessageTopic, recallRequest.toByteArray(), result -> { + sendApiMessage(response, recallMessageData.operator, IMTopic.RecallMultiCastMessageTopic, recallRequest.toByteArray(), result -> { ByteBuf byteBuf = Unpooled.buffer(); byteBuf.writeBytes(result); ErrorCode errorCode = ErrorCode.fromCode(byteBuf.readByte()); @@ -48,7 +49,7 @@ public boolean action(Request request) { }); return false; } else { - setResponseContent(RestResult.resultOf(ErrorCode.INVALID_PARAMETER)); + setResponseContent(RestResult.resultOf(ErrorCode.INVALID_PARAMETER), response); } } return true; diff --git a/broker/src/main/java/com/xiaoleilu/loServer/action/admin/RelationGetAction.java b/broker/src/main/java/com/xiaoleilu/loServer/action/admin/RelationGetAction.java index dbcaf81e2..99c6509b2 100755 --- a/broker/src/main/java/com/xiaoleilu/loServer/action/admin/RelationGetAction.java +++ b/broker/src/main/java/com/xiaoleilu/loServer/action/admin/RelationGetAction.java @@ -37,7 +37,7 @@ public boolean isTransactionAction() { } @Override - public boolean action(Request request) { + public boolean action(Request request, Response response) { if (request.getNettyRequest() instanceof FullHttpRequest) { StringPairPojo input = getRequestBody(request.getNettyRequest(), StringPairPojo.class); FriendData data = messagesStore.getFriendData(input.getFirst(), input.getSecond()); @@ -51,7 +51,7 @@ public boolean action(Request request) { out.alias = data.getAlias(); out.extra = data.getExtra(); } - setResponseContent(RestResult.ok(out)); + setResponseContent(RestResult.ok(out), response); } return true; } diff --git a/broker/src/main/java/com/xiaoleilu/loServer/action/admin/SendMessageAction.java b/broker/src/main/java/com/xiaoleilu/loServer/action/admin/SendMessageAction.java index ce014271c..0cdef11d3 100755 --- a/broker/src/main/java/com/xiaoleilu/loServer/action/admin/SendMessageAction.java +++ b/broker/src/main/java/com/xiaoleilu/loServer/action/admin/SendMessageAction.java @@ -18,6 +18,7 @@ import com.xiaoleilu.loServer.handler.Request; import cn.wildfirechat.pojos.SendMessageData; import cn.wildfirechat.pojos.SendMessageResult; +import com.xiaoleilu.loServer.handler.Response; import io.netty.buffer.ByteBuf; import io.netty.buffer.Unpooled; import io.netty.handler.codec.http.FullHttpRequest; @@ -35,11 +36,11 @@ public boolean isTransactionAction() { } @Override - public boolean action(Request request) { + public boolean action(Request request, Response response) { if (request.getNettyRequest() instanceof FullHttpRequest) { SendMessageData sendMessageData = getRequestBody(request.getNettyRequest(), SendMessageData.class); if (SendMessageData.isValide(sendMessageData) && !StringUtil.isNullOrEmpty(sendMessageData.getSender())) { - sendApiMessage(sendMessageData.getSender(), IMTopic.SendMessageTopic, sendMessageData.toProtoMessage().toByteArray(), result -> { + sendApiMessage(response, sendMessageData.getSender(), IMTopic.SendMessageTopic, sendMessageData.toProtoMessage().toByteArray(), result -> { ByteBuf byteBuf = Unpooled.buffer(); byteBuf.writeBytes(result); ErrorCode errorCode = ErrorCode.fromCode(byteBuf.readByte()); @@ -53,7 +54,7 @@ public boolean action(Request request) { }); return false; } else { - setResponseContent(RestResult.resultOf(ErrorCode.INVALID_PARAMETER)); + setResponseContent(RestResult.resultOf(ErrorCode.INVALID_PARAMETER), response); } } return true; diff --git a/broker/src/main/java/com/xiaoleilu/loServer/action/admin/SensitiveWordAddAction.java b/broker/src/main/java/com/xiaoleilu/loServer/action/admin/SensitiveWordAddAction.java index e95a830b6..9d701e426 100755 --- a/broker/src/main/java/com/xiaoleilu/loServer/action/admin/SensitiveWordAddAction.java +++ b/broker/src/main/java/com/xiaoleilu/loServer/action/admin/SensitiveWordAddAction.java @@ -30,7 +30,7 @@ public boolean isTransactionAction() { } @Override - public boolean action(Request request) { + public boolean action(Request request, Response response) { if (request.getNettyRequest() instanceof FullHttpRequest) { InputOutputSensitiveWords input = getRequestBody(request.getNettyRequest(), InputOutputSensitiveWords.class); if (input != null && input.getWords() != null && !input.getWords().isEmpty()) { @@ -38,7 +38,7 @@ public boolean action(Request request) { response.setStatus(HttpResponseStatus.OK); sendResponse(response, errorCode, null); } else { - setResponseContent(RestResult.resultOf(ErrorCode.INVALID_PARAMETER)); + setResponseContent(RestResult.resultOf(ErrorCode.INVALID_PARAMETER), response); } } diff --git a/broker/src/main/java/com/xiaoleilu/loServer/action/admin/SensitiveWordDeleteAction.java b/broker/src/main/java/com/xiaoleilu/loServer/action/admin/SensitiveWordDeleteAction.java index 00a8f46e4..6259f6471 100755 --- a/broker/src/main/java/com/xiaoleilu/loServer/action/admin/SensitiveWordDeleteAction.java +++ b/broker/src/main/java/com/xiaoleilu/loServer/action/admin/SensitiveWordDeleteAction.java @@ -30,7 +30,7 @@ public boolean isTransactionAction() { } @Override - public boolean action(Request request) { + public boolean action(Request request, Response response) { if (request.getNettyRequest() instanceof FullHttpRequest) { InputOutputSensitiveWords input = getRequestBody(request.getNettyRequest(), InputOutputSensitiveWords.class); if (input != null && input.getWords() != null && !input.getWords().isEmpty()) { @@ -39,7 +39,7 @@ public boolean action(Request request) { sendResponse(response, errorCode, null); } else { - setResponseContent(RestResult.resultOf(ErrorCode.INVALID_PARAMETER)); + setResponseContent(RestResult.resultOf(ErrorCode.INVALID_PARAMETER), response); } } diff --git a/broker/src/main/java/com/xiaoleilu/loServer/action/admin/SensitiveWordQueryAction.java b/broker/src/main/java/com/xiaoleilu/loServer/action/admin/SensitiveWordQueryAction.java index ed090d94b..5416a9793 100755 --- a/broker/src/main/java/com/xiaoleilu/loServer/action/admin/SensitiveWordQueryAction.java +++ b/broker/src/main/java/com/xiaoleilu/loServer/action/admin/SensitiveWordQueryAction.java @@ -29,7 +29,7 @@ public boolean isTransactionAction() { } @Override - public boolean action(Request request) { + public boolean action(Request request, Response response) { if (request.getNettyRequest() instanceof FullHttpRequest) { List words = messagesStore.getAllSensitiveWords(); InputOutputSensitiveWords out = new InputOutputSensitiveWords(); diff --git a/broker/src/main/java/com/xiaoleilu/loServer/action/admin/SetGroupManagerAction.java b/broker/src/main/java/com/xiaoleilu/loServer/action/admin/SetGroupManagerAction.java index 7c40211bb..448d91355 100755 --- a/broker/src/main/java/com/xiaoleilu/loServer/action/admin/SetGroupManagerAction.java +++ b/broker/src/main/java/com/xiaoleilu/loServer/action/admin/SetGroupManagerAction.java @@ -17,6 +17,7 @@ import com.xiaoleilu.loServer.annotation.HttpMethod; import com.xiaoleilu.loServer.annotation.Route; import com.xiaoleilu.loServer.handler.Request; +import com.xiaoleilu.loServer.handler.Response; import io.netty.buffer.ByteBuf; import io.netty.buffer.Unpooled; import io.netty.handler.codec.http.FullHttpRequest; @@ -33,11 +34,11 @@ public boolean isTransactionAction() { } @Override - public boolean action(Request request) { + public boolean action(Request request, Response response) { if (request.getNettyRequest() instanceof FullHttpRequest) { InputSetGroupManager inputAddGroupMember = getRequestBody(request.getNettyRequest(), InputSetGroupManager.class); if (inputAddGroupMember.isValide()) { - sendApiMessage(inputAddGroupMember.getOperator(), IMTopic.SetGroupManagerTopic, inputAddGroupMember.toProtoGroupRequest().toByteArray(), result -> { + sendApiMessage(response, inputAddGroupMember.getOperator(), IMTopic.SetGroupManagerTopic, inputAddGroupMember.toProtoGroupRequest().toByteArray(), result -> { ByteBuf byteBuf = Unpooled.buffer(); byteBuf.writeBytes(result); ErrorCode errorCode = ErrorCode.fromCode(byteBuf.readByte()); @@ -45,7 +46,7 @@ public boolean action(Request request) { }); return false; } else { - setResponseContent(RestResult.resultOf(ErrorCode.INVALID_PARAMETER)); + setResponseContent(RestResult.resultOf(ErrorCode.INVALID_PARAMETER), response); } } return true; diff --git a/broker/src/main/java/com/xiaoleilu/loServer/action/admin/TransferGroupAction.java b/broker/src/main/java/com/xiaoleilu/loServer/action/admin/TransferGroupAction.java index 2de278151..ebd5eccfd 100755 --- a/broker/src/main/java/com/xiaoleilu/loServer/action/admin/TransferGroupAction.java +++ b/broker/src/main/java/com/xiaoleilu/loServer/action/admin/TransferGroupAction.java @@ -16,6 +16,7 @@ import com.xiaoleilu.loServer.annotation.Route; import com.xiaoleilu.loServer.handler.Request; import cn.wildfirechat.pojos.InputTransferGroup; +import com.xiaoleilu.loServer.handler.Response; import io.netty.buffer.ByteBuf; import io.netty.buffer.Unpooled; import io.netty.handler.codec.http.FullHttpRequest; @@ -33,11 +34,11 @@ public boolean isTransactionAction() { } @Override - public boolean action(Request request) { + public boolean action(Request request, Response response) { if (request.getNettyRequest() instanceof FullHttpRequest) { InputTransferGroup inputDismissGroup = getRequestBody(request.getNettyRequest(), InputTransferGroup.class); if (inputDismissGroup.isValide()) { - sendApiMessage(inputDismissGroup.getOperator(), IMTopic.TransferGroupTopic, inputDismissGroup.toProtoGroupRequest().toByteArray(), result -> { + sendApiMessage(response, inputDismissGroup.getOperator(), IMTopic.TransferGroupTopic, inputDismissGroup.toProtoGroupRequest().toByteArray(), result -> { ByteBuf byteBuf = Unpooled.buffer(); byteBuf.writeBytes(result); ErrorCode errorCode = ErrorCode.fromCode(byteBuf.readByte()); @@ -45,7 +46,7 @@ public boolean action(Request request) { }); return false; } else { - setResponseContent(RestResult.resultOf(ErrorCode.INVALID_PARAMETER)); + setResponseContent(RestResult.resultOf(ErrorCode.INVALID_PARAMETER), response); } } return true; diff --git a/broker/src/main/java/com/xiaoleilu/loServer/action/admin/UpdateUserAction.java b/broker/src/main/java/com/xiaoleilu/loServer/action/admin/UpdateUserAction.java index b41539873..b2f9fb0c0 100755 --- a/broker/src/main/java/com/xiaoleilu/loServer/action/admin/UpdateUserAction.java +++ b/broker/src/main/java/com/xiaoleilu/loServer/action/admin/UpdateUserAction.java @@ -41,7 +41,7 @@ public boolean isTransactionAction() { } @Override - public boolean action(Request request) { + public boolean action(Request request, Response response) { if (request.getNettyRequest() instanceof FullHttpRequest) { InputUpdateUserInfo inputCreateUser = getRequestBody(request.getNettyRequest(), InputUpdateUserInfo.class); if (inputCreateUser != null @@ -50,9 +50,9 @@ public boolean action(Request request) { && inputCreateUser.flag > 0) { ErrorCode errorCode = messagesStore.updateUserInfo(inputCreateUser.userInfo, inputCreateUser.flag); - setResponseContent(RestResult.resultOf(errorCode)); + setResponseContent(RestResult.resultOf(errorCode), response); } else { - setResponseContent(RestResult.resultOf(ErrorCode.INVALID_PARAMETER)); + setResponseContent(RestResult.resultOf(ErrorCode.INVALID_PARAMETER), response); } } diff --git a/broker/src/main/java/com/xiaoleilu/loServer/action/channel/ChannelAction.java b/broker/src/main/java/com/xiaoleilu/loServer/action/channel/ChannelAction.java index d926f54f0..4a68a83e2 100644 --- a/broker/src/main/java/com/xiaoleilu/loServer/action/channel/ChannelAction.java +++ b/broker/src/main/java/com/xiaoleilu/loServer/action/channel/ChannelAction.java @@ -92,7 +92,7 @@ public ErrorCode preAction(Request request, Response response) { return localSign.equals(sign) ? ErrorCode.ERROR_CODE_SUCCESS : ErrorCode.ERROR_CODE_AUTH_FAILURE; } - protected void sendResponse(ErrorCode errorCode, Object data) { + protected void sendResponse(Response response, ErrorCode errorCode, Object data) { response.setStatus(HttpResponseStatus.OK); if (errorCode == null) { errorCode = ErrorCode.ERROR_CODE_SUCCESS; @@ -115,10 +115,10 @@ protected T getRequestBody(HttpRequest request, Class cls) { return null; } - protected void sendApiMessage(String topic, byte[] message, Callback callback) { - sendApiMessage(channelInfo.getOwner(), topic, message, callback); + protected void sendApiMessage(Response response, String topic, byte[] message, Callback callback) { + sendApiMessage(response, channelInfo.getOwner(), topic, message, callback); } - protected void sendApiMessage(String user, String topic, byte[] message, Callback callback) { + protected void sendApiMessage(Response response, String user, String topic, byte[] message, Callback callback) { ServerAPIHelper.sendRequest(user, null, topic, message, new ServerAPIHelper.Callback() { @Override public void onSuccess(byte[] response) { @@ -126,12 +126,12 @@ public void onSuccess(byte[] response) { } @Override public void onError(ErrorCode errorCode) { - sendResponse(errorCode, null); + sendResponse(response, errorCode, null); } @Override public void onTimeout() { - sendResponse(ErrorCode.ERROR_CODE_TIMEOUT, null); + sendResponse(response, ErrorCode.ERROR_CODE_TIMEOUT, null); } @Override diff --git a/broker/src/main/java/com/xiaoleilu/loServer/action/channel/GetChannelAction.java b/broker/src/main/java/com/xiaoleilu/loServer/action/channel/GetChannelAction.java index 290e41208..4b35013bf 100755 --- a/broker/src/main/java/com/xiaoleilu/loServer/action/channel/GetChannelAction.java +++ b/broker/src/main/java/com/xiaoleilu/loServer/action/channel/GetChannelAction.java @@ -29,9 +29,9 @@ public class GetChannelAction extends ChannelAction { @Override - public boolean action(Request request) { + public boolean action(Request request, Response response) { if (request.getNettyRequest() instanceof FullHttpRequest) { - setResponseContent(RestResult.ok(OutputGetChannelInfo.fromPbInfo(channelInfo))); + setResponseContent(RestResult.ok(OutputGetChannelInfo.fromPbInfo(channelInfo)), response); } return true; } diff --git a/broker/src/main/java/com/xiaoleilu/loServer/action/channel/GetChannelSubscribersAction.java b/broker/src/main/java/com/xiaoleilu/loServer/action/channel/GetChannelSubscribersAction.java index bb382bb5f..b740e1340 100755 --- a/broker/src/main/java/com/xiaoleilu/loServer/action/channel/GetChannelSubscribersAction.java +++ b/broker/src/main/java/com/xiaoleilu/loServer/action/channel/GetChannelSubscribersAction.java @@ -31,12 +31,12 @@ public class GetChannelSubscribersAction extends ChannelAction { @Override - public boolean action(Request request) { + public boolean action(Request request, Response response) { if (request.getNettyRequest() instanceof FullHttpRequest) { OutputStringList outputStringList = new OutputStringList(); outputStringList.setList(new ArrayList<>()); outputStringList.getList().addAll(messagesStore.getChannelSubscriber(channelInfo.getTargetId())); - setResponseContent(RestResult.ok(outputStringList)); + setResponseContent(RestResult.ok(outputStringList), response); } return true; } diff --git a/broker/src/main/java/com/xiaoleilu/loServer/action/channel/GetUserAction.java b/broker/src/main/java/com/xiaoleilu/loServer/action/channel/GetUserAction.java index de0c1e249..cc508067e 100755 --- a/broker/src/main/java/com/xiaoleilu/loServer/action/channel/GetUserAction.java +++ b/broker/src/main/java/com/xiaoleilu/loServer/action/channel/GetUserAction.java @@ -31,7 +31,7 @@ public class GetUserAction extends ChannelAction { @Override - public boolean action(Request request) { + public boolean action(Request request, Response response) { if (request.getNettyRequest() instanceof FullHttpRequest) { InputGetUserInfo inputUserId = getRequestBody(request.getNettyRequest(), InputGetUserInfo.class); if (inputUserId != null @@ -69,9 +69,9 @@ public boolean action(Request request) { } } - setResponseContent(result); + setResponseContent(result, response); } else { - setResponseContent(RestResult.resultOf(ErrorCode.INVALID_PARAMETER)); + setResponseContent(RestResult.resultOf(ErrorCode.INVALID_PARAMETER), response); } } diff --git a/broker/src/main/java/com/xiaoleilu/loServer/action/channel/ModifyChannelProfileAction.java b/broker/src/main/java/com/xiaoleilu/loServer/action/channel/ModifyChannelProfileAction.java index 4cdc3c5af..a59a75a8e 100755 --- a/broker/src/main/java/com/xiaoleilu/loServer/action/channel/ModifyChannelProfileAction.java +++ b/broker/src/main/java/com/xiaoleilu/loServer/action/channel/ModifyChannelProfileAction.java @@ -28,24 +28,24 @@ @HttpMethod("POST") public class ModifyChannelProfileAction extends ChannelAction { @Override - public boolean action(Request request) { + public boolean action(Request request, Response response) { if (request.getNettyRequest() instanceof FullHttpRequest) { InputModifyChannelInfo input = getRequestBody(request.getNettyRequest(), InputModifyChannelInfo.class); if (input != null) { WFCMessage.ModifyChannelInfo modifyChannelInfo = WFCMessage.ModifyChannelInfo.newBuilder().setChannelId(channelInfo.getTargetId()).setType(input.getType()).setValue(input.getValue()).build(); - sendApiMessage(IMTopic.ModifyChannelInfoTopic, modifyChannelInfo.toByteArray(), result -> { + sendApiMessage(response, IMTopic.ModifyChannelInfoTopic, modifyChannelInfo.toByteArray(), result -> { ByteBuf byteBuf = Unpooled.buffer(); byteBuf.writeBytes(result); ErrorCode errorCode = ErrorCode.fromCode(byteBuf.readByte()); if (errorCode == ErrorCode.ERROR_CODE_SUCCESS) { - sendResponse(null, null); + sendResponse(response, null, null); } else { - sendResponse(errorCode, null); + sendResponse(response, errorCode, null); } }); return false; } else { - setResponseContent(RestResult.resultOf(ErrorCode.INVALID_PARAMETER)); + setResponseContent(RestResult.resultOf(ErrorCode.INVALID_PARAMETER), response); } } diff --git a/broker/src/main/java/com/xiaoleilu/loServer/action/channel/SendMessageAction.java b/broker/src/main/java/com/xiaoleilu/loServer/action/channel/SendMessageAction.java index f332b7e87..102515191 100755 --- a/broker/src/main/java/com/xiaoleilu/loServer/action/channel/SendMessageAction.java +++ b/broker/src/main/java/com/xiaoleilu/loServer/action/channel/SendMessageAction.java @@ -40,14 +40,14 @@ public boolean isTransactionAction() { } @Override - public boolean action(Request request) { + public boolean action(Request request, Response response) { if (request.getNettyRequest() instanceof FullHttpRequest) { SendChannelMessageData sendChannelMessageData = getRequestBody(request.getNettyRequest(), SendChannelMessageData.class); if(sendChannelMessageData.getTargets() != null && !sendChannelMessageData.getTargets().isEmpty()) { if((channelInfo.getStatus() & ProtoConstants.ChannelState.Channel_State_Mask_Message_Unsubscribed) == 0 && (channelInfo.getStatus() & ProtoConstants.ChannelState.Channel_State_Mask_Global) == 0) { for (String target:sendChannelMessageData.getTargets()) { if(!messagesStore.checkUserInChannel(target, channelInfo.getTargetId())) { - setResponseContent(RestResult.resultOf(ErrorCode.ERROR_CODE_NOT_RIGHT, "User " + target + " not in channel")); + setResponseContent(RestResult.resultOf(ErrorCode.ERROR_CODE_NOT_RIGHT, "User " + target + " not in channel"), response); return true; } } @@ -63,21 +63,21 @@ public boolean action(Request request) { sendMessageData.setPayload(sendChannelMessageData.getPayload()); sendMessageData.setToUsers(sendChannelMessageData.getTargets()); if (SendMessageData.isValide(sendMessageData)) { - sendApiMessage(IMTopic.SendMessageTopic, sendMessageData.toProtoMessage().toByteArray(), result -> { + sendApiMessage(response, IMTopic.SendMessageTopic, sendMessageData.toProtoMessage().toByteArray(), result -> { ByteBuf byteBuf = Unpooled.buffer(); byteBuf.writeBytes(result); ErrorCode errorCode = ErrorCode.fromCode(byteBuf.readByte()); if (errorCode == ErrorCode.ERROR_CODE_SUCCESS) { long messageId = byteBuf.readLong(); long timestamp = byteBuf.readLong(); - sendResponse(null, new SendMessageResult(messageId, timestamp)); + sendResponse(response, null, new SendMessageResult(messageId, timestamp)); } else { - sendResponse(errorCode, null); + sendResponse(response, errorCode, null); } }); return false; } else { - setResponseContent(RestResult.resultOf(ErrorCode.INVALID_PARAMETER)); + setResponseContent(RestResult.resultOf(ErrorCode.INVALID_PARAMETER), response); } } return true; diff --git a/broker/src/main/java/com/xiaoleilu/loServer/action/channel/SubscriberChannelAction.java b/broker/src/main/java/com/xiaoleilu/loServer/action/channel/SubscriberChannelAction.java index dcc5766ef..f12e2a70b 100755 --- a/broker/src/main/java/com/xiaoleilu/loServer/action/channel/SubscriberChannelAction.java +++ b/broker/src/main/java/com/xiaoleilu/loServer/action/channel/SubscriberChannelAction.java @@ -19,6 +19,7 @@ import com.xiaoleilu.loServer.annotation.HttpMethod; import com.xiaoleilu.loServer.annotation.Route; import com.xiaoleilu.loServer.handler.Request; +import com.xiaoleilu.loServer.handler.Response; import io.netty.buffer.ByteBuf; import io.netty.buffer.Unpooled; import io.netty.handler.codec.http.FullHttpRequest; @@ -30,7 +31,7 @@ public class SubscriberChannelAction extends ChannelAction { @Override - public boolean action(Request request) { + public boolean action(Request request, Response response) { if (request.getNettyRequest() instanceof FullHttpRequest) { InputChannelSubscribe input = getRequestBody(request.getNettyRequest(), InputChannelSubscribe.class); if (input != null && !StringUtil.isNullOrEmpty(input.getTarget())) { @@ -41,19 +42,19 @@ public boolean action(Request request) { return true; } WFCMessage.ListenChannel listenChannel = WFCMessage.ListenChannel.newBuilder().setChannelId(channelInfo.getTargetId()).setListen(input.getSubscribe()).build(); - sendApiMessage(input.getTarget(), IMTopic.ChannelListenTopic, listenChannel.toByteArray(), result -> { + sendApiMessage(response, input.getTarget(), IMTopic.ChannelListenTopic, listenChannel.toByteArray(), result -> { ByteBuf byteBuf = Unpooled.buffer(); byteBuf.writeBytes(result); ErrorCode errorCode = ErrorCode.fromCode(byteBuf.readByte()); if (errorCode == ErrorCode.ERROR_CODE_SUCCESS) { - sendResponse(null, null); + sendResponse(response, null, null); } else { - sendResponse(errorCode, null); + sendResponse(response, errorCode, null); } }); return false; } else { - setResponseContent(RestResult.resultOf(ErrorCode.INVALID_PARAMETER)); + setResponseContent(RestResult.resultOf(ErrorCode.INVALID_PARAMETER), response); } } diff --git a/broker/src/main/java/com/xiaoleilu/loServer/action/robot/AddGroupMemberAction.java b/broker/src/main/java/com/xiaoleilu/loServer/action/robot/AddGroupMemberAction.java index 5e713571d..54e5f1a39 100755 --- a/broker/src/main/java/com/xiaoleilu/loServer/action/robot/AddGroupMemberAction.java +++ b/broker/src/main/java/com/xiaoleilu/loServer/action/robot/AddGroupMemberAction.java @@ -34,24 +34,24 @@ public boolean isTransactionAction() { } @Override - public boolean action(Request request) { + public boolean action(Request request, Response response) { if (request.getNettyRequest() instanceof FullHttpRequest) { InputAddGroupMember inputAddGroupMember = getRequestBody(request.getNettyRequest(), InputAddGroupMember.class); inputAddGroupMember.setOperator(robot.getUid()); if (inputAddGroupMember.isValide()) { - sendApiRequest(IMTopic.AddGroupMemberTopic, inputAddGroupMember.toProtoGroupRequest().toByteArray(), result -> { + sendApiRequest(response, IMTopic.AddGroupMemberTopic, inputAddGroupMember.toProtoGroupRequest().toByteArray(), result -> { ByteBuf byteBuf = Unpooled.buffer(); byteBuf.writeBytes(result); ErrorCode errorCode = ErrorCode.fromCode(byteBuf.readByte()); if (errorCode == ErrorCode.ERROR_CODE_SUCCESS) { - sendResponse(null, null); + sendResponse(response, null, null); } else { - sendResponse(errorCode, null); + sendResponse(response, errorCode, null); } }); return false; } else { - setResponseContent(RestResult.resultOf(ErrorCode.INVALID_PARAMETER)); + setResponseContent(RestResult.resultOf(ErrorCode.INVALID_PARAMETER), response); } } return true; diff --git a/broker/src/main/java/com/xiaoleilu/loServer/action/robot/CreateGroupAction.java b/broker/src/main/java/com/xiaoleilu/loServer/action/robot/CreateGroupAction.java index 2039c5dbc..650c96213 100755 --- a/broker/src/main/java/com/xiaoleilu/loServer/action/robot/CreateGroupAction.java +++ b/broker/src/main/java/com/xiaoleilu/loServer/action/robot/CreateGroupAction.java @@ -37,7 +37,7 @@ public boolean isTransactionAction() { } @Override - public boolean action(Request request) { + public boolean action(Request request, Response response) { if (request.getNettyRequest() instanceof FullHttpRequest) { InputCreateGroup inputCreateGroup = getRequestBody(request.getNettyRequest(), InputCreateGroup.class); inputCreateGroup.setOperator(robot.getUid()); @@ -45,7 +45,7 @@ public boolean action(Request request) { if (inputCreateGroup.isValide()) { PojoGroupInfo group_info = inputCreateGroup.getGroup().getGroup_info(); WFCMessage.CreateGroupRequest createGroupRequest = inputCreateGroup.toProtoGroupRequest(); - sendApiRequest(IMTopic.CreateGroupTopic, createGroupRequest.toByteArray(), result -> { + sendApiRequest(response, IMTopic.CreateGroupTopic, createGroupRequest.toByteArray(), result -> { ByteBuf byteBuf = Unpooled.buffer(); byteBuf.writeBytes(result); ErrorCode errorCode = ErrorCode.fromCode(byteBuf.readByte()); @@ -53,14 +53,14 @@ public boolean action(Request request) { byte[] data = new byte[byteBuf.readableBytes()]; byteBuf.readBytes(data); String groupId = new String(data); - sendResponse(null, new OutputCreateGroupResult(groupId)); + sendResponse(response, null, new OutputCreateGroupResult(groupId)); } else { - sendResponse(errorCode, null); + sendResponse(response, errorCode, null); } }); return false; } else { - setResponseContent(RestResult.resultOf(ErrorCode.INVALID_PARAMETER)); + setResponseContent(RestResult.resultOf(ErrorCode.INVALID_PARAMETER), response); } } return true; diff --git a/broker/src/main/java/com/xiaoleilu/loServer/action/robot/DeleteCallbackAction.java b/broker/src/main/java/com/xiaoleilu/loServer/action/robot/DeleteCallbackAction.java index f62143a85..503f2ae90 100755 --- a/broker/src/main/java/com/xiaoleilu/loServer/action/robot/DeleteCallbackAction.java +++ b/broker/src/main/java/com/xiaoleilu/loServer/action/robot/DeleteCallbackAction.java @@ -26,13 +26,13 @@ public class DeleteCallbackAction extends RobotAction { @Override - public boolean action(Request request) { + public boolean action(Request request, Response response) { if (request.getNettyRequest() instanceof FullHttpRequest) { if(!StringUtil.isNullOrEmpty(robot.getCallback())) { robot = robot.toBuilder().clearCallback().setState(0).build(); messagesStore.addRobot(robot); } - setResponseContent(RestResult.ok()); + setResponseContent(RestResult.ok(), response); } return true; } diff --git a/broker/src/main/java/com/xiaoleilu/loServer/action/robot/DismissGroupAction.java b/broker/src/main/java/com/xiaoleilu/loServer/action/robot/DismissGroupAction.java index 791f05f69..30f81111c 100755 --- a/broker/src/main/java/com/xiaoleilu/loServer/action/robot/DismissGroupAction.java +++ b/broker/src/main/java/com/xiaoleilu/loServer/action/robot/DismissGroupAction.java @@ -34,24 +34,24 @@ public boolean isTransactionAction() { } @Override - public boolean action(Request request) { + public boolean action(Request request, Response response) { if (request.getNettyRequest() instanceof FullHttpRequest) { InputDismissGroup inputDismissGroup = getRequestBody(request.getNettyRequest(), InputDismissGroup.class); inputDismissGroup.setOperator(robot.getUid()); if (inputDismissGroup.isValide()) { - sendApiRequest(IMTopic.DismissGroupTopic, inputDismissGroup.toProtoGroupRequest().toByteArray(), result -> { + sendApiRequest(response, IMTopic.DismissGroupTopic, inputDismissGroup.toProtoGroupRequest().toByteArray(), result -> { ByteBuf byteBuf = Unpooled.buffer(); byteBuf.writeBytes(result); ErrorCode errorCode = ErrorCode.fromCode(byteBuf.readByte()); if (errorCode == ErrorCode.ERROR_CODE_SUCCESS) { - sendResponse(null, null); + sendResponse(response, null, null); } else { - sendResponse(errorCode, null); + sendResponse(response, errorCode, null); } }); return false; } else { - setResponseContent(RestResult.resultOf(ErrorCode.INVALID_PARAMETER)); + setResponseContent(RestResult.resultOf(ErrorCode.INVALID_PARAMETER), response); } } return true; diff --git a/broker/src/main/java/com/xiaoleilu/loServer/action/robot/GetCallbackAction.java b/broker/src/main/java/com/xiaoleilu/loServer/action/robot/GetCallbackAction.java index 29d1ad337..093452234 100755 --- a/broker/src/main/java/com/xiaoleilu/loServer/action/robot/GetCallbackAction.java +++ b/broker/src/main/java/com/xiaoleilu/loServer/action/robot/GetCallbackAction.java @@ -29,11 +29,11 @@ public class GetCallbackAction extends RobotAction { @Override - public boolean action(Request request) { + public boolean action(Request request, Response response) { if (request.getNettyRequest() instanceof FullHttpRequest) { RobotCallbackPojo out = new RobotCallbackPojo(); out.setUrl(robot.getCallback()); - setResponseContent(RestResult.ok(out)); + setResponseContent(RestResult.ok(out), response); } return true; } diff --git a/broker/src/main/java/com/xiaoleilu/loServer/action/robot/GetGroupInfoAction.java b/broker/src/main/java/com/xiaoleilu/loServer/action/robot/GetGroupInfoAction.java index 1ba9ffecc..3b57f2860 100755 --- a/broker/src/main/java/com/xiaoleilu/loServer/action/robot/GetGroupInfoAction.java +++ b/broker/src/main/java/com/xiaoleilu/loServer/action/robot/GetGroupInfoAction.java @@ -34,7 +34,7 @@ public boolean isTransactionAction() { } @Override - public boolean action(Request request) { + public boolean action(Request request, Response response) { if (request.getNettyRequest() instanceof FullHttpRequest) { InputGetGroup inputGetGroup = getRequestBody(request.getNettyRequest(), InputGetGroup.class); if (inputGetGroup != null @@ -58,9 +58,9 @@ public boolean action(Request request) { pojoGroupInfo.setSearchable(groupInfo.getSearchable()); result = RestResult.ok(pojoGroupInfo); } - setResponseContent(result); + setResponseContent(result, response); } else { - setResponseContent(RestResult.resultOf(ErrorCode.INVALID_PARAMETER)); + setResponseContent(RestResult.resultOf(ErrorCode.INVALID_PARAMETER), response); } } diff --git a/broker/src/main/java/com/xiaoleilu/loServer/action/robot/GetGroupMembersAction.java b/broker/src/main/java/com/xiaoleilu/loServer/action/robot/GetGroupMembersAction.java index 8ac60fea4..dddf9ea27 100755 --- a/broker/src/main/java/com/xiaoleilu/loServer/action/robot/GetGroupMembersAction.java +++ b/broker/src/main/java/com/xiaoleilu/loServer/action/robot/GetGroupMembersAction.java @@ -39,7 +39,7 @@ public boolean isTransactionAction() { } @Override - public boolean action(Request request) { + public boolean action(Request request, Response response) { if (request.getNettyRequest() instanceof FullHttpRequest) { InputGetGroup inputGetGroup = getRequestBody(request.getNettyRequest(), InputGetGroup.class); String robotId = robot.getUid(); @@ -75,9 +75,9 @@ public boolean action(Request request) { result = RestResult.ok(out); } - setResponseContent(result); + setResponseContent(result, response); } else { - setResponseContent(RestResult.resultOf(ErrorCode.INVALID_PARAMETER)); + setResponseContent(RestResult.resultOf(ErrorCode.INVALID_PARAMETER), response); } } diff --git a/broker/src/main/java/com/xiaoleilu/loServer/action/robot/GetUserAction.java b/broker/src/main/java/com/xiaoleilu/loServer/action/robot/GetUserAction.java index 3451eebd5..193d7465c 100755 --- a/broker/src/main/java/com/xiaoleilu/loServer/action/robot/GetUserAction.java +++ b/broker/src/main/java/com/xiaoleilu/loServer/action/robot/GetUserAction.java @@ -28,7 +28,7 @@ public class GetUserAction extends RobotAction { @Override - public boolean action(Request request) { + public boolean action(Request request, Response response) { if (request.getNettyRequest() instanceof FullHttpRequest) { InputGetUserInfo inputUserId = getRequestBody(request.getNettyRequest(), InputGetUserInfo.class); if (inputUserId != null @@ -49,9 +49,9 @@ public boolean action(Request request) { } else { result = RestResult.ok(InputOutputUserInfo.fromPbUser(user)); } - setResponseContent(result); + setResponseContent(result, response); } else { - setResponseContent(RestResult.resultOf(ErrorCode.INVALID_PARAMETER)); + setResponseContent(RestResult.resultOf(ErrorCode.INVALID_PARAMETER), response); } } diff --git a/broker/src/main/java/com/xiaoleilu/loServer/action/robot/KickoffGroupMemberAction.java b/broker/src/main/java/com/xiaoleilu/loServer/action/robot/KickoffGroupMemberAction.java index 2bda31810..9a1a5c31a 100755 --- a/broker/src/main/java/com/xiaoleilu/loServer/action/robot/KickoffGroupMemberAction.java +++ b/broker/src/main/java/com/xiaoleilu/loServer/action/robot/KickoffGroupMemberAction.java @@ -34,24 +34,24 @@ public boolean isTransactionAction() { } @Override - public boolean action(Request request) { + public boolean action(Request request, Response response) { if (request.getNettyRequest() instanceof FullHttpRequest) { InputKickoffGroupMember inputKickoffGroupMember = getRequestBody(request.getNettyRequest(), InputKickoffGroupMember.class); inputKickoffGroupMember.setOperator(robot.getUid()); if (inputKickoffGroupMember.isValide()) { - sendApiRequest(IMTopic.KickoffGroupMemberTopic, inputKickoffGroupMember.toProtoGroupRequest().toByteArray(), result -> { + sendApiRequest(response, IMTopic.KickoffGroupMemberTopic, inputKickoffGroupMember.toProtoGroupRequest().toByteArray(), result -> { ByteBuf byteBuf = Unpooled.buffer(); byteBuf.writeBytes(result); ErrorCode errorCode = ErrorCode.fromCode(byteBuf.readByte()); if (errorCode == ErrorCode.ERROR_CODE_SUCCESS) { - sendResponse(null, null); + sendResponse(response, null, null); } else { - sendResponse(errorCode, null); + sendResponse(response, errorCode, null); } }); return false; } else { - setResponseContent(RestResult.resultOf(ErrorCode.INVALID_PARAMETER)); + setResponseContent(RestResult.resultOf(ErrorCode.INVALID_PARAMETER), response); } } return true; diff --git a/broker/src/main/java/com/xiaoleilu/loServer/action/robot/ModifyGroupInfoAction.java b/broker/src/main/java/com/xiaoleilu/loServer/action/robot/ModifyGroupInfoAction.java index ebeac36e6..f4af98378 100755 --- a/broker/src/main/java/com/xiaoleilu/loServer/action/robot/ModifyGroupInfoAction.java +++ b/broker/src/main/java/com/xiaoleilu/loServer/action/robot/ModifyGroupInfoAction.java @@ -34,24 +34,24 @@ public boolean isTransactionAction() { } @Override - public boolean action(Request request) { + public boolean action(Request request, Response response) { if (request.getNettyRequest() instanceof FullHttpRequest) { InputModifyGroupInfo inputAddGroupMember = getRequestBody(request.getNettyRequest(), InputModifyGroupInfo.class); inputAddGroupMember.setOperator(robot.getUid()); if (inputAddGroupMember.isValide()) { - sendApiRequest(IMTopic.ModifyGroupInfoTopic, inputAddGroupMember.toProtoGroupRequest().toByteArray(), result -> { + sendApiRequest(response, IMTopic.ModifyGroupInfoTopic, inputAddGroupMember.toProtoGroupRequest().toByteArray(), result -> { ByteBuf byteBuf = Unpooled.buffer(); byteBuf.writeBytes(result); ErrorCode errorCode = ErrorCode.fromCode(byteBuf.readByte()); if (errorCode == ErrorCode.ERROR_CODE_SUCCESS) { - sendResponse(null, null); + sendResponse(response, null, null); } else { - sendResponse(errorCode, null); + sendResponse(response, errorCode, null); } }); return false; } else { - setResponseContent(RestResult.resultOf(ErrorCode.INVALID_PARAMETER)); + setResponseContent(RestResult.resultOf(ErrorCode.INVALID_PARAMETER), response); } } return true; diff --git a/broker/src/main/java/com/xiaoleilu/loServer/action/robot/ModifyGroupMemberAliasAction.java b/broker/src/main/java/com/xiaoleilu/loServer/action/robot/ModifyGroupMemberAliasAction.java index f31d64256..4ef4537a2 100755 --- a/broker/src/main/java/com/xiaoleilu/loServer/action/robot/ModifyGroupMemberAliasAction.java +++ b/broker/src/main/java/com/xiaoleilu/loServer/action/robot/ModifyGroupMemberAliasAction.java @@ -34,24 +34,24 @@ public boolean isTransactionAction() { } @Override - public boolean action(Request request) { + public boolean action(Request request, Response response) { if (request.getNettyRequest() instanceof FullHttpRequest) { InputSetGroupMemberAlias inputSetGroupMemberAlias = getRequestBody(request.getNettyRequest(), InputSetGroupMemberAlias.class); inputSetGroupMemberAlias.setOperator(robot.getUid()); if (inputSetGroupMemberAlias.isValide()) { - sendApiRequest(IMTopic.ModifyGroupMemberAliasTopic, inputSetGroupMemberAlias.toProtoGroupRequest().toByteArray(), result -> { + sendApiRequest(response, IMTopic.ModifyGroupMemberAliasTopic, inputSetGroupMemberAlias.toProtoGroupRequest().toByteArray(), result -> { ByteBuf byteBuf = Unpooled.buffer(); byteBuf.writeBytes(result); ErrorCode errorCode = ErrorCode.fromCode(byteBuf.readByte()); if (errorCode == ErrorCode.ERROR_CODE_SUCCESS) { - sendResponse(null, null); + sendResponse(response, null, null); } else { - sendResponse(errorCode, null); + sendResponse(response, errorCode, null); } }); return false; } else { - setResponseContent(RestResult.resultOf(ErrorCode.INVALID_PARAMETER)); + setResponseContent(RestResult.resultOf(ErrorCode.INVALID_PARAMETER), response); } } return true; diff --git a/broker/src/main/java/com/xiaoleilu/loServer/action/robot/QuitGroupMemberAction.java b/broker/src/main/java/com/xiaoleilu/loServer/action/robot/QuitGroupMemberAction.java index 569fc049a..8e1561b45 100755 --- a/broker/src/main/java/com/xiaoleilu/loServer/action/robot/QuitGroupMemberAction.java +++ b/broker/src/main/java/com/xiaoleilu/loServer/action/robot/QuitGroupMemberAction.java @@ -34,24 +34,24 @@ public boolean isTransactionAction() { } @Override - public boolean action(Request request) { + public boolean action(Request request, Response response) { if (request.getNettyRequest() instanceof FullHttpRequest) { InputQuitGroup inputQuitGroup = getRequestBody(request.getNettyRequest(), InputQuitGroup.class); inputQuitGroup.setOperator(robot.getUid()); if (inputQuitGroup.isValide()) { - sendApiRequest(IMTopic.QuitGroupTopic, inputQuitGroup.toProtoGroupRequest().toByteArray(), result -> { + sendApiRequest(response, IMTopic.QuitGroupTopic, inputQuitGroup.toProtoGroupRequest().toByteArray(), result -> { ByteBuf byteBuf = Unpooled.buffer(); byteBuf.writeBytes(result); ErrorCode errorCode = ErrorCode.fromCode(byteBuf.readByte()); if (errorCode == ErrorCode.ERROR_CODE_SUCCESS) { - sendResponse(null, null); + sendResponse(response, null, null); } else { - sendResponse(errorCode, null); + sendResponse(response, errorCode, null); } }); return false; } else { - setResponseContent(RestResult.resultOf(ErrorCode.INVALID_PARAMETER)); + setResponseContent(RestResult.resultOf(ErrorCode.INVALID_PARAMETER), response); } } return true; diff --git a/broker/src/main/java/com/xiaoleilu/loServer/action/robot/RobotAction.java b/broker/src/main/java/com/xiaoleilu/loServer/action/robot/RobotAction.java index 1fa6eb17d..22b1968b9 100644 --- a/broker/src/main/java/com/xiaoleilu/loServer/action/robot/RobotAction.java +++ b/broker/src/main/java/com/xiaoleilu/loServer/action/robot/RobotAction.java @@ -95,7 +95,7 @@ public ErrorCode preAction(Request request, Response response) { return localSign.equals(sign) ? ErrorCode.ERROR_CODE_SUCCESS : ErrorCode.ERROR_CODE_AUTH_FAILURE; } - protected void sendResponse(ErrorCode errorCode, Object data) { + protected void sendResponse(Response response, ErrorCode errorCode, Object data) { response.setStatus(HttpResponseStatus.OK); if (errorCode == null) { errorCode = ErrorCode.ERROR_CODE_SUCCESS; @@ -124,7 +124,7 @@ protected T getRequestBody(HttpRequest request, Class cls) { return null; } - protected void sendApiRequest(String topic, byte[] message, Callback callback) { + protected void sendApiRequest(Response response, String topic, byte[] message, Callback callback) { ServerAPIHelper.sendRequest(robot.getUid(), null, topic, message, new ServerAPIHelper.Callback() { @Override public void onSuccess(byte[] response) { @@ -133,12 +133,12 @@ public void onSuccess(byte[] response) { @Override public void onError(ErrorCode errorCode) { - sendResponse(errorCode, null); + sendResponse(response, errorCode, null); } @Override public void onTimeout() { - sendResponse(ErrorCode.ERROR_CODE_TIMEOUT, null); + sendResponse(response, ErrorCode.ERROR_CODE_TIMEOUT, null); } @Override diff --git a/broker/src/main/java/com/xiaoleilu/loServer/action/robot/SendMessageAction.java b/broker/src/main/java/com/xiaoleilu/loServer/action/robot/SendMessageAction.java index effbb10eb..566f4f843 100755 --- a/broker/src/main/java/com/xiaoleilu/loServer/action/robot/SendMessageAction.java +++ b/broker/src/main/java/com/xiaoleilu/loServer/action/robot/SendMessageAction.java @@ -35,26 +35,26 @@ public boolean isTransactionAction() { } @Override - public boolean action(Request request) { + public boolean action(Request request, Response response) { if (request.getNettyRequest() instanceof FullHttpRequest) { SendMessageData sendMessageData = getRequestBody(request.getNettyRequest(), SendMessageData.class); sendMessageData.setSender(robot.getUid()); if (SendMessageData.isValide(sendMessageData)) { - sendApiRequest(IMTopic.SendMessageTopic, sendMessageData.toProtoMessage().toByteArray(), result -> { + sendApiRequest(response, IMTopic.SendMessageTopic, sendMessageData.toProtoMessage().toByteArray(), result -> { ByteBuf byteBuf = Unpooled.buffer(); byteBuf.writeBytes(result); ErrorCode errorCode = ErrorCode.fromCode(byteBuf.readByte()); if (errorCode == ErrorCode.ERROR_CODE_SUCCESS) { long messageId = byteBuf.readLong(); long timestamp = byteBuf.readLong(); - sendResponse(null, new SendMessageResult(messageId, timestamp)); + sendResponse(response, null, new SendMessageResult(messageId, timestamp)); } else { - sendResponse(errorCode, null); + sendResponse(response, errorCode, null); } }); return false; } else { - setResponseContent(RestResult.resultOf(ErrorCode.INVALID_PARAMETER)); + setResponseContent(RestResult.resultOf(ErrorCode.INVALID_PARAMETER), response); } } return true; diff --git a/broker/src/main/java/com/xiaoleilu/loServer/action/robot/SetCallbackAction.java b/broker/src/main/java/com/xiaoleilu/loServer/action/robot/SetCallbackAction.java index 1c0ccf347..3e821c97f 100755 --- a/broker/src/main/java/com/xiaoleilu/loServer/action/robot/SetCallbackAction.java +++ b/broker/src/main/java/com/xiaoleilu/loServer/action/robot/SetCallbackAction.java @@ -27,7 +27,7 @@ public class SetCallbackAction extends RobotAction { @Override - public boolean action(Request request) { + public boolean action(Request request, Response response) { if (request.getNettyRequest() instanceof FullHttpRequest) { RobotCallbackPojo input = getRequestBody(request.getNettyRequest(), RobotCallbackPojo.class); if(!StringUtil.isNullOrEmpty(input.getUrl())) { @@ -35,9 +35,9 @@ public boolean action(Request request) { robot = robot.toBuilder().setCallback(input.getUrl()).setState(1).build(); messagesStore.addRobot(robot); } - setResponseContent(RestResult.ok()); + setResponseContent(RestResult.ok(), response); } else { - setResponseContent(RestResult.resultOf(ErrorCode.INVALID_PARAMETER)); + setResponseContent(RestResult.resultOf(ErrorCode.INVALID_PARAMETER), response); } } diff --git a/broker/src/main/java/com/xiaoleilu/loServer/action/robot/TransferGroupAction.java b/broker/src/main/java/com/xiaoleilu/loServer/action/robot/TransferGroupAction.java index 19cbeb8c7..bf9deb04a 100755 --- a/broker/src/main/java/com/xiaoleilu/loServer/action/robot/TransferGroupAction.java +++ b/broker/src/main/java/com/xiaoleilu/loServer/action/robot/TransferGroupAction.java @@ -34,24 +34,24 @@ public boolean isTransactionAction() { } @Override - public boolean action(Request request) { + public boolean action(Request request, Response response) { if (request.getNettyRequest() instanceof FullHttpRequest) { InputTransferGroup inputDismissGroup = getRequestBody(request.getNettyRequest(), InputTransferGroup.class); inputDismissGroup.setOperator(robot.getUid()); if (inputDismissGroup.isValide()) { - sendApiRequest(IMTopic.TransferGroupTopic, inputDismissGroup.toProtoGroupRequest().toByteArray(), result -> { + sendApiRequest(response, IMTopic.TransferGroupTopic, inputDismissGroup.toProtoGroupRequest().toByteArray(), result -> { ByteBuf byteBuf = Unpooled.buffer(); byteBuf.writeBytes(result); ErrorCode errorCode = ErrorCode.fromCode(byteBuf.readByte()); if (errorCode == ErrorCode.ERROR_CODE_SUCCESS) { - sendResponse(null, null); + sendResponse(response, null, null); } else { - sendResponse(errorCode, null); + sendResponse(response, errorCode, null); } }); return false; } else { - setResponseContent(RestResult.resultOf(ErrorCode.INVALID_PARAMETER)); + setResponseContent(RestResult.resultOf(ErrorCode.INVALID_PARAMETER), response); } } return true; diff --git a/broker/src/main/java/com/xiaoleilu/loServer/action/robot/UpdateProfileAction.java b/broker/src/main/java/com/xiaoleilu/loServer/action/robot/UpdateProfileAction.java index 74bd0e458..8c53f83be 100755 --- a/broker/src/main/java/com/xiaoleilu/loServer/action/robot/UpdateProfileAction.java +++ b/broker/src/main/java/com/xiaoleilu/loServer/action/robot/UpdateProfileAction.java @@ -28,7 +28,7 @@ public class UpdateProfileAction extends RobotAction { @Override - public boolean action(Request request) { + public boolean action(Request request, Response response) { if (request.getNettyRequest() instanceof FullHttpRequest) { IntStringPairPojo input = getRequestBody(request.getNettyRequest(), IntStringPairPojo.class); @@ -85,7 +85,7 @@ public boolean action(Request request) { result.setErrorCode(ErrorCode.ERROR_CODE_SERVER_ERROR); } } - setResponseContent(result); + setResponseContent(result, response); } return true; } diff --git a/broker/src/main/java/com/xiaoleilu/loServer/handler/ActionHandler.java b/broker/src/main/java/com/xiaoleilu/loServer/handler/ActionHandler.java index d24482b49..eca67cf21 100755 --- a/broker/src/main/java/com/xiaoleilu/loServer/handler/ActionHandler.java +++ b/broker/src/main/java/com/xiaoleilu/loServer/handler/ActionHandler.java @@ -53,7 +53,7 @@ protected void channelRead0(ChannelHandlerContext ctx, FullHttpRequest fullHttpR Action errorAction = ServerSetting.getErrorAction(ServerSetting.MAPPING_ERROR); request.putParam(UnknownErrorAction.ERROR_PARAM_NAME, e); response.setContent(e.toString()); - errorAction.doAction(request); + errorAction.doAction(request, response); //如果发送请求未被触发,则触发之,否则跳过。 if(!response.isSent()){ @@ -134,9 +134,8 @@ private void doAction(ChannelHandlerContext ctx, Request request, Response respo } } action.ctx = ctx; - action.response = response; - boolean isSync = action.doAction(request); + boolean isSync = action.doAction(request, response); if(isSync) { //如果发送请求未被触发,则触发之,否则跳过。