메시지 수신 처리 오류 수정

main
semin.baek 9 months ago
parent 865cb30cb3
commit 4107b4f789

@ -2,7 +2,10 @@
<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
<mapper namespace="address.dropbox.cubrid.ttoBd">
<insert id="insertTtoBd" parameterType="map">
INSERT INTO TTO_BD (
MERGE INTO TTO_BD
USING DUAL ON (BLDG_MNG_NO = #{BLDG_MNG_NO})
WHEN NOT MATCHED THEN
INSERT (
STDG_CD, CTPV_NM, SGG_NM, STTY_EMD_NM, STLI_NM, MTN_YN, LOTNO_MNO, LOTNO_SNO, ROAD_NM_CD, ROAD_NM, UDGD_YN, BMNO, BSNO, BDRG_BLDG_NM, DTL_BLDG_NM, BLDG_MNG_NO, EMD_SN, DONG_CD, DONG_NM, ZIP, ZIP_SN, BULK_DLDTN_NM, MVMN_RSN_CD, ANCMNT_YMD, CHG_BFR_ROAD_NM_ADDR, SGG_BLDG_NM, APTCPX_YN, BSCS_ZONE_NO, DADDR_YN, RMRK1, RMRK2, TRANSFER_YN, TRANSFER_DATE
)
VALUES (

@ -13,6 +13,7 @@ import org.springframework.web.bind.annotation.RestController;
import java.io.IOException;
import java.util.Collection;
import java.util.UUID;
@Slf4j
@RestController
@ -53,7 +54,13 @@ public class ListenerController {
*/
@PostMapping(value = "/telegram")
public AckDto telegram(HttpServletRequest request) {
AckDto ackDto = AckDto.builder().build();
AckDto ackDto;
try {
String bodyString= ServletUtils.getBodyString(request);
ackDto = listenerService.receiveAck(bodyString);
} catch (IOException e) {
ackDto = AckDto.builder().result(AckDto.ResultType.RECEIVE_FAIL).resultText(e.getLocalizedMessage()).messageUuid("").build();
}
return ackDto;
}
}

@ -1,12 +1,12 @@
package com.bsmlab.dfx.agent.listener.dto;
import lombok.Builder;
import lombok.Getter;
import lombok.Setter;
import lombok.*;
@Getter
@Setter
@Builder
@AllArgsConstructor
@NoArgsConstructor
/**
* Listen
* 1. listener

@ -107,4 +107,15 @@ public class ListenerService {
}
return ackDto;
}
public AckDto receiveAck(String messageJsonString) {
AckDto ackDto;
try {
ackDto = MessageUtils.toAckDto(messageJsonString);
}
catch (NullMessageException | IllegalMessageException e) {
ackDto = AckDto.builder().result(AckDto.ResultType.RECEIVE_FAIL).resultText(e.getLocalizedMessage()).messageUuid("").build();
}
return ackDto;
}
}

@ -1,6 +1,7 @@
package com.bsmlab.dfx.agent.support;
import com.bsmlab.dfx.agent.config.AgentConfigDto;
import com.bsmlab.dfx.agent.listener.dto.AckDto;
import com.bsmlab.dfx.agent.listener.dto.ReceiveMessageDto;
import com.bsmlab.dfx.agent.support.exception.IllegalMessageException;
import com.bsmlab.dfx.agent.support.exception.InCompleteMessageException;
@ -140,4 +141,26 @@ public class MessageUtils {
}
return receiveMessageDto;
}
public static AckDto toAckDto(String messageJsonString) throws NullMessageException, IllegalMessageException {
ObjectMapper objectMapper = new ObjectMapper();
Map<String, Object> map = null;
AckDto ackDto;
try {
map = objectMapper.readValue(messageJsonString, new TypeReference<HashMap<String, Object>>() {});
if(map == null) {
throw new NullMessageException("");
}
else {
AckDto.ResultType result = EnumUtils.getEnum(AckDto.ResultType.class, String.valueOf(map.get("result")));
String resultText = String.valueOf(map.get("resultText"));
String messageUuid = String.valueOf(map.get("messageUuid"));
ackDto = AckDto.builder().result(result).resultText(resultText).messageUuid(messageUuid).build();
}
}
catch(JsonProcessingException e) {
throw new IllegalMessageException(e.getMessage());
}
return ackDto;
}
}

@ -134,7 +134,7 @@ public class DropBoxTaskExecutorService {
HttpEntity<AckDto> bodyEntity = new HttpEntity<>(ackDto, httpHeaders);
RestTemplate restTemplate = new RestTemplate();
AgentConfigDto.KnownAgent knownAgent = agentConfigReader.getKnownAgent(receiveMessageDto.getSenderHostId());
String url = "https://" + knownAgent.getHostName() + ":" + knownAgent.getListenPort() + "/telegram";
String url = "http://" + knownAgent.getHostName() + ":" + knownAgent.getListenPort() + "/telegram";
String response = restTemplate.postForObject(url, bodyEntity, String.class);
ObjectMapper objectMapper = new ObjectMapper();
AckDto responseAckDto;

@ -90,15 +90,16 @@ public class PostmanSchedulerService {
RestTemplate restTemplate = new RestTemplate();
AgentConfigDto.KnownAgent knownAgent = agentConfigReader.getKnownAgent(postman.getRecipientHostId());
String url = "http://" + knownAgent.getHostName() + ":" + knownAgent.getListenPort() + "/listen";
log.debug("postman to {} send a message {}", receiveMessageDto.getRecipientHostId(), receiveMessageDto.toString());
log.debug("postman to {} send a message UUID {}", receiveMessageDto.getRecipientHostId(), receiveMessageDto.getMessageUuid());
String response = restTemplate.postForObject(url, bodyEntity, String.class);
AckDto ackDto = objectMapper.readValue(response, new TypeReference<AckDto>() {});
log.debug("postman received ack from {} ack: {}", receiveMessageDto.getRecipientHostId(), ackDto);
if(AckDto.ResultType.RECEIVE_SUCCESS != ackDto.getResult()) {
throw new DfxException(postman.getRecipientHostId() + "에게 전송하였으나 상대방이 수신하지 못하였습니다." + response);
}
else {
String postProcessingSqlId = postman.getMessage().getPostProcessingSqlId();
sqlExecuteService.update(dataSourceId, postProcessingSqlId, null);
sqlExecuteService.update(dataSourceId, postProcessingSqlId, new HashMap<String, Object>());
}
} catch (JsonProcessingException e) {
throw new RuntimeException(e);

Loading…
Cancel
Save