spring-integrationspring-cloud-streamspring-cloud-dataflowspring-expression-language

How to specify headers-expression in Spring Cloud Data Flow processor "http-request"?


We are trying to pass the basic authentication header when using the SCDF prebuilt processor "http-request" to call an external service. From my understanding, the message http headers are not automatically carried over in making the call, we need to populate the "headers-expression" property instead. The following is the the call processor step of the stream definition:

http-request --body-expression=payload
--url-expression='headers.reportURL' --http-method-expression='headers.httpMethod' --headers-expression='headers.Authorization'

We already had set the message header "Authorization" as "Basic <base64encoded("user:password")>" in previous step so "headers.Authorization" has the correct Basic Authentication header value when the message arrives to "http-request" processor. However, this doesn't work, the stream log has the following error:

org.springframework.expression.spel.SpelEvaluationException: EL1001E: Type conversion problem, cannot convert from java.lang.String to java.util.Map at org.springframework.expression.spel.support.StandardTypeConverter.convertValue(StandardTypeConverter.java:75) at org.springframework.expression.common.ExpressionUtils.convertTypedValue(ExpressionUtils.java:57)

From the error message, it appears we need to pass a map? Something like "Authorization : headers.Authorization"? (The stream wasn't even deployed successfully by coding this way). We don't want to hard-code the "headers.Authorization" as the literal Basic Auth base64 string. Also how to specify more than one header (like adding "content-type") in the "headers-expression"? We have searched the SCDF documentation and online but can't seem to find an example of how to do it.

Thanks.


Solution

  • If you say that you have already set those headers upfront, consider just that expression like this: --headers-expression='headers'. The headersproperty of theMessageis aMap` by itself.

    If that still doesn't fit your requirements, consider to use an in-line map syntax for SpEL: https://docs.spring.io/spring-framework/docs/current/reference/html/core.html#expressions-inline-maps