Uploaded image for project: 'Spring Integration'
  1. Spring Integration
  2. INT-4478

LambdaMessageProcessor: headers not passed into handle lambda if payload is a Map

    Details

    • Type: Bug
    • Status: Closed
    • Priority: Minor
    • Resolution: Complete
    • Affects Version/s: 5.0.5
    • Fix Version/s: 5.1 M1, 5.0.6
    • Component/s: Core
    • Labels:

      Description

      The handle() lambda in the following flow receives the empty payload map as second parameter, i.e. p and h are the same object and h does not contain the headers.

          @Bean
          public IntegrationFlow eventMessagesPerCustomer() {
              return IntegrationFlows
                      .from(WebFlux.inboundGateway("/events/{customer}")
                              .requestMapping(m -> m.produces(TEXT_EVENT_STREAM_VALUE))
                              .headerExpression("customer", "#pathVariables.customer")
                              // .payloadExpression("''") <-- workaround
                              .requestPayloadType(JsonNode.class)
                      )
                      .log()
                      .handle((p, h) -> {
                          String customer = h.get("customer")
                                  .toString(); // nullpointer here
                          return customer;
                      })
                      .get();
          }
      

      The reason is in LambdaMessageProcessor from line 102; args[1], which is the header arg of handle(), gets assigned the payload because the payload is an empty map:

      else if (Map.class.isAssignableFrom(parameterType)) {
         if (message.getPayload() instanceof Map) { // (1) payload is an empty map
            args[i] = message.getPayload(); // (2) hence args[1] becomes the payload 
         }
         else {
            args[i] = message.getHeaders();
         }
      }
      

      Instead, the return value of message.getHeaders() needs to be assigned to args[1] .

      Workaround: ensure that the body is not a Map, e.g. by commenting in the payloadExpression above.

        Attachments

          Activity

            People

            • Assignee:
              abilan Artem Bilan
              Reporter:
              dschulten Dietrich Schulten
            • Votes:
              0 Vote for this issue
              Watchers:
              1 Start watching this issue

              Dates

              • Created:
                Updated:
                Resolved: