Does Integrator have access to HTTP_RESPONSE_CONTENT.TXT when error 500 from server?

This Q&A forum allows users to post and respond to "How Do I Do ....." questions. Please do not use to report (suspected) errors - you must use your regional help desk for this. The information contained in this forum has not been validated by LANSA and, as such, LANSA cannot guarantee the accuracy of the information.
Post Reply
jabdefiant
Posts: 16
Joined: Fri May 31, 2019 1:07 pm

Does Integrator have access to HTTP_RESPONSE_CONTENT.TXT when error 500 from server?

Post by jabdefiant »

Hi All,

I would appreciate any insight that anyone would have on this.

I have a https json client written in LANSA. It using httpService and consumes a JSON API. Occasionally the API will fail with an error 500. The reason for the error is returned, and Integrator logs it to HTTP_RESPONSE_CONTENT.TXT.
Wondering if my LANSA code has access to the error message which was returned. It's not in the JSMXMSG field.

This is an automated process, and I would like to have my code email the error message to an admin.

Thanks

Andy
User avatar
Dino
Posts: 472
Joined: Fri Jul 19, 2019 7:49 am
Location: Robbinsville, NC
Contact:

Re: Does Integrator have access to HTTP_RESPONSE_CONTENT.TXT when error 500 from server?

Post by Dino »

Hi Andy

Just yesterday the new technical newsletter was talking about this in the page 4:

https://www.lansa.com/support/newsletter.htm

Out of curiosity, what do you get in JSMXSTS in these cases?

If you receive a HTTP_RESPONSE_CONTENT you should be able to receive and process that using HTTPInboundJSONBindService using the JSON Binding Wizard https://docs.lansa.com/14/en/lansa093/i ... 9_0075.htm

Other related post in the forum: viewtopic.php?t=38
User avatar
Dino
Posts: 472
Joined: Fri Jul 19, 2019 7:49 am
Location: Robbinsville, NC
Contact:

Re: Does Integrator have access to HTTP_RESPONSE_CONTENT.TXT when error 500 from server?

Post by Dino »

This is an old rdml example I did once for getting results from this page, which basically reads the HTTP_RESPONSE_CONTENT.TXT which in a good case, and I think in a bad case, returns the response as json:

http://jsonplaceholder.typicode.com/todos/1

Code: Select all

Function Options(*DIRECT)
* The following fields should be defined in the dictionary
* DEFINE     FIELD(#JSMSTS) TYPE(*CHAR) LENGTH(20)
* DEFINE     FIELD(#JSMMSG) TYPE(*CHAR) LENGTH(256)
* DEFINE     FIELD(#JSMCMD) TYPE(*CHAR) LENGTH(256)

* The following fields are used by the json binding map
* #STD_DAY
* #STD_BOOL
* #STD_NUM
* #STD_TITLE

* Open service
Use Builtin(JSM_OPEN) To_Get(#JSMSTS #JSMMSG)
Execute Subroutine(CHECK) With_Parms(#JSMSTS #JSMMSG)

* Load service
Change Field(#JSMCMD) To('SERVICE_LOAD SERVICE(HTTPSERVICE) TRACE(*YES)')
Use Builtin(JSM_COMMAND) With_Args(#JSMCMD) To_Get(#JSMSTS #JSMMSG)
Execute Subroutine(CHECK) With_Parms(#JSMSTS #JSMMSG)

* Access the URL https://jsonplaceholder.typicode.com/todos/1'
Change Field(#JSMCMD) To('SEND HOST(jsonplaceholder.typicode.com) CONTENT(*JSON) URI(/todos/1) HANDLER(OutboundFile) METHOD(GET) WAIT(*YES)')
Use Builtin(JSM_COMMAND) With_Args(#JSMCMD) To_Get(#JSMSTS #JSMMSG)
Execute Subroutine(CHECK) With_Parms(#JSMSTS #JSMMSG)

* * Receive the response in HTTP_RESPONSE_CONTENT.TXT as c:\temp\receivedjson.json
Change Field(#JSMCMD) To('RECEIVE HANDLER(IFILE) CONTENT(*JSON) TO(c:\temp\receivedjson.json)')
Use Builtin(JSM_COMMAND) With_Args(#JSMCMD) To_Get(#JSMSTS #JSMMSG)
Execute Subroutine(CHECK) With_Parms(#JSMSTS #JSMMSG)

* Unload service
Use Builtin(JSM_COMMAND) With_Args('SERVICE_UNLOAD') To_Get(#JSMSTS #JSMMSG)
Execute Subroutine(CHECK) With_Parms(#JSMSTS #JSMMSG)

* Load service
Change Field(#JSMCMD) To('SERVICE_LOAD SERVICE(JSONBindFileService) TRACE(*YES)')
Use Builtin(JSM_COMMAND) With_Args(#JSMCMD) To_Get(#JSMSTS #JSMMSG)
Execute Subroutine(CHECK) With_Parms(#JSMSTS #JSMMSG)

* * Reads the received information in the previous step
Change Field(#JSMCMD) To('READ FILE(c:\temp\receivedjson.json)')
Use Builtin(JSM_COMMAND) With_Args(#JSMCMD) To_Get(#JSMSTS #JSMMSG)
Execute Subroutine(CHECK) With_Parms(#JSMSTS #JSMMSG)

* Bind service to read HTTP request content
Change Field(#JSMCMD) To('BIND SERVICE(REST005BW) TYPE(*INBOUND) BINDTRACE(*YES) SERVICE_EXCHANGE(*FIELD) CONTENT(*JSON)')
Use Builtin(JSM_COMMAND) With_Args(#JSMCMD) To_Get(#JSMSTS #JSMMSG)
Execute Subroutine(CHECK) With_Parms(#JSMSTS #JSMMSG)

* Unload service
Use Builtin(JSM_COMMAND) With_Args('SERVICE_UNLOAD') To_Get(#JSMSTS #JSMMSG)
Execute Subroutine(CHECK) With_Parms(#JSMSTS #JSMMSG)

* Close service
Use Builtin(JSM_CLOSE) To_Get(#JSMSTS #JSMMSG)
Execute Subroutine(CHECK) With_Parms(#JSMSTS #JSMMSG)

Display Fields(#STD_DAY #STD_BOOL #STD_NUM #STD_TITLE)

* Check routine
Subroutine Name(CHECK) Parms((#JSMSTS *RECEIVED) (#JSMMSG *RECEIVED))
If Cond('#JSMSTS *NE OK')
Use Builtin(JSM_CLOSE) To_Get(#JSMSTS #JSMMSG)
* Exit
Endif
Endroutine

jsontypi01.png
jsontypi01.png (13.13 KiB) Viewed 10463 times
jabdefiant
Posts: 16
Joined: Fri May 31, 2019 1:07 pm

Re: Does Integrator have access to HTTP_RESPONSE_CONTENT.TXT when error 500 from server?

Post by jabdefiant »

Hi Dino,

Thanks for putting together the newsletter, and for your attention to this.

I am using the httpService with the JSON handler....I think I originally coded with this because of a need to work with the headers which was not in the JSONBindServices (I think that was the limitation).

I just checked and this is what I get back.
JSMXSTS: ERROR
JSMXMSG: HTTP response has failed

I'll check out the links, and play around with your code sample, and let you know how I make out.

Regards,
Andy
User avatar
Dino
Posts: 472
Joined: Fri Jul 19, 2019 7:49 am
Location: Robbinsville, NC
Contact:

Re: Does Integrator have access to HTTP_RESPONSE_CONTENT.TXT when error 500 from server?

Post by Dino »

"putting together the newsletter" <---- that would be Rene
caseywhite
Posts: 192
Joined: Thu May 26, 2016 1:17 am

Re: Does Integrator have access to HTTP_RESPONSE_CONTENT.TXT when error 500 from server?

Post by caseywhite »

Here is what I use. I think this works for any Integrator HTTP service, not just JSONBinding. That being said, I am using it with JSONBinding.

#SA_JSMCMD := 'GET PROPERTY(STATUS)'
Use Builtin(JSMX_COMMAND) With_Args(#JSMHND #JSMCMD) To_Get(#JSMSTS #JSMMSG)

#SA_JSMCMD := 'GET PROPERTY(STATUS-MESSAGE)'
Use Builtin(JSMX_COMMAND) With_Args(#JSMHND #JSMCMD) To_Get(#JSMSTS #JSMMSG)
jabdefiant
Posts: 16
Joined: Fri May 31, 2019 1:07 pm

Re: Does Integrator have access to HTTP_RESPONSE_CONTENT.TXT when error 500 from server?

Post by jabdefiant »

Dino,

I was able to get it running thanks to your input.
While reviewing your sample code, It occurred to me that after getting the error, that I could still do the RETRIEVE command to get the actual returned document.

Casey: It's been a long time. Hope all is well. For me "STATUS" and "STATUS-MESSAGE" both just returned 500.

This is my final solution
=====================
#JSMXCMD := 'SEND HOST(testhost) URI(/services/Products) HANDLER(OutboundJSONBind) SECURE(*YES) METHOD(POST)'
Use Builtin(JSMX_COMMAND) With_Args(#JSMXHDL #JSMXCMD) To_Get(#JSMXSTS #JSMXMSG)

If Cond(#JSMXMSG *EQ 'HTTP response has failed')

Change Field(#JSMXCMD) To('RECEIVE HANDLER(IFILE) CONTENT(*JSON) TO(/tmp/ProdFeedResonse.json)')
Use Builtin(JSMX_COMMAND) With_Args(#JSMXHDL #JSMXCMD) To_Get(#JSMXSTS #JSMXMSG)

#COM_SELF.uEmailAlertForFailure( #PRCF04 True ) // SEND EMAIL WITH ATTACHMENT
#JSMXSTS := ERROR // FORCE A CLEAN SHUTDOWN

Endif

If Cond(*Not #COM_SELF.uCheck)
Return
Endif
Post Reply