Compare commits

...
18 Commits
40 changed files with 479 additions and 92 deletions
+3
View File
@@ -51,3 +51,6 @@ broker/config/git.properties
distribution/src/main/resources/git.properties
broker/h2db
broker/media
common/target
server/target
sdk/target
+8
View File
@@ -28,6 +28,8 @@
<img src="http://static.wildfirechat.cn/wx_wfc_qrcode.jpg" width = 50% height = 50% />
> 强烈建议关注我们的公众号。我们有新版本发布或者有重大更新会通过公众号通知大家,另外我们也会不定期的发布一些关于野火IM的技术介绍。
#### 体验Demo
我们提供了体验demo,请使用微信扫码下载安装体验
@@ -59,6 +61,12 @@
## 编译
在安装JDK1.8以上及maven的前提下,在命令行中执行```mvn clean compile package```,生成的目标文件在```./distribution/target/distribution-xxxx-bundle-tar.tar.gz```
## 捐赠者名单
| 捐赠者 | 商标 | 金额 | 简介 |
| ----- | ---- | -------- | --- |
| [SAMOS](http://samos.io) | ![SAMOS](http://static.wildfirechat.cn/SAMOS.png) | 每月2000¥ | 一站式区块链解决方案服务商(http://samos.io) |
## 特别感谢
1. [moquette](https://github.com/moquette-io/moquette) 本项目是基于此项目二次开发而来,处理MQTT相关业务。
2. [loServer](https://github.com/looly/loServer) 本项目使用loServer处理HTTP相关业务。
+1 -1
View File
@@ -5,7 +5,7 @@
<relativePath>../</relativePath>
<artifactId>wildfirechat-parent</artifactId>
<groupId>cn.wildfirechat</groupId>
<version>0.21</version>
<version>0.22</version>
</parent>
<artifactId>moquette-broker</artifactId>
@@ -18,6 +18,7 @@ import cn.wildfirechat.pojos.OutputLoginData;
import io.netty.handler.codec.http.FullHttpRequest;
import io.netty.handler.codec.http.HttpResponseStatus;
import win.liyufan.im.GitRepositoryState;
import win.liyufan.im.Utility;
import java.io.IOException;
@@ -32,7 +33,8 @@ public class VersionAction extends Action {
response.setStatus(HttpResponseStatus.OK);
try {
response.setContent(new Gson().toJson(GitRepositoryState.getGitRepositoryState()));
response.setContent(Utility.formatJson(new Gson().toJson(GitRepositoryState.getGitRepositoryState())));
} catch (IOException e) {
e.printStackTrace();
response.setContent("{\"version\":\"unknown\"}");
@@ -0,0 +1,90 @@
/*
* This file is part of the Wildfire Chat package.
* (c) Heavyrain2012 <[email protected]>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
package com.xiaoleilu.loServer.action.admin;
import cn.wildfirechat.common.APIPath;
import cn.wildfirechat.common.ErrorCode;
import cn.wildfirechat.pojos.BroadMessageData;
import cn.wildfirechat.pojos.BroadMessageResult;
import cn.wildfirechat.pojos.SendMessageData;
import cn.wildfirechat.pojos.SendMessageResult;
import com.google.gson.Gson;
import com.hazelcast.util.StringUtil;
import com.xiaoleilu.loServer.RestResult;
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.moquette.persistence.RPCCenter;
import io.moquette.persistence.TargetEntry;
import io.netty.buffer.ByteBuf;
import io.netty.buffer.Unpooled;
import io.netty.handler.codec.http.FullHttpRequest;
import io.netty.handler.codec.http.HttpResponseStatus;
import win.liyufan.im.IMTopic;
import java.util.concurrent.Executor;
@Route(APIPath.Msg_Broadcast)
@HttpMethod("POST")
public class BroadcastMessageAction extends AdminAction {
@Override
public boolean isTransactionAction() {
return true;
}
@Override
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())) {
RPCCenter.getInstance().sendRequest(sendMessageData.getSender(), null, IMTopic.BroadcastMessageTopic, sendMessageData.toProtoMessage().toByteArray(), sendMessageData.getSender(), TargetEntry.Type.TARGET_TYPE_USER, new RPCCenter.Callback() {
@Override
public void onSuccess(byte[] 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 count = byteBuf.readLong();
sendResponse(response, null, new BroadMessageResult(messageId, count));
} else {
sendResponse(response, errorCode, null);
}
}
@Override
public void onError(ErrorCode errorCode) {
sendResponse(response, errorCode, null);
}
@Override
public void onTimeout() {
sendResponse(response, ErrorCode.ERROR_CODE_TIMEOUT, null);
}
@Override
public Executor getResponseExecutor() {
return command -> {
ctx.executor().execute(command);
};
}
}, true);
return false;
} else {
response.setStatus(HttpResponseStatus.OK);
RestResult result = RestResult.resultOf(ErrorCode.INVALID_PARAMETER);
response.setContent(new Gson().toJson(result));
}
}
return true;
}
}
@@ -48,10 +48,6 @@ public class CreateUserAction extends AdminAction {
inputCreateUser.setUserId(messagesStore.getShortUUID());
}
if (inputCreateUser.getPortrait() == null || inputCreateUser.getPortrait().length() == 0) {
inputCreateUser.setPortrait("https://avatars.io/gravatar/" + inputCreateUser.getUserId());
}
WFCMessage.User.Builder newUserBuilder = WFCMessage.User.newBuilder()
.setUid(StringUtil.isNullOrEmpty(inputCreateUser.getUserId()) ? "" : inputCreateUser.getUserId());
if (inputCreateUser.getName() != null)
@@ -0,0 +1,49 @@
/*
* This file is part of the Wildfire Chat package.
* (c) Heavyrain2012 <[email protected]>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
package io.moquette.imhandler;
import cn.wildfirechat.common.ErrorCode;
import cn.wildfirechat.proto.ProtoConstants;
import cn.wildfirechat.proto.WFCMessage;
import com.hazelcast.util.StringUtil;
import io.moquette.BrokerConstants;
import io.moquette.spi.impl.Qos1PublishHandler;
import io.netty.buffer.ByteBuf;
import win.liyufan.im.IMTopic;
import win.liyufan.im.MessageShardingUtil;
import java.util.Set;
import static cn.wildfirechat.proto.ProtoConstants.ContentType.Text;
@Handler(value = IMTopic.BroadcastMessageTopic)
public class BroadcastMessageHandler extends IMHandler<WFCMessage.Message> {
@Override
public ErrorCode action(ByteBuf ackPayload, String clientID, String fromUser, boolean isAdmin, WFCMessage.Message message, Qos1PublishHandler.IMCallback callback) {
ErrorCode errorCode = ErrorCode.ERROR_CODE_SUCCESS;
if (message != null) {
if (!isAdmin) { //only admin can broadcast message
return ErrorCode.ERROR_CODE_NOT_RIGHT;
}
long timestamp = System.currentTimeMillis();
long messageId = MessageShardingUtil.generateId();
message = message.toBuilder().setFromUser(fromUser).setMessageId(messageId).setServerTimestamp(timestamp).setConversation(WFCMessage.Conversation.newBuilder().setTarget(fromUser).setLine(message.getConversation().getLine()).setType(ProtoConstants.ConversationType.ConversationType_Private).build()).build();
long count = saveAndBroadcast(fromUser, clientID, message);
ackPayload = ackPayload.capacity(20);
ackPayload.writeLong(messageId);
ackPayload.writeLong(count);
} else {
errorCode = ErrorCode.ERROR_CODE_INVALID_MESSAGE;
}
return errorCode;
}
}
@@ -8,6 +8,7 @@
package io.moquette.imhandler;
import cn.wildfirechat.proto.ProtoConstants;
import cn.wildfirechat.proto.WFCMessage;
import cn.wildfirechat.server.ThreadPoolExecutorWrapper;
import com.google.gson.Gson;
@@ -205,9 +206,7 @@ abstract public class IMHandler<T> {
}
}
if(errorCode != ErrorCode.ERROR_CODE_ASYNC_HANDLER) {
response(ackPayload, errorCode, callback);
}
response(ackPayload, errorCode, callback);
} else {
LOG.error("Handler {} preAction failure", this.getClass().getName());
ByteBuf ackPayload = Unpooled.buffer(1);
@@ -241,6 +240,13 @@ abstract public class IMHandler<T> {
message = m_messagesStore.storeMessage(username, clientID, message);
int pullType = m_messagesStore.getNotifyReceivers(username, message, notifyReceivers);
this.publisher.publish2Receivers(message, notifyReceivers, clientID, pullType);
return message.getMessageId();
return notifyReceivers.size();
}
protected long saveAndBroadcast(String username, String clientID, WFCMessage.Message message) {
Set<String> notifyReceivers = m_messagesStore.getAllEnds();
WFCMessage.Message updatedMessage = m_messagesStore.storeMessage(username, clientID, message);
mServer.getImBusinessScheduler().execute(() -> publisher.publish2Receivers(updatedMessage, notifyReceivers, clientID, ProtoConstants.PullType.Pull_Normal));
return notifyReceivers.size();
}
}
@@ -97,9 +97,9 @@ public class DatabaseStore {
", `_extra`" +
", `_dt` from t_user";
if (buzzy) {
sql += " where `_display_name` like ?";
sql += " where (`_display_name` like ? or `_name` = ? or `_mobile` = ?) ";
} else {
sql += " where `_display_name` = ?";
sql += " where (`_display_name` = ? or `_name` = ? or `_mobile` = ?) ";
}
sql += " and _type <> 2"; //can search normal user(0) and robot(1), can not search things
@@ -118,6 +118,8 @@ public class DatabaseStore {
} else {
statement.setString(index++, keyword);
}
statement.setString(index++, keyword);
statement.setString(index++, keyword);
rs = statement.executeQuery();
while (rs.next()) {
@@ -1774,6 +1776,33 @@ public class DatabaseStore {
return null;
}
Set<String> getAllEnds() {
Connection connection = null;
PreparedStatement statement = null;
ResultSet rs = null;
try {
connection = DBUtil.getConnection();
String sql = "select distinct(`_uid`) from t_user_session";
statement = connection.prepareStatement(sql);
rs = statement.executeQuery();
Set<String> out = new HashSet<>();
while (rs.next()) {
String uid = rs.getString(1);
out.add(uid);
}
return out;
} catch (SQLException e) {
// TODO Auto-generated catch block
e.printStackTrace();
Utility.printExecption(LOG, e);
} finally {
DBUtil.closeDB(connection, statement, rs);
}
return null;
}
List<FriendData> getPersistFriends(String userId) {
Connection connection = null;
PreparedStatement statement = null;
@@ -245,6 +245,10 @@ public class MemoryMessagesStore implements IMessagesStore {
return pullType;
}
@Override
public Set<String> getAllEnds() {
return databaseStore.getAllEnds();
}
@Override
public WFCMessage.PullMessageResult fetchMessage(String user, String exceptClientId, long fromMessageId, int pullType) {
WFCMessage.PullMessageResult.Builder builder = WFCMessage.PullMessageResult.newBuilder();
@@ -315,9 +319,6 @@ public class MemoryMessagesStore implements IMessagesStore {
long targetMessageId = entry.getValue();
MessageBundle bundle = mIMap.get(targetMessageId);
if (bundle == null) {
bundle = databaseStore.getMessage(targetMessageId);
}
if (bundle != null) {
if (exceptClientId == null || !exceptClientId.equals(bundle.getFromClientId()) || !user.equals(bundle.getFromUser())) {
@@ -407,10 +408,6 @@ public class MemoryMessagesStore implements IMessagesStore {
long targetMessageId = entry.getValue();
MessageBundle bundle = mIMap.get(targetMessageId);
if (bundle == null) {
bundle = databaseStore.getMessage(targetMessageId);
}
if (bundle != null) {
if (exceptClientId == null || !exceptClientId.equals(bundle.getFromClientId()) || !fromUser.equals(bundle.getFromUser())) {
size += bundle.getMessage().getSerializedSize();
@@ -2111,10 +2108,6 @@ public class MemoryMessagesStore implements IMessagesStore {
MessageBundle bundle = mIMap.get(messageId);
if (bundle != null) {
return bundle.getMessage();
} else {
bundle = databaseStore.getMessage(messageId);
if (bundle != null)
return bundle.getMessage();
}
return null;
}
@@ -23,6 +23,7 @@ import io.moquette.spi.ClientSession;
import io.moquette.spi.IMessagesStore.StoredMessage;
import io.moquette.spi.ISessionsStore;
import io.netty.handler.codec.mqtt.MqttVersion;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import cn.wildfirechat.common.ErrorCode;
@@ -49,6 +50,8 @@ public class MemorySessionStore implements ISessionsStore {
private volatile int unReceivedMsgs;
private MqttVersion mqttVersion = MqttVersion.MQTT_3_1_1;
public long getLastActiveTime() {
return lastActiveTime;
}
@@ -230,7 +233,13 @@ public class MemorySessionStore implements ISessionsStore {
}
public MqttVersion getMqttVersion() {
return mqttVersion;
}
public void setMqttVersion(MqttVersion mqttVersion) {
this.mqttVersion = mqttVersion;
}
}
private final Map<String, Session> sessions = new ConcurrentHashMap<>();
@@ -73,7 +73,7 @@ public class RPCCenter {
info.future.cancel(true);
if (info.callback != null) {
info.callback.getResponseExecutor().execute(() -> {
if (errorCode == 0) {
if (errorCode == 0 || errorCode == ErrorCode.ERROR_CODE_SUCCESS_GZIPED.getCode()) {
info.callback.onSuccess(message);
} else {
info.callback.onError(ErrorCode.fromCode(errorCode));
@@ -97,6 +97,7 @@ public interface IMessagesStore {
DatabaseStore getDatabaseStore();
WFCMessage.Message storeMessage(String fromUser, String fromClientId, WFCMessage.Message message);
int getNotifyReceivers(String fromUser, WFCMessage.Message message, Set<String> notifyReceivers);
Set<String> getAllEnds();
WFCMessage.PullMessageResult fetchMessage(String user, String exceptClientId, long fromMessageId, int pullType);
WFCMessage.PullMessageResult loadRemoteMessages(String user, WFCMessage.Conversation conversation, long beforeUid, int count);
long insertUserMessages(String sender, int conversationType, String target, int line, int messageContentType, String userId, long messageId);
@@ -143,7 +143,8 @@ public class ProtocolProcessor {
LOG.info("Processing CONNECT message. CId={}, username={}", clientId, payload.userName());
if (msg.variableHeader().version() != MqttVersion.MQTT_3_1.protocolLevel()
&& msg.variableHeader().version() != MqttVersion.MQTT_3_1_1.protocolLevel()) {
&& msg.variableHeader().version() != MqttVersion.MQTT_3_1_1.protocolLevel()
&& msg.variableHeader().version() != MqttVersion.Wildfire_1.protocolLevel()) {
MqttConnAckMessage badProto = connAck(CONNECTION_REFUSED_UNACCEPTABLE_PROTOCOL_VERSION);
LOG.error("MQTT protocol version is not valid. CId={}", clientId);
@@ -162,7 +163,8 @@ public class ProtocolProcessor {
}
if (!login(channel, msg, clientId)) {
MqttVersion mqttVersion = MqttVersion.fromProtocolLevel(msg.variableHeader().version());
if (!login(channel, msg, clientId, mqttVersion)) {
channel.close();
return;
}
@@ -238,7 +240,7 @@ public class ProtocolProcessor {
MqttConnAckVariableHeader mqttConnAckVariableHeader = new MqttConnAckVariableHeader(returnCode, sessionPresent);
return new MqttConnAckMessage(mqttFixedHeader, mqttConnAckVariableHeader, new MqttConnectAckPayload(data));
}
private boolean login(Channel channel, MqttConnectMessage msg, final String clientId) {
private boolean login(Channel channel, MqttConnectMessage msg, final String clientId, MqttVersion mqttVersion) {
// handle user authentication
if (msg.variableHeader().hasUserName()) {
int status = m_messagesStore.getUserStatus(msg.payload().userName());
@@ -269,6 +271,7 @@ public class ProtocolProcessor {
failedCredentials(channel);
return false;
}
session.setMqttVersion(mqttVersion);
} else if (!this.allowAnonymous) {
LOG.error("Client didn't supply any password and MQTT anonymous mode is disabled CId={}", clientId);
failedCredentials(channel);
@@ -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_SUCCESS;
import java.io.ByteArrayOutputStream;
import java.io.IOException;
import java.util.*;
import java.util.zip.GZIPOutputStream;
import cn.wildfirechat.server.ThreadPoolExecutorWrapper;
import com.google.gson.Gson;
@@ -39,6 +41,7 @@ import io.moquette.server.ConnectionDescriptor;
import io.moquette.server.Server;
import io.moquette.spi.ClientSession;
import io.moquette.spi.impl.security.AES;
import io.netty.handler.codec.mqtt.MqttVersion;
import io.netty.util.ReferenceCountUtil;
import io.netty.util.internal.StringUtil;
import org.slf4j.Logger;
@@ -114,7 +117,7 @@ public class Qos1PublishHandler extends QosPublishHandler {
byte[] response = new byte[ackPayload.readableBytes()];
ackPayload.readBytes(response);
ReferenceCountUtil.release(ackPayload);
RPCCenter.getInstance().sendResponse(ERROR_CODE_SUCCESS.getCode(), response, from, requestId);
RPCCenter.getInstance().sendResponse(errorCode.getCode(), response, from, requestId);
}
}, isAdmin);
}
@@ -174,8 +177,23 @@ public class Qos1PublishHandler extends QosPublishHandler {
data = AES.AESEncrypt(data, "");
} else {
MemorySessionStore.Session session = m_sessionStore.getSession(clientID);
if (session != null && session.getUsername().equals(fromUser))
data = AES.AESEncrypt(data, session.getSecret());
if (session != null && session.getUsername().equals(fromUser)) {
if (data.length > 7*1024 && session.getMqttVersion() == MqttVersion.Wildfire_1) {
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_SUCCESS_GZIPED.code;
}
data = AES.AESEncrypt(data, session.getSecret());
}
}
}
ackPayload.clear();
@@ -43,7 +43,7 @@ final class MqttCodecUtil {
return clientId != null && clientId.length() >= MIN_CLIENT_ID_LENGTH &&
clientId.length() <= MAX_CLIENT_ID_LENGTH;
}
if (mqttVersion == MqttVersion.MQTT_3_1_1) {
if (mqttVersion == MqttVersion.MQTT_3_1_1 || mqttVersion == MqttVersion.Wildfire_1) {
// In 3.1.3.1 Client Identifier of MQTT 3.1.1 specification, The Server MAY allow ClientId’s
// that contain more than 23 encoded bytes. And, The Server MAY allow zero-length ClientId.
return clientId != null;
@@ -223,7 +223,7 @@ public final class MqttDecoder extends ReplayingDecoder<DecoderState> {
final int willQos = (b1 & 0x18) >> 3;
final boolean willFlag = (b1 & 0x04) == 0x04;
final boolean cleanSession = (b1 & 0x02) == 0x02;
if (mqttVersion == MqttVersion.MQTT_3_1_1) {
if (mqttVersion == MqttVersion.MQTT_3_1_1 || mqttVersion == MqttVersion.Wildfire_1) {
final boolean zeroReservedFlag = (b1 & 0x01) == 0x0;
if (!zeroReservedFlag) {
// MQTT v3.1.1: The Server MUST validate that the reserved flag in the CONNECT Control Packet is
@@ -24,7 +24,8 @@ import io.netty.util.internal.ObjectUtil;
*/
public enum MqttVersion {
MQTT_3_1("MQIsdp", (byte) 3),
MQTT_3_1_1("MQTT", (byte) 4);
MQTT_3_1_1("MQTT", (byte) 4),
Wildfire_1("MQTT", (byte) 5);
private final String name;
private final byte level;
@@ -52,11 +53,19 @@ public enum MqttVersion {
if (mv.level == protocolLevel) {
return mv;
} else {
throw new MqttUnacceptableProtocolVersionException(protocolName + " and " +
protocolLevel + " are not match");
continue;
}
}
}
throw new MqttUnacceptableProtocolVersionException(protocolName + "is unknown protocol name");
}
public static MqttVersion fromProtocolLevel(int protocolLevel) {
for (MqttVersion mv : values()) {
if (mv.level == (byte )protocolLevel) {
return mv;
}
}
throw new MqttUnacceptableProtocolVersionException(protocolLevel + "is unknown protocol level");
}
}
@@ -8,8 +8,7 @@
package win.liyufan.im;
import java.io.FileInputStream;
import java.io.IOException;
import java.io.*;
import java.util.Properties;
public class GitRepositoryState {
@@ -64,7 +63,9 @@ public class GitRepositoryState {
public static GitRepositoryState getGitRepositoryState() throws IOException {
Properties properties = new Properties();
try {
properties.load(new FileInputStream("config/git.properties"));
InputStream inputStream = new FileInputStream("config/git.properties");
BufferedReader bf = new BufferedReader(new InputStreamReader(inputStream));
properties.load(bf);
} catch (IOException e) {
}
@@ -14,6 +14,7 @@ public interface IMTopic {
String PullMessageTopic = "MP";
String NotifyMessageTopic = "MN";
String NotifyRecallMessageTopic = "RMN";
String BroadcastMessageTopic = "MBC";
String GetUserSettingTopic = "UG";
String PutUserSettingTopic = "UP";
@@ -65,6 +65,11 @@ public class MessageBundle implements Serializable {
}
public void setMessage(WFCMessage.Message message) {
this.fromUser = message.getFromUser();
this.type = message.getConversation().getType();
this.targetId = message.getConversation().getTarget();
this.line = message.getConversation().getLine();
this.message = message;
this.messageId = message.getMessageId();
}
}
@@ -59,4 +59,78 @@ public class Utility {
return macAddressBuilder.toString();
}
/**
* 格式化
*
* @param jsonStr
* @return
* @author lizhgb
* @Date 2015-10-14 下午1:17:35
* @Modified 2017-04-28 下午8:55:35
*/
public static String formatJson(String jsonStr) {
if (null == jsonStr || "".equals(jsonStr))
return "";
StringBuilder sb = new StringBuilder();
char last = '\0';
char current = '\0';
int indent = 0;
boolean isInQuotationMarks = false;
for (int i = 0; i < jsonStr.length(); i++) {
last = current;
current = jsonStr.charAt(i);
switch (current) {
case '"':
if (last != '\\'){
isInQuotationMarks = !isInQuotationMarks;
}
sb.append(current);
break;
case '{':
case '[':
sb.append(current);
if (!isInQuotationMarks) {
sb.append('\n');
indent++;
addIndentBlank(sb, indent);
}
break;
case '}':
case ']':
if (!isInQuotationMarks) {
sb.append('\n');
indent--;
addIndentBlank(sb, indent);
}
sb.append(current);
break;
case ',':
sb.append(current);
if (last != '\\' && !isInQuotationMarks) {
sb.append('\n');
addIndentBlank(sb, indent);
}
break;
default:
sb.append(current);
}
}
return sb.toString();
}
/**
* 添加space
*
* @param sb
* @param indent
* @author lizhgb
* @Date 2015-10-14 上午10:38:04
*/
private static void addIndentBlank(StringBuilder sb, int indent) {
for (int i = 0; i < indent; i++) {
sb.append('\t');
}
}
}
+1 -1
View File
@@ -15,7 +15,7 @@
<!--MySQL数据库驱动程序-->
<property name="driverClass">com.mysql.cj.jdbc.Driver</property>
<!--MySQL数据库地址-->
<property name="jdbcUrl">jdbc:mysql://localhost:3306/wfchat?useSSL=false&amp;serverTimezone=GMT&amp;allowPublicKeyRetrieval=true</property>
<property name="jdbcUrl">jdbc:mysql://localhost:3306/wfchat?useSSL=false&amp;serverTimezone=GMT&amp;allowPublicKeyRetrieval=true&amp;useUnicode=true&amp;characterEncoding=utf8</property>
<!--MySQL数据库用户名-->
<property name="user">root</property>
<!--MySQL数据库密码-->
+1 -1
View File
@@ -6,7 +6,7 @@
<relativePath>../</relativePath>
<artifactId>wildfirechat-parent</artifactId>
<groupId>cn.wildfirechat</groupId>
<version>0.21</version>
<version>0.22</version>
</parent>
<modelVersion>4.0.0</modelVersion>
+1 -1
View File
@@ -5,7 +5,7 @@
<parent>
<artifactId>wildfirechat-parent</artifactId>
<groupId>cn.wildfirechat</groupId>
<version>0.21</version>
<version>0.22</version>
</parent>
<modelVersion>4.0.0</modelVersion>
@@ -0,0 +1,59 @@
/*
* This file is part of the Wildfire Chat package.
* (c) Heavyrain2012 <[email protected]>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
package cn.wildfirechat.pojos;
import cn.wildfirechat.proto.ProtoConstants;
import cn.wildfirechat.proto.WFCMessage;
import io.netty.util.internal.StringUtil;
public class BroadMessageData {
private String sender;
private int line;
private MessagePayload payload;
public String getSender() {
return sender;
}
public void setSender(String sender) {
this.sender = sender;
}
public int getLine() {
return line;
}
public void setLine(int line) {
this.line = line;
}
public MessagePayload getPayload() {
return payload;
}
public void setPayload(MessagePayload payload) {
this.payload = payload;
}
public static boolean isValide(BroadMessageData sendMessageData) {
if(sendMessageData == null ||
StringUtil.isNullOrEmpty(sendMessageData.getSender()) ||
sendMessageData.getPayload() == null) {
return false;
}
return true;
}
public WFCMessage.Message toProtoMessage() {
return WFCMessage.Message.newBuilder().setFromUser(sender)
.setConversation(WFCMessage.Conversation.newBuilder().setType(ProtoConstants.ConversationType.ConversationType_Private).setTarget(sender).setLine(line))
.setContent(payload.toProtoMessageContent())
.build();
}
}
@@ -0,0 +1,38 @@
/*
* This file is part of the Wildfire Chat package.
* (c) Heavyrain2012 <[email protected]>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
package cn.wildfirechat.pojos;
public class BroadMessageResult {
private long messageUid;
private long count;
public BroadMessageResult() {
}
public BroadMessageResult(long messageUid, long count) {
this.messageUid = messageUid;
this.count = count;
}
public long getMessageUid() {
return messageUid;
}
public void setMessageUid(long messageUid) {
this.messageUid = messageUid;
}
public long getCount() {
return count;
}
public void setCount(long count) {
this.count = count;
}
}
@@ -25,6 +25,7 @@ public interface APIPath {
String Msg_Send = "/admin/message/send";
String Msg_Recall = "/admin/message/recall";
String Msg_Broadcast = "/admin/message/broadcast";
String Create_Group = "/admin/group/create";
String Group_Dismiss = "/admin/group/del";
@@ -56,7 +56,7 @@ public enum ErrorCode {
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 String msg;
+1 -1
View File
@@ -6,7 +6,7 @@
<!--<relativePath>../pom.xml</relativePath>-->
<artifactId>wildfirechat-parent</artifactId>
<groupId>cn.wildfirechat</groupId>
<version>0.21</version>
<version>0.22</version>
</parent>
<artifactId>distribution</artifactId>
@@ -15,7 +15,7 @@
<!--MySQL数据库驱动程序-->
<property name="driverClass">com.mysql.cj.jdbc.Driver</property>
<!--MySQL数据库地址-->
<property name="jdbcUrl">jdbc:mysql://localhost:3306/wfchat?useSSL=false&amp;serverTimezone=GMT&amp;allowPublicKeyRetrieval=true</property>
<property name="jdbcUrl">jdbc:mysql://localhost:3306/wfchat?useSSL=false&amp;serverTimezone=GMT&amp;allowPublicKeyRetrieval=true&amp;useUnicode=true&amp;characterEncoding=utf8</property>
<!--MySQL数据库用户名-->
<property name="user">root</property>
<!--MySQL数据库密码-->
@@ -80,8 +80,8 @@ JAVA_OPTS="$JAVA_OPTS -XX:+UseGCLogFileRotation"
JAVA_OPTS="$JAVA_OPTS -XX:NumberOfGCLogFiles=10"
JAVA_OPTS="$JAVA_OPTS -XX:GCLogFileSize=10M"
#JAVA_OPTS="$JAVA_OPTS -Xmx128M"
#JAVA_OPTS="$JAVA_OPTS -Xms128M"
JAVA_OPTS="$JAVA_OPTS -Xmx128M"
JAVA_OPTS="$JAVA_OPTS -Xms128M"
$JAVA -server $JAVA_OPTS $JAVA_OPTS_SCRIPT -Dlog4j.configuration="file:$LOG_FILE" -Dcom.mchange.v2.c3p0.cfg.xml="$C3P0_CONF_FILE" -Dhazelcast.configuration="file:$HZ_CONF_FILE" -Dwildfirechat.path="$WILDFIRECHAT_PATH" -cp "$WILDFIRECHAT_HOME/lib/*" cn.wildfirechat.server.Server
+1 -1
View File
@@ -12,7 +12,7 @@
<artifactId>wildfirechat-parent</artifactId>
<packaging>pom</packaging>
<version>0.21</version>
<version>0.22</version>
<name>Wildfire Chat</name>
<description>Wildfire Chat Server</description>
<inceptionYear>2019</inceptionYear>
+1 -1
View File
@@ -5,7 +5,7 @@
<parent>
<artifactId>wildfirechat-parent</artifactId>
<groupId>cn.wildfirechat</groupId>
<version>0.21</version>
<version>0.22</version>
</parent>
<modelVersion>4.0.0</modelVersion>
@@ -264,6 +264,14 @@ public class Main {
}
IMResult<BroadMessageResult> resultBroadcastMessage = MessageAdmin.broadcastMessage("user1", 0, payload);
if (resultBroadcastMessage != null && resultBroadcastMessage.getErrorCode() == ErrorCode.ERROR_CODE_SUCCESS) {
System.out.println("broad message success, send message to " + resultBroadcastMessage.getResult().getCount() + " users");
} else {
System.out.println("broad message failure");
System.exit(-1);
}
//初始化机器人API
RobotHttpUtils.init("http://localhost:18080", "robot1", "123456");
@@ -22,4 +22,13 @@ public class MessageAdmin {
messageData.setMessageUid(messageUid);
return AdminHttpUtils.httpJsonPost(path, messageData, Void.class);
}
public static IMResult<BroadMessageResult> broadcastMessage(String sender, int line, MessagePayload payload) throws Exception {
String path = APIPath.Msg_Broadcast;
BroadMessageData messageData = new BroadMessageData();
messageData.setSender(sender);
messageData.setLine(line);
messageData.setPayload(payload);
return AdminHttpUtils.httpJsonPost(path, messageData, BroadMessageResult.class);
}
}
+1 -1
View File
@@ -5,7 +5,7 @@
<relativePath>../</relativePath>
<artifactId>wildfirechat-parent</artifactId>
<groupId>cn.wildfirechat</groupId>
<version>0.21</version>
<version>0.22</version>
</parent>
<groupId>net.xmeter</groupId>
@@ -29,7 +29,7 @@ public class SendMessageSamplerUI extends AbstractSamplerGui implements Constant
*/
private static final long serialVersionUID = 2479085966683186422L;
private JLabeledChoice conversationTypeChoice;
private JLabeledChoice conversationTypeChoice = new JLabeledChoice("ConversationType:", new String[] { CONV_TYPE_SINGLE, CONV_TYPE_GROUP }, true, false);
private final JLabeledTextField target = new JLabeledTextField("Target:");
// private JCheckBox timestamp = new JCheckBox("Add timestamp in payload");
@@ -62,13 +62,11 @@ public class SendMessageSamplerUI extends AbstractSamplerGui implements Constant
JPanel optsPanelCon = new VerticalPanel();
optsPanelCon.setBorder(BorderFactory.createTitledBorder(BorderFactory.createEtchedBorder(), "Send message options"));
conversationTypeChoice = new JLabeledChoice("ConversationType:", new String[] { CONV_TYPE_SINGLE, CONV_TYPE_GROUP }, true, false);
conversationTypeChoice.addChangeListener(this);
JPanel optsPanel = new HorizontalPanel();
optsPanel.add(conversationTypeChoice);
optsPanel.add(target);
// optsPanel.add(timestamp);
optsPanelCon.add(optsPanel);
return optsPanelCon;
@@ -77,17 +75,11 @@ public class SendMessageSamplerUI extends AbstractSamplerGui implements Constant
private JPanel createPayload() {
JPanel optsPanelCon = new VerticalPanel();
optsPanelCon.setBorder(BorderFactory.createTitledBorder(BorderFactory.createEtchedBorder(), "Message Content"));
// JPanel horizon1 = new HorizontalPanel();
//
// stringLength.setVisible(true);
// horizon1.add(stringLength);
JPanel horizon2 = new VerticalPanel();
messagePanel.setVisible(true);
horizon2.add(messagePanel);
// optsPanelCon.add(horizon1);
optsPanelCon.add(horizon2);
return optsPanelCon;
}
@@ -135,12 +127,16 @@ public class SendMessageSamplerUI extends AbstractSamplerGui implements Constant
connUI.configure(sampler);
// if(sampler.getQOS().trim().indexOf(JMETER_VARIABLE_PREFIX) == -1){
this.conversationTypeChoice.setSelectedIndex(0);
if ("1".equals(sampler.getConvType())) {
this.conversationTypeChoice.setSelectedIndex(1);
} else {
this.conversationTypeChoice.setSelectedIndex(0);
}
// } else {
// this.conversationTypeChoice.setText(sampler.getQOS());
// }
this.target.setText(sampler.getTopic());
this.target.setText(sampler.getTarget());
// this.timestamp.setSelected(sampler.isAddTimestamp());
// if(MESSAGE_TYPE_STRING.equalsIgnoreCase(sampler.getMessageType())) {
// this.messageTypes.setSelectedIndex(0);
@@ -168,27 +164,7 @@ public class SendMessageSamplerUI extends AbstractSamplerGui implements Constant
connUI.setupSamplerProperties(sampler);
sampler.setTarget(this.target.getText());
// if(this.conversationTypeChoice.getText().indexOf(JMETER_VARIABLE_PREFIX) == -1) {
// int qos = QOS_0;
// try {
// qos = Integer.parseInt(this.conversationTypeChoice.getText());
// if (qos < QOS_0 || qos > QOS_2) {
// qos = QOS_0;
// logger.info("Invalid QoS value, set to default QoS value 0.");
// }
// } catch (Exception ex) {
// logger.info("Invalid QoS value, set to default QoS value 0.");
// qos = QOS_0;
// }
// sampler.setQOS(String.valueOf(qos));
// } else {
// sampler.setQOS(this.conversationTypeChoice.getText());
// }
// sampler.setAddTimestamp(this.timestamp.isSelected());
// sampler.setMessageType(this.messageTypes.getText());
// sampler.setMessageLength(this.stringLength.getText());
sampler.setConvType(this.conversationTypeChoice.getSelectedIndex() + "");
sampler.setMessage(this.sendMessage.getText());
}
@@ -199,11 +175,7 @@ public class SendMessageSamplerUI extends AbstractSamplerGui implements Constant
connUI.clearUI();
connUI.connNamePrefix.setText(DEFAULT_CONN_PREFIX_FOR_PUB);
this.target.setText(DEFAULT_TARGET);
this.conversationTypeChoice.setText(CONV_TYPE_SINGLE);
// this.timestamp.setSelected(false);
// this.messageTypes.setSelectedIndex(0);
// this.stringLength.setText(String.valueOf(DEFAULT_MESSAGE_FIX_LENGTH));
this.conversationTypeChoice.setSelectedIndex(0);
this.sendMessage.setText("");
}
}
@@ -189,7 +189,7 @@ public abstract class AbstractMQTTSampler extends AbstractSampler implements Con
protected String token;
protected boolean getToken(String userId, String clientId) {
String url = "http://" + getServer() + ":18080/admin/user/token";
String url = "http://" + getServer() + ":18080/admin/user/get_token";
String adminSecret = "123456";
HttpPost post = null;
try {
@@ -191,8 +191,11 @@ public class SendMessageSampler extends AbstractMQTTSampler implements ThreadLis
result.sampleStart();
final Object lock = new Object();
WFCMessage.Conversation conversation = WFCMessage.Conversation.newBuilder().setType(0).setTarget(getTarget()).setLine(0).build();
int converType = 0;
if ("1".equals(getConvType())) {
converType = 1;
}
WFCMessage.Conversation conversation = WFCMessage.Conversation.newBuilder().setType(converType).setTarget(getTarget()).setLine(0).build();
WFCMessage.MessageContent messageContent = WFCMessage.MessageContent.newBuilder().setType(1).setSearchableContent(getMessage()).build();
final List<Long> ret = new ArrayList<>();