@ -23,12 +23,13 @@ import java.util.*;
@Slf4j
public class MessageUtils {
private static final ObjectMapper objectMapper = new ObjectMapper ( ) ;
private MessageUtils ( ) { } ;
@SuppressWarnings ( "unchecked" )
public static ReceiveMessageDto toReceiveMessageDto ( String messageJsonString ) throws IllegalMessageException , NullMessageException , InCompleteMessageException {
ReceiveMessageDto receiveMessageDto = null ;
ObjectMapper objectMapper = new ObjectMapper ( ) ;
Map < String , Object > map = null ;
try {
map = objectMapper . readValue ( messageJsonString , new TypeReference < HashMap < String , Object > > ( ) { } ) ;
@ -164,7 +165,6 @@ public class MessageUtils {
}
public static AckDto toAckDto ( String messageJsonString ) throws NullMessageException , IllegalMessageException {
ObjectMapper objectMapper = new ObjectMapper ( ) ;
Map < String , Object > map = null ;
AckDto ackDto ;
try {
@ -187,7 +187,6 @@ public class MessageUtils {
public static CommandDto toCommandDto ( String messageJsonString ) throws IllegalMessageException , NullMessageException {
CommandDto commandDto ;
ObjectMapper objectMapper = new ObjectMapper ( ) ;
Map < String , Object > map = null ;
try {
map = objectMapper . readValue ( messageJsonString , new TypeReference < Map < String , Object > > ( ) { } ) ;
@ -209,7 +208,6 @@ public class MessageUtils {
AgentConfigDto . KnownAgent recipientAgent = agentConfigReader . getKnownAgent ( receiveMessageDto . getRecipientHostId ( ) ) ;
String targetHostId = recipientAgent . getRoutingHostIdList ( ) . get ( 0 ) ;
AgentConfigDto . KnownAgent knownAgent = agentConfigReader . getKnownAgent ( targetHostId ) ;
ObjectMapper objectMapper = new ObjectMapper ( ) ;
HttpHeaders httpHeaders = new HttpHeaders ( ) ;
httpHeaders . setContentType ( MediaType . APPLICATION_JSON ) ;
httpHeaders . set ( "User-Agent" , agentConfigReader . getApplicationName ( ) + ", version: " + agentConfigReader . getApplicationVersion ( ) + "(" + agentConfigReader . getApplicationCommitId ( ) + ")"
@ -238,7 +236,6 @@ public class MessageUtils {
}
}
AgentConfigDto . KnownAgent knownAgent = agentConfigReader . getKnownAgent ( targetHostId ) ;
ObjectMapper objectMapper = new ObjectMapper ( ) ;
HttpHeaders httpHeaders = new HttpHeaders ( ) ;
httpHeaders . setContentType ( MediaType . APPLICATION_JSON ) ;
httpHeaders . set ( "User-Agent" , agentConfigReader . getApplicationName ( ) + ", version: " + agentConfigReader . getApplicationVersion ( ) + "(" + agentConfigReader . getApplicationCommitId ( ) + ")"
@ -267,7 +264,6 @@ public class MessageUtils {
String url = "http://" + knownAgent . getHostName ( ) + ":" + knownAgent . getListenPort ( ) + "/command" ;
log . debug ( "StatusChecker to {} send a message UUID {}" , knownAgent . getHostName ( ) , messageUuid ) ;
String response = "" ;
ObjectMapper objectMapper = new ObjectMapper ( ) ;
AckDto ackDto = null ;
response = restTemplate . postForObject ( url , bodyEntity , String . class ) ;
ackDto = objectMapper . readValue ( response , new TypeReference < AckDto > ( ) { } ) ;
@ -275,7 +271,6 @@ public class MessageUtils {
}
public static AckDto announceInformation ( AgentConfigReader agentConfigReader ) throws JsonProcessingException {
ObjectMapper objectMapper = new ObjectMapper ( ) ;
String messageUuid = UUID . randomUUID ( ) . toString ( ) ;
String data = objectMapper . writeValueAsString ( agentConfigReader . getAgentConfigDto ( ) ) ;
CommandDto commandDto = CommandDto . builder ( ) . commandType ( CommandDto . CommandType . INFORMATION ) . messageUuid ( messageUuid ) . data ( data ) . build ( ) ;
@ -291,7 +286,7 @@ public class MessageUtils {
+ agentConfigReader . getAgentConfigDto ( ) . getStatusChecker ( ) . getConsoleHostName ( ) + ":"
+ agentConfigReader . getAgentConfigDto ( ) . getStatusChecker ( ) . getConsoleListenPort ( )
+ "/command" ;
log . debug ( " StatusChecker to console {} send a message UUID {}", agentConfigReader . getAgentConfigDto ( ) . getStatusChecker ( ) . getConsoleHostName ( ) , messageUuid ) ;
log . debug ( " announceInformation to console {} send a message UUID {}", agentConfigReader . getAgentConfigDto ( ) . getStatusChecker ( ) . getConsoleHostName ( ) , messageUuid ) ;
String response = "" ;
AckDto ackDto = null ;
response = restTemplate . postForObject ( url , bodyEntity , String . class ) ;
@ -299,4 +294,24 @@ public class MessageUtils {
return ackDto ;
}
public static AckDto announceMessageHistory ( AgentConfigReader agentConfigReader , ReceiveMessageDto receiveMessageDto ) throws JsonProcessingException {
HttpHeaders httpHeaders = new HttpHeaders ( ) ;
httpHeaders . setContentType ( MediaType . APPLICATION_JSON ) ;
httpHeaders . set ( "User-Agent" , agentConfigReader . getApplicationName ( ) + ", version: " + agentConfigReader . getApplicationVersion ( ) + "(" + agentConfigReader . getApplicationCommitId ( ) + ")"
+ ", host ID: " + agentConfigReader . getAgentConfigDto ( ) . getMyHostId ( )
+ ", action: message-history"
) ;
HttpEntity < ReceiveMessageDto > bodyEntity = new HttpEntity < > ( receiveMessageDto , httpHeaders ) ;
RestTemplate restTemplate = new RestTemplate ( ) ;
String url = ( agentConfigReader . getAgentConfigDto ( ) . getStatusChecker ( ) . isConsoleSslEnabled ( ) ? "https://" : "http://" )
+ agentConfigReader . getAgentConfigDto ( ) . getStatusChecker ( ) . getConsoleHostName ( ) + ":"
+ agentConfigReader . getAgentConfigDto ( ) . getStatusChecker ( ) . getConsoleListenPort ( )
+ "/listen" ;
log . debug ( "announceMessageHistory to console {} send a message UUID {}" , agentConfigReader . getAgentConfigDto ( ) . getStatusChecker ( ) . getConsoleHostName ( ) , receiveMessageDto . getMessageUuid ( ) ) ;
String response = "" ;
AckDto ackDto = null ;
response = restTemplate . postForObject ( url , bodyEntity , String . class ) ;
ackDto = objectMapper . readValue ( response , new TypeReference < AckDto > ( ) { } ) ;
return ackDto ;
}
}