Spring 集成 - http 入站
Spring Integration - http inbound
我正在尝试创建一个 http 入站,但是当我打印我的消息时,有效负载为空,我在这里缺少什么?
@Slf4j
@Component
public class HttpInboundGateway {
@Bean
public IntegrationFlow inGate1() {
log.info("Initializing inbound gateway...");
return IntegrationFlows.from(Http.inboundChannelAdapter("/")
.requestPayloadType(PayloadObj.class))
.channel("transfer_next_channel")
.get();
}
@Bean
@ServiceActivator(inputChannel = "transfer_next_channel")
public MessageHandler handler() {
return new MessageHandler() {
@Override
public void handleMessage(Message<?> message) throws MessagingException {
System.out.println("myHandlerPayload: " + message.getPayload());
System.out.println("myHandlerHeader: " + message.getHeaders());
}
};
}
}
PayloadObj class 预期:
@Data
@NoArgsConstructor
public class PayloadObj {
String name;
String job;
}
编辑 1:根据要求
来自 Postman 的卷曲
curl --location --request GET 'http://localhost:9090/' \
--header 'Content-Type: application/json' \
--data-raw '{
"name":"Marcos",
"job":"Dev Jr"
}'
从处理程序打印:
myHandlerPayload: {} --- Payload
myHandlerHeader: {content-length=46, http_requestMethod=GET,
host=localhost:9090, http_requestUrl=http://localhost:9090/,
connection=keep-alive, id=e67aef3d-938a-7ac3-eb7d-ddaf9cd74f4e,
contentType=application/json;charset=UTF-8, accept-encoding=gzip,
deflate, br, user-agent=PostmanRuntime/7.28.4, accept=*/*,
timestamp=1642168826837}
curl --location --request GET 'http://localhost:9090/'
你做了 GET
请求。这样请求的主体就被忽略了。
并且只有请求参数作为有效载荷传输。由于您也没有这些,这意味着有效负载为空 Map
.
考虑改用 POST
或 PUT
。
并了解有关 HTTP 协议及其方法细节的更多信息。
我正在尝试创建一个 http 入站,但是当我打印我的消息时,有效负载为空,我在这里缺少什么?
@Slf4j
@Component
public class HttpInboundGateway {
@Bean
public IntegrationFlow inGate1() {
log.info("Initializing inbound gateway...");
return IntegrationFlows.from(Http.inboundChannelAdapter("/")
.requestPayloadType(PayloadObj.class))
.channel("transfer_next_channel")
.get();
}
@Bean
@ServiceActivator(inputChannel = "transfer_next_channel")
public MessageHandler handler() {
return new MessageHandler() {
@Override
public void handleMessage(Message<?> message) throws MessagingException {
System.out.println("myHandlerPayload: " + message.getPayload());
System.out.println("myHandlerHeader: " + message.getHeaders());
}
};
}
}
PayloadObj class 预期:
@Data
@NoArgsConstructor
public class PayloadObj {
String name;
String job;
}
编辑 1:根据要求
来自 Postman 的卷曲
curl --location --request GET 'http://localhost:9090/' \
--header 'Content-Type: application/json' \
--data-raw '{
"name":"Marcos",
"job":"Dev Jr"
}'
从处理程序打印:
myHandlerPayload: {} --- Payload
myHandlerHeader: {content-length=46, http_requestMethod=GET,
host=localhost:9090, http_requestUrl=http://localhost:9090/,
connection=keep-alive, id=e67aef3d-938a-7ac3-eb7d-ddaf9cd74f4e,
contentType=application/json;charset=UTF-8, accept-encoding=gzip,
deflate, br, user-agent=PostmanRuntime/7.28.4, accept=*/*,
timestamp=1642168826837}
curl --location --request GET 'http://localhost:9090/'
你做了 GET
请求。这样请求的主体就被忽略了。
并且只有请求参数作为有效载荷传输。由于您也没有这些,这意味着有效负载为空 Map
.
考虑改用 POST
或 PUT
。
并了解有关 HTTP 协议及其方法细节的更多信息。