1
votes

I have a system use spring integration to exchange data. AppClient request AppServer with a TableInfoRequest and AppServer will response a TableInfoResponse.It work fine now.

    

    @MessagingGateway()
    public interface SyncGateway {

      @Gateway(requestChannel = "requestFlow.input")
      TableInfoResponse info(TableInfoRequest payload);

    }

But I want to respond with an http code 204 when no data to response that will reduce the data in response. So how can I set 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();
      }

The syncHandler will return TableInfoResponse.And AppClient use syncGateway.info(request) to get tableInfoResponse.

2

2 Answers

0
votes

Set the HttpHeaders.STATUS_CODE header (http_statusCode) in the reply message.

0
votes

just use:

 .statusCodeFunction(m -> HttpStatus.NO_CONTENT)

e.g.

@Bean
      public IntegrationFlow syncFlow() {
        return IntegrationFlows
            .from(
              Http.inboundGateway(HTTP_ENDPOINT_PATH).id("syncGateway")
                .replyTimeout(serverProps.getReplyTimeout() * 1000)
                .requestTimeout(serverProps.getRequestTimeout() * 1000)
                .statusCodeFunction(m -> HttpStatus.NO_CONTENT)
                .messageConverters(new SerializingHttpMessageConverter())
                .convertExceptions(true)
                .mappedResponseHeaders(IDENTIFICATION, TOKEN))
            .channel(c -> c.direct("syncChannel")
                .interceptor(new ChannelAuthenticationInterceptor(dataService)))
            .handle(syncHandler)
            .get();
      }