![](/img/trans.png)
[英]How to pass object/json to post method using int-http:outbound-gateway in Spring Integration
[英]How to get payload values from byte[] message in Spring Integration int-http:outbound-gateway?
我在context.xml中配置了一個outbound-gateway
,我想在其中從byte[]
類型的有效負載中提取值,並使用它們來構造URI
。 我發現SpEL允許您以這種方式構建它:
url-expression="T(org.springframework.web.util.UriComponentsBuilder)
.fromHttpUrl('http://HOST:PORT/PATH')
.queryParams(payload)
.build()
.toUri()"
來源: https : //docs.spring.io/spring-integration/reference/html/http.html#mapping-uri-variables
我對解決方案的變化如下所示:
<int-http:outbound-gateway id="candleRequestGateway"
request-channel="candleRequestChannel"
reply-channel="dataResponseChannel"
http-method="GET"
url-expression="T(org.springframework.web.util.UriComponentsBuilder)
.fromHttpUrl('some/{path}')
.queryParam('myParam', payload.get('myParam'))
.buildAndExpand(payload.get('path'))
.toUri()"/>
但是,在執行payload.get('myParam')
部分時,出現以下錯誤:
org.springframework.messaging.MessageHandlingException: error occurred in message handler [org.springframework.integration.http.outbound.HttpRequestExecutingMessageHandler#3]; nested exception is org.springframework.expression.spel.SpelEvaluationException: EL1004E: Method call: Method get(java.lang.String) cannot be found on type byte[]
我理解並同意錯誤。 我的問題:是否有一種方法(特定的SpEL表達式(?))從byte[]
有效載荷中提取值,而無需在到達outbound-gateway
之前對其進行轉換? 這是一個有效的解決方案嗎?
當有效負載為byte[]
時,您究竟期望payload.get('myParam')
和payload.get('myParam')
payload.get('path')
做什么。
顯然, byte[]
沒有get(String)
方法。
從
byte[]
提取值
提取方式如何? byte[]
是byte[]
的非結構化數組; 唯一可以做的就是類似new String(payload).substring(0, 5)
類的東西。
如果字節包含JSON,則可以使用#jsonPath
SpEL函數。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.