인코딩캐릭터셋 변경, 리포트 프로세스 수정
This commit is contained in:
parent
c38fbfa1ff
commit
23c9b75bc7
@ -1,5 +1,6 @@
|
||||
package com.munjaon.client.server.packet;
|
||||
|
||||
import java.io.UnsupportedEncodingException;
|
||||
import java.nio.ByteBuffer;
|
||||
import java.util.Arrays;
|
||||
|
||||
@ -19,32 +20,32 @@ public final class Bind {
|
||||
|
||||
public static final String ENCRYPTION = "0";
|
||||
|
||||
public static ByteBuffer makeBindBuffer(String id, String pwd) {
|
||||
public static ByteBuffer makeBindBuffer(String id, String pwd) throws UnsupportedEncodingException {
|
||||
ByteBuffer buffer = ByteBuffer.allocate(Header.HEADER_LENGTH + BIND_BODY_LENGTH);
|
||||
Packet.setDefaultByte(buffer);
|
||||
Header.putHeader(buffer, Header.COMMAND_BIND, BIND_BODY_LENGTH);
|
||||
/* ID */
|
||||
if (id != null) {
|
||||
buffer.put(BIND_ID_POSITION, id.getBytes());
|
||||
buffer.put(BIND_ID_POSITION, id.getBytes(Packet.AGENT_CHARACTER_SET));
|
||||
}
|
||||
/* PWD */
|
||||
if (pwd != null) {
|
||||
buffer.put(BIND_PWD_POSITION, pwd.getBytes());
|
||||
buffer.put(BIND_PWD_POSITION, pwd.getBytes(Packet.AGENT_CHARACTER_SET));
|
||||
}
|
||||
/* ENCRYPTION */
|
||||
buffer.put(BIND_ENCRYPTION_POSITION, ENCRYPTION.getBytes());
|
||||
buffer.put(BIND_ENCRYPTION_POSITION, ENCRYPTION.getBytes(Packet.AGENT_CHARACTER_SET));
|
||||
// buffer.limit(buffer.capacity());
|
||||
|
||||
return buffer;
|
||||
}
|
||||
|
||||
public static ByteBuffer makeBindAckBuffer(String resultCode) {
|
||||
public static ByteBuffer makeBindAckBuffer(String resultCode) throws UnsupportedEncodingException {
|
||||
ByteBuffer buffer = ByteBuffer.allocate(Header.HEADER_LENGTH + BIND_ACK_BODY_LENGTH);
|
||||
Packet.setDefaultByte(buffer);
|
||||
Header.putHeader(buffer, Header.COMMAND_BIND_ACK, BIND_ACK_BODY_LENGTH);
|
||||
/* resultCode */
|
||||
if (resultCode != null) {
|
||||
buffer.put(BIND_ACK_RESULT_CODE_POSITION, resultCode.getBytes());
|
||||
buffer.put(BIND_ACK_RESULT_CODE_POSITION, resultCode.getBytes(Packet.AGENT_CHARACTER_SET));
|
||||
}
|
||||
|
||||
return buffer;
|
||||
|
||||
@ -2,6 +2,7 @@ package com.munjaon.client.server.packet;
|
||||
|
||||
import com.munjaon.client.util.CommonUtil;
|
||||
|
||||
import java.io.UnsupportedEncodingException;
|
||||
import java.nio.ByteBuffer;
|
||||
import java.util.Arrays;
|
||||
|
||||
@ -34,11 +35,11 @@ public final class CommonMessage {
|
||||
public static final int DELIVER_ACK_RESULT_LENGTH = 1;
|
||||
public static final int DELIVER_ACK_RESULT_POSITION = DELIVER_ACK_MESSAGE_ID_POSITION + DELIVER_ACK_MESSAGE_ID_LENGTH;
|
||||
|
||||
public static void putMessageIdForDeliver(ByteBuffer buffer, String messageId) {
|
||||
public static void putMessageIdForDeliver(ByteBuffer buffer, String messageId) throws UnsupportedEncodingException {
|
||||
if (buffer == null || messageId == null) {
|
||||
return;
|
||||
}
|
||||
buffer.put(DELIVER_MESSAGE_ID_POSITION, messageId.getBytes());
|
||||
buffer.put(DELIVER_MESSAGE_ID_POSITION, messageId.getBytes(Packet.AGENT_CHARACTER_SET));
|
||||
}
|
||||
public static String getMessageIdForDeliver(ByteBuffer buffer) {
|
||||
if (buffer == null) {
|
||||
@ -52,12 +53,12 @@ public final class CommonMessage {
|
||||
return Packet.getString(destArray);
|
||||
}
|
||||
|
||||
public static void putSenderForDeliver(ByteBuffer buffer, String sender) {
|
||||
public static void putSenderForDeliver(ByteBuffer buffer, String sender) throws UnsupportedEncodingException {
|
||||
if (buffer == null || sender == null) {
|
||||
return;
|
||||
}
|
||||
sender = CommonUtil.cutString(CommonUtil.doNumber(sender), DELIVER_SENDER_LENGTH);
|
||||
buffer.put(DELIVER_SENDER_POSITION, sender.getBytes());
|
||||
buffer.put(DELIVER_SENDER_POSITION, sender.getBytes(Packet.AGENT_CHARACTER_SET));
|
||||
}
|
||||
public static String getSenderForDeliver(ByteBuffer buffer) {
|
||||
if (buffer == null) {
|
||||
@ -71,12 +72,12 @@ public final class CommonMessage {
|
||||
return Packet.getString(destArray);
|
||||
}
|
||||
|
||||
public static void putReceiverForDeliver(ByteBuffer buffer, String receiver) {
|
||||
public static void putReceiverForDeliver(ByteBuffer buffer, String receiver) throws UnsupportedEncodingException {
|
||||
if (buffer == null || receiver == null) {
|
||||
return;
|
||||
}
|
||||
receiver = CommonUtil.cutString(CommonUtil.doNumber(receiver), DELIVER_RECEIVER_LENGTH);
|
||||
buffer.put(DELIVER_RECEIVER_POSITION, receiver.getBytes());
|
||||
buffer.put(DELIVER_RECEIVER_POSITION, receiver.getBytes(Packet.AGENT_CHARACTER_SET));
|
||||
}
|
||||
public static String getReceiverForDeliver(ByteBuffer buffer) {
|
||||
if (buffer == null) {
|
||||
@ -90,11 +91,11 @@ public final class CommonMessage {
|
||||
return Packet.getString(destArray);
|
||||
}
|
||||
|
||||
public static void putReserveTimeForDeliver(ByteBuffer buffer, String reserveTime) {
|
||||
public static void putReserveTimeForDeliver(ByteBuffer buffer, String reserveTime) throws UnsupportedEncodingException {
|
||||
if (buffer == null || reserveTime == null) {
|
||||
return;
|
||||
}
|
||||
buffer.put(DELIVER_RESERVE_TIME_POSITION, reserveTime.getBytes());
|
||||
buffer.put(DELIVER_RESERVE_TIME_POSITION, reserveTime.getBytes(Packet.AGENT_CHARACTER_SET));
|
||||
}
|
||||
public static String getReserveTimeForDeliver(ByteBuffer buffer) {
|
||||
if (buffer == null) {
|
||||
@ -108,11 +109,11 @@ public final class CommonMessage {
|
||||
return Packet.getString(destArray);
|
||||
}
|
||||
|
||||
public static void putRequestTimeForDeliver(ByteBuffer buffer, String requestTime) {
|
||||
public static void putRequestTimeForDeliver(ByteBuffer buffer, String requestTime) throws UnsupportedEncodingException {
|
||||
if (buffer == null || requestTime == null) {
|
||||
return;
|
||||
}
|
||||
buffer.put(DELIVER_REQUEST_TIME_POSITION, requestTime.getBytes());
|
||||
buffer.put(DELIVER_REQUEST_TIME_POSITION, requestTime.getBytes(Packet.AGENT_CHARACTER_SET));
|
||||
}
|
||||
public static String getRequestTimeForDeliver(ByteBuffer buffer) {
|
||||
if (buffer == null) {
|
||||
@ -126,11 +127,11 @@ public final class CommonMessage {
|
||||
return Packet.getString(destArray);
|
||||
}
|
||||
|
||||
public static void putMsgTypeForDeliver(ByteBuffer buffer, String msgType) {
|
||||
public static void putMsgTypeForDeliver(ByteBuffer buffer, String msgType) throws UnsupportedEncodingException {
|
||||
if (buffer == null || msgType == null) {
|
||||
return;
|
||||
}
|
||||
buffer.put(DELIVER_MSG_TYPE_POSITION, msgType.getBytes());
|
||||
buffer.put(DELIVER_MSG_TYPE_POSITION, msgType.getBytes(Packet.AGENT_CHARACTER_SET));
|
||||
}
|
||||
public static String getMsgTypeForDeliver(ByteBuffer buffer) {
|
||||
if (buffer == null) {
|
||||
@ -145,11 +146,11 @@ public final class CommonMessage {
|
||||
}
|
||||
|
||||
|
||||
public static void putMessageIdForDeliverAck(ByteBuffer buffer, String messageId) {
|
||||
public static void putMessageIdForDeliverAck(ByteBuffer buffer, String messageId) throws UnsupportedEncodingException {
|
||||
if (buffer == null || messageId == null) {
|
||||
return;
|
||||
}
|
||||
buffer.put(DELIVER_ACK_MESSAGE_ID_POSITION, messageId.getBytes());
|
||||
buffer.put(DELIVER_ACK_MESSAGE_ID_POSITION, messageId.getBytes(Packet.AGENT_CHARACTER_SET));
|
||||
}
|
||||
public static String getMessageIdForDeliverAck(ByteBuffer buffer) {
|
||||
if (buffer == null) {
|
||||
@ -163,11 +164,11 @@ public final class CommonMessage {
|
||||
return Packet.getString(destArray);
|
||||
}
|
||||
|
||||
public static void putResultForDeliverAck(ByteBuffer buffer, String result) {
|
||||
public static void putResultForDeliverAck(ByteBuffer buffer, String result) throws UnsupportedEncodingException {
|
||||
if (buffer == null || result == null) {
|
||||
return;
|
||||
}
|
||||
buffer.put(DELIVER_ACK_RESULT_POSITION, result.getBytes());
|
||||
buffer.put(DELIVER_ACK_RESULT_POSITION, result.getBytes(Packet.AGENT_CHARACTER_SET));
|
||||
}
|
||||
public static String getResultForDeliverAck(ByteBuffer buffer) {
|
||||
if (buffer == null) {
|
||||
|
||||
@ -2,6 +2,7 @@ package com.munjaon.client.server.packet;
|
||||
|
||||
import com.munjaon.client.util.ByteUtil;
|
||||
|
||||
import java.io.UnsupportedEncodingException;
|
||||
import java.nio.ByteBuffer;
|
||||
import java.util.Arrays;
|
||||
|
||||
@ -40,11 +41,11 @@ public final class Header {
|
||||
public static final int BODY_REPORT_LENGTH = 58;
|
||||
public static final int BODY_REPORT_ACK_LENGTH = 1;
|
||||
|
||||
public static void putVersion(final ByteBuffer buffer) {
|
||||
public static void putVersion(final ByteBuffer buffer) throws UnsupportedEncodingException {
|
||||
if (buffer == null) {
|
||||
return;
|
||||
}
|
||||
buffer.put(VERSION_POSITION, VERSION.getBytes());
|
||||
buffer.put(VERSION_POSITION, VERSION.getBytes(Packet.AGENT_CHARACTER_SET));
|
||||
}
|
||||
public static String getVersion(final ByteBuffer buffer) {
|
||||
if (buffer == null) {
|
||||
@ -58,11 +59,11 @@ public final class Header {
|
||||
return Packet.getString(destArray);
|
||||
}
|
||||
|
||||
public static void putCommand(final ByteBuffer buffer, String command) {
|
||||
public static void putCommand(final ByteBuffer buffer, String command) throws UnsupportedEncodingException {
|
||||
if (buffer == null) {
|
||||
return;
|
||||
}
|
||||
buffer.put(COMMAND_POSITION, command.getBytes());
|
||||
buffer.put(COMMAND_POSITION, command.getBytes(Packet.AGENT_CHARACTER_SET));
|
||||
}
|
||||
public static String getCommand(final ByteBuffer buffer) {
|
||||
if (buffer == null) {
|
||||
@ -76,7 +77,7 @@ public final class Header {
|
||||
return Packet.getString(destArray);
|
||||
}
|
||||
|
||||
public static void putBodyLength(final ByteBuffer buffer, int bodyLength) {
|
||||
public static void putBodyLength(final ByteBuffer buffer, int bodyLength) throws UnsupportedEncodingException {
|
||||
putBodyLength(buffer, Integer.toString(bodyLength));
|
||||
}
|
||||
public static String getBodyLength(final ByteBuffer buffer) {
|
||||
@ -91,18 +92,18 @@ public final class Header {
|
||||
return Packet.getString(destArray);
|
||||
}
|
||||
|
||||
public static void putBodyLength(final ByteBuffer buffer, String bodyLength) {
|
||||
public static void putBodyLength(final ByteBuffer buffer, String bodyLength) throws UnsupportedEncodingException {
|
||||
if (buffer == null) {
|
||||
return;
|
||||
}
|
||||
System.out.println(ByteUtil.byteToHex(bodyLength.getBytes(), true));
|
||||
// System.out.println(ByteUtil.byteToHex(bodyLength.getBytes(), true));
|
||||
|
||||
buffer.put(BODY_POSITION, bodyLength.getBytes());
|
||||
buffer.put(BODY_POSITION, bodyLength.getBytes(Packet.AGENT_CHARACTER_SET));
|
||||
}
|
||||
public static void putHeader(final ByteBuffer buffer, String command, int bodyLength) {
|
||||
public static void putHeader(final ByteBuffer buffer, String command, int bodyLength) throws UnsupportedEncodingException {
|
||||
putHeader(buffer, command, Integer.toString(bodyLength));
|
||||
}
|
||||
public static void putHeader(final ByteBuffer buffer, String command, String bodyLength) {
|
||||
public static void putHeader(final ByteBuffer buffer, String command, String bodyLength) throws UnsupportedEncodingException {
|
||||
putVersion(buffer);
|
||||
putCommand(buffer, command);
|
||||
putBodyLength(buffer, bodyLength);
|
||||
|
||||
@ -5,6 +5,7 @@ import com.munjaon.client.util.CommonUtil;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
import java.io.UnsupportedEncodingException;
|
||||
import java.nio.ByteBuffer;
|
||||
import java.nio.file.Files;
|
||||
|
||||
@ -34,12 +35,12 @@ public final class KakaoMessage {
|
||||
public static final int DELIVER_KAKAO_TEMPLATE_CODE_LENGTH = 64;
|
||||
public static final int DELIVER_KAKAO_TEMPLATE_CODE_POSITION = DELIVER_KAKAO_SENDER_KEY_POSITION + DELIVER_KAKAO_SENDER_KEY_LENGTH;
|
||||
|
||||
public static void putSubjectForDeliver(ByteBuffer buffer, String subject) {
|
||||
public static void putSubjectForDeliver(ByteBuffer buffer, String subject) throws UnsupportedEncodingException {
|
||||
if (buffer == null || subject == null) {
|
||||
return;
|
||||
}
|
||||
subject = CommonUtil.cutString(subject, DELIVER_SUBJECT_LENGTH);
|
||||
buffer.put(DELIVER_SUBJECT_POSITION, subject.getBytes());
|
||||
buffer.put(DELIVER_SUBJECT_POSITION, subject.getBytes(Packet.AGENT_CHARACTER_SET));
|
||||
}
|
||||
public static String getSubjectForDeliver(ByteBuffer buffer) {
|
||||
if (buffer == null) {
|
||||
@ -53,12 +54,12 @@ public final class KakaoMessage {
|
||||
return Packet.getString(destArray);
|
||||
}
|
||||
|
||||
public static void putMessageForDeliver(ByteBuffer buffer, String message) {
|
||||
public static void putMessageForDeliver(ByteBuffer buffer, String message) throws UnsupportedEncodingException {
|
||||
if (buffer == null || message == null) {
|
||||
return;
|
||||
}
|
||||
message = CommonUtil.cutString(message, DELIVER_MESSAGE_LENGTH);
|
||||
buffer.put(DELIVER_MESSAGE_POSITION, message.getBytes());
|
||||
buffer.put(DELIVER_MESSAGE_POSITION, message.getBytes(Packet.AGENT_CHARACTER_SET));
|
||||
}
|
||||
public static String getMessageForDeliver(ByteBuffer buffer) {
|
||||
if (buffer == null) {
|
||||
@ -71,12 +72,12 @@ public final class KakaoMessage {
|
||||
|
||||
return Packet.getString(destArray);
|
||||
}
|
||||
public static void putKakaoSenderKeyForDeliver(ByteBuffer buffer, String kakaoSenderKey) {
|
||||
public static void putKakaoSenderKeyForDeliver(ByteBuffer buffer, String kakaoSenderKey) throws UnsupportedEncodingException {
|
||||
if (buffer == null || kakaoSenderKey == null) {
|
||||
return;
|
||||
}
|
||||
kakaoSenderKey = CommonUtil.cutString(kakaoSenderKey, DELIVER_KAKAO_SENDER_KEY_LENGTH);
|
||||
buffer.put(DELIVER_KAKAO_SENDER_KEY_POSITION, kakaoSenderKey.getBytes());
|
||||
buffer.put(DELIVER_KAKAO_SENDER_KEY_POSITION, kakaoSenderKey.getBytes(Packet.AGENT_CHARACTER_SET));
|
||||
}
|
||||
public static String getKakaoSenderKeyForDeliver(ByteBuffer buffer) {
|
||||
if (buffer == null) {
|
||||
@ -89,12 +90,12 @@ public final class KakaoMessage {
|
||||
|
||||
return Packet.getString(destArray);
|
||||
}
|
||||
public static void putKakaoTemplateCodeForDeliver(ByteBuffer buffer, String kakaoTemplateCode) {
|
||||
public static void putKakaoTemplateCodeForDeliver(ByteBuffer buffer, String kakaoTemplateCode) throws UnsupportedEncodingException {
|
||||
if (buffer == null || kakaoTemplateCode == null) {
|
||||
return;
|
||||
}
|
||||
kakaoTemplateCode = CommonUtil.cutString(kakaoTemplateCode, DELIVER_KAKAO_TEMPLATE_CODE_LENGTH);
|
||||
buffer.put(DELIVER_KAKAO_TEMPLATE_CODE_POSITION, kakaoTemplateCode.getBytes());
|
||||
buffer.put(DELIVER_KAKAO_TEMPLATE_CODE_POSITION, kakaoTemplateCode.getBytes(Packet.AGENT_CHARACTER_SET));
|
||||
}
|
||||
public static String getKakaoTemplateCodeForDeliver(ByteBuffer buffer) {
|
||||
if (buffer == null) {
|
||||
@ -107,7 +108,7 @@ public final class KakaoMessage {
|
||||
|
||||
return Packet.getString(destArray);
|
||||
}
|
||||
public static void makeDataForDeliver(ByteBuffer buffer, MunjaonMsg data) {
|
||||
public static void makeDataForDeliver(ByteBuffer buffer, MunjaonMsg data) throws UnsupportedEncodingException {
|
||||
if (buffer == null || data == null) {
|
||||
return;
|
||||
}
|
||||
@ -133,7 +134,7 @@ public final class KakaoMessage {
|
||||
putKakaoTemplateCodeForDeliver(buffer, data.getKakaoTemplateCode());
|
||||
}
|
||||
|
||||
public static ByteBuffer makeJsonForDeliver(String path, String fileName) {
|
||||
public static ByteBuffer makeJsonForDeliver(String path, String fileName) throws UnsupportedEncodingException {
|
||||
if (path == null || fileName == null) {
|
||||
return null;
|
||||
}
|
||||
@ -142,8 +143,8 @@ public final class KakaoMessage {
|
||||
return null;
|
||||
}
|
||||
ByteBuffer fileHeadBuffer = ByteBuffer.allocate(MmsMessage.DELIVER_MMS_FILENAME_LENGTH + MmsMessage.DELIVER_MMS_FILESIZE_LENGTH);
|
||||
fileHeadBuffer.put(DELIVER_JSON_FILENAME_POSITION, fileName.getBytes());
|
||||
fileHeadBuffer.put(DELIVER_JSON_FILESIZE_POSITION, String.valueOf(file.length()).getBytes());
|
||||
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));
|
||||
ByteBuffer fileBodyBuffer = ByteBuffer.allocate((int) file.length());
|
||||
ByteBuffer fileBuffer = null;
|
||||
try {
|
||||
|
||||
@ -1,5 +1,6 @@
|
||||
package com.munjaon.client.server.packet;
|
||||
|
||||
import java.io.UnsupportedEncodingException;
|
||||
import java.nio.ByteBuffer;
|
||||
|
||||
public final class LinkCheck {
|
||||
@ -11,20 +12,20 @@ public final class LinkCheck {
|
||||
public static String LINK_CHECK_VALUE = "100";
|
||||
public static String LINK_CHECK_ACK_VALUE = "100";
|
||||
|
||||
public static ByteBuffer makeLinkCheckBuffer() {
|
||||
public static ByteBuffer makeLinkCheckBuffer() throws UnsupportedEncodingException {
|
||||
ByteBuffer buffer = ByteBuffer.allocate(Header.HEADER_LENGTH + LINK_CHECK_BODY_LENGTH);
|
||||
Packet.setDefaultByte(buffer);
|
||||
Header.putHeader(buffer, Header.COMMAND_LINK_CHECK, LINK_CHECK_BODY_LENGTH);
|
||||
buffer.put(LINK_CHECK_BODY_POSITION, LINK_CHECK_VALUE.getBytes());
|
||||
buffer.put(LINK_CHECK_BODY_POSITION, LINK_CHECK_VALUE.getBytes(Packet.AGENT_CHARACTER_SET));
|
||||
|
||||
return buffer;
|
||||
}
|
||||
|
||||
public static ByteBuffer makeLinkCheckAckBuffer() {
|
||||
public static ByteBuffer makeLinkCheckAckBuffer() throws UnsupportedEncodingException {
|
||||
ByteBuffer buffer = ByteBuffer.allocate(Header.HEADER_LENGTH + LINK_CHECK_ACK_BODY_LENGTH);
|
||||
Packet.setDefaultByte(buffer);
|
||||
Header.putHeader(buffer, Header.COMMAND_LINK_CHECK_ACK, LINK_CHECK_ACK_BODY_LENGTH);
|
||||
buffer.put(LINK_CHECK_ACK_BODY_POSITION, LINK_CHECK_ACK_VALUE.getBytes());
|
||||
buffer.put(LINK_CHECK_ACK_BODY_POSITION, LINK_CHECK_ACK_VALUE.getBytes(Packet.AGENT_CHARACTER_SET));
|
||||
|
||||
return buffer;
|
||||
}
|
||||
|
||||
@ -3,6 +3,7 @@ package com.munjaon.client.server.packet;
|
||||
import com.munjaon.client.model.MunjaonMsg;
|
||||
import com.munjaon.client.util.CommonUtil;
|
||||
|
||||
import java.io.UnsupportedEncodingException;
|
||||
import java.nio.ByteBuffer;
|
||||
|
||||
public final class LmsMessage {
|
||||
@ -17,12 +18,12 @@ public final class LmsMessage {
|
||||
public static final int DELIVER_MESSAGE_LENGTH = 2000;
|
||||
public static final int DELIVER_MESSAGE_POSITION = DELIVER_SUBJECT_POSITION + DELIVER_SUBJECT_LENGTH;
|
||||
|
||||
public static void putSubjectForDeliver(ByteBuffer buffer, String subject) {
|
||||
public static void putSubjectForDeliver(ByteBuffer buffer, String subject) throws UnsupportedEncodingException {
|
||||
if (buffer == null || subject == null) {
|
||||
return;
|
||||
}
|
||||
subject = CommonUtil.cutString(subject, DELIVER_SUBJECT_LENGTH);
|
||||
buffer.put(DELIVER_SUBJECT_POSITION, subject.getBytes());
|
||||
buffer.put(DELIVER_SUBJECT_POSITION, subject.getBytes(Packet.AGENT_CHARACTER_SET));
|
||||
}
|
||||
public static String getSubjectForDeliver(ByteBuffer buffer) {
|
||||
if (buffer == null) {
|
||||
@ -36,12 +37,12 @@ public final class LmsMessage {
|
||||
return Packet.getString(destArray);
|
||||
}
|
||||
|
||||
public static void putMessageForDeliver(ByteBuffer buffer, String message) {
|
||||
public static void putMessageForDeliver(ByteBuffer buffer, String message) throws UnsupportedEncodingException {
|
||||
if (buffer == null || message == null) {
|
||||
return;
|
||||
}
|
||||
message = CommonUtil.cutString(message, DELIVER_MESSAGE_LENGTH);
|
||||
buffer.put(DELIVER_MESSAGE_POSITION, message.getBytes());
|
||||
buffer.put(DELIVER_MESSAGE_POSITION, message.getBytes(Packet.AGENT_CHARACTER_SET));
|
||||
}
|
||||
public static String getMessageForDeliver(ByteBuffer buffer) {
|
||||
if (buffer == null) {
|
||||
@ -54,7 +55,7 @@ public final class LmsMessage {
|
||||
|
||||
return Packet.getString(destArray);
|
||||
}
|
||||
public static void makeDataForDeliver(ByteBuffer buffer, MunjaonMsg data) {
|
||||
public static void makeDataForDeliver(ByteBuffer buffer, MunjaonMsg data) throws UnsupportedEncodingException {
|
||||
if (buffer == null || data == null) {
|
||||
return;
|
||||
}
|
||||
|
||||
@ -5,6 +5,7 @@ import com.munjaon.client.util.CommonUtil;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
import java.io.UnsupportedEncodingException;
|
||||
import java.nio.ByteBuffer;
|
||||
import java.nio.file.Files;
|
||||
|
||||
@ -31,12 +32,12 @@ public final class MmsMessage {
|
||||
public static final int DELIVER_FILECOUNT_LENGTH = 1;
|
||||
public static final int DELIVER_FILECOUNT_POSITION = DELIVER_MESSAGE_POSITION + DELIVER_MESSAGE_LENGTH;
|
||||
|
||||
public static void putSubjectForDeliver(ByteBuffer buffer, String subject) {
|
||||
public static void putSubjectForDeliver(ByteBuffer buffer, String subject) throws UnsupportedEncodingException {
|
||||
if (buffer == null || subject == null) {
|
||||
return;
|
||||
}
|
||||
subject = CommonUtil.cutString(subject, DELIVER_SUBJECT_LENGTH);
|
||||
buffer.put(DELIVER_SUBJECT_POSITION, subject.getBytes());
|
||||
buffer.put(DELIVER_SUBJECT_POSITION, subject.getBytes(Packet.AGENT_CHARACTER_SET));
|
||||
}
|
||||
public static String getSubjectForDeliver(ByteBuffer buffer) {
|
||||
if (buffer == null) {
|
||||
@ -50,12 +51,12 @@ public final class MmsMessage {
|
||||
return Packet.getString(destArray);
|
||||
}
|
||||
|
||||
public static void putMessageForDeliver(ByteBuffer buffer, String message) {
|
||||
public static void putMessageForDeliver(ByteBuffer buffer, String message) throws UnsupportedEncodingException {
|
||||
if (buffer == null || message == null) {
|
||||
return;
|
||||
}
|
||||
message = CommonUtil.cutString(message, DELIVER_MESSAGE_LENGTH);
|
||||
buffer.put(DELIVER_MESSAGE_POSITION, message.getBytes());
|
||||
buffer.put(DELIVER_MESSAGE_POSITION, message.getBytes(Packet.AGENT_CHARACTER_SET));
|
||||
}
|
||||
public static String getMessageForDeliver(ByteBuffer buffer) {
|
||||
if (buffer == null) {
|
||||
@ -69,15 +70,15 @@ public final class MmsMessage {
|
||||
return Packet.getString(destArray);
|
||||
}
|
||||
|
||||
public static void putFileCountForDeliver(ByteBuffer buffer, int fileCount) {
|
||||
public static void putFileCountForDeliver(ByteBuffer buffer, int fileCount) throws UnsupportedEncodingException {
|
||||
putFileCountForDeliver(buffer, Integer.toString(fileCount));
|
||||
}
|
||||
|
||||
public static void putFileCountForDeliver(ByteBuffer buffer, String fileCount) {
|
||||
public static void putFileCountForDeliver(ByteBuffer buffer, String fileCount) throws UnsupportedEncodingException {
|
||||
if (buffer == null || fileCount == null) {
|
||||
return;
|
||||
}
|
||||
buffer.put(DELIVER_FILECOUNT_POSITION, fileCount.getBytes());
|
||||
buffer.put(DELIVER_FILECOUNT_POSITION, fileCount.getBytes(Packet.AGENT_CHARACTER_SET));
|
||||
}
|
||||
public static String getFileCountForDeliver(ByteBuffer buffer) {
|
||||
if (buffer == null) {
|
||||
@ -90,7 +91,7 @@ public final class MmsMessage {
|
||||
|
||||
return Packet.getString(destArray);
|
||||
}
|
||||
public static void makeDataForDeliver(ByteBuffer buffer, MunjaonMsg data) {
|
||||
public static void makeDataForDeliver(ByteBuffer buffer, MunjaonMsg data) throws UnsupportedEncodingException {
|
||||
if (buffer == null || data == null) {
|
||||
return;
|
||||
}
|
||||
@ -114,7 +115,7 @@ public final class MmsMessage {
|
||||
putFileCountForDeliver(buffer, data.getFileCount());
|
||||
}
|
||||
|
||||
public static ByteBuffer makeImageForDeliver(String path, String fileName) {
|
||||
public static ByteBuffer makeImageForDeliver(String path, String fileName) throws UnsupportedEncodingException {
|
||||
if (path == null || fileName == null) {
|
||||
return null;
|
||||
}
|
||||
@ -123,8 +124,8 @@ public final class MmsMessage {
|
||||
return null;
|
||||
}
|
||||
ByteBuffer fileHeadBuffer = ByteBuffer.allocate(MmsMessage.DELIVER_MMS_FILENAME_LENGTH + MmsMessage.DELIVER_MMS_FILESIZE_LENGTH);
|
||||
fileHeadBuffer.put(DELIVER_MMS_FILENAME_POSITION, fileName.getBytes());
|
||||
fileHeadBuffer.put(DELIVER_MMS_FILESIZE_POSITION, String.valueOf(file.length()).getBytes());
|
||||
fileHeadBuffer.put(DELIVER_MMS_FILENAME_POSITION, fileName.getBytes(Packet.AGENT_CHARACTER_SET));
|
||||
fileHeadBuffer.put(DELIVER_MMS_FILESIZE_POSITION, String.valueOf(file.length()).getBytes(Packet.AGENT_CHARACTER_SET));
|
||||
ByteBuffer fileBodyBuffer = ByteBuffer.allocate((int) file.length());
|
||||
ByteBuffer fileBuffer = null;
|
||||
try {
|
||||
|
||||
@ -3,6 +3,7 @@ package com.munjaon.client.server.packet;
|
||||
import java.nio.ByteBuffer;
|
||||
|
||||
public final class Packet {
|
||||
public static final String AGENT_CHARACTER_SET = "EUC-KR";
|
||||
public static final byte SET_DEFAULT_BYTE = (byte) 0x00;
|
||||
public static final long LINK_CHECK_CYCLE = 10000L;
|
||||
/* 패킷 만료 시간 체크 */
|
||||
|
||||
@ -2,6 +2,7 @@ package com.munjaon.client.server.packet;
|
||||
|
||||
import com.munjaon.client.model.MunjaonMsg;
|
||||
|
||||
import java.io.UnsupportedEncodingException;
|
||||
import java.nio.ByteBuffer;
|
||||
|
||||
public final class Report {
|
||||
@ -22,7 +23,7 @@ public final class Report {
|
||||
public static final int REPORT_ACK_RESULT_CODE_LENGTH = 1;
|
||||
public static final int REPORT_ACK_RESULT_CODE_POSITION = Header.BODY_POSITION + Header.BODY_LENGTH;
|
||||
|
||||
public static ByteBuffer makeReport(MunjaonMsg msgData) {
|
||||
public static ByteBuffer makeReport(MunjaonMsg msgData) throws UnsupportedEncodingException {
|
||||
ByteBuffer buffer = ByteBuffer.allocate(Header.HEADER_LENGTH + REPORT_BODY_LENGTH);
|
||||
Packet.setDefaultByte(buffer);
|
||||
Header.putHeader(buffer, Header.COMMAND_REPORT, REPORT_BODY_LENGTH);
|
||||
@ -54,12 +55,12 @@ public final class Report {
|
||||
return msgData;
|
||||
}
|
||||
|
||||
public static void makeReportForMsgId(final ByteBuffer buffer, final String msgId) {
|
||||
public static void makeReportForMsgId(final ByteBuffer buffer, final String msgId) throws UnsupportedEncodingException {
|
||||
if (buffer == null || msgId == null) {
|
||||
return;
|
||||
}
|
||||
|
||||
buffer.put(REPORT_MSG_ID_POSITION, msgId.getBytes());
|
||||
buffer.put(REPORT_MSG_ID_POSITION, msgId.getBytes(Packet.AGENT_CHARACTER_SET));
|
||||
}
|
||||
|
||||
public static String getReportForMsgId(final ByteBuffer buffer) {
|
||||
@ -74,12 +75,12 @@ public final class Report {
|
||||
return Packet.getString(destArray);
|
||||
}
|
||||
|
||||
public static void makeReportForAgentCode(final ByteBuffer buffer, final String agentCode) {
|
||||
public static void makeReportForAgentCode(final ByteBuffer buffer, final String agentCode) throws UnsupportedEncodingException {
|
||||
if (buffer == null || agentCode == null) {
|
||||
return;
|
||||
}
|
||||
|
||||
buffer.put(REPORT_AGENT_CODE_POSITION, agentCode.getBytes());
|
||||
buffer.put(REPORT_AGENT_CODE_POSITION, agentCode.getBytes(Packet.AGENT_CHARACTER_SET));
|
||||
}
|
||||
|
||||
public static String getReportForAgentCode(final ByteBuffer buffer) {
|
||||
@ -94,12 +95,12 @@ public final class Report {
|
||||
return Packet.getString(destArray);
|
||||
}
|
||||
|
||||
public static void makeReportForSendTime(final ByteBuffer buffer, final String sendTime) {
|
||||
public static void makeReportForSendTime(final ByteBuffer buffer, final String sendTime) throws UnsupportedEncodingException {
|
||||
if (buffer == null || sendTime == null) {
|
||||
return;
|
||||
}
|
||||
|
||||
buffer.put(REPORT_SEND_TIME_POSITION, sendTime.getBytes());
|
||||
buffer.put(REPORT_SEND_TIME_POSITION, sendTime.getBytes(Packet.AGENT_CHARACTER_SET));
|
||||
}
|
||||
|
||||
public static String getReportForSendTime(final ByteBuffer buffer) {
|
||||
@ -114,12 +115,12 @@ public final class Report {
|
||||
return Packet.getString(destArray);
|
||||
}
|
||||
|
||||
public static void makeReportForTelecom(final ByteBuffer buffer, final String telecom) {
|
||||
public static void makeReportForTelecom(final ByteBuffer buffer, final String telecom) throws UnsupportedEncodingException {
|
||||
if (buffer == null || telecom == null) {
|
||||
return;
|
||||
}
|
||||
|
||||
buffer.put(REPORT_TELECOM_POSITION, telecom.getBytes());
|
||||
buffer.put(REPORT_TELECOM_POSITION, telecom.getBytes(Packet.AGENT_CHARACTER_SET));
|
||||
}
|
||||
|
||||
public static String getReportForTelecom(final ByteBuffer buffer) {
|
||||
@ -134,12 +135,12 @@ public final class Report {
|
||||
return Packet.getString(destArray);
|
||||
}
|
||||
|
||||
public static void makeReportForResult(final ByteBuffer buffer, final String result) {
|
||||
public static void makeReportForResult(final ByteBuffer buffer, final String result) throws UnsupportedEncodingException {
|
||||
if (buffer == null || result == null) {
|
||||
return;
|
||||
}
|
||||
|
||||
buffer.put(REPORT_RESULT_POSITION, result.getBytes());
|
||||
buffer.put(REPORT_RESULT_POSITION, result.getBytes(Packet.AGENT_CHARACTER_SET));
|
||||
}
|
||||
|
||||
public static String getReportForResult(final ByteBuffer buffer) {
|
||||
@ -154,11 +155,11 @@ public final class Report {
|
||||
return Packet.getString(destArray);
|
||||
}
|
||||
|
||||
public static ByteBuffer makeReportAckBuffer() {
|
||||
public static ByteBuffer makeReportAckBuffer() throws UnsupportedEncodingException {
|
||||
ByteBuffer buffer = ByteBuffer.allocate(Header.HEADER_LENGTH + REPORT_ACK_BODY_LENGTH);
|
||||
Packet.setDefaultByte(buffer);
|
||||
Header.putHeader(buffer, Header.COMMAND_REPORT_ACK, REPORT_ACK_BODY_LENGTH);
|
||||
buffer.put(REPORT_ACK_RESULT_CODE_POSITION, "1".getBytes());
|
||||
buffer.put(REPORT_ACK_RESULT_CODE_POSITION, "1".getBytes(Packet.AGENT_CHARACTER_SET));
|
||||
|
||||
return buffer;
|
||||
}
|
||||
|
||||
@ -3,6 +3,7 @@ package com.munjaon.client.server.packet;
|
||||
import com.munjaon.client.model.MunjaonMsg;
|
||||
import com.munjaon.client.util.CommonUtil;
|
||||
|
||||
import java.io.UnsupportedEncodingException;
|
||||
import java.nio.ByteBuffer;
|
||||
import java.util.Arrays;
|
||||
|
||||
@ -16,12 +17,12 @@ public final class SmsMessage {
|
||||
public static final int DELIVER_MESSAGE_LENGTH = 160;
|
||||
public static final int DELIVER_MESSAGE_POSITION = CommonMessage.DELIVER_MSG_TYPE_POSITION + CommonMessage.DELIVER_MSG_TYPE_LENGTH;
|
||||
|
||||
public static void putMessageForDeliver(ByteBuffer buffer, String message) {
|
||||
public static void putMessageForDeliver(ByteBuffer buffer, String message) throws UnsupportedEncodingException {
|
||||
if (buffer == null || message == null) {
|
||||
return;
|
||||
}
|
||||
message = CommonUtil.cutString(message, DELIVER_MESSAGE_LENGTH);
|
||||
buffer.put(DELIVER_MESSAGE_POSITION, message.getBytes());
|
||||
buffer.put(DELIVER_MESSAGE_POSITION, message.getBytes(Packet.AGENT_CHARACTER_SET));
|
||||
}
|
||||
public static String getMessageForDeliver(ByteBuffer buffer) {
|
||||
if (buffer == null) {
|
||||
@ -34,7 +35,7 @@ public final class SmsMessage {
|
||||
|
||||
return Packet.getString(destArray);
|
||||
}
|
||||
public static void makeDataForDeliver(ByteBuffer buffer, MunjaonMsg data) {
|
||||
public static void makeDataForDeliver(ByteBuffer buffer, MunjaonMsg data) throws UnsupportedEncodingException {
|
||||
if (buffer == null || data == null) {
|
||||
return;
|
||||
}
|
||||
|
||||
@ -61,6 +61,23 @@ public class CollectClientService extends Service {
|
||||
try {
|
||||
socketChannel = SocketChannel.open(new InetSocketAddress(this.address, this.port));
|
||||
socketChannel.configureBlocking(false);
|
||||
|
||||
boolean isConnected = false;
|
||||
long connectStartTime = System.currentTimeMillis();
|
||||
while (true) {
|
||||
if (socketChannel.finishConnect()) {
|
||||
isConnected = true;
|
||||
break;
|
||||
}
|
||||
if (System.currentTimeMillis() - connectStartTime > 3000) {
|
||||
break;
|
||||
}
|
||||
}
|
||||
if (isConnected) {
|
||||
saveSystemLog("Connected to [ADDRESS : " + this.address + "] [PORT : " + this.port + "] [ID : " + this.id + "]");
|
||||
} else {
|
||||
throw new IOException("Connection Timeout");
|
||||
}
|
||||
} catch (IOException e) {
|
||||
saveSystemLog("Connect Fail to [ADDRESS : " + this.address + "] [PORT : " + this.port + "] [ID : " + this.id + "]");
|
||||
saveSystemLog("ERROR [" + e.getMessage() + "]");
|
||||
@ -105,9 +122,10 @@ public class CollectClientService extends Service {
|
||||
}
|
||||
|
||||
private void bind() {
|
||||
ByteBuffer sendBuffer = Bind.makeBindBuffer(id, pwd);
|
||||
ByteBuffer recvBuffer = ByteBuffer.allocate(Header.HEADER_LENGTH + Bind.BIND_ACK_BODY_LENGTH);
|
||||
try {
|
||||
ByteBuffer sendBuffer = Bind.makeBindBuffer(id, pwd);
|
||||
ByteBuffer recvBuffer = ByteBuffer.allocate(Header.HEADER_LENGTH + Bind.BIND_ACK_BODY_LENGTH);
|
||||
|
||||
saveSystemLog("[BIND REQUEST] [IP : " + this.address + "] [PORT : " + this.port + "] [ID : " + this.id + "]");
|
||||
socketChannel.write(sendBuffer);
|
||||
long BIND_SEND_TIME = System.currentTimeMillis();
|
||||
|
||||
@ -55,6 +55,23 @@ public class ReportClientService extends Service {
|
||||
try {
|
||||
socketChannel = SocketChannel.open(new InetSocketAddress(this.address, this.port));
|
||||
socketChannel.configureBlocking(false);
|
||||
|
||||
boolean isConnected = false;
|
||||
long connectStartTime = System.currentTimeMillis();
|
||||
while (true) {
|
||||
if (socketChannel.finishConnect()) {
|
||||
isConnected = true;
|
||||
break;
|
||||
}
|
||||
if (System.currentTimeMillis() - connectStartTime > 3000) {
|
||||
break;
|
||||
}
|
||||
}
|
||||
if (isConnected) {
|
||||
saveSystemLog("Connected to [ADDRESS : " + this.address + "] [PORT : " + this.port + "] [ID : " + this.id + "]");
|
||||
} else {
|
||||
throw new IOException("Connection Timeout");
|
||||
}
|
||||
} catch (IOException e) {
|
||||
saveSystemLog("Connect Fail to [ADDRESS : " + this.address + "] [PORT : " + this.port + "] [ID : " + this.id + "]");
|
||||
saveSystemLog("ERROR [" + e.getMessage() + "]");
|
||||
@ -99,15 +116,19 @@ public class ReportClientService extends Service {
|
||||
}
|
||||
|
||||
private void bind() {
|
||||
ByteBuffer sendBuffer = Bind.makeBindBuffer(id, pwd);
|
||||
ByteBuffer recvBuffer = ByteBuffer.allocate(Header.HEADER_LENGTH + Bind.BIND_ACK_BODY_LENGTH);
|
||||
try {
|
||||
// saveSystemLog("sendBuffer " + sendBuffer.position() + ":" + sendBuffer.limit());
|
||||
ByteBuffer sendBuffer = Bind.makeBindBuffer(id, pwd);
|
||||
ByteBuffer recvBuffer = ByteBuffer.allocate(Header.HEADER_LENGTH + Bind.BIND_ACK_BODY_LENGTH);
|
||||
|
||||
saveSystemLog("Bind Try Connect to " + this.address + ":" + this.port);
|
||||
Thread.sleep(300);
|
||||
socketChannel.write(sendBuffer);
|
||||
saveSystemLog("Bind Read to " + this.address + ":" + this.port);
|
||||
long BIND_SEND_TIME = System.currentTimeMillis();
|
||||
while (true) {
|
||||
if (System.currentTimeMillis() - BIND_SEND_TIME >= Packet.LIMIT_PACKET_SEND_TIMEOUT) {
|
||||
saveSystemLog("[bindTimeOut : Expired ... ... ... ... ... ... ...]");
|
||||
throw new RuntimeException("bindTimeOut : Expired ... ... ... ... ... ... ...");
|
||||
}
|
||||
int recvCount = socketChannel.read(recvBuffer);
|
||||
if (recvCount == -1) {
|
||||
throw new RuntimeException("BIND ERROR");
|
||||
|
||||
@ -1,5 +1,7 @@
|
||||
package com.munjaon.client.server.service;
|
||||
|
||||
import com.munjaon.client.server.packet.Packet;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.net.InetSocketAddress;
|
||||
import java.net.Socket;
|
||||
@ -176,7 +178,7 @@ public class Server implements Runnable {
|
||||
// StringBuffer 초기화
|
||||
sb.setLength(0);
|
||||
// byte 형식으로 변환
|
||||
ByteBuffer buffer = ByteBuffer.wrap(data.getBytes());
|
||||
ByteBuffer buffer = ByteBuffer.wrap(data.getBytes(Packet.AGENT_CHARACTER_SET));
|
||||
// ***데이터 송신***
|
||||
channel.write(buffer);
|
||||
// Socket 채널을 channel에 수신 등록한다
|
||||
|
||||
@ -5,6 +5,10 @@
|
||||
|
||||
package com.munjaon.client.util;
|
||||
|
||||
import com.munjaon.client.server.packet.Packet;
|
||||
|
||||
import java.io.UnsupportedEncodingException;
|
||||
|
||||
/**
|
||||
* bytes 관련 유틸리티 클래스
|
||||
* @author JDS
|
||||
@ -130,10 +134,10 @@ public final class ByteUtil {
|
||||
return src[offset];
|
||||
}
|
||||
|
||||
public static byte[] getBytes(String data) {
|
||||
public static byte[] getBytes(String data) throws UnsupportedEncodingException {
|
||||
byte[] b = null;
|
||||
|
||||
b = data.getBytes();
|
||||
b = data.getBytes(Packet.AGENT_CHARACTER_SET);
|
||||
|
||||
return (b);
|
||||
}
|
||||
@ -171,8 +175,8 @@ public final class ByteUtil {
|
||||
return dest;
|
||||
}
|
||||
|
||||
public static void setBytes(byte[] dest, int offset, String s) {
|
||||
setBytes(dest, offset, s.getBytes());
|
||||
public static void setBytes(byte[] dest, int offset, String s) throws UnsupportedEncodingException {
|
||||
setBytes(dest, offset, s.getBytes(Packet.AGENT_CHARACTER_SET));
|
||||
}
|
||||
|
||||
public static byte[] setBytes(byte dest[], int offset, byte src[]) {
|
||||
|
||||
@ -1,5 +1,8 @@
|
||||
package com.munjaon.client.util;
|
||||
|
||||
import com.munjaon.client.server.packet.Packet;
|
||||
|
||||
import java.io.UnsupportedEncodingException;
|
||||
import java.text.ParseException;
|
||||
import java.text.SimpleDateFormat;
|
||||
import java.util.Calendar;
|
||||
@ -69,12 +72,11 @@ public final class CommonUtil {
|
||||
return isValid;
|
||||
}
|
||||
// 해당 길이만큼 문자열을 자르는 함수
|
||||
public static String cutString(String str, int limit)
|
||||
{
|
||||
public static String cutString(String str, int limit) throws UnsupportedEncodingException {
|
||||
int len = str.length();
|
||||
int sumLength=0;
|
||||
String cutString = null;
|
||||
byte[] toByte = str.getBytes();
|
||||
byte[] toByte = str.getBytes(Packet.AGENT_CHARACTER_SET);
|
||||
|
||||
if(limit < 2)
|
||||
return "";
|
||||
|
||||
@ -5,9 +5,10 @@ import com.munjaon.client.server.config.ErrorCode;
|
||||
import com.munjaon.client.server.packet.*;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.UnsupportedEncodingException;
|
||||
|
||||
public class MessageCheckUtil {
|
||||
public static int validateMessageForCommon(MunjaonMsg data) {
|
||||
public static int validateMessageForCommon(MunjaonMsg data) throws UnsupportedEncodingException {
|
||||
int code = isNullMessageForCommon(data);
|
||||
if (code != ErrorCode.OK.getCode()) {
|
||||
return code;
|
||||
@ -15,20 +16,20 @@ public class MessageCheckUtil {
|
||||
|
||||
return isLengthMessageForCommon(data);
|
||||
}
|
||||
public static int isLengthMessageForCommon(MunjaonMsg data) {
|
||||
public static int isLengthMessageForCommon(MunjaonMsg data) throws UnsupportedEncodingException {
|
||||
/* MSG_ID */
|
||||
String value = data.getMsgId().trim();
|
||||
if (value.length() == 0 || value.getBytes().length > CommonMessage.DELIVER_MESSAGE_ID_LENGTH) {
|
||||
if (value.length() == 0 || value.getBytes(Packet.AGENT_CHARACTER_SET).length > CommonMessage.DELIVER_MESSAGE_ID_LENGTH) {
|
||||
return ErrorCode.ERROR_MSGID_IS_CAPACITY.getCode();
|
||||
}
|
||||
/* SENDER */
|
||||
value = MessageUtil.doNumber(data.getSendPhone());
|
||||
if (value.getBytes().length < 8 || value.getBytes().length > CommonMessage.DELIVER_SENDER_LENGTH) {
|
||||
if (value.getBytes().length < 8 || value.getBytes(Packet.AGENT_CHARACTER_SET).length > CommonMessage.DELIVER_SENDER_LENGTH) {
|
||||
return ErrorCode.ERROR_SENDER_IS_CAPACITY.getCode();
|
||||
}
|
||||
/* RECEIVER */
|
||||
value = MessageUtil.doNumber(data.getRecvPhone());
|
||||
if (value.getBytes().length < 10 || value.getBytes().length > CommonMessage.DELIVER_RECEIVER_LENGTH) {
|
||||
if (value.getBytes().length < 10 || value.getBytes(Packet.AGENT_CHARACTER_SET).length > CommonMessage.DELIVER_RECEIVER_LENGTH) {
|
||||
return ErrorCode.ERROR_RECEIVER_IS_CAPACITY.getCode();
|
||||
}
|
||||
if ("01".equals(value.substring(0, 2)) == false) {
|
||||
@ -55,18 +56,18 @@ public class MessageCheckUtil {
|
||||
return ErrorCode.OK.getCode();
|
||||
}
|
||||
|
||||
public static int validateMessageForSms(MunjaonMsg data) {
|
||||
public static int validateMessageForSms(MunjaonMsg data) throws UnsupportedEncodingException {
|
||||
if (data.getMessage() == null || data.getMessage().isEmpty()) {
|
||||
return ErrorCode.ERROR_SMS_MSG_IS_NULL.getCode();
|
||||
}
|
||||
if (data.getMessage().getBytes().length > SmsMessage.DELIVER_MESSAGE_TRANS_LENGTH) {
|
||||
if (data.getMessage().getBytes(Packet.AGENT_CHARACTER_SET).length > SmsMessage.DELIVER_MESSAGE_TRANS_LENGTH) {
|
||||
return ErrorCode.ERROR_SMS_MSG_IS_CAPACITY.getCode();
|
||||
}
|
||||
|
||||
return ErrorCode.OK.getCode();
|
||||
}
|
||||
|
||||
public static int validateMessageForMedia(MunjaonMsg data) {
|
||||
public static int validateMessageForMedia(MunjaonMsg data) throws UnsupportedEncodingException {
|
||||
if (data == null) {
|
||||
return ErrorCode.ERROR_DATA_IS_NULL.getCode();
|
||||
}
|
||||
@ -76,10 +77,10 @@ public class MessageCheckUtil {
|
||||
if (data.getMessage() == null) {
|
||||
return ErrorCode.ERROR_MULTI_MESSAGE_IS_NULL.getCode();
|
||||
}
|
||||
if (data.getSubject().getBytes().length > LmsMessage.DELIVER_SUBJECT_LENGTH) {
|
||||
if (data.getSubject().getBytes(Packet.AGENT_CHARACTER_SET).length > LmsMessage.DELIVER_SUBJECT_LENGTH) {
|
||||
return ErrorCode.ERROR_SUBJECT_OVER_CAPACITY.getCode();
|
||||
}
|
||||
if (data.getMessage().getBytes().length > LmsMessage.DELIVER_MESSAGE_LENGTH) {
|
||||
if (data.getMessage().getBytes(Packet.AGENT_CHARACTER_SET).length > LmsMessage.DELIVER_MESSAGE_LENGTH) {
|
||||
return ErrorCode.ERROR_MULTI_MESSAGE_OVER_CAPACITY.getCode();
|
||||
}
|
||||
|
||||
@ -193,7 +194,7 @@ public class MessageCheckUtil {
|
||||
return false;
|
||||
}
|
||||
|
||||
public static int validateMessageForKakao(MunjaonMsg data) {
|
||||
public static int validateMessageForKakao(MunjaonMsg data) throws UnsupportedEncodingException {
|
||||
if (data == null) {
|
||||
return ErrorCode.ERROR_DATA_IS_NULL.getCode();
|
||||
}
|
||||
@ -212,16 +213,16 @@ public class MessageCheckUtil {
|
||||
if (data.getKakaoJsonFile() == null) {
|
||||
return ErrorCode.ERROR_KAKAO_JSON_FILE_IS_NULL.getCode();
|
||||
}
|
||||
if (data.getSubject().getBytes().length > LmsMessage.DELIVER_SUBJECT_LENGTH) {
|
||||
if (data.getSubject().getBytes(Packet.AGENT_CHARACTER_SET).length > LmsMessage.DELIVER_SUBJECT_LENGTH) {
|
||||
return ErrorCode.ERROR_SUBJECT_OVER_CAPACITY.getCode();
|
||||
}
|
||||
if (data.getMessage().getBytes().length > LmsMessage.DELIVER_MESSAGE_LENGTH) {
|
||||
if (data.getMessage().getBytes(Packet.AGENT_CHARACTER_SET).length > LmsMessage.DELIVER_MESSAGE_LENGTH) {
|
||||
return ErrorCode.ERROR_MULTI_MESSAGE_OVER_CAPACITY.getCode();
|
||||
}
|
||||
if (data.getKakaoSenderKey().getBytes().length > KakaoMessage.DELIVER_KAKAO_SENDER_KEY_LENGTH) {
|
||||
if (data.getKakaoSenderKey().getBytes(Packet.AGENT_CHARACTER_SET).length > KakaoMessage.DELIVER_KAKAO_SENDER_KEY_LENGTH) {
|
||||
return ErrorCode.ERROR_KAKAO_SENDER_KEY_OVER_CAPACITY.getCode();
|
||||
}
|
||||
if (data.getKakaoTemplateCode().getBytes().length > KakaoMessage.DELIVER_KAKAO_TEMPLATE_CODE_LENGTH) {
|
||||
if (data.getKakaoTemplateCode().getBytes(Packet.AGENT_CHARACTER_SET).length > KakaoMessage.DELIVER_KAKAO_TEMPLATE_CODE_LENGTH) {
|
||||
return ErrorCode.ERROR_KAKAO_TEMPLATE_CODE_OVER_CAPACITY.getCode();
|
||||
}
|
||||
|
||||
@ -264,14 +265,15 @@ public class MessageCheckUtil {
|
||||
}
|
||||
|
||||
|
||||
public static void main(String[] args) {
|
||||
String fileName = " .dat";
|
||||
int lastIndex = fileName.lastIndexOf(".");
|
||||
if (lastIndex < 0) {
|
||||
System.out.println("EXT is not ");
|
||||
} else {
|
||||
System.out.println("EXT : " + fileName.substring(fileName.lastIndexOf(".") + 1, fileName.length()));
|
||||
}
|
||||
System.out.println("NM :" + fileName.substring(0, lastIndex) + "<<");
|
||||
public static void main(String[] args) throws UnsupportedEncodingException {
|
||||
// String fileName = " .dat";
|
||||
// int lastIndex = fileName.lastIndexOf(".");
|
||||
// if (lastIndex < 0) {
|
||||
// System.out.println("EXT is not ");
|
||||
// } else {
|
||||
// System.out.println("EXT : " + fileName.substring(fileName.lastIndexOf(".") + 1, fileName.length()));
|
||||
// }
|
||||
// System.out.println("NM :" + fileName.substring(0, lastIndex) + "<<");
|
||||
System.out.println("한c".getBytes("EUC-KR").length);
|
||||
}
|
||||
}
|
||||
|
||||
@ -1,5 +1,8 @@
|
||||
package com.munjaon.client.util;
|
||||
|
||||
import com.munjaon.client.server.packet.Packet;
|
||||
|
||||
import java.io.UnsupportedEncodingException;
|
||||
import java.time.LocalDateTime;
|
||||
import java.time.format.DateTimeFormatter;
|
||||
|
||||
@ -94,15 +97,15 @@ public final class MessageUtil {
|
||||
return isEmptyForMessage(obj, false);
|
||||
}
|
||||
|
||||
public static boolean isOverByteForMessage(String obj, int limitCount, boolean trimFlag) {
|
||||
public static boolean isOverByteForMessage(String obj, int limitCount, boolean trimFlag) throws UnsupportedEncodingException {
|
||||
if (isEmptyForMessage(obj, trimFlag)) {
|
||||
return true;
|
||||
}
|
||||
|
||||
return obj.getBytes().length > limitCount;
|
||||
return obj.getBytes(Packet.AGENT_CHARACTER_SET).length > limitCount;
|
||||
}
|
||||
|
||||
public static boolean isOverByteForMessage(String obj, int limitCount) {
|
||||
public static boolean isOverByteForMessage(String obj, int limitCount) throws UnsupportedEncodingException {
|
||||
return isOverByteForMessage(obj, limitCount, false);
|
||||
}
|
||||
}
|
||||
|
||||
@ -5,6 +5,9 @@
|
||||
|
||||
package com.munjaon.client.util;
|
||||
|
||||
import com.munjaon.client.server.packet.Packet;
|
||||
|
||||
import java.io.UnsupportedEncodingException;
|
||||
import java.text.DecimalFormat;
|
||||
import java.util.ArrayList;
|
||||
|
||||
@ -123,19 +126,19 @@ public final class StringUtil {
|
||||
return sRet;
|
||||
}
|
||||
|
||||
public static String substring(String obj, int idx, int length) {
|
||||
if( obj.getBytes().length <= idx ) {
|
||||
public static String substring(String obj, int idx, int length) throws UnsupportedEncodingException {
|
||||
if( obj.getBytes(Packet.AGENT_CHARACTER_SET).length <= idx ) {
|
||||
return "";
|
||||
}
|
||||
|
||||
if( obj.getBytes().length <= length ) {
|
||||
if( obj.getBytes(Packet.AGENT_CHARACTER_SET).length <= length ) {
|
||||
return obj;
|
||||
}
|
||||
|
||||
int totallen=0;
|
||||
int i=idx;
|
||||
for( i=idx; i<obj.length(); i++ ) {
|
||||
totallen += obj.substring(i, i+1).getBytes().length;
|
||||
totallen += obj.substring(i, i+1).getBytes(Packet.AGENT_CHARACTER_SET).length;
|
||||
|
||||
if( length < totallen ) {
|
||||
break;
|
||||
@ -145,7 +148,7 @@ public final class StringUtil {
|
||||
return obj.substring(idx, i);
|
||||
}
|
||||
|
||||
public static String substring(String obj, int length) {
|
||||
public static String substring(String obj, int length) throws UnsupportedEncodingException {
|
||||
return substring(obj, 0, length);
|
||||
}
|
||||
|
||||
|
||||
Loading…
Reference in New Issue
Block a user