AsynchJSONRequest.js 4.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180
  1. /*
  2. *+------------------------------------------------------------------------+
  3. *| Licensed Materials - Property of IBM
  4. *| IBM Cognos Products: Viewer
  5. *| (C) Copyright IBM Corp. 2001, 2012, 2013
  6. *|
  7. *| US Government Users Restricted Rights - Use, duplication or
  8. *| disclosure restricted by GSA ADP Schedule Contract with IBM Corp.
  9. *|
  10. *+------------------------------------------------------------------------+
  11. */
  12. function AsynchJSONRequest(gateway, webContentRoot) {
  13. // initialize the base class
  14. AsynchJSONRequest.baseConstructor.call(this, gateway, webContentRoot);
  15. this.m_jsonResponse = null;
  16. }
  17. // set up the base class
  18. AsynchJSONRequest.prototype = new AsynchRequest();
  19. AsynchJSONRequest.baseConstructor = AsynchRequest;
  20. AsynchJSONRequest.prototype.getJSONResponseObject = function() {
  21. if(this.m_jsonResponse == null) {
  22. if(this.getResponseHeader("Content-type").indexOf("application/json") != -1) {
  23. var text = this.getResponseText();
  24. if(text != null) {
  25. var validJson = this.removeInvalidCharacters(text);
  26. this.m_jsonResponse = eval("(" + validJson + ")");
  27. }
  28. }
  29. }
  30. return this.m_jsonResponse;
  31. };
  32. AsynchJSONRequest.prototype.getTracking = function() {
  33. var jsonResponse = this.getJSONResponseObject();
  34. if(jsonResponse) {
  35. return jsonResponse.tracking;
  36. }
  37. return "";
  38. };
  39. AsynchJSONRequest.prototype.getConversation = function() {
  40. var jsonResponse = this.getJSONResponseObject();
  41. if(jsonResponse) {
  42. return jsonResponse.conversation;
  43. }
  44. return "";
  45. };
  46. AsynchJSONRequest.prototype.getAsynchStatus = function() {
  47. var jsonResponse = this.getJSONResponseObject();
  48. if(jsonResponse) {
  49. return jsonResponse.status;
  50. }
  51. return "unknown";
  52. };
  53. AsynchJSONRequest.prototype.getPrimaryAction = function() {
  54. var jsonResponse = this.getJSONResponseObject();
  55. if(jsonResponse) {
  56. return jsonResponse.primaryAction;
  57. }
  58. return "";
  59. };
  60. AsynchJSONRequest.prototype.getActionState = function() {
  61. var jsonResponse = this.getJSONResponseObject();
  62. if(jsonResponse) {
  63. return jsonResponse.actionState;
  64. }
  65. return "";
  66. };
  67. AsynchJSONRequest.prototype.getDebugLogs = function() {
  68. var jsonResponse = this.getJSONResponseObject();
  69. if(jsonResponse) {
  70. return jsonResponse.debugLogs;
  71. }
  72. return "";
  73. };
  74. AsynchJSONRequest.prototype.isRAPWaitTrue = function() {
  75. var jsonResponse = this.getJSONResponseObject();
  76. if(jsonResponse) {
  77. return (jsonResponse.rapWait === "true");
  78. }
  79. return false;
  80. };
  81. AsynchJSONRequest.prototype.getRAPRequestCache = function() {
  82. var jsonResponse = this.getJSONResponseObject();
  83. if(jsonResponse) {
  84. var requestCache = jsonResponse.rapRequestCache;
  85. if (requestCache !== null && typeof requestCache != "undefined" ) {
  86. return requestCache;
  87. }
  88. }
  89. return null;
  90. };
  91. AsynchJSONRequest.prototype.getMainConversation = function() {
  92. var jsonResponse = this.getJSONResponseObject();
  93. if(jsonResponse) {
  94. return jsonResponse.mainConversation;
  95. }
  96. return null;
  97. };
  98. AsynchJSONRequest.prototype.getMainTracking = function() {
  99. var jsonResponse = this.getJSONResponseObject();
  100. if(jsonResponse) {
  101. return jsonResponse.mainTracking;
  102. }
  103. return null;
  104. };
  105. AsynchJSONRequest.prototype.getResult = function() {
  106. var jsonResponse = this.getJSONResponseObject();
  107. if(jsonResponse && jsonResponse.json) {
  108. var validJson = this.removeInvalidCharacters(jsonResponse.json);
  109. return eval("(" + validJson + ")");
  110. }
  111. return null;
  112. };
  113. AsynchJSONRequest.prototype.removeInvalidCharacters = function(text) {
  114. if (text) {
  115. text = text.replace(/(\n|\r|\t)+/g,"");//characters throw exception in eval
  116. }
  117. return text;
  118. };
  119. AsynchJSONRequest.prototype.getPromptHTMLFragment = function() {
  120. var jsonResponse = this.getJSONResponseObject();
  121. if(jsonResponse && jsonResponse.promptHTMLFragment) {
  122. return jsonResponse.promptHTMLFragment;
  123. }
  124. return "";
  125. };
  126. AsynchJSONRequest.prototype.constructFaultEnvelope = function() {
  127. if(this.m_soapFault == null) {
  128. var jsonResponse = this.getJSONResponseObject();
  129. if(jsonResponse.status == "fault") {
  130. this.m_soapFault = XMLBuilderLoadXMLFromString(jsonResponse.fault);
  131. }
  132. }
  133. return this.m_soapFault;
  134. };
  135. AsynchJSONRequest.prototype.construct = function() {
  136. var asynchRequest = new AsynchJSONRequest(this.m_gateway, this.m_webContentRoot);
  137. asynchRequest.setCallbacks(this.m_callbacks);
  138. if (this.getFormFields().exists("cv.responseFormat")) {
  139. asynchRequest.addFormField("cv.responseFormat", this.getFormField("cv.responseFormat"));
  140. }
  141. else {
  142. asynchRequest.addFormField("cv.responseFormat", "asynchJSON");
  143. }
  144. return asynchRequest;
  145. };