如何解决Siddhi中http-call的basic authentication认证不生效问题
Siddhi http-call sink 基础认证不生效解决方案
问题根因
http-call 不会默认启用基础认证逻辑,仅配置用户名和密码参数不会触发认证逻辑,缺少基础认证启用开关是Siddhi没有自动生成并携带Authorization请求头的核心原因。此外提供的代码中还存在JSON payload语法错误问题。
修正步骤
- 在http-call sink的配置中新增
basic.auth.enabled="true"参数,显式开启基础认证能力 - 修正payload中的JSON语法错误,补全
someStandardPayloadField字段名后遗漏的双引号
修正后的完整流代码
@App:name('Test Flow') @App:description('Listen, call, log') @source(type = 'http', receiver.url = "http://0.0.0.0:8007/myListener", @map(type = 'json', @attributes(someInputField = "$.someInputField"))) @sink(type = 'http-call', publisher.url = "https://somehost.com/someApiPath", sink.id = "callAPI.sink", basic.auth.enabled = "true", basic.auth.username = "testUser", basic.auth.password = "testPass", https.truststore.file = "/usr/local/ssl/keystore.jks", https.truststore.password = "someTruststorePass", headers = "'Content-Type: application/json'", method = "POST", hostname.verification.enabled = "true", @map(type = 'json', @payload(""" { "someStandardPayloadField": "abc", "someInputField": "{{someInputField}}" } """))) define stream APIStream (someInputField string); @source(type = 'http-call-response', sink.id = "callAPI.sink", http.status.code = "200", @map(type = 'json', enclosing.element = "$.outputs", @attributes(someResponseField = "someOutputfield"))) @sink(type = 'log', prefix = "LOGGER") define stream logStream (someResponseField string);
额外排查建议
如果修改配置后问题依然存在,可以将Siddhi的HTTP传输层日志级别调整为DEBUG,即可打印完整的请求头、请求体内容,确认Authorization头是否正常携带。
内容的提问来源于stack exchange,提问作者user2879614
相关产品推荐
相关产品推荐

