카카오 알림톡, 친구톡 파일처리 로직 수정
This commit is contained in:
parent
7060c19665
commit
5205f7bbe3
@ -155,4 +155,19 @@ public final class KakaoMessage {
|
||||
|
||||
return fileBuffer;
|
||||
}
|
||||
|
||||
public static ByteBuffer makeJsonHeaderForDeliver(String path, String fileName) throws UnsupportedEncodingException {
|
||||
if (path == null || fileName == null) {
|
||||
return null;
|
||||
}
|
||||
File file = new File(path + fileName);
|
||||
if (file.exists() == false) {
|
||||
return null;
|
||||
}
|
||||
ByteBuffer fileHeadBuffer = ByteBuffer.allocate(MmsMessage.DELIVER_MMS_FILENAME_LENGTH + MmsMessage.DELIVER_MMS_FILESIZE_LENGTH);
|
||||
fileHeadBuffer.put(DELIVER_JSON_FILENAME_POSITION, fileName.getBytes(Packet.AGENT_CHARACTER_SET));
|
||||
fileHeadBuffer.put(DELIVER_JSON_FILESIZE_POSITION, String.valueOf(file.length()).getBytes(Packet.AGENT_CHARACTER_SET));
|
||||
|
||||
return fileHeadBuffer;
|
||||
}
|
||||
}
|
||||
|
||||
@ -4,7 +4,6 @@ import com.munjaon.client.model.MunjaonMsg;
|
||||
import com.munjaon.client.server.config.ErrorCode;
|
||||
import com.munjaon.client.server.packet.*;
|
||||
import com.munjaon.client.service.DatabaseTypeWorker;
|
||||
import com.munjaon.client.util.ByteUtil;
|
||||
import com.munjaon.client.util.MessageCheckUtil;
|
||||
import com.munjaon.client.util.MessageUtil;
|
||||
import org.json.simple.JSONObject;
|
||||
@ -417,20 +416,19 @@ public class CollectClientService extends Service {
|
||||
saveLog("[MESSAGE SEND] [... ...]");
|
||||
saveLog("[MESSAGE DATA : " + data.toString() + "]");
|
||||
|
||||
int mmsBufferLength = sendBuffer.capacity();
|
||||
socketChannel.write(sendBuffer);
|
||||
|
||||
if (file01HeadBuffer != null) {
|
||||
socketChannel.write(file01HeadBuffer);
|
||||
mmsImageSend(path + data.getFilename01());
|
||||
uploadFileSend(path + data.getFilename01());
|
||||
}
|
||||
if (file02HeadBuffer != null) {
|
||||
socketChannel.write(file02HeadBuffer);
|
||||
mmsImageSend(path + data.getFilename02());
|
||||
uploadFileSend(path + data.getFilename02());
|
||||
}
|
||||
if (file03HeadBuffer != null) {
|
||||
socketChannel.write(file03HeadBuffer);
|
||||
mmsImageSend(path + data.getFilename03());
|
||||
uploadFileSend(path + data.getFilename03());
|
||||
}
|
||||
|
||||
long MSG_SEND_TIME = System.currentTimeMillis();
|
||||
@ -460,9 +458,9 @@ public class CollectClientService extends Service {
|
||||
}
|
||||
}
|
||||
|
||||
private void mmsImageSend(String imagePath) throws IOException {
|
||||
private void uploadFileSend(String filePath) throws IOException {
|
||||
ByteBuffer buff = ByteBuffer.allocate(1024);
|
||||
Path src = Paths.get(imagePath);
|
||||
Path src = Paths.get(filePath);
|
||||
|
||||
try (FileChannel rc = FileChannel.open(src, StandardOpenOption.READ)) {
|
||||
int num;
|
||||
@ -609,6 +607,83 @@ public class CollectClientService extends Service {
|
||||
}
|
||||
|
||||
private void katMessageService(MunjaonMsg data) throws Exception {
|
||||
try {
|
||||
/* 이미지 경로 디폴트 경로 사용 여부 */
|
||||
String defaultYn = getProp("KAKAO", "DEFAULT_PATH_YN");
|
||||
/* Kakao Json 저장 경로 */
|
||||
String path = null;
|
||||
if ("Y".equals(defaultYn)) {
|
||||
path = System.getProperty("ROOTPATH") + File.separator + "kakaofile" + File.separator;
|
||||
} else {
|
||||
path = getProp("KAKAO", "FILEPATH") + File.separator;
|
||||
}
|
||||
/* 공통 메시지 유효성 체크 */
|
||||
int checkCommonCode = MessageCheckUtil.validateMessageForCommon(data);
|
||||
int checkMsgCode = MessageCheckUtil.validateMessageForKakao(data);
|
||||
int checkFileCode = MessageCheckUtil.validateJsonFile(path, data.getKakaoJsonFile());
|
||||
|
||||
if (checkCommonCode != ErrorCode.OK.getCode() || checkMsgCode != ErrorCode.OK.getCode() || checkFileCode != ErrorCode.OK.getCode()) {
|
||||
saveLog("[MESSAGE FILTER] [COMMON_CODE : " + checkCommonCode + "] [MSG_CODE : " + checkMsgCode + "] [JSON_FILE_CODE : " + checkFileCode + "]");
|
||||
saveLog("[MESSAGE DATA : " + data.toString() + "]");
|
||||
/* 전송처리 */
|
||||
worker.updateToDeliver(data.getMsgId());
|
||||
/* 실패처리 */
|
||||
MunjaonMsg errorMsg = null;
|
||||
if (checkCommonCode != ErrorCode.OK.getCode()) {
|
||||
errorMsg = MessageCheckUtil.setReportMessage(data.getMsgId(), "00", String.valueOf(checkCommonCode), MessageUtil.getTime(), "ETC");
|
||||
}else if (checkMsgCode != ErrorCode.OK.getCode()) {
|
||||
errorMsg = MessageCheckUtil.setReportMessage(data.getMsgId(), "00", String.valueOf(checkMsgCode), MessageUtil.getTime(), "ETC");
|
||||
} else {
|
||||
errorMsg = MessageCheckUtil.setReportMessage(data.getMsgId(), "00", String.valueOf(checkFileCode), MessageUtil.getTime(), "ETC");
|
||||
}
|
||||
worker.updateToReport(errorMsg);
|
||||
/* 처리완료 */
|
||||
return;
|
||||
}
|
||||
|
||||
/* 정상인 경우 메시지 전송 */
|
||||
ByteBuffer sendBuffer = ByteBuffer.allocate(Header.HEADER_LENGTH + KakaoMessage.DELIVER_KAKAO_BODY_LENGTH);
|
||||
ByteBuffer recvBuffer = ByteBuffer.allocate(Header.HEADER_LENGTH + KakaoMessage.DELIVER_KAKAO_ACK_BODY_LENGTH);
|
||||
|
||||
Header.putHeader(sendBuffer, Header.COMMAND_DELIVER, KakaoMessage.DELIVER_KAKAO_BODY_LENGTH);
|
||||
KakaoMessage.makeDataForDeliver(sendBuffer, data);
|
||||
saveLog("[MESSAGE SEND] [... ...]");
|
||||
saveLog("[MESSAGE DATA : " + data.toString() + "]");
|
||||
|
||||
socketChannel.write(sendBuffer);
|
||||
|
||||
/* 파일 전송 */
|
||||
ByteBuffer fileHeadBuffer = KakaoMessage.makeJsonHeaderForDeliver(path, data.getKakaoJsonFile());
|
||||
socketChannel.write(fileHeadBuffer);
|
||||
uploadFileSend(path + data.getKakaoJsonFile());
|
||||
|
||||
long MSG_SEND_TIME = System.currentTimeMillis();
|
||||
while (true) {
|
||||
if (System.currentTimeMillis() - MSG_SEND_TIME >= Packet.LIMIT_PACKET_SEND_TIMEOUT) {
|
||||
saveLog("[messageSendTimeOut : Expired ... ... ... ... ... ... ...]");
|
||||
throw new Exception("messageSendTimeOut : Expired ... ... ... ... ... ... ...");
|
||||
}
|
||||
int recvCount = socketChannel.read(recvBuffer);
|
||||
if (recvCount == -1) {
|
||||
saveLog("[MESSAGE SEND] [FAIL] [SOCKET IS CLOSED]");
|
||||
throw new Exception("DELIVER ERROR");
|
||||
} else if (recvCount > 0) {
|
||||
setDeliverMsgId(data.getMsgId());
|
||||
// worker.updateToDeliver(data.getMsgId());
|
||||
saveLog("[MESSAGE SEND] [SUCCESS]");
|
||||
lastPacketSendTime = System.currentTimeMillis();
|
||||
break;
|
||||
}
|
||||
}
|
||||
} catch (Exception e) {
|
||||
saveSystemLog("ERROR [" + e.getMessage() + "]");
|
||||
saveSystemLog("ERROR DETAIL");
|
||||
saveSystemLog(e.toString());
|
||||
throw new Exception(e);
|
||||
}
|
||||
}
|
||||
|
||||
private void katMessageService_bak(MunjaonMsg data) throws Exception {
|
||||
try {
|
||||
/* 이미지 경로 디폴트 경로 사용 여부 */
|
||||
String defaultYn = getProp("KAKAO", "DEFAULT_PATH_YN");
|
||||
@ -686,6 +761,82 @@ public class CollectClientService extends Service {
|
||||
}
|
||||
|
||||
private void kftMessageService(MunjaonMsg data) throws Exception {
|
||||
try {
|
||||
/* 이미지 경로 디폴트 경로 사용 여부 */
|
||||
String defaultYn = getProp("KAKAO", "DEFAULT_PATH_YN");
|
||||
/* Kakao Json 저장 경로 */
|
||||
String path = null;
|
||||
if ("Y".equals(defaultYn)) {
|
||||
path = System.getProperty("ROOTPATH") + File.separator + "kakaofile" + File.separator;
|
||||
} else {
|
||||
path = getProp("KAKAO", "FILEPATH") + File.separator;
|
||||
}
|
||||
/* 공통 메시지 유효성 체크 */
|
||||
int checkCommonCode = MessageCheckUtil.validateMessageForCommon(data);
|
||||
int checkMsgCode = MessageCheckUtil.validateMessageForKakao(data);
|
||||
int checkFileCode = MessageCheckUtil.validateJsonFile(path, data.getKakaoJsonFile());
|
||||
if (checkCommonCode != ErrorCode.OK.getCode() || checkMsgCode != ErrorCode.OK.getCode() || checkFileCode != ErrorCode.OK.getCode()) {
|
||||
saveLog("[MESSAGE FILTER] [COMMON_CODE : " + checkCommonCode + "] [MSG_CODE : " + checkMsgCode + "] [JSON_FILE_CODE : " + checkFileCode + "]");
|
||||
saveLog("[MESSAGE DATA : " + data.toString() + "]");
|
||||
/* 전송처리 */
|
||||
worker.updateToDeliver(data.getMsgId());
|
||||
/* 실패처리 */
|
||||
MunjaonMsg errorMsg = null;
|
||||
if (checkCommonCode != ErrorCode.OK.getCode()) {
|
||||
errorMsg = MessageCheckUtil.setReportMessage(data.getMsgId(), "00", String.valueOf(checkCommonCode), MessageUtil.getTime(), "ETC");
|
||||
}else if (checkMsgCode != ErrorCode.OK.getCode()) {
|
||||
errorMsg = MessageCheckUtil.setReportMessage(data.getMsgId(), "00", String.valueOf(checkMsgCode), MessageUtil.getTime(), "ETC");
|
||||
} else {
|
||||
errorMsg = MessageCheckUtil.setReportMessage(data.getMsgId(), "00", String.valueOf(checkFileCode), MessageUtil.getTime(), "ETC");
|
||||
}
|
||||
worker.updateToReport(errorMsg);
|
||||
/* 처리완료 */
|
||||
return;
|
||||
}
|
||||
|
||||
/* 정상인 경우 메시지 전송 */
|
||||
ByteBuffer sendBuffer = ByteBuffer.allocate(Header.HEADER_LENGTH + KakaoMessage.DELIVER_KAKAO_BODY_LENGTH);
|
||||
ByteBuffer recvBuffer = ByteBuffer.allocate(Header.HEADER_LENGTH + KakaoMessage.DELIVER_KAKAO_ACK_BODY_LENGTH);
|
||||
|
||||
Header.putHeader(sendBuffer, Header.COMMAND_DELIVER, KakaoMessage.DELIVER_KAKAO_BODY_LENGTH);
|
||||
KakaoMessage.makeDataForDeliver(sendBuffer, data);
|
||||
saveLog("[MESSAGE SEND] [... ...]");
|
||||
saveLog("[MESSAGE DATA : " + data.toString() + "]");
|
||||
|
||||
socketChannel.write(sendBuffer);
|
||||
|
||||
/* 파일 전송 */
|
||||
ByteBuffer fileHeadBuffer = KakaoMessage.makeJsonHeaderForDeliver(path, data.getKakaoJsonFile());
|
||||
socketChannel.write(fileHeadBuffer);
|
||||
uploadFileSend(path + data.getKakaoJsonFile());
|
||||
|
||||
long MSG_SEND_TIME = System.currentTimeMillis();
|
||||
while (true) {
|
||||
if (System.currentTimeMillis() - MSG_SEND_TIME >= Packet.LIMIT_PACKET_SEND_TIMEOUT) {
|
||||
saveLog("[messageSendTimeOut : Expired ... ... ... ... ... ... ...]");
|
||||
throw new Exception("messageSendTimeOut : Expired ... ... ... ... ... ... ...");
|
||||
}
|
||||
int recvCount = socketChannel.read(recvBuffer);
|
||||
if (recvCount == -1) {
|
||||
saveLog("[MESSAGE SEND] [FAIL] [SOCKET IS CLOSED]");
|
||||
throw new Exception("DELIVER ERROR");
|
||||
} else if (recvCount > 0) {
|
||||
setDeliverMsgId(data.getMsgId());
|
||||
// worker.updateToDeliver(data.getMsgId());
|
||||
saveLog("[MESSAGE SEND] [SUCCESS]");
|
||||
lastPacketSendTime = System.currentTimeMillis();
|
||||
break;
|
||||
}
|
||||
}
|
||||
} catch (Exception e) {
|
||||
saveSystemLog("ERROR [" + e.getMessage() + "]");
|
||||
saveSystemLog("ERROR DETAIL");
|
||||
saveSystemLog(e.toString());
|
||||
throw new Exception(e);
|
||||
}
|
||||
}
|
||||
|
||||
private void kftMessageService_bak(MunjaonMsg data) throws Exception {
|
||||
try {
|
||||
/* 이미지 경로 디폴트 경로 사용 여부 */
|
||||
String defaultYn = getProp("KAKAO", "DEFAULT_PATH_YN");
|
||||
|
||||
Loading…
Reference in New Issue
Block a user