midrange.com code scratchpad
Name:
Code snippets
Scriptlanguage:
Plain Text
Tabwidth:
4
Date:
05/24/2019 12:37:17 pm
IP:
Logged
Description:
Please find code snippets attached.

Issue: First scenario , Code works fine if I have no header and during IWS deployment . I choose Allow output media as XML/JSON.

Second Scenario , Code is same and I just converted allow output media to JSON or use application header as JSON . I start getting the extra with every tag, These are escape characters and IWS can not recognize the " with every tag
Code:
  1. Actual code : It has one input and one output parms and I am retrieving the values and returning it back to webservices end point.
  2.  
  3.  
  4.  
  5. Columns . . . :    1 100                                      Browse                                               NEWCM/QRPGLESRC 
  6.  SEU==>                                                                                                                   HEDQTRGET 
  7.  FMT **  ...+... 1 ...+... 2 ...+... 3 ...+... 4 ...+... 5 ...+... 6 ...+... 7 ...+... 8 ...+... 9 ...+... 0                        
  8.         *************** Beginning of data ***************************************************************************************   
  9. 0001.00 **free                                                                                                  
  10. 0002.00 ctl-opt OPTION(*SRCSTMT : *NODEBUGIO : *SHOWCPY);                                                        
  11. 0007.00                                                                                                                 
  12. 0008.00 dcl-Pr main extpgm('HEDQTRGET');                                                
  13. 0009.00       *n Char(1000);                                                                             
  14. 0010.00       *n Char(16000000);                                                                      
  15. 0011.00 end-Pr;                                                                                                 
  16. 0012.00       dcl-Pi main ;                                                                                    
  17. 0013.00          p Char(1000);                                                                                 
  18. 0014.00          dataOut Char(16000000);                                                             
  19. 0015.00       end-Pi;                                                                                           
  20. 0016.00       /include IUTILITYP,IUTILITY                                                              
  21. 0017.00       /include UTILITYP,UTILITY                                                             
  22. 0018.00       /include APCJSONP,HEADQTRS                                                
  23. 0019.00                                                                                                          
  24. 0020.00        dcl-s routeParameters1 varChar(1000);                                                       
  25. 0021.00        dcl-s JSONOut1 varChar(16000000);                                                             
  26. 0022.00                                                                                                        
  27. 0023.00        routeParameters1 = '?idpk=' + p;                                                                                                                                                  190521
  28. 0025.00          callp json_get_Headquarters(routeParameters1:JSONOut1);                                         190521
  29. 0026.00                                                                                                          
  30. 0027.00        dataout = JSONOut1;                                                                 
  31. 0028.00                                                                                                          
  32. 0029.00        *inlr = *on;                                                                                                                                                                                                           
  33.  
  34.  F3=Exit   F5=Refresh   F9=Retrieve   F10=Cursor   F11=Toggle   F12=Cancel                                                          
  35.  F16=Repeat find        F24=More keys                                                                                               
  36.                                                                                                                                     
  37.  
  38. Value of JSONOUT1 in debug 
  39.                                                                              
  40.  > EVAL JSONOut1                                                             
  41.    JSONOUT1 =                                                                
  42.              ....5...10...15...20...25...30...35...40...45...50...55...60    
  43.         1   '{"headquarterNumber":800000000,"headquarterName":"TEST8     '   
  44.        61   '                                          ","headquarterAddr'   
  45.       121   'essLine1":"ADR8                                             '   
  46.       181   '   ","headquarterAddressLine2":"ADDRESS2                    '   
  47.       241   '                        ","headquarterAddressLine3":"ADDRESS'   
  48.       301   '3                                            ","headquarterC”};
  49.  
  50. Response in Postman
  51. {
  52.     "headquarterNumber": 800000000,
  53.     "headquarterName": "TEST8                                               ",
  54.     "headquarterAddressLine1": "ADR8                                                ",
  55.     "headquarterAddressLine2": "ADDRESS2                                            ",
  56.     "headquarterAddressLine3": "ADDRESS3                                            ",
  57.      }
  58.  
  59. Header info ( Content typ-Application/xml)
  60. Date →Thu, 23 May 2019 16:55:53 GMT
  61. Server →Apache
  62. X-Powered-By →IBM i
  63. Content-Length →1156
  64. Access-Control-Allow-Origin →*
  65. Access-Control-Allow-Headers →origin, x-requested-with, content-type
  66. Access-Control-Allow-Methods →PUT, GET, POST, DELETE, OPTIONS
  67. Connection →close
  68. Content-Type →application/xml
  69. Content-Language →en-US
  70.  
  71.  
  72. Webservices details
  73. Procedure name:    MAIN
  74. HTTP request method:    GET
  75. URI path template for method:    *NONE
  76. HTTP response code output parameter:    *NONE
  77. HTTP header array output parameter:    *NONE
  78. Allowed input media types:    *ALL
  79. Returned output media types:    *XML_AND_JSON
  80. Input parameter mappings:
  81. Parameter name    Data type    Input source    Identifier    Default Value
  82. P    char    *QUERY_PARAM    INPUT    *NONE
  83.  
  84.  
  85.  
  86.  
  87.  
  88.  
  89.  
  90. Now I am expecting the content type to be application/Json( it means I can set up header-application json or I can set up output media as JSON
  91. EVAL dataout                                                           
  92.  DATAOUT =                                                              
  93.            ....5...10...15...20...25...30...35...40...45...50...55...60 
  94.       1   '{"headquarterNumber":800000000,"headquarterName":"TEST8     '
  95.      61   '                                          ","headquarterAddr'
  96.     121   'essLine1":"ADR8                                             '
  97.     181   '   ","headquarterAddressLine2":"ADDRESS2                    '
  98.     241   '                        ","headquarterAddressLine3":"ADDRESS'
  99.     301   '3  "}’
  100.  
  101. Output shown in Postman with \
  102.  
  103. {
  104.     "DATAOUT": "{\"headquarterNumber\":800000000,\"headquarterName\":\"TEST8                                               \",\"headquarterAddressLine1\":\"ADR8                                                \",\"headquarterAddressLine2\":\"ADDRESS2                                            \",\"headquarterAddressLine3\":\"ADDRESS3                                            \”}”
  105.  
  106. Header info
  107. 200 OK
  108. Time:191347 ms
  109. Size:1.47 KB
  110.  
  111. Date →Thu, 23 May 2019 17:29:59 GMT
  112. Server →Apache
  113. X-Powered-By →IBM i
  114. Content-Length →1153
  115. Access-Control-Allow-Origin →*
  116. Access-Control-Allow-Headers →origin, x-requested-with, content-type
  117. Access-Control-Allow-Methods →PUT, GET, POST, DELETE, OPTIONS
  118. Connection →close
  119. Content-Type →application/json
  120. Content-Language →en-US
  121.  
  122.  
  123.  
© 2004-2019 by midrange.com generated in 0.007s valid xhtml & css