简体   繁体   中英

Access Violation when accessing REST service

I've built an interface to a thridparty Rest/Json web API, everything is working great with valid test cases, but when I request something invalid from the API, say a job that doesn't exist, the API returns a response where the body = 'null' and has a the content type as "application/json; charset=utf-8". I'm not sure if this is standard practice for a web API, but when I call Execute on the IHttpClient I end up with an Access Violation and the client exits.

Protrace is a follows

    Exception code: C0000005 ACCESS_VIOLATION
    Fault address:  00007FFC6733DAAD 01:000000000077CAAD C:\Apps\Progress\117\bin\prow.dll

        ** ABL Stack Trace **

   --> Write OpenEdge.Net.HTTP.Filter.Payload.JsonEntityWriter at line 463  (OpenEdge/Net/HTTP/Filter/Payload/JsonEntityWriter.r)
        ExtractEntity OpenEdge.Net.HTTP.Lib.ABLSockets.ABLSocketLibrary at line 360  (OpenEdge/Net/HTTP/Lib/ABLSockets/ABLSocketLibrary.r)
        Execute OpenEdge.Net.HTTP.Lib.ABLSockets.ABLSocketLibrary at line 312  (OpenEdge/Net/HTTP/Lib/ABLSockets/ABLSocketLibrary.r)
        Execute OpenEdge.Net.HTTP.HttpClient at line 154  (OpenEdge/Net/HTTP/HttpClient.r)
        TryRest Tempo.TempoApi at line 1264  (D:\_Dev\OnTap-Trunk\rcode\Tempo\TempoApi.r)
        ExecuteRest Tempo.TempoApi at line 234  (D:\_Dev\OnTap-Trunk\rcode\Tempo\TempoApi.r)

TryRest is:

    METHOD PRIVATE INTEGER TryRest(
        INPUT  oUri AS URI,  
        INPUT  cType AS CHARACTER,
        INPUT  cContentType AS CHARACTER,
        INPUT  oContent AS Object,
        OUTPUT oResponse AS IHttpResponse ):

        DEFINE VARIABLE result AS INTEGER NO-UNDO.

        DEFINE VARIABLE oRequest AS IHttpRequest NO-UNDO.

        CASE cType:

            WHEN "GET" THEN
                oRequest = RequestBuilder:GET(oURI)
                                         :AddHeader("Authorization", "Bearer " + STRING(cAccessToken))
                                         :AcceptJson()
                                         :REQUEST.
        END CASE.    

        oResponse = ResponseBuilder:Build():Response.
        oClient:EXECUTE(oRequest,oResponse).

        RETURN oResponse:StatusCode.

        CATCH e AS Progress.Lang.Error:
            UNDO, THROW e.
        END CATCH.

    END METHOD.

I'm using the latest OpenEdge client, 11.7.2 Windows x64.

My question is, is it normal for a web API to return 'Null' for an invalid request?

And secondly, this is obviously an unhandled exception in OpenEdge.Net.HTTP.Lib, which should not result in client crash.. Any ideas for working around it? I've tried changing AcceptJson() to AcceptAll, and AcceptHTML, but the protrace is the same, crashing in JsonEntityWriter.

Thanks

No, typically RESTful APIs will return a 404 if you make a request to a route that isn't valid. The only exception that I can think of off the top of my head is if you attempt to access a route that has parameters as part of the URI.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM