Hi Guys
I'm using the Clientbuilder for a while now. For speed I've set it up based on one of the examples online
Now I'm wondering, if I where to change the example below and insert a timeout
Example
oResponse = ClientBuilder:Build():Client:Execute(oRequest).
Would become
oResponse = ClientBuilder:Build():Client:SetRequestTimeout(10):Execute(oRequest).
What would be the best way to capture the timeout?
Will the clientbuilder throw an error? Or will it return an error statuscode?
Couldn't find this in the documentation, so I thought I'd just ask before logging a supprt case.
REgards, Onno
-------- UPDATE EXAMPLE ------
BLOCK-LEVEL ON ERROR UNDO, THROW.
USING OpenEdge.Core.String.
USING OpenEdge.Net.HTTP.ClientBuilder.
USING OpenEdge.Net.HTTP.IHttpRequest.
USING OpenEdge.Net.HTTP.IHttpResponse.
USING OpenEdge.Net.HTTP.RequestBuilder.
USING Progress.Json.ObjectModel.JsonObject.
DEFINE VARIABLE httpUrl AS CHARACTER NO-UNDO.
DEFINE VARIABLE oRequest AS IHttpRequest NO-UNDO.
DEFINE VARIABLE oResponse AS IHttpResponse NO-UNDO.
DEFINE VARIABLE oRequestBody AS String NO-UNDO.
DEFINE VARIABLE oJsonEntity AS JsonObject NO-UNDO.
DEFINE VARIABLE JsonString AS LONGCHAR NO-UNDO.
SESSION:DEBUG-ALERT = TRUE.
httpUrl = "www.googleapis.com/.../token".
oRequestBody = new String('client_id=your_client_id&client_secret=your_client_secret&refresh_token=your_refresh_token&grant_type=refresh_token').
oRequest = RequestBuilder:Post("www.googleapis.com/.../token", oRequestBody)
:ContentType('application/x-www-form-urlencoded')
:AcceptJson()
:Request.
oResponse = ClientBuilder:Build():Client:SetRequestTimeout(10):Execute(oRequest).
MESSAGE
oResponse:StatusCode SKIP
oResponse:StatusReason SKIP
VIEW-AS ALERT-BOX.
oJsonEntity = CAST(oResponse:Entity, JsonObject).
oJsonEntity:Write(JsonString, TRUE).
MESSAGE STRING(JsonString)
VIEW-AS ALERT-BOX.
Hi guys
Anyone any thoughts on this?
Are you able to create a timeout scenario and test your code? Maybe you can just change the host name in the url to something that doesn't exist.
I'm fairly certain you will catch an error from that code if anything goes wrong. OO programming and SEH error handling work well together, and I'd guess that all these new API's would throw errors by convention. It is much better for API's to follow a standard pattern than come up with their own strange and unique error -publication strategies (just thinking about ugly API's like OS-COPY give me a cold chill).
Are you already familiar with structured error handling (SEH)? If not I would highly recommend that you read the "Error Handling" document from beginning to end.
community.progress.com/.../2911.openedge-11-7-product-documentation
The most important parts in there are related to "Structured Error Handling". This is a similar error-handling pattern to what is found in other languages like Java and C#.
I suspect that if you put a do/catch block around all that code, you will probably be able to CATCH a Progress.Lang.Error (or more specifically a class that derives from it). See. documentation.progress.com/.../index.html
Have you tried that? The OpenEdge.Net.HTTP stuff is open source so you can go look for yourself to see if there are lots of UNDO, THROW statements in the case of error conditions. This will be your biggest clue. Here is a link to another conversation about that API. Peter Judge seems to be the expert, if not the author:
Hi Peter,
The reason I'm looking into this, is becauase once in a while we see the HttpClient hang on "Connect". The appserver busy, but seems stuck in the Connect method.
I'm not sure how to proceed. Setting a timeout might not work. And a stop-after is perhaps also ignored, because it seems that something is blocking inside the Connect method.
The strange thing is, that this happens seamingly at random and not very often. We already ruled out the REST-service that we are calling, that's working fine.
Any suggestions?
This was also created as Progress knowledgebase article:
000096511 - How to set the Connection Timeout for a request using OpenEdge HttpClient?
Hi Peter, Ken
I get an error when I try to compile the ConnectCSCP class from the samples. It can be fixed by commenting out the line below.
Why is that? Did something change in the parent class? I'm currently on 11.7
constructor public ConnectCSCP ( input pScheme as character, input pHost as character, input pPort as integer ):
// super (input pScheme, input pHost, input pPort).
end constructor.
You need 11.7.2 or newer for the sample to work!
Hi Torben,
Does that mean tha tI can't set a -connectTimeOut using the HTTP Client when a customer is using 11.7.1 for example?
Don't know.
I'm just see that constructor for ClientSocketConnectionParameters with needed signature was added in OE 11.7.2!
super (input pScheme, input pHost, input pPort).
I got it to work by using peters example combined with a stop-after block to catch the hanging “connect”