Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- @Service
- public class ActuatorTraceService {
- private JsonParser jsonParser = new JsonParser();
- private List<String> listWithInformationFromTrace = new ArrayList<>();
- private JSONArray jsonArrayFromString;
- private JSONArray listWithoutRequestAndTracePath;
- public void takeInformationFromActuatorTrace() {
- jsonArrayFromString = new JSONArray("[{}]");
- String urlAddressForTrace = "http://localhost:8080/trace";
- jsonArrayFromString = new JSONArray(jsonParser.takeJsonAsAStringFromUrl(urlAddressForTrace));
- }
- public String createPathForCheck(int i) {
- String pathForCheck = jsonArrayFromString
- .getJSONObject(i)
- .getJSONObject("info")
- .get("path")
- .toString();
- return pathForCheck;
- }
- public void createListWithoutRequestAndTracePath() {
- listWithInformationFromTrace.clear();
- takeInformationFromActuatorTrace();
- listWithoutRequestAndTracePath = new JSONArray();
- for (int i = 0; i < jsonArrayFromString.length(); i++) {
- if (!createPathForCheck(i).equals("/request") &&
- !createPathForCheck(i).equals("/trace")) {
- listWithoutRequestAndTracePath.put(jsonArrayFromString.get(i));
- }
- }
- }
- public List<String> createListWithInformationsFromTrace(){
- createListWithoutRequestAndTracePath();
- for (int i=0; i<listWithoutRequestAndTracePath.length(); i++){
- String timestampAndRequestInformation = takeTimestampFromTrace(i) + "n" + takeRequestInformationFromTrace(i) + "n";
- listWithInformationFromTrace.add(timestampAndRequestInformation);
- }
- return listWithInformationFromTrace;
- }
- public String takeRequestInformationFromTrace(int i) {
- return listWithoutRequestAndTracePath
- .getJSONObject(i)
- .getJSONObject("info")
- .getJSONObject("headers")
- .get("request")
- .toString()
- + "n";
- }
- public String takeTimestampFromTrace(int i) {
- return jsonArrayFromString.getJSONObject(i).get("timestamp").toString() + "n";
- }
- public String printLastTenRequestInformationFromTrace() {
- StringBuilder stringToPrint = new StringBuilder();
- createListWithInformationsFromTrace();
- if (listWithInformationFromTrace.size() > 10) {
- for (int i = 0; i < StaticValues.NUMBER_POSITION_TO_PRINT; i++) {
- stringToPrint.append(listWithInformationFromTrace.get(i));
- }
- } else {
- for (int i = 0; i < listWithInformationFromTrace.size(); i++) {
- stringToPrint.append(listWithInformationFromTrace.get(i));
- }
- }
- return stringToPrint.toString();
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement