I'm trying to actually get the response data to disk but am getting to following error:
However the code does not stop and goes into a infinite loop. Here my code below and I've been executing from the procedure editor. I don't have the fancy OE Developer IDE.
USING OpenEdge.Net.HTTP.IHttpRequest.
USING OpenEdge.Net.HTTP.IHttpResponse.
USING OpenEdge.Net.HTTP.RequestBuilder.
USING OpenEdge.Net.HTTP.ClientBuilder.
USING OpenEdge.Core.String.
USING OpenEdge.Core.WidgetHandle.
USING Progress.Lang.Object.
USING Progress.Json.ObjectModel.JsonObject.
DEFINE VARIABLE oRequest AS IhttpRequest NO-UNDO.
DEFINE VARIABLE oResponse AS IhttpResponse NO-UNDO.
DEFINE VARIABLE httpUrl AS CHARACTER NO-UNDO.
DEFINE VARIABLE oEntity AS OBJECT NO-UNDO.
DEFINE VARIABLE XMLDocument AS HANDLE NO-UNDO.
DEFINE VARIABLE payload AS LONGCHAR NO-UNDO.
httpUrl = "http://www.progress.com".
oRequest = RequestBuilder:Get(httpUrl,oEntity):Request.
oResponse = ClientBuilder:Build():Client:Execute(oRequest).
MESSAGE
oResponse:StatusCode
oResponse:StatusReason
view-as alert-box info.
CASE TRUE:
WHEN TYPE-OF(oEntity, JsonObject) THEN
CAST(oEntity,JsonObject):WriteFile('temp/payload.json', true).
WHEN TYPE-OF(oEntity, WidgetHandle) THEN
DO:
MESSAGE 'Lookes LIke an XML document'.
XMLDocument = CAST(oEntity, WidgetHandle ):Value.
XMLDocument:Save('file','temp/payload.xml').
END.
OTHERWISE
DO:
IF TYPE-OF(oEntity, String) THEN
payload = CAST(oEntity, String):Value.
ELSE
payload = oEntity:ToString().
CASE oResponse:ContentType:
WHEN 'application/xml' THEN
COPY-LOB payload to file 'temp/payload.xml'.
WHEN 'application/json' THEN
COPY-LOB payload to file 'temp/payload.json'.
WHEN 'text/html' THEN
COPY-LOB payload to file 'temp/payload.html'.
OTHERWISE
COPY-LOB payload to file 'temp/payload.txt'.
END CASE.
END.
END CASE.
I think I figured out where I'm going wrong. The servers response is in the Response:Entity public property. See the code below for my revised version.
USING OpenEdge.Net.HTTP.*.
USING OpenEdge.Core.String.
USING OpenEdge.Core.WidgetHandle.
USING Progress.Lang.Object.
USING Progress.Json.ObjectModel.JsonObject.
DEFINE VARIABLE oRequest AS IhttpRequest NO-UNDO.
DEFINE VARIABLE oResponse AS IhttpResponse NO-UNDO.
DEFINE VARIABLE httpUrl AS CHARACTER NO-UNDO.
DEFINE VARIABLE oEntity AS OBJECT NO-UNDO.
DEFINE VARIABLE XMLDocument AS HANDLE NO-UNDO.
DEFINE VARIABLE payload AS LONGCHAR NO-UNDO.
DEFINE VARIABLE HttpHeaders AS CLASS HttpHeader NO-UNDO EXTENT.
httpUrl = "http://www.progress.com".
oRequest = RequestBuilder:Get(httpUrl):Request.
oResponse = ClientBuilder:Build():Client:Execute(oRequest).
/** Debug HTTP Response Headers **/
DEFINE VARIABLE iNumHeaders AS INTEGER NO-UNDO.
DEFINE VARIABLE iHeaderEntry AS INTEGER NO-UNDO.
iNumHeaders = oResponse:GetHeaders(OUTPUT HttpHeaders).
DO iHeaderEntry = 1 TO iNumHeaders:
MESSAGE
HttpHeaders[iHeaderEntry]:Name
HttpHeaders[iHeaderEntry]:Value.
END.
MESSAGE
'Status:' oResponse:StatusCode
oResponse:StatusReason SKIP
'Version:' oResponse:Version SKIP
'Character Encoding:' oResponse:CharacterEncoding SKIP
'Transfer Encoding:' oResponse:TransferEncoding SKIP
'Content Length:' oResponse:ContentLength SKIP
'MD5' STRING(oResponse:ContentMD5)
view-as alert-box info
TITLE ''.
/** Get the payload.**/
oEntity = oResponse:Entity.
CASE TRUE:
WHEN TYPE-OF(oEntity, JsonObject) THEN
CAST(oEntity,JsonObject):WriteFile('temp/payload.json', true).
WHEN TYPE-OF(oEntity, WidgetHandle) THEN
DO:
MESSAGE 'Lookes LIke an XML document'.
XMLDocument = CAST(oEntity, WidgetHandle ):Value.
XMLDocument:Save('file','temp/payload.xml').
END.
OTHERWISE
DO:
IF TYPE-OF(oEntity, String) THEN
payload = CAST(oEntity, String):Value.
ELSE
payload = oEntity:ToString().
CASE oResponse:ContentType:
WHEN 'application/xml' THEN
COPY-LOB payload to file 'temp/payload.xml'.
WHEN 'application/json' THEN
COPY-LOB payload to file 'temp/payload.json'.
WHEN 'text/html' THEN
COPY-LOB payload to file 'temp/payload.html'.
OTHERWISE
COPY-LOB payload to file 'temp/payload.txt'.
END CASE.
END.
END CASE.
I think I figured out where I'm going wrong. The servers response is in the Response:Entity public property. See the code below for my revised version.
USING OpenEdge.Net.HTTP.*.
USING OpenEdge.Core.String.
USING OpenEdge.Core.WidgetHandle.
USING Progress.Lang.Object.
USING Progress.Json.ObjectModel.JsonObject.
DEFINE VARIABLE oRequest AS IhttpRequest NO-UNDO.
DEFINE VARIABLE oResponse AS IhttpResponse NO-UNDO.
DEFINE VARIABLE httpUrl AS CHARACTER NO-UNDO.
DEFINE VARIABLE oEntity AS OBJECT NO-UNDO.
DEFINE VARIABLE XMLDocument AS HANDLE NO-UNDO.
DEFINE VARIABLE payload AS LONGCHAR NO-UNDO.
DEFINE VARIABLE HttpHeaders AS CLASS HttpHeader NO-UNDO EXTENT.
httpUrl = "http://www.progress.com".
oRequest = RequestBuilder:Get(httpUrl):Request.
oResponse = ClientBuilder:Build():Client:Execute(oRequest).
/** Debug HTTP Response Headers **/
DEFINE VARIABLE iNumHeaders AS INTEGER NO-UNDO.
DEFINE VARIABLE iHeaderEntry AS INTEGER NO-UNDO.
iNumHeaders = oResponse:GetHeaders(OUTPUT HttpHeaders).
DO iHeaderEntry = 1 TO iNumHeaders:
MESSAGE
HttpHeaders[iHeaderEntry]:Name
HttpHeaders[iHeaderEntry]:Value.
END.
MESSAGE
'Status:' oResponse:StatusCode
oResponse:StatusReason SKIP
'Version:' oResponse:Version SKIP
'Character Encoding:' oResponse:CharacterEncoding SKIP
'Transfer Encoding:' oResponse:TransferEncoding SKIP
'Content Length:' oResponse:ContentLength SKIP
'MD5' STRING(oResponse:ContentMD5)
view-as alert-box info
TITLE ''.
/** Get the payload.**/
oEntity = oResponse:Entity.
CASE TRUE:
WHEN TYPE-OF(oEntity, JsonObject) THEN
CAST(oEntity,JsonObject):WriteFile('temp/payload.json', true).
WHEN TYPE-OF(oEntity, WidgetHandle) THEN
DO:
MESSAGE 'Lookes LIke an XML document'.
XMLDocument = CAST(oEntity, WidgetHandle ):Value.
XMLDocument:Save('file','temp/payload.xml').
END.
OTHERWISE
DO:
IF TYPE-OF(oEntity, String) THEN
payload = CAST(oEntity, String):Value.
ELSE
payload = oEntity:ToString().
CASE oResponse:ContentType:
WHEN 'application/xml' THEN
COPY-LOB payload to file 'temp/payload.xml'.
WHEN 'application/json' THEN
COPY-LOB payload to file 'temp/payload.json'.
WHEN 'text/html' THEN
COPY-LOB payload to file 'temp/payload.html'.
OTHERWISE
COPY-LOB payload to file 'temp/payload.txt'.
END CASE.
END.
END CASE.
The line
/** Get the payload.**/
oEntity = oResponse:Entity.
was missing from the earlier whitepaper, but should have been in the doc. I'll make sure it appears there if it doesn't already ....
dammit I thought we'd fixed that. Sorry 'bout that. Will see about getting it updated in the 11.5.1 "New Information" doc.
[ "earlier" means the doc/whitepaper that was provided as part of the 11.5.0 tech preview for this feature ]
Hay, it's not a problem. I'm just slowly going through each of the class files making up my own documentation (until the official 11.6 comes out) highlighting all the public properties & methods.
On another note, should to code go into a retry loop if there was an error. If this a happened on a AppServer or WebSpeed agent it would be constantly locked/busy. Is this a possible issue/bug or should the developer have better error handling when utilising the OpenEdge.Net.HTTP classes?
On another note, should to code go into a retry loop if there was an error. If this a happened on a AppServer or WebSpeed agent it would be constantly locked/busy. Is this a possible issue/bug or should the developer have better error handling when utilising the OpenEdge.Net.HTTP classes?
Flag this post as spam/abuse.