--- src/main/java/com/munjaon/client/server/packet/MmsMessage.java
+++ src/main/java/com/munjaon/client/server/packet/MmsMessage.java
... | ... | @@ -125,15 +125,62 @@ |
| 125 | 125 |
} |
| 126 | 126 |
ByteBuffer fileHeadBuffer = ByteBuffer.allocate(MmsMessage.DELIVER_MMS_FILENAME_LENGTH + MmsMessage.DELIVER_MMS_FILESIZE_LENGTH); |
| 127 | 127 |
fileHeadBuffer.put(DELIVER_MMS_FILENAME_POSITION, fileName.getBytes(Packet.AGENT_CHARACTER_SET)); |
| 128 |
- fileHeadBuffer.put(DELIVER_MMS_FILESIZE_POSITION, String.valueOf(file.length()).getBytes(Packet.AGENT_CHARACTER_SET)); |
|
| 128 |
+ fileHeadBuffer.put(DELIVER_MMS_FILESIZE_POSITION, String.valueOf(file.length()).getBytes()); |
|
| 129 | 129 |
ByteBuffer fileBodyBuffer = ByteBuffer.allocate((int) file.length()); |
| 130 | 130 |
ByteBuffer fileBuffer = null; |
| 131 |
+// FileInputStream fis = null; |
|
| 131 | 132 |
try {
|
| 133 |
+// fis = new FileInputStream(file); |
|
| 134 |
+// int bytesRead = 0; |
|
| 135 |
+// int position = 0; |
|
| 136 |
+// while ((bytesRead = fis.read()) != -1) {
|
|
| 137 |
+// fileBodyBuffer.put(position++, (byte) bytesRead); |
|
| 138 |
+// } |
|
| 139 |
+ |
|
| 140 |
+// System.out.println("Put Position = " + position);
|
|
| 141 |
+// int read = fis.read(fileBodyBuffer.array()); |
|
| 142 |
+// System.out.println("Position = " + fileBodyBuffer.position() + " : Limit : " + fileBodyBuffer.limit());
|
|
| 132 | 143 |
fileBodyBuffer.put(Files.readAllBytes(file.toPath())); |
| 144 |
+ System.out.println("Files.readAllBytes() = " + fileBodyBuffer.get(fileBodyBuffer.capacity() - 1));
|
|
| 133 | 145 |
fileBuffer = ByteBuffer.allocate(fileHeadBuffer.capacity() + fileBodyBuffer.capacity()); |
| 134 | 146 |
Packet.mergeBuffers(fileBuffer, fileHeadBuffer, fileBodyBuffer); |
| 135 |
- } catch (IOException e) {}
|
|
| 147 |
+ } catch (IOException e) {
|
|
| 148 |
+ } |
|
| 136 | 149 |
|
| 137 | 150 |
return fileBuffer; |
| 138 | 151 |
} |
| 152 |
+ |
|
| 153 |
+ public static ByteBuffer makeImageHeaderForDeliver(String path, String fileName) throws UnsupportedEncodingException {
|
|
| 154 |
+ if (path == null || fileName == null) {
|
|
| 155 |
+ return null; |
|
| 156 |
+ } |
|
| 157 |
+ File file = new File(path + fileName); |
|
| 158 |
+ if (file.exists() == false) {
|
|
| 159 |
+ return null; |
|
| 160 |
+ } |
|
| 161 |
+ ByteBuffer fileHeadBuffer = ByteBuffer.allocate(MmsMessage.DELIVER_MMS_FILENAME_LENGTH + MmsMessage.DELIVER_MMS_FILESIZE_LENGTH); |
|
| 162 |
+ fileHeadBuffer.put(DELIVER_MMS_FILENAME_POSITION, fileName.getBytes(Packet.AGENT_CHARACTER_SET)); |
|
| 163 |
+ fileHeadBuffer.put(DELIVER_MMS_FILESIZE_POSITION, String.valueOf(file.length()).getBytes()); |
|
| 164 |
+ |
|
| 165 |
+ return fileHeadBuffer; |
|
| 166 |
+ } |
|
| 167 |
+ |
|
| 168 |
+ public static ByteBuffer makeImageBodyForDeliver(String path, String fileName) throws UnsupportedEncodingException {
|
|
| 169 |
+ if (path == null || fileName == null) {
|
|
| 170 |
+ return null; |
|
| 171 |
+ } |
|
| 172 |
+ File file = new File(path + fileName); |
|
| 173 |
+ if (file.exists() == false) {
|
|
| 174 |
+ return null; |
|
| 175 |
+ } |
|
| 176 |
+ |
|
| 177 |
+ ByteBuffer fileBodyBuffer = null; |
|
| 178 |
+ try {
|
|
| 179 |
+ fileBodyBuffer = ByteBuffer.allocate((int) file.length()); |
|
| 180 |
+ fileBodyBuffer.put(Files.readAllBytes(file.toPath())); |
|
| 181 |
+ } catch (IOException e) {
|
|
| 182 |
+ } |
|
| 183 |
+ |
|
| 184 |
+ return fileBodyBuffer; |
|
| 185 |
+ } |
|
| 139 | 186 |
} |
--- src/main/java/com/munjaon/client/server/packet/Packet.java
+++ src/main/java/com/munjaon/client/server/packet/Packet.java
... | ... | @@ -69,6 +69,21 @@ |
| 69 | 69 |
// dest.put(srcHeadArray.length, srcBodyArray); |
| 70 | 70 |
} |
| 71 | 71 |
|
| 72 |
+ public static void mergeBuffers(ByteBuffer dest, ByteBuffer[] srcArray) {
|
|
| 73 |
+ if (dest == null || srcArray == null || srcArray.length == 0) {
|
|
| 74 |
+ return; |
|
| 75 |
+ } |
|
| 76 |
+ |
|
| 77 |
+ int destPosition = 0; |
|
| 78 |
+ for (int i = 0; i < srcArray.length; i++) {
|
|
| 79 |
+ for (int j = 0; j < srcArray[i].capacity(); j++) {
|
|
| 80 |
+ dest.put(destPosition++, srcArray[i].get(j)); |
|
| 81 |
+ System.out.println("i : " + i + " : j : " + j + " | byte : " + srcArray[i].get(j));
|
|
| 82 |
+ } |
|
| 83 |
+ System.out.println("destPosition : " + destPosition);
|
|
| 84 |
+ } |
|
| 85 |
+ } |
|
| 86 |
+ |
|
| 72 | 87 |
public static void printBuffer(ByteBuffer buffer) {
|
| 73 | 88 |
if (buffer == null) {
|
| 74 | 89 |
return; |
--- src/main/java/com/munjaon/client/server/service/CollectClientService.java
+++ src/main/java/com/munjaon/client/server/service/CollectClientService.java
... | ... | @@ -4,6 +4,7 @@ |
| 4 | 4 |
import com.munjaon.client.server.config.ErrorCode; |
| 5 | 5 |
import com.munjaon.client.server.packet.*; |
| 6 | 6 |
import com.munjaon.client.service.DatabaseTypeWorker; |
| 7 |
+import com.munjaon.client.util.ByteUtil; |
|
| 7 | 8 |
import com.munjaon.client.util.MessageCheckUtil; |
| 8 | 9 |
import com.munjaon.client.util.MessageUtil; |
| 9 | 10 |
import org.json.simple.JSONObject; |
... | ... | @@ -12,7 +13,11 @@ |
| 12 | 13 |
import java.io.IOException; |
| 13 | 14 |
import java.net.InetSocketAddress; |
| 14 | 15 |
import java.nio.ByteBuffer; |
| 16 |
+import java.nio.channels.FileChannel; |
|
| 15 | 17 |
import java.nio.channels.SocketChannel; |
| 18 |
+import java.nio.file.Path; |
|
| 19 |
+import java.nio.file.Paths; |
|
| 20 |
+import java.nio.file.StandardOpenOption; |
|
| 16 | 21 |
import java.util.ArrayList; |
| 17 | 22 |
import java.util.List; |
| 18 | 23 |
|
... | ... | @@ -31,12 +36,16 @@ |
| 31 | 36 |
private String pwd; // 접속 비밀번호 |
| 32 | 37 |
|
| 33 | 38 |
private List<String> deliverList = null; |
| 39 |
+ private boolean IS_ERROR = false; |
|
| 34 | 40 |
|
| 35 | 41 |
public CollectClientService(String serviceName, String serviceType) {
|
| 36 | 42 |
super(serviceName); |
| 37 | 43 |
this.serviceType = serviceType; |
| 38 | 44 |
} |
| 39 | 45 |
|
| 46 |
+ /** |
|
| 47 |
+ * DBMS 테이블 생성여부 확인 |
|
| 48 |
+ */ |
|
| 40 | 49 |
@Override |
| 41 | 50 |
public void checkReady() {
|
| 42 | 51 |
worker = DatabaseTypeWorker.find(System.getProperty("DBMS"));
|
... | ... | @@ -62,9 +71,13 @@ |
| 62 | 71 |
this.pwd = getProp("PASSWORD");
|
| 63 | 72 |
saveSystemLog("Try Connect to [ADDRESS : " + this.address + "] [PORT : " + this.port + "] [ID : " + this.id + "]");
|
| 64 | 73 |
try {
|
| 74 |
+ /* 클라이언트 소켓 오픈, nonblocking 모드 설정 */ |
|
| 65 | 75 |
socketChannel = SocketChannel.open(new InetSocketAddress(this.address, this.port)); |
| 66 | 76 |
socketChannel.configureBlocking(false); |
| 67 | 77 |
|
| 78 |
+ /* 연결이 완료되었는지 체크 |
|
| 79 |
+ * 3초간 서버와의 연결이 완료되었는지 체크 |
|
| 80 |
+ * */ |
|
| 68 | 81 |
boolean isConnected = false; |
| 69 | 82 |
long connectStartTime = System.currentTimeMillis(); |
| 70 | 83 |
while (true) {
|
... | ... | @@ -88,6 +101,9 @@ |
| 88 | 101 |
} |
| 89 | 102 |
} |
| 90 | 103 |
|
| 104 |
+ /** |
|
| 105 |
+ * socket 연결 해제 |
|
| 106 |
+ */ |
|
| 91 | 107 |
@Override |
| 92 | 108 |
public void releaseResources() {
|
| 93 | 109 |
if (socketChannel != null) {
|
... | ... | @@ -100,21 +116,29 @@ |
| 100 | 116 |
} |
| 101 | 117 |
} |
| 102 | 118 |
|
| 119 |
+ /** |
|
| 120 |
+ * 패킷을 송수신한 마지막 시간 체크 |
|
| 121 |
+ * @return |
|
| 122 |
+ */ |
|
| 103 | 123 |
private boolean checkTimeOut() {
|
| 104 | 124 |
return System.currentTimeMillis() - lastPacketSendTime >= Packet.LIMIT_PACKET_TIMEOUT; |
| 105 | 125 |
} |
| 106 | 126 |
|
| 107 | 127 |
@Override |
| 108 | 128 |
public void doService() {
|
| 109 |
- bind(); |
|
| 129 |
+ IS_ERROR = false; // 에러체크 초기화 |
|
| 130 |
+ bind(); // 바이드 요청 |
|
| 110 | 131 |
while (isRun()) {
|
| 132 |
+ if (IS_ERROR) {
|
|
| 133 |
+ break; |
|
| 134 |
+ } |
|
| 111 | 135 |
try {
|
| 112 | 136 |
if (checkTimeOut()) {
|
| 113 | 137 |
saveSystemLog("[checkTimeOut : Expired ... ... ... ... ... ... ...]");
|
| 114 | 138 |
break; |
| 115 | 139 |
}; |
| 116 |
- messageService(); |
|
| 117 |
- linkCheckService(); |
|
| 140 |
+ messageService(); // 메시지 전송 처리 |
|
| 141 |
+ linkCheckService(); // alive 체크 |
|
| 118 | 142 |
} catch (Exception e) {
|
| 119 | 143 |
saveSystemLog("ERROR [" + e.getMessage() + "]");
|
| 120 | 144 |
saveSystemLog("ERROR DETAIL");
|
... | ... | @@ -207,6 +231,7 @@ |
| 207 | 231 |
} |
| 208 | 232 |
} |
| 209 | 233 |
} catch (Exception e) {
|
| 234 |
+ IS_ERROR = true; |
|
| 210 | 235 |
saveSystemLog("ERROR [" + e.getMessage() + "]");
|
| 211 | 236 |
saveSystemLog("ERROR DETAIL");
|
| 212 | 237 |
saveSystemLog(e.toString()); |
... | ... | @@ -216,9 +241,10 @@ |
| 216 | 241 |
worker.updateDeliverForList(this.deliverList); |
| 217 | 242 |
this.deliverList = null; // NULL로 초기화 |
| 218 | 243 |
} |
| 244 |
+ |
|
| 219 | 245 |
} |
| 220 | 246 |
|
| 221 |
- private void smsMessageService(MunjaonMsg data) {
|
|
| 247 |
+ private void smsMessageService(MunjaonMsg data) throws Exception {
|
|
| 222 | 248 |
try {
|
| 223 | 249 |
/* 공통 메시지 유효성 체크 */ |
| 224 | 250 |
int checkCommonCode = MessageCheckUtil.validateMessageForCommon(data); |
... | ... | @@ -252,12 +278,12 @@ |
| 252 | 278 |
while (true) {
|
| 253 | 279 |
if (System.currentTimeMillis() - MSG_SEND_TIME >= Packet.LIMIT_PACKET_SEND_TIMEOUT) {
|
| 254 | 280 |
saveLog("[messageSendTimeOut : Expired ... ... ... ... ... ... ...]");
|
| 255 |
- throw new RuntimeException("messageSendTimeOut : Expired ... ... ... ... ... ... ...");
|
|
| 281 |
+ throw new Exception("messageSendTimeOut : Expired ... ... ... ... ... ... ...");
|
|
| 256 | 282 |
} |
| 257 | 283 |
int recvCount = socketChannel.read(recvBuffer); |
| 258 | 284 |
if (recvCount == -1) {
|
| 259 | 285 |
saveLog("[MESSAGE SEND] [FAIL] [SOCKET IS CLOSED]");
|
| 260 |
- throw new RuntimeException("DELIVER ERROR");
|
|
| 286 |
+ throw new Exception("DELIVER ERROR");
|
|
| 261 | 287 |
} else if (recvCount > 0) {
|
| 262 | 288 |
setDeliverMsgId(data.getMsgId()); |
| 263 | 289 |
// worker.updateToDeliver(data.getMsgId()); |
... | ... | @@ -266,15 +292,15 @@ |
| 266 | 292 |
break; |
| 267 | 293 |
} |
| 268 | 294 |
} |
| 269 |
- } catch (IOException e) {
|
|
| 295 |
+ } catch (Exception e) {
|
|
| 270 | 296 |
saveSystemLog("ERROR [" + e.getMessage() + "]");
|
| 271 | 297 |
saveSystemLog("ERROR DETAIL");
|
| 272 | 298 |
saveSystemLog(e.toString()); |
| 273 |
- throw new RuntimeException(e); |
|
| 299 |
+ throw new Exception(e); |
|
| 274 | 300 |
} |
| 275 | 301 |
} |
| 276 | 302 |
|
| 277 |
- private void lmsMessageService(MunjaonMsg data) {
|
|
| 303 |
+ private void lmsMessageService(MunjaonMsg data) throws Exception {
|
|
| 278 | 304 |
try {
|
| 279 | 305 |
/* 공통 메시지 유효성 체크 */ |
| 280 | 306 |
int checkCommonCode = MessageCheckUtil.validateMessageForCommon(data); |
... | ... | @@ -308,12 +334,12 @@ |
| 308 | 334 |
while (true) {
|
| 309 | 335 |
if (System.currentTimeMillis() - MSG_SEND_TIME >= Packet.LIMIT_PACKET_SEND_TIMEOUT) {
|
| 310 | 336 |
saveLog("[messageSendTimeOut : Expired ... ... ... ... ... ... ...]");
|
| 311 |
- throw new RuntimeException("messageSendTimeOut : Expired ... ... ... ... ... ... ...");
|
|
| 337 |
+ throw new Exception("messageSendTimeOut : Expired ... ... ... ... ... ... ...");
|
|
| 312 | 338 |
} |
| 313 | 339 |
int recvCount = socketChannel.read(recvBuffer); |
| 314 | 340 |
if (recvCount == -1) {
|
| 315 | 341 |
saveLog("[MESSAGE SEND] [FAIL] [SOCKET IS CLOSED]");
|
| 316 |
- throw new RuntimeException("DELIVER ERROR");
|
|
| 342 |
+ throw new Exception("DELIVER ERROR");
|
|
| 317 | 343 |
} else if (recvCount > 0) {
|
| 318 | 344 |
setDeliverMsgId(data.getMsgId()); |
| 319 | 345 |
// worker.updateToDeliver(data.getMsgId()); |
... | ... | @@ -322,15 +348,141 @@ |
| 322 | 348 |
break; |
| 323 | 349 |
} |
| 324 | 350 |
} |
| 325 |
- } catch (IOException e) {
|
|
| 351 |
+ } catch (Exception e) {
|
|
| 326 | 352 |
saveSystemLog("ERROR [" + e.getMessage() + "]");
|
| 327 | 353 |
saveSystemLog("ERROR DETAIL");
|
| 328 | 354 |
saveSystemLog(e.toString()); |
| 329 |
- throw new RuntimeException(e); |
|
| 355 |
+ throw new Exception(e); |
|
| 330 | 356 |
} |
| 331 | 357 |
} |
| 332 | 358 |
|
| 333 |
- private void mmsMessageService(MunjaonMsg data) {
|
|
| 359 |
+ private void mmsMessageService(MunjaonMsg data) throws Exception {
|
|
| 360 |
+ try {
|
|
| 361 |
+ /* 이미지 경로 디폴트 경로 사용 여부 */ |
|
| 362 |
+ String defaultYn = getProp("MMS", "DEFAULT_PATH_YN");
|
|
| 363 |
+ /* MMS Image 저장 경로 */ |
|
| 364 |
+ String path = null; |
|
| 365 |
+ if ("Y".equals(defaultYn)) {
|
|
| 366 |
+ path = System.getProperty("ROOTPATH") + File.separator + "mmsfile" + File.separator;
|
|
| 367 |
+ } else {
|
|
| 368 |
+ path = getProp("MMS", "FILEPATH") + File.separator;
|
|
| 369 |
+ } |
|
| 370 |
+ |
|
| 371 |
+ /* 공통 메시지 유효성 체크 */ |
|
| 372 |
+ int checkCommonCode = MessageCheckUtil.validateMessageForCommon(data); |
|
| 373 |
+ int checkMsgCode = MessageCheckUtil.validateMessageForMedia(data); |
|
| 374 |
+ int checkImageCode = MessageCheckUtil.validateMessageForImage(data, path); |
|
| 375 |
+ if (checkCommonCode != ErrorCode.OK.getCode() || checkMsgCode != ErrorCode.OK.getCode() || checkImageCode != ErrorCode.OK.getCode()) {
|
|
| 376 |
+ saveLog("[MESSAGE FILTER] [COMMON_CODE : " + checkCommonCode + "] [MSG_CODE : " + checkMsgCode + "] [IMAGE_CODE : " + checkImageCode + "]");
|
|
| 377 |
+ saveLog("[MESSAGE DATA : " + data.toString() + "]");
|
|
| 378 |
+ /* 전송처리 */ |
|
| 379 |
+ worker.updateToDeliver(data.getMsgId()); |
|
| 380 |
+ /* 실패처리 */ |
|
| 381 |
+ MunjaonMsg errorMsg = null; |
|
| 382 |
+ if (checkCommonCode != ErrorCode.OK.getCode()) {
|
|
| 383 |
+ errorMsg = MessageCheckUtil.setReportMessage(data.getMsgId(), "00", String.valueOf(checkCommonCode), MessageUtil.getTime(), "ETC"); |
|
| 384 |
+ }else if (checkMsgCode != ErrorCode.OK.getCode()) {
|
|
| 385 |
+ errorMsg = MessageCheckUtil.setReportMessage(data.getMsgId(), "00", String.valueOf(checkMsgCode), MessageUtil.getTime(), "ETC"); |
|
| 386 |
+ } else {
|
|
| 387 |
+ errorMsg = MessageCheckUtil.setReportMessage(data.getMsgId(), "00", String.valueOf(checkImageCode), MessageUtil.getTime(), "ETC"); |
|
| 388 |
+ } |
|
| 389 |
+ worker.updateToReport(errorMsg); |
|
| 390 |
+ /* 처리완료 */ |
|
| 391 |
+ return; |
|
| 392 |
+ } |
|
| 393 |
+ |
|
| 394 |
+ /* 정상인 경우 메시지 전송 */ |
|
| 395 |
+ ByteBuffer sendBuffer = ByteBuffer.allocate(Header.HEADER_LENGTH + MmsMessage.DELIVER_MMS_BODY_LENGTH); |
|
| 396 |
+ ByteBuffer recvBuffer = ByteBuffer.allocate(Header.HEADER_LENGTH + MmsMessage.DELIVER_MMS_ACK_BODY_LENGTH); |
|
| 397 |
+ int fileCount = 0; |
|
| 398 |
+ /* File check */ |
|
| 399 |
+ ByteBuffer file01HeadBuffer = MmsMessage.makeImageHeaderForDeliver(path, data.getFilename01()); |
|
| 400 |
+ if (file01HeadBuffer != null) {
|
|
| 401 |
+ fileCount++; |
|
| 402 |
+ } |
|
| 403 |
+ ByteBuffer file02HeadBuffer = MmsMessage.makeImageHeaderForDeliver(path, data.getFilename02()); |
|
| 404 |
+ if (file02HeadBuffer != null) {
|
|
| 405 |
+ fileCount++; |
|
| 406 |
+ } |
|
| 407 |
+ ByteBuffer file03HeadBuffer = MmsMessage.makeImageHeaderForDeliver(path, data.getFilename03()); |
|
| 408 |
+ if (file03HeadBuffer != null) {
|
|
| 409 |
+ fileCount++; |
|
| 410 |
+ } |
|
| 411 |
+ |
|
| 412 |
+ /* fileCount 저장 */ |
|
| 413 |
+ data.setFileCount(fileCount); |
|
| 414 |
+ |
|
| 415 |
+ Header.putHeader(sendBuffer, Header.COMMAND_DELIVER, MmsMessage.DELIVER_MMS_BODY_LENGTH); |
|
| 416 |
+ MmsMessage.makeDataForDeliver(sendBuffer, data); |
|
| 417 |
+ saveLog("[MESSAGE SEND] [... ...]");
|
|
| 418 |
+ saveLog("[MESSAGE DATA : " + data.toString() + "]");
|
|
| 419 |
+ |
|
| 420 |
+ int mmsBufferLength = sendBuffer.capacity(); |
|
| 421 |
+ socketChannel.write(sendBuffer); |
|
| 422 |
+ |
|
| 423 |
+ if (file01HeadBuffer != null) {
|
|
| 424 |
+ socketChannel.write(file01HeadBuffer); |
|
| 425 |
+ mmsImageSend(path + data.getFilename01()); |
|
| 426 |
+ } |
|
| 427 |
+ if (file02HeadBuffer != null) {
|
|
| 428 |
+ socketChannel.write(file02HeadBuffer); |
|
| 429 |
+ mmsImageSend(path + data.getFilename02()); |
|
| 430 |
+ } |
|
| 431 |
+ if (file03HeadBuffer != null) {
|
|
| 432 |
+ socketChannel.write(file03HeadBuffer); |
|
| 433 |
+ mmsImageSend(path + data.getFilename03()); |
|
| 434 |
+ } |
|
| 435 |
+ |
|
| 436 |
+ long MSG_SEND_TIME = System.currentTimeMillis(); |
|
| 437 |
+ while (true) {
|
|
| 438 |
+ if (System.currentTimeMillis() - MSG_SEND_TIME >= Packet.LIMIT_PACKET_SEND_TIMEOUT) {
|
|
| 439 |
+ saveLog("[messageSendTimeOut : Expired ... ... ... ... ... ... ...]");
|
|
| 440 |
+ throw new Exception("messageSendTimeOut : Expired ... ... ... ... ... ... ...");
|
|
| 441 |
+ } |
|
| 442 |
+ int recvCount = socketChannel.read(recvBuffer); |
|
| 443 |
+ if (recvCount == -1) {
|
|
| 444 |
+ saveLog("[MESSAGE SEND] [FAIL] [SOCKET IS CLOSED]");
|
|
| 445 |
+ throw new Exception("DELIVER ERROR");
|
|
| 446 |
+ } else if (recvCount > 0) {
|
|
| 447 |
+ setDeliverMsgId(data.getMsgId()); |
|
| 448 |
+// worker.updateToDeliver(data.getMsgId()); |
|
| 449 |
+ saveLog("[MESSAGE SEND] [SUCCESS]");
|
|
| 450 |
+ lastPacketSendTime = System.currentTimeMillis(); |
|
| 451 |
+ break; |
|
| 452 |
+ } |
|
| 453 |
+ } |
|
| 454 |
+ } catch (Exception e) {
|
|
| 455 |
+ e.printStackTrace(); |
|
| 456 |
+ saveSystemLog("ERROR [" + e.getMessage() + "]");
|
|
| 457 |
+ saveSystemLog("ERROR DETAIL");
|
|
| 458 |
+ saveSystemLog(e.toString()); |
|
| 459 |
+ throw new Exception(e); |
|
| 460 |
+ } |
|
| 461 |
+ } |
|
| 462 |
+ |
|
| 463 |
+ private void mmsImageSend(String imagePath) throws IOException {
|
|
| 464 |
+ ByteBuffer buff = ByteBuffer.allocate(1024); |
|
| 465 |
+ Path src = Paths.get(imagePath); |
|
| 466 |
+ |
|
| 467 |
+ try (FileChannel rc = FileChannel.open(src, StandardOpenOption.READ)) {
|
|
| 468 |
+ int num; |
|
| 469 |
+ while (true) {
|
|
| 470 |
+ num = rc.read(buff); |
|
| 471 |
+ if (num == -1) {
|
|
| 472 |
+ break; |
|
| 473 |
+ } |
|
| 474 |
+ |
|
| 475 |
+ buff.flip(); |
|
| 476 |
+ socketChannel.write(buff); |
|
| 477 |
+ buff.clear(); |
|
| 478 |
+ } |
|
| 479 |
+ |
|
| 480 |
+ } catch (IOException e) {
|
|
| 481 |
+ throw e; |
|
| 482 |
+ } |
|
| 483 |
+ } |
|
| 484 |
+ |
|
| 485 |
+ private void mmsMessageService_bak(MunjaonMsg data) throws Exception {
|
|
| 334 | 486 |
try {
|
| 335 | 487 |
/* 이미지 경로 디폴트 경로 사용 여부 */ |
| 336 | 488 |
String defaultYn = getProp("MMS", "DEFAULT_PATH_YN");
|
... | ... | @@ -373,22 +525,16 @@ |
| 373 | 525 |
ByteBuffer file01Buffer = MmsMessage.makeImageForDeliver(path, data.getFilename01()); |
| 374 | 526 |
if (file01Buffer != null) {
|
| 375 | 527 |
saveLog("file01Buffer : " + file01Buffer.capacity());
|
| 376 |
- } |
|
| 377 |
- if (file01Buffer != null) {
|
|
| 378 | 528 |
fileCount++; |
| 379 | 529 |
} |
| 380 | 530 |
ByteBuffer file02Buffer = MmsMessage.makeImageForDeliver(path, data.getFilename02()); |
| 381 | 531 |
if (file02Buffer != null) {
|
| 382 | 532 |
saveLog("file02Buffer : " + file02Buffer.capacity());
|
| 383 |
- } |
|
| 384 |
- if (file02Buffer != null) {
|
|
| 385 | 533 |
fileCount++; |
| 386 | 534 |
} |
| 387 | 535 |
ByteBuffer file03Buffer = MmsMessage.makeImageForDeliver(path, data.getFilename03()); |
| 388 | 536 |
if (file03Buffer != null) {
|
| 389 | 537 |
saveLog("file03Buffer : " + file03Buffer.capacity());
|
| 390 |
- } |
|
| 391 |
- if (file03Buffer != null) {
|
|
| 392 | 538 |
fileCount++; |
| 393 | 539 |
} |
| 394 | 540 |
/* fileCount 저장 */ |
... | ... | @@ -401,32 +547,50 @@ |
| 401 | 547 |
|
| 402 | 548 |
ByteBuffer[] byteBuffers = new ByteBuffer[fileCount + 1]; |
| 403 | 549 |
int index = 0; |
| 550 |
+ int mmsBufferLength = sendBuffer.capacity(); |
|
| 404 | 551 |
byteBuffers[index] = sendBuffer; |
| 552 |
+ socketChannel.write(sendBuffer); |
|
| 405 | 553 |
index++; |
| 406 | 554 |
if (file01Buffer != null) {
|
| 555 |
+ System.out.println("file01Buffer Last = " + file01Buffer.get(file01Buffer.capacity() - 1));
|
|
| 556 |
+ mmsBufferLength += file01Buffer.capacity(); |
|
| 407 | 557 |
byteBuffers[index] = file01Buffer; |
| 558 |
+ socketChannel.write(file01Buffer); |
|
| 408 | 559 |
index++; |
| 409 | 560 |
} |
| 410 | 561 |
if (file02Buffer != null) {
|
| 562 |
+ System.out.println("file02Buffer Last = " + file02Buffer.get(file02Buffer.capacity() - 1));
|
|
| 563 |
+ mmsBufferLength += file02Buffer.capacity(); |
|
| 411 | 564 |
byteBuffers[index] = file02Buffer; |
| 565 |
+ socketChannel.write(file02Buffer); |
|
| 412 | 566 |
index++; |
| 413 | 567 |
} |
| 414 | 568 |
if (file03Buffer != null) {
|
| 569 |
+ System.out.println("file03Buffer Last = " + file03Buffer.get(file03Buffer.capacity() - 1));
|
|
| 570 |
+ mmsBufferLength += file03Buffer.capacity(); |
|
| 415 | 571 |
byteBuffers[index] = file03Buffer; |
| 416 |
- index++; |
|
| 572 |
+ socketChannel.write(file03Buffer); |
|
| 417 | 573 |
} |
| 418 | 574 |
|
| 419 |
- socketChannel.write(byteBuffers); |
|
| 575 |
+ saveSystemLog("mmsBufferLength : " + mmsBufferLength);
|
|
| 576 |
+ saveSystemLog("byteBuffers : " + byteBuffers.length);
|
|
| 577 |
+ ByteBuffer mmsSendBuffer = ByteBuffer.allocate(mmsBufferLength); |
|
| 578 |
+ Packet.mergeBuffers(mmsSendBuffer, byteBuffers); |
|
| 579 |
+ |
|
| 580 |
+ System.out.println("mmsSendBuffer Last = " + mmsSendBuffer.get(mmsSendBuffer.capacity() - 1));
|
|
| 581 |
+ |
|
| 582 |
+// socketChannel.write(mmsSendBuffer); |
|
| 583 |
+// socketChannel.write(byteBuffers); |
|
| 420 | 584 |
long MSG_SEND_TIME = System.currentTimeMillis(); |
| 421 | 585 |
while (true) {
|
| 422 | 586 |
if (System.currentTimeMillis() - MSG_SEND_TIME >= Packet.LIMIT_PACKET_SEND_TIMEOUT) {
|
| 423 | 587 |
saveLog("[messageSendTimeOut : Expired ... ... ... ... ... ... ...]");
|
| 424 |
- throw new RuntimeException("messageSendTimeOut : Expired ... ... ... ... ... ... ...");
|
|
| 588 |
+ throw new Exception("messageSendTimeOut : Expired ... ... ... ... ... ... ...");
|
|
| 425 | 589 |
} |
| 426 | 590 |
int recvCount = socketChannel.read(recvBuffer); |
| 427 | 591 |
if (recvCount == -1) {
|
| 428 | 592 |
saveLog("[MESSAGE SEND] [FAIL] [SOCKET IS CLOSED]");
|
| 429 |
- throw new RuntimeException("DELIVER ERROR");
|
|
| 593 |
+ throw new Exception("DELIVER ERROR");
|
|
| 430 | 594 |
} else if (recvCount > 0) {
|
| 431 | 595 |
setDeliverMsgId(data.getMsgId()); |
| 432 | 596 |
// worker.updateToDeliver(data.getMsgId()); |
... | ... | @@ -435,15 +599,16 @@ |
| 435 | 599 |
break; |
| 436 | 600 |
} |
| 437 | 601 |
} |
| 438 |
- } catch (IOException e) {
|
|
| 602 |
+ } catch (Exception e) {
|
|
| 603 |
+ e.printStackTrace(); |
|
| 439 | 604 |
saveSystemLog("ERROR [" + e.getMessage() + "]");
|
| 440 | 605 |
saveSystemLog("ERROR DETAIL");
|
| 441 | 606 |
saveSystemLog(e.toString()); |
| 442 |
- throw new RuntimeException(e); |
|
| 607 |
+ throw new Exception(e); |
|
| 443 | 608 |
} |
| 444 | 609 |
} |
| 445 | 610 |
|
| 446 |
- private void katMessageService(MunjaonMsg data) {
|
|
| 611 |
+ private void katMessageService(MunjaonMsg data) throws Exception {
|
|
| 447 | 612 |
try {
|
| 448 | 613 |
/* 이미지 경로 디폴트 경로 사용 여부 */ |
| 449 | 614 |
String defaultYn = getProp("KAKAO", "DEFAULT_PATH_YN");
|
... | ... | @@ -498,12 +663,12 @@ |
| 498 | 663 |
while (true) {
|
| 499 | 664 |
if (System.currentTimeMillis() - MSG_SEND_TIME >= Packet.LIMIT_PACKET_SEND_TIMEOUT) {
|
| 500 | 665 |
saveLog("[messageSendTimeOut : Expired ... ... ... ... ... ... ...]");
|
| 501 |
- throw new RuntimeException("messageSendTimeOut : Expired ... ... ... ... ... ... ...");
|
|
| 666 |
+ throw new Exception("messageSendTimeOut : Expired ... ... ... ... ... ... ...");
|
|
| 502 | 667 |
} |
| 503 | 668 |
int recvCount = socketChannel.read(recvBuffer); |
| 504 | 669 |
if (recvCount == -1) {
|
| 505 | 670 |
saveLog("[MESSAGE SEND] [FAIL] [SOCKET IS CLOSED]");
|
| 506 |
- throw new RuntimeException("DELIVER ERROR");
|
|
| 671 |
+ throw new Exception("DELIVER ERROR");
|
|
| 507 | 672 |
} else if (recvCount > 0) {
|
| 508 | 673 |
setDeliverMsgId(data.getMsgId()); |
| 509 | 674 |
// worker.updateToDeliver(data.getMsgId()); |
... | ... | @@ -512,15 +677,15 @@ |
| 512 | 677 |
break; |
| 513 | 678 |
} |
| 514 | 679 |
} |
| 515 |
- } catch (IOException e) {
|
|
| 680 |
+ } catch (Exception e) {
|
|
| 516 | 681 |
saveSystemLog("ERROR [" + e.getMessage() + "]");
|
| 517 | 682 |
saveSystemLog("ERROR DETAIL");
|
| 518 | 683 |
saveSystemLog(e.toString()); |
| 519 |
- throw new RuntimeException(e); |
|
| 684 |
+ throw new Exception(e); |
|
| 520 | 685 |
} |
| 521 | 686 |
} |
| 522 | 687 |
|
| 523 |
- private void kftMessageService(MunjaonMsg data) {
|
|
| 688 |
+ private void kftMessageService(MunjaonMsg data) throws Exception {
|
|
| 524 | 689 |
try {
|
| 525 | 690 |
/* 이미지 경로 디폴트 경로 사용 여부 */ |
| 526 | 691 |
String defaultYn = getProp("KAKAO", "DEFAULT_PATH_YN");
|
... | ... | @@ -574,12 +739,12 @@ |
| 574 | 739 |
while (true) {
|
| 575 | 740 |
if (System.currentTimeMillis() - MSG_SEND_TIME >= Packet.LIMIT_PACKET_SEND_TIMEOUT) {
|
| 576 | 741 |
saveLog("[messageSendTimeOut : Expired ... ... ... ... ... ... ...]");
|
| 577 |
- throw new RuntimeException("messageSendTimeOut : Expired ... ... ... ... ... ... ...");
|
|
| 742 |
+ throw new Exception("messageSendTimeOut : Expired ... ... ... ... ... ... ...");
|
|
| 578 | 743 |
} |
| 579 | 744 |
int recvCount = socketChannel.read(recvBuffer); |
| 580 | 745 |
if (recvCount == -1) {
|
| 581 | 746 |
saveLog("[MESSAGE SEND] [FAIL] [SOCKET IS CLOSED]");
|
| 582 |
- throw new RuntimeException("DELIVER ERROR");
|
|
| 747 |
+ throw new Exception("DELIVER ERROR");
|
|
| 583 | 748 |
} else if (recvCount > 0) {
|
| 584 | 749 |
setDeliverMsgId(data.getMsgId()); |
| 585 | 750 |
// worker.updateToDeliver(data.getMsgId()); |
... | ... | @@ -588,11 +753,11 @@ |
| 588 | 753 |
break; |
| 589 | 754 |
} |
| 590 | 755 |
} |
| 591 |
- } catch (IOException e) {
|
|
| 756 |
+ } catch (Exception e) {
|
|
| 592 | 757 |
saveSystemLog("ERROR [" + e.getMessage() + "]");
|
| 593 | 758 |
saveSystemLog("ERROR DETAIL");
|
| 594 | 759 |
saveSystemLog(e.toString()); |
| 595 |
- throw new RuntimeException(e); |
|
| 760 |
+ throw new Exception(e); |
|
| 596 | 761 |
} |
| 597 | 762 |
} |
| 598 | 763 |
|
... | ... | @@ -622,10 +787,10 @@ |
| 622 | 787 |
} |
| 623 | 788 |
} |
| 624 | 789 |
} catch (Exception e) {
|
| 790 |
+ IS_ERROR = true; |
|
| 625 | 791 |
saveSystemLog("ERROR [" + e.getMessage() + "]");
|
| 626 | 792 |
saveSystemLog("ERROR DETAIL");
|
| 627 | 793 |
saveSystemLog(e.toString()); |
| 628 |
- throw new RuntimeException(e); |
|
| 629 | 794 |
} |
| 630 | 795 |
} |
| 631 | 796 |
|
Add a comment
Delete comment
Once you delete this comment, you won't be able to recover it. Are you sure you want to delete this comment?