Advertisement
Guest User

Untitled

a guest
Jul 17th, 2017
76
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.80 KB | None | 0 0
  1. @Service
  2. public class ActuatorTraceService {
  3.  
  4. private JsonParser jsonParser = new JsonParser();
  5. private List<String> listWithInformationFromTrace = new ArrayList<>();
  6. private JSONArray jsonArrayFromString;
  7. private JSONArray listWithoutRequestAndTracePath;
  8.  
  9. public void takeInformationFromActuatorTrace() {
  10. jsonArrayFromString = new JSONArray("[{}]");
  11. String urlAddressForTrace = "http://localhost:8080/trace";
  12. jsonArrayFromString = new JSONArray(jsonParser.takeJsonAsAStringFromUrl(urlAddressForTrace));
  13. }
  14.  
  15. public String createPathForCheck(int i) {
  16. String pathForCheck = jsonArrayFromString
  17. .getJSONObject(i)
  18. .getJSONObject("info")
  19. .get("path")
  20. .toString();
  21. return pathForCheck;
  22. }
  23.  
  24. public void createListWithoutRequestAndTracePath() {
  25. listWithInformationFromTrace.clear();
  26. takeInformationFromActuatorTrace();
  27. listWithoutRequestAndTracePath = new JSONArray();
  28.  
  29. for (int i = 0; i < jsonArrayFromString.length(); i++) {
  30. if (!createPathForCheck(i).equals("/request") &&
  31. !createPathForCheck(i).equals("/trace")) {
  32. listWithoutRequestAndTracePath.put(jsonArrayFromString.get(i));
  33. }
  34. }
  35. }
  36.  
  37. public List<String> createListWithInformationsFromTrace(){
  38. createListWithoutRequestAndTracePath();
  39.  
  40. for (int i=0; i<listWithoutRequestAndTracePath.length(); i++){
  41. String timestampAndRequestInformation = takeTimestampFromTrace(i) + "n" + takeRequestInformationFromTrace(i) + "n";
  42. listWithInformationFromTrace.add(timestampAndRequestInformation);
  43. }
  44. return listWithInformationFromTrace;
  45. }
  46.  
  47. public String takeRequestInformationFromTrace(int i) {
  48. return listWithoutRequestAndTracePath
  49. .getJSONObject(i)
  50. .getJSONObject("info")
  51. .getJSONObject("headers")
  52. .get("request")
  53. .toString()
  54. + "n";
  55. }
  56.  
  57. public String takeTimestampFromTrace(int i) {
  58. return jsonArrayFromString.getJSONObject(i).get("timestamp").toString() + "n";
  59. }
  60.  
  61. public String printLastTenRequestInformationFromTrace() {
  62. StringBuilder stringToPrint = new StringBuilder();
  63. createListWithInformationsFromTrace();
  64.  
  65. if (listWithInformationFromTrace.size() > 10) {
  66. for (int i = 0; i < StaticValues.NUMBER_POSITION_TO_PRINT; i++) {
  67. stringToPrint.append(listWithInformationFromTrace.get(i));
  68. }
  69. } else {
  70. for (int i = 0; i < listWithInformationFromTrace.size(); i++) {
  71. stringToPrint.append(listWithInformationFromTrace.get(i));
  72. }
  73. }
  74.  
  75. return stringToPrint.toString();
  76. }
  77. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement