|
|
|
|
@ -3,12 +3,15 @@ package com.bsmlab.dfx.agent.listener.service;
|
|
|
|
|
import com.bsmlab.dfx.agent.config.AgentConfigDto;
|
|
|
|
|
import com.bsmlab.dfx.agent.config.AgentConfigReader;
|
|
|
|
|
import com.bsmlab.dfx.agent.listener.dto.AckDto;
|
|
|
|
|
import com.bsmlab.dfx.agent.listener.dto.CommandDto;
|
|
|
|
|
import com.bsmlab.dfx.agent.listener.dto.ReceiveMessageDto;
|
|
|
|
|
import com.bsmlab.dfx.agent.support.MessageUtils;
|
|
|
|
|
import com.bsmlab.dfx.agent.support.exception.IllegalMessageException;
|
|
|
|
|
import com.bsmlab.dfx.agent.support.exception.InCompleteMessageException;
|
|
|
|
|
import com.bsmlab.dfx.agent.support.exception.NullMessageException;
|
|
|
|
|
import com.bsmlab.dfx.agent.task.dropbox.DropBoxService;
|
|
|
|
|
import com.fasterxml.jackson.core.JsonProcessingException;
|
|
|
|
|
import com.fasterxml.jackson.databind.ObjectMapper;
|
|
|
|
|
import jakarta.servlet.http.Part;
|
|
|
|
|
import lombok.RequiredArgsConstructor;
|
|
|
|
|
import lombok.extern.slf4j.Slf4j;
|
|
|
|
|
@ -39,7 +42,7 @@ public class ListenerService {
|
|
|
|
|
try {
|
|
|
|
|
ReceiveMessageDto receiveMessageDto = MessageUtils.toReceiveMessageDto(messageJsonString);
|
|
|
|
|
if(dropBoxService.isExistToday(receiveMessageDto)) {
|
|
|
|
|
ackDto = AckDto.builder().result(AckDto.ResultType.RECEIVE_FAIL).resultText("금일 전송한 메시지 중 중복된 UUID가 존재합니다.").build();
|
|
|
|
|
ackDto = AckDto.builder().result(AckDto.ResultType.RECEIVE_FAIL).resultText("금일 전송한 메시지 중 중복된 UUID 가 존재합니다.").build();
|
|
|
|
|
}
|
|
|
|
|
else {
|
|
|
|
|
dropBoxService.add(receiveMessageDto);
|
|
|
|
|
@ -62,12 +65,12 @@ public class ListenerService {
|
|
|
|
|
Iterator<Part> iterator = parts.iterator();
|
|
|
|
|
Part firstPart = iterator.next();
|
|
|
|
|
if(firstPart.getContentType() == null || !firstPart.getContentType().contains("application/json")) {
|
|
|
|
|
throw new IllegalMessageException("Multipart의 첫 번째 데이터는 application/json 이어야 합니다.");
|
|
|
|
|
throw new IllegalMessageException("Multipart 의 첫 번째 데이터는 application/json 이어야 합니다.");
|
|
|
|
|
}
|
|
|
|
|
while(iterator.hasNext()) {
|
|
|
|
|
Part filePart = iterator.next();
|
|
|
|
|
if(filePart.getSubmittedFileName() == null) {
|
|
|
|
|
throw new IllegalMessageException("Multipart의 두 번째 데이터 및 그 이후 데이터는 File 이어야 합니다.");
|
|
|
|
|
throw new IllegalMessageException("Multipart 의 두 번째 데이터 및 그 이후 데이터는 File 이어야 합니다.");
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
firstPart = iterator.next();
|
|
|
|
|
@ -118,4 +121,30 @@ public class ListenerService {
|
|
|
|
|
}
|
|
|
|
|
return ackDto;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public AckDto receiveCommand(String messageJsonString) {
|
|
|
|
|
AckDto ackDto;
|
|
|
|
|
CommandDto commandDto;
|
|
|
|
|
try {
|
|
|
|
|
commandDto = MessageUtils.toCommandDto(messageJsonString);
|
|
|
|
|
String resultText = null;
|
|
|
|
|
if(CommandDto.CommandType.ALIVE == commandDto.getCommandType()) {
|
|
|
|
|
resultText = "ALIVE";
|
|
|
|
|
}
|
|
|
|
|
else if(CommandDto.CommandType.INFORMATION == commandDto.getCommandType()) {
|
|
|
|
|
AgentConfigDto agentConfigDto = this.agentConfigReader.getAgentConfigDto();
|
|
|
|
|
ObjectMapper objectMapper = new ObjectMapper();
|
|
|
|
|
try {
|
|
|
|
|
resultText = objectMapper.writeValueAsString(agentConfigDto);
|
|
|
|
|
} catch (JsonProcessingException e) {
|
|
|
|
|
resultText = "";
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
ackDto = AckDto.builder().result(AckDto.ResultType.PROCESS_SUCCESS).messageUuid(commandDto.getMessageUuid()).resultText(resultText).build();
|
|
|
|
|
}
|
|
|
|
|
catch (IllegalMessageException | NullMessageException e) {
|
|
|
|
|
ackDto = AckDto.builder().result(AckDto.ResultType.RECEIVE_FAIL).resultText(e.getLocalizedMessage()).messageUuid("").build();
|
|
|
|
|
}
|
|
|
|
|
return ackDto;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|