add gzip
This commit is contained in:
@@ -205,9 +205,7 @@ abstract public class IMHandler<T> {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if(errorCode != ErrorCode.ERROR_CODE_ASYNC_HANDLER) {
|
response(ackPayload, errorCode, callback);
|
||||||
response(ackPayload, errorCode, callback);
|
|
||||||
}
|
|
||||||
} else {
|
} else {
|
||||||
LOG.error("Handler {} preAction failure", this.getClass().getName());
|
LOG.error("Handler {} preAction failure", this.getClass().getName());
|
||||||
ByteBuf ackPayload = Unpooled.buffer(1);
|
ByteBuf ackPayload = Unpooled.buffer(1);
|
||||||
|
|||||||
@@ -73,7 +73,7 @@ public class RPCCenter {
|
|||||||
info.future.cancel(true);
|
info.future.cancel(true);
|
||||||
if (info.callback != null) {
|
if (info.callback != null) {
|
||||||
info.callback.getResponseExecutor().execute(() -> {
|
info.callback.getResponseExecutor().execute(() -> {
|
||||||
if (errorCode == 0) {
|
if (errorCode == 0 || errorCode == ErrorCode.ERROR_CODE_ASYNC_HANDLER.getCode()) {
|
||||||
info.callback.onSuccess(message);
|
info.callback.onSuccess(message);
|
||||||
} else {
|
} else {
|
||||||
info.callback.onError(ErrorCode.fromCode(errorCode));
|
info.callback.onError(ErrorCode.fromCode(errorCode));
|
||||||
|
|||||||
@@ -23,8 +23,10 @@ import static cn.wildfirechat.common.ErrorCode.ERROR_CODE_NOT_IMPLEMENT;
|
|||||||
import static cn.wildfirechat.common.ErrorCode.ERROR_CODE_OVER_FREQUENCY;
|
import static cn.wildfirechat.common.ErrorCode.ERROR_CODE_OVER_FREQUENCY;
|
||||||
import static cn.wildfirechat.common.ErrorCode.ERROR_CODE_SUCCESS;
|
import static cn.wildfirechat.common.ErrorCode.ERROR_CODE_SUCCESS;
|
||||||
|
|
||||||
|
import java.io.ByteArrayOutputStream;
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.util.*;
|
import java.util.*;
|
||||||
|
import java.util.zip.GZIPOutputStream;
|
||||||
|
|
||||||
import cn.wildfirechat.server.ThreadPoolExecutorWrapper;
|
import cn.wildfirechat.server.ThreadPoolExecutorWrapper;
|
||||||
import com.google.gson.Gson;
|
import com.google.gson.Gson;
|
||||||
@@ -174,8 +176,23 @@ public class Qos1PublishHandler extends QosPublishHandler {
|
|||||||
data = AES.AESEncrypt(data, "");
|
data = AES.AESEncrypt(data, "");
|
||||||
} else {
|
} else {
|
||||||
MemorySessionStore.Session session = m_sessionStore.getSession(clientID);
|
MemorySessionStore.Session session = m_sessionStore.getSession(clientID);
|
||||||
if (session != null && session.getUsername().equals(fromUser))
|
if (session != null && session.getUsername().equals(fromUser)) {
|
||||||
data = AES.AESEncrypt(data, session.getSecret());
|
if (data.length > 10*1024) {
|
||||||
|
ByteArrayOutputStream out = new ByteArrayOutputStream();
|
||||||
|
GZIPOutputStream gzip;
|
||||||
|
try {
|
||||||
|
gzip = new GZIPOutputStream(out);
|
||||||
|
gzip.write(data);
|
||||||
|
gzip.close();
|
||||||
|
} catch (Exception e) {
|
||||||
|
e.printStackTrace();
|
||||||
|
}
|
||||||
|
data = out.toByteArray();
|
||||||
|
code = (byte)ErrorCode.ERROR_CODE_ASYNC_HANDLER.code;
|
||||||
|
}
|
||||||
|
|
||||||
|
data = AES.AESEncrypt(data, session.getSecret());
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
ackPayload.clear();
|
ackPayload.clear();
|
||||||
|
|||||||
@@ -56,7 +56,7 @@ public enum ErrorCode {
|
|||||||
ERROR_CODE_NOT_IMPLEMENT(254, "not implement"),
|
ERROR_CODE_NOT_IMPLEMENT(254, "not implement"),
|
||||||
|
|
||||||
|
|
||||||
ERROR_CODE_ASYNC_HANDLER(255, "异步执行,服务器内部逻辑需要此代码,为正常情况,不能返回客户端"),;
|
ERROR_CODE_SUCCESS_GZIPED(255, "success withe gzip response"),;
|
||||||
|
|
||||||
public int code;
|
public int code;
|
||||||
public String msg;
|
public String msg;
|
||||||
|
|||||||
Reference in New Issue
Block a user