|
|
|
@ -1,21 +1,31 @@
|
|
|
|
package com.bsmlab.dfx.agent.listener.service;
|
|
|
|
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.AckDto;
|
|
|
|
import com.bsmlab.dfx.agent.listener.dto.ReceiveMessageDto;
|
|
|
|
import com.bsmlab.dfx.agent.listener.dto.ReceiveMessageDto;
|
|
|
|
import com.bsmlab.dfx.agent.support.MessageUtils;
|
|
|
|
import com.bsmlab.dfx.agent.support.MessageUtils;
|
|
|
|
import com.bsmlab.dfx.agent.support.exception.IllegalMessageException;
|
|
|
|
import com.bsmlab.dfx.agent.support.exception.IllegalMessageException;
|
|
|
|
import com.bsmlab.dfx.agent.support.exception.InCompleteMessageException;
|
|
|
|
import com.bsmlab.dfx.agent.support.exception.InCompleteMessageException;
|
|
|
|
import com.bsmlab.dfx.agent.support.exception.NullMessageException;
|
|
|
|
import com.bsmlab.dfx.agent.support.exception.NullMessageException;
|
|
|
|
|
|
|
|
import com.bsmlab.dfx.agent.task.dropbox.DropBoxDto;
|
|
|
|
import com.bsmlab.dfx.agent.task.dropbox.DropBoxService;
|
|
|
|
import com.bsmlab.dfx.agent.task.dropbox.DropBoxService;
|
|
|
|
|
|
|
|
import jakarta.servlet.http.Part;
|
|
|
|
import lombok.RequiredArgsConstructor;
|
|
|
|
import lombok.RequiredArgsConstructor;
|
|
|
|
import lombok.extern.slf4j.Slf4j;
|
|
|
|
import lombok.extern.slf4j.Slf4j;
|
|
|
|
import org.springframework.stereotype.Service;
|
|
|
|
import org.springframework.stereotype.Service;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
import java.io.IOException;
|
|
|
|
|
|
|
|
import java.nio.charset.StandardCharsets;
|
|
|
|
|
|
|
|
import java.util.Collection;
|
|
|
|
|
|
|
|
import java.util.Iterator;
|
|
|
|
|
|
|
|
|
|
|
|
@RequiredArgsConstructor
|
|
|
|
@RequiredArgsConstructor
|
|
|
|
@Slf4j
|
|
|
|
@Slf4j
|
|
|
|
@Service
|
|
|
|
@Service
|
|
|
|
public class ListenerService {
|
|
|
|
public class ListenerService {
|
|
|
|
private final DropBoxService dropBoxService;
|
|
|
|
private final DropBoxService dropBoxService;
|
|
|
|
|
|
|
|
private final AgentConfigReader agentConfigReader;
|
|
|
|
|
|
|
|
|
|
|
|
public AckDto receiveMessage(String messageJsonString) {
|
|
|
|
public AckDto receiveMessage(String messageJsonString) {
|
|
|
|
AckDto ackDto = null;
|
|
|
|
AckDto ackDto = null;
|
|
|
|
@ -35,4 +45,40 @@ public class ListenerService {
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return ackDto;
|
|
|
|
return ackDto;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
public AckDto receiveFiles(Collection<Part> parts) {
|
|
|
|
|
|
|
|
AckDto ackDto = null;
|
|
|
|
|
|
|
|
try {
|
|
|
|
|
|
|
|
if(parts == null || parts.size() < 2) {
|
|
|
|
|
|
|
|
throw new IllegalMessageException("파일 전송은 파일의 메타데이터인 application/json 과 n개의 파일 본문인 File Multipart 를 합쳐서 전송하여야 합니다.");
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
else {
|
|
|
|
|
|
|
|
Iterator<Part> iterator = parts.iterator();
|
|
|
|
|
|
|
|
Part firstPart = iterator.next();
|
|
|
|
|
|
|
|
if(firstPart.getContentType() == null || !firstPart.getContentType().contains("application/json")) {
|
|
|
|
|
|
|
|
throw new IllegalMessageException("Multipart의 첫 번째 데이터는 application/json 이어야 합니다.");
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
while(iterator.hasNext()) {
|
|
|
|
|
|
|
|
Part filePart = iterator.next();
|
|
|
|
|
|
|
|
if(filePart.getSubmittedFileName() == null) {
|
|
|
|
|
|
|
|
throw new IllegalMessageException("Multipart의 두 번째 데이터 및 그 이후 데이터는 File 이어야 합니다.");
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
firstPart = iterator.next();
|
|
|
|
|
|
|
|
String messageJsonString = new String(firstPart.getInputStream().readAllBytes(), StandardCharsets.UTF_8);
|
|
|
|
|
|
|
|
ReceiveMessageDto receiveMessageDto = MessageUtils.toReceiveMessageDto(messageJsonString);
|
|
|
|
|
|
|
|
AgentConfigDto.DropBox dropBox = agentConfigReader.getDropBox(receiveMessageDto.getRecipientDropBoxId());
|
|
|
|
|
|
|
|
String saveDirectoryRoot = dropBox.getSaveDirectoryRoot();
|
|
|
|
|
|
|
|
while(iterator.hasNext()) {
|
|
|
|
|
|
|
|
Part part = iterator.next();
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
catch(IllegalMessageException | IOException | InCompleteMessageException | NullMessageException e) {
|
|
|
|
|
|
|
|
log.error("{}", e, e);
|
|
|
|
|
|
|
|
ackDto = AckDto.builder().result(AckDto.ResultType.RECEIVE_FAIL).resultText(e.getLocalizedMessage()).build();
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
return ackDto;
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|