简体   繁体   English

如何在 Spring 云数据流处理器“http-request”中指定标头表达式?

[英]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.当使用 SCDF 预构建处理器“ http-request ”调用外部服务时,我们正在尝试通过基本身份验证 header。 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.据我了解,消息 http 标头在调用时不会自动传递,我们需要填充“ headers-expression ”属性。 The following is the the call processor step of the stream definition:以下是 stream 定义的调用处理器步骤:

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.我们已经在上一步中将消息 header“授权”设置为“基本 <base64encoded(“user:password”)> ”,因此当消息到达“ http-request ”时,“ headers.Authorization ”具有正确的基本身份验证 header 值处理器。 However, this doesn't work, the stream log has the following error:但是这样不行,stream日志出现如下错误:

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) 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 ) 在 org.springframework.expression.common.ExpressionUtils.convertTypedValue(ExpressionUtils.java:57)

From the error message, it appears we need to pass a map?从错误消息来看,我们似乎需要传递一个 map? Something like " Authorization: headers.Authorization "?类似“ Authorization: headers.Authorization ”? (The stream wasn't even deployed successfully by coding this way). (stream 甚至没有通过这种方式编码成功部署)。 We don't want to hard-code the " headers.Authorization " as the literal Basic Auth base64 string.我们不想将“ headers.Authorization ”硬编码为文字 Basic Auth base64 字符串。 Also how to specify more than one header (like adding " content-type ") in the " headers-expression "?另外如何在“ headers-expression ”中指定多个 header (如添加“ content-type ”)? We have searched the SCDF documentation and online but can't seem to find an example of how to do it.我们已经搜索了 SCDF 文档和在线,但似乎找不到如何执行此操作的示例。

Thanks.谢谢。

If you say that you have already set those headers upfront, consider just that expression like this: --headers-expression='headers'. The如果您说您已经预先设置了这些标头,请考虑如下表达式: --headers-expression='headers'. The --headers-expression='headers'. The headers property of the Message is a Map` by itself. Message --headers-expression='headers'. The headers property of the本身is a Map 。

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如果这仍然不符合您的要求,请考虑对 SpEL 使用in-line map语法: https://docs.Z2A2D595E6ED9A0B24F027F2B63B134D-6Z/currentreference/spring-framework内联地图

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM