저장된 메시지를 json으로 변환하여 출력하는 command line 기능 추가

main
semin.baek 7 months ago
parent 738d37b2c9
commit c45e62d5eb

@ -5,6 +5,7 @@ import com.bsmlab.dfx.agent.config.AgentConfigReader;
import com.bsmlab.dfx.agent.config.datasource.DynamicRoutingDataSource; import com.bsmlab.dfx.agent.config.datasource.DynamicRoutingDataSource;
import com.bsmlab.dfx.agent.listener.dto.AckDto; import com.bsmlab.dfx.agent.listener.dto.AckDto;
import com.bsmlab.dfx.agent.listener.dto.CommandDto; import com.bsmlab.dfx.agent.listener.dto.CommandDto;
import com.bsmlab.dfx.agent.listener.dto.ReceiveMessageDto;
import com.fasterxml.jackson.core.JsonProcessingException; import com.fasterxml.jackson.core.JsonProcessingException;
import com.fasterxml.jackson.core.type.TypeReference; import com.fasterxml.jackson.core.type.TypeReference;
import com.fasterxml.jackson.databind.ObjectMapper; import com.fasterxml.jackson.databind.ObjectMapper;
@ -20,6 +21,7 @@ import org.springframework.web.client.ResourceAccessException;
import org.springframework.web.client.RestTemplate; import org.springframework.web.client.RestTemplate;
import javax.sql.DataSource; import javax.sql.DataSource;
import java.io.*;
import java.sql.Connection; import java.sql.Connection;
import java.sql.SQLException; import java.sql.SQLException;
import java.util.HashMap; import java.util.HashMap;
@ -39,6 +41,71 @@ public class DfxAgentRunner implements ApplicationRunner {
// command line 실행 중 --check-config 가 있는 경우 settings.json 을 로드하여 DB 연결, knownAgent 연결 테스트를 진행한다. // command line 실행 중 --check-config 가 있는 경우 settings.json 을 로드하여 DB 연결, knownAgent 연결 테스트를 진행한다.
// java -jar $AGENT_HOME/lib/dfxagent.jar --setting.check --setting.file=$AGENT_HOME/conf/settings.json & // java -jar $AGENT_HOME/lib/dfxagent.jar --setting.check --setting.file=$AGENT_HOME/conf/settings.json &
if(args.containsOption("setting.check")) { if(args.containsOption("setting.check")) {
this.checkConfig(args);
}
else if(args.containsOption("parse.message.file")) {
this.parseMessageFile(args);
}
}
private void print(String text) {
System.out.println(text);
}
private void parseMessageFile(ApplicationArguments args) throws IOException {
OutputStream outputStream = null;
try {
this.print("-----------------------");
this.print("변환을 시작합니다.");
File sourceFile = new File(args.getOptionValues("parse.message.file").get(0));
this.print("메시지 파일: " + sourceFile.getAbsoluteFile());
if(args.getOptionValues("output") != null && !args.getOptionValues("output").isEmpty()) {
File outputFile = new File(args.getOptionValues("output").get(0));
this.print("결과저장: " + outputFile.getAbsoluteFile());
outputStream = new FileOutputStream(outputFile);
}
else {
this.print("결과저장: 화면출력");
outputStream = System.out;
}
this.print("-----------------------");
if(!sourceFile.exists()) {
new FileNotFoundException("cannot find: " + sourceFile.getAbsolutePath());
}
ObjectInputStream objectInputStream = new ObjectInputStream(new FileInputStream(sourceFile));
ReceiveMessageDto receiveMessageDto = (ReceiveMessageDto) objectInputStream.readObject();
ObjectMapper objectMapper = new ObjectMapper();
String parsedString = objectMapper.writerWithDefaultPrettyPrinter().writeValueAsString(receiveMessageDto);
outputStream.write(parsedString.getBytes());
}
catch(FileNotFoundException e) {
this.print("오류가 포함되어 있습니다.");
this.print(e.getLocalizedMessage());
this.print("점검을 종료합니다.");
System.exit(2);
} catch (ClassNotFoundException e) {
this.print("오류가 포함되어 있습니다.");
this.print(e.getLocalizedMessage());
this.print("점검을 종료합니다.");
System.exit(2);
} catch (JsonProcessingException e) {
this.print("오류가 포함되어 있습니다.");
this.print(e.getLocalizedMessage());
this.print("점검을 종료합니다.");
} catch (IOException e) {
this.print("오류가 포함되어 있습니다.");
this.print(e.getLocalizedMessage());
this.print("점검을 종료합니다.");
} finally {
outputStream.close();
}
this.print("-----------------------");
this.print("변환을 종료합니다.");
this.print("-----------------------");
System.exit(0);
}
private void checkConfig(ApplicationArguments args) {
this.print("-----------------------"); this.print("-----------------------");
this.print("DfxAgent 설정 및 환경 점검"); this.print("DfxAgent 설정 및 환경 점검");
this.print("-----------------------"); this.print("-----------------------");
@ -209,8 +276,3 @@ public class DfxAgentRunner implements ApplicationRunner {
} }
} }
private void print(String text) {
System.out.println(text);
}
}

Loading…
Cancel
Save