2

我正在尝试使用 Apama HTTP 客户端插件对 REST API 进行 HTTP 调用。我能够向 REST 资源发送请求,但是在解析响应时,我收到以下错误。

WARN  [20176] - Failed to parse the event "`{contentType:application/json,sag.type:apamax.httpserversample.HTTPResponse,http:{headers:{contentLength:50,content-type:application/json,content-length:50},statusCode:200,method:POST,path:/rest/POC_422837/WS/provider/apamaTestConn,cookies:{},statusReason:OK}}{body:{status:Hello Apama. How are you doing?}}" 
   from httpClient due to the error: Unable to parse event apamax.httpserversample.HTTPResponse: 
   Unable to parse string from the map '{status:Hello Apama. How are you doing?}': 
   Invalid datatype, could not cast to string` 

YAML 配置文件如下所示,

connectivityPlugins:
  HTTPClientGenericTransport:
    libraryName: connectivity-http-client
    class: HTTPClient

startChains:
  httpClient:
    - apama.eventMap
    - mapperCodec:
        apamax.httpserversample.HTTPRequest:
          towardsTransport:
            mapFrom:
              - metadata.http.path: payload.path
              - metadata.requestId: payload.id
              - metadata.http.method: payload.method
              - payload: payload.data
            defaultValue:
              - metadata.contentType: application/json
              - metadata.sag.type: HelloWorld
        apamax.httpserversample.HTTPResponse:
          towardsHost:
            mapFrom:
              - payload.body: payload
              - payload.id: metadata.requestId
        apamax.httpserversample.HTTPError:
          towardsHost:
            mapFrom:
              - payload.id: metadata.requestId
              - payload.code: metadata.http.statusCode
              - payload.message: metadata.http.statusReason
    - classifierCodec:
        rules:
          - apamax.httpserversample.HTTPResponse:
            - metadata.http.statusCode: 200
          - apamax.httpserversample.HTTPError:
            - metadata.http.statusCode:
    - jsonCodec:
        filterOnContentType: true
    - stringCodec
    - HTTPClientGenericTransport:
        host: ${CORRELATOR_HOST}
        port: ${CORRELATOR_PORT}

请帮忙。

4

1 回答 1

1

我相信问题是你在配置中映射

    apamax.httpserversample.HTTPResponse:
      towardsHost:
        mapFrom:
          - payload.body: payload
          - payload.id: metadata.requestId

对 HTTPResponse.body 的响应的有效负载。

但是,正如您从警告中看到的那样,有效负载实际上是一张地图,因此您需要这样做

- payload.body: payload.status

于 2019-04-30T08:56:31.523 回答