访问REST服务时访问冲突

时间:2018-01-30 01:23:17

标签: rest openedge progress-4gl

我已经为thridparty Rest / Json Web API构建了一个接口,所有内容都适用于有效的测试用例,但是当我从API请求一些无效的东西时,比如说一个不存在的作业,API会返回一个响应where body ='null'并且内容类型为“application / json; charset = utf-8”。我不确定这是否是Web API的标准做法,但是当我在IHttpClient上调用Execute时,我最终会出现访问冲突并且客户端退出。

Protrace是以下

    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是:

    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.

我正在使用最新的OpenEdge客户端,11.7.2 Windows x64。

我的问题是,对于无效请求,Web API返回'Null'是否正常?

其次,这显然是OpenEdge.Net.HTTP.Lib中未处理的异常,它不会导致客户端崩溃。任何解决它的想法?我已经尝试将AcceptJson()更改为AcceptAll和AcceptHTML,但是protrace是相同的,在JsonEntityWriter中崩溃。

由于

1 个答案:

答案 0 :(得分:0)

不,如果您向无效的路由发出请求,通常RESTful API将返回404。我能想到的唯一例外是,如果您尝试访问具有参数作为URI一部分的路由。