1
我有一个系统使用spring集成来交换数据。 AppClient请求带有TableInfoRequest的AppServer,并且AppServer将响应TableInfoResponse.It现在工作正常。如何在Spring集成中响应HTTP 204
@MessagingGateway() public interface SyncGateway { @Gateway(requestChannel = "requestFlow.input") TableInfoResponse info(TableInfoRequest payload); }
但我想用HTTP代码204回应时,没有数据来响应,这将降低相关的数据。那么我怎样才能设置DSL?
@Bean public IntegrationFlow syncFlow() { return IntegrationFlows .from( Http.inboundGateway(HTTP_ENDPOINT_PATH).id("syncGateway") .replyTimeout(serverProps.getReplyTimeout() * 1000) .requestTimeout(serverProps.getRequestTimeout() * 1000) .messageConverters(new SerializingHttpMessageConverter()) .convertExceptions(true) .mappedResponseHeaders(IDENTIFICATION, TOKEN)) .channel(c -> c.direct("syncChannel") .interceptor(new ChannelAuthenticationInterceptor(dataService))) .handle(syncHandler) .get(); }
的syncHandler将返回TableInfoResponse.And AppClient使用 syncGateway.info(要求)得到tableInfoResponse。
换句话说,如果你想返回'204 No Content'回复,你应该这么做 - 用'HttpStatus.NO_CONTENT'回复Inbond网关:http://docs.spring.io/spring-integration /reference/html/http.html#http-response-statuscode –
感谢您的回答。但我不明白如何在没有数据时回复204。 '.handle(syncHandler)'也会回复一个对象,并且AppClient也希望接收一个对象 - '.expectedResponseType(Serializable.class)' – Roy