Progress KB - How to set the Connection Timeout for a request using OpenEdge HttpClient?




Feedback
Did this article resolve your question/issue?

   

Article

How to set the Connection Timeout for a request using OpenEdge HttpClient?

« Go Back

Information

 
TitleHow to set the Connection Timeout for a request using OpenEdge HttpClient?
URL NameHow-to-set-the-Connection-Timeout-for-a-request-using-OpenEdge-HttpClient
Article Number000122658
EnvironmentProduct: OpenEdge
Version: 11.5.1,11.6,11.7,12.x
OS: All Supported Platforms
Other: HttpClient
Question/Problem Description
The below code demonstrates setting a connection timeout in milliseconds for the HttpClient.
 
Steps to Reproduce
Clarifying Information
Error Message
Defect/Enhancement Number
Cause
Resolution
/*------------------------------------------------------------------------
    File        : set_connect_timeout.p
    Purpose     : Shows how to set a timeout (in milliseconds) for the HTTP Client's CONNECT 
  ----------------------------------------------------------------------*/
BLOCK-LEVEL ON ERROR UNDO, THROW.

USING HttpClient.ConnectCSCP.
USING OpenEdge.Net.HTTP.ClientBuilder.
USING OpenEdge.Net.HTTP.IHttpClient.
USING OpenEdge.Net.HTTP.IHttpClientLibrary.
USING OpenEdge.Net.HTTP.Lib.ClientLibraryBuilder.
USING OpenEdge.Net.HTTP.RequestBuilder.
USING OpenEdge.Net.ServerConnection.ClientSocket.
USING OpenEdge.Net.ServerConnection.ClientSocketConnectionParameters.

/* ***************************  Settings *************************** */
SESSION:ERROR-STACK-TRACE = TRUE.

/* ***************************  Main Block  *************************** */
DEFINE VARIABLE oClient AS IHttpClient            NO-UNDO.
DEFINE VARIABLE oLib    AS IHttpClientLibrary     NO-UNDO.
DEFINE VARIABLE oSocket AS ClientSocket           NO-UNDO.
DEFINE VARIABLE oCSCP   AS HttpClient.ConnectCSCP NO-UNDO.

       // create a custom connection param with connect-timeout
ASSIGN oCSCP                = NEW HttpClient.ConnectCSCP()
       oCSCP:ConnectTimeout = 1000
       // tell the abl-socket-library to use the new connection params
       oLib = ClientLibraryBuilder:Build()
                    // use the custom ConnectionParameters 
                    :Option(GET-CLASS(ClientSocketConnectionParameters):TypeName,
                            oCSCP)
                    :Library
       // tell the client to use the custom library
       oClient = ClientBuilder:Build()
                    :UsingLibrary(oLib)
                    :Client.
// there's no server here
oClient:Execute(RequestBuilder:Get('http://localhost:9999'):Request).

CATCH oError AS Progress.Lang.Error :
    MESSAGE oError:GetMessage(1) SKIP(2)
            oError:CallStack
        VIEW-AS ALERT-BOX.
END CATCH.
 
/*------------------------------------------------------------------------
    File        : ConnectCSCP
    Description : Connection Parameters with the Connect Timeout 
    Notes       : Save this as HttpClient/ConnectCSCP.cls
  ----------------------------------------------------------------------*/
BLOCK-LEVEL ON ERROR UNDO, THROW.

USING OpenEdge.Core.Assert.
USING OpenEdge.Net.ServerConnection.ClientSocketConnectionParameters.
USING OpenEdge.Net.URI.

CLASS ConnectCSCP INHERITS ClientSocketConnectionParameters:
    /* The timeout for the socket CONNECT, in milliseconds */
    DEFINE PUBLIC PROPERTY ConnectTimeout AS INTEGER NO-UNDO
        GET.
        SET(INPUT pTimeout AS INTEGER):
            Assert:NotNull(pTimeout, 'Connect timeout').
            THIS-OBJECT:ConnectTimeout = pTimeout.
        END SET.
    
    CONSTRUCTOR PUBLIC ConnectCSCP (  ):
        SUPER ().
    END CONSTRUCTOR.
    
    CONSTRUCTOR PUBLIC ConnectCSCP ( INPUT pScheme AS CHARACTER, 
                                     INPUT pHost   AS CHARACTER, 
                                     INPUT pPort   AS INTEGER ):
        SUPER (INPUT pScheme, INPUT pHost, INPUT pPort).
    END CONSTRUCTOR.
        
    CONSTRUCTOR PUBLIC ConnectCSCP ( INPUT poURI AS URI ):
        SUPER (INPUT poURI).
    END CONSTRUCTOR.

    METHOD OVERRIDE PUBLIC CHARACTER GetConnectionString():
        DEFINE VARIABLE cConnectionParams AS CHARACTER NO-UNDO.
        
        cConnectionParams = SUPER:GetConnectionString().
        IF THIS-OBJECT:ConnectTimeout GT 0 THEN
            cConnectionParams = SUBSTITUTE('&1 -clientConnectTimeout &2':u,
                                                                        cConnectionParams, ConnectTimeout).
        
        RETURN cConnectionParams.
    END METHOD.    

END CLASS.

 
Workaround
Notes
References to Other Documentation:

Progress Article(s):
000060873, Is there an HTTP client for OpenEdge?
000095515, OpenEdge.Net.pl is missing from PROPATH

​​​​​​​
Last Modified Date6/20/2019 6:28 PM
Attachment 
Files
Disclaimer The origins of the information on this site may be internal or external to Progress Software Corporation (“Progress”). Progress Software Corporation makes all reasonable efforts to verify this information. However, the information provided is for your information only. Progress Software Corporation makes no explicit or implied claims to the validity of this information.

Any sample code provided on this site is not supported under any Progress support program or service. The sample code is provided on an "AS IS" basis. Progress makes no warranties, express or implied, and disclaims all implied warranties including, without limitation, the implied warranties of merchantability or of fitness for a particular purpose. The entire risk arising out of the use or performance of the sample code is borne by the user. In no event shall Progress, its employees, or anyone else involved in the creation, production, or delivery of the code be liable for any damages whatsoever (including, without limitation, damages for loss of business profits, business interruption, loss of business information, or other pecuniary loss) arising out of the use of or inability to use the sample code, even if Progress has been advised of the possibility of such damages.