英文:
Response returned to caller Method is empty with Java DSL
问题
以下是翻译好的内容:
我正在使用 Spring Boot 项目,我的需求是从外部客户端调用 GET 请求,并将其发送到另一个内部的 Rest 服务。我在这方面使用了 Java DSL,但在处理响应时遇到了问题(一个服务调用另一个服务)。我在这里没有包含变量声明。
以下是代码片段:
// 这是一个类
// 类 A
@Gateway
public HttpRequestHandlerEndpointSpec getTestApi() {
return Http.inboundGateway("/test")
.requestChannel(MessageChannels.direct("testRequest").get())
.replyChannel(MessageChannels.direct("testResponse").get())
.errorChannel("errorChannel").replyTimeout(REPLY_TIMEOUT);
}
@Gateway
public HttpRequestHandlerEndpointSpec getFoobarApi() {
return Http.inboundGateway("/foobar")
.requestChannel(MessageChannels.direct("foobarRequest").get())
.replyChannel(MessageChannels.direct("foobarResponse").get())
.errorChannel("errorChannel").replyTimeout(REPLY_TIMEOUT);
}
// 这在另一个类中
// 类 B
@Override
protected IntegrationFlowDefinition<?> buildFlow() {
return IntegrationFlows.from(httpGateway.getTestApi())
.enrichHeaders(h -> h.header("Content-Type", "application/json"))
.gateway(outboundFlow());
}
private IntegrationFlow outboundFlow() {
return flow -> flow
.handle(httpGateway.sendToHost("http://localhost:8080/foobar")
.httpMethod(HttpMethod.POST)
.expectedResponseType(JSONObject.class))
.handle(jsonHelper, "handleJsonResponse"); // 返回的值是空对象
}
// 这在另一个类中
// 类 C
@Override
protected IntegrationFlowDefinition<?> buildFlow() {
return IntegrationFlows.from(httpGateway.getFoobarApi())
.handle(responsMsg); // 此方法获取 Json 响应
}
然而,在处理完 getFoobarApi 后,控制权转移到 handleJsonResponse 方法,但响应是一个空对象。你能告诉我我哪里出错了吗?
英文:
I am using Spring boot project and my requirement is to call get a request from external client and send it another internal Rest Service. I am using Java DSL for the same and stuck when it comes to response handling. (One service calling another service). I have not included variable declaration here.
Below is the code snippet.
//This is one class
//Class A
@Gateway
public HttpRequestHandlerEndpointSpec getTestApi() {
return Http.inboundGateway("/test")
.requestChannel(MessageChannels.direct("testRequest").get())
.replyChannel(MessageChannels.direct("testResponse").get())
.errorChannel("errorChannel").replyTimeout(REPLY_TIMEOUT);
}
@Gateway
public HttpRequestHandlerEndpointSpec getFoobarApi() {
return Http.inboundGateway("/foobar")
.requestChannel(MessageChannels.direct("foobarRequest").get())
.replyChannel(MessageChannels.direct("foobarResponse").get())
.errorChannel("errorChannel").replyTimeout(REPLY_TIMEOUT);
}
//This is in another class
//Class B
@Override
protected IntegrationFlowDefinition<?> buildFlow() {
return IntegrationFlows.from(httpGateway.getTestApi())
.enrichHeaders(h -> h.header("Content-Type", "application/json"))
.gateway(outboundFlow());
}
private IntegrationFlow outboundFlow() {
return flow -> flow
.handle(httpGateway.sendToHost("http://localhost:8080/foobar")
.httpMethod(HttpMethod.POST)
.expectedResponseType(JSONObject.class))
.handle(jsonHelper, "handleJsonResponse"); // The value returned is empty object
}
//This is in another class
//Class C
@Override
protected IntegrationFlowDefinition<?> buildFlow() {
return IntegrationFlows.from(httpGateway.getFoobarApi())
.handle(responsMsg); // this method gets the Json Response
}
However when the control goes to handleJsonResponse Method after processing the getFoorbarApi, the response is an empty object.Can you please tell me where I am going wrong?
专注分享java语言的经验与见解,让所有开发者获益!
评论