Uploaded image for project: 'Camel'
  1. Camel
  2. CAMEL-20100

Camel-jsonpath can't fetch missing field in some cases when body is returned from a http/https call

    XMLWordPrintableJSON

Details

    • Bug
    • Status: Resolved
    • Minor
    • Resolution: Fixed
    • 4.1.0
    • 4.0.3, 4.3.0
    • camel-jsonpath
    • None
    • Unknown

    Description

      When json response is received from the external REST endpoint using camel-http component, it fails to read missing json value, although DEFAULT_PATH_LEAF_TO_NULL option is set.

      This can be reproduced using mockable.io service, but we noticed this behavior when calling many other REST endpoints (from real implementations). 

      How to reproduce:

      1. Create mocked POST REST endpoint using mockable.io
      2. For example, our looks like following:
        `POST http://demo0405481.mockable.io/camel`
        Response: {"errorcode":0,"errormessage":""}
      3. Create integration where REST endpoint from step 2. is called using camel-http
      4. Read missing summary field using Set Property and Jsonpath with DEFAULT_PATH_LEAF_TO_NULL enabled
      5. Observe the error "Cannot read message body as supported JSON value. "

      Actual result:

      org.apache.camel.ExpressionEvaluationException: org.apache.camel.CamelExchangeException: Cannot read message body as supported JSON value. 

      Expected result:

      ${exchangeProperty.summary} to be null
      

      YAML DSL to reproduce:

      - route:
          nodePrefixId: route-7e2
          id: route-dafc
          from:
            uri: scheduler
            id: from-64dc
            parameters:
              name: scheduler
              repeatCount: 2
            steps:
              - setHeader:
                  name: Content-Type
                  expression:
                    simple:
                      expression: application/json
                      id: simple-dc79
                  id: setHeader-2f26
              - setBody:
                  expression:
                    simple:
                      expression: |-
                        {
                          "some": "value"
                        }
                      id: simple-bfca
                  id: setBody-243c
              - to:
                  uri: http
                  id: to-2cfa
                  parameters:
                    httpUri: demo0405481.mockable.io/camel
                    httpMethod: POST
              - setProperty:
                  name: summary
                  expression:
                    jsonpath:
                      expression: $.summary
                      option: DEFAULT_PATH_LEAF_TO_NULL
                      id: jsonpath-54df
                  id: setProperty-0d81
              - log:
                  message: 'Value: ${exchangeProperty.summary}'
                  id: log-6839
       

      Additional notes:

      • Please create your own mock using mockable.io and create some POST REST endpoint and return any json you want
      • In case summary field exists, it reads it normally
      • In case body is set using Set Body component, instead of reading it from from REST endpoint, everything works fine

       

       

       

      Attachments

        Issue Links

          Activity

            People

              davsclaus Claus Ibsen
              dpalinic Damir Palinic
              Votes:
              0 Vote for this issue
              Watchers:
              2 Start watching this issue

              Dates

                Created:
                Updated:
                Resolved: