API call not returning response with HttpRequestExecutingMessageHandler

Viewed 25

I'm facing an issue where which ever API I call first using

HttpRequestExecutingMessageHandler

will return response back and second API called again using

HttpRequestExecutingMessageHandler

just hangs and return 504 timeout response back even though the request gets accepted for second API at server and processing is also done. Both the APIs call methods are listed in two different classes with separate output queue channels.

If I now restart the server and call second API first, this time, will return 200 response back but now first API start failing to respond back the 200 response.

@Configuration
class OutgoingHttpChannelAdapterConfig {

@Bean
@Qualifier("responseChannel1")
fun fromResponseChannel1(): QueueChannel = MessageChannels.queue().get()

@Bean
@Qualifier("customRestTemplateOut")
fun customRestTemplateOut(): RestTemplate {
    return RestTemplate()
}

@Bean
@ServiceActivator(inputChannel = "forwardDataChannel")
@Throws(MessageHandlingException::class)
fun forwardRequestMethod(
    @Qualifier("customRestTemplateOut") restTemplate: RestTemplate
): MessageHandler {
    val headerMapper = DefaultHttpHeaderMapper()
    headerMapper.setOutboundHeaderNames("Authorization","key")
    val msgHandler = HttpRequestExecutingMessageHandler(url)
    msgHandler.setHeaderMapper(headerMapper)
    msgHandler.setHttpMethod(HttpMethod.POST)
    msgHandler.isExpectReply = true
    msgHandler.outputChannel = fromResponseChannel1()
    msgHandler.setExpectedResponseType(DataResponse::class.java)
    return msgHandler
 }
}

@Configuration
class IncomingHttpChannelAdapterConfig{

@Bean
@Qualifier("responseChannel2")
fun fromResponseChannel2(): QueueChannel = MessageChannels.queue().get()

@Bean
@Qualifier("customRestTemplate")
fun customRestTemplate(): RestTemplate {
    return RestTemplate()
}

@Bean
@ServiceActivator(inputChannel = "acceptRequestChannel")
@Throws(MessageHandlingException::class)
fun acceptRequestMethod(
    @Qualifier("customRestTemplate") restTemplate: RestTemplate
): MessageHandler {
    val parser = SpelExpressionParser()
    val map = mapOf<String, Expression>(
        "id" to parser.parseRaw("payload.id")
    )
    val msgHandler = HttpRequestExecutingMessageHandler(url, restTemplate)
    msgHandler.setHeaderMapper(headerMapper)
    msgHandler.setHttpMethod(HttpMethod.PUT)
    msgHandler.outputChannel = fromResponseChannel2()
    msgHandler.setUriVariableExpressions(map)
    return msgHandler
 }
}

@MessagingGateway(
    defaultRequestChannel = "forwardDataChannel", errorChannel = "newErrorChannel",
    defaultReplyChannel = "replyChannel1"
)
interface ForwardRequest {
    fun forwardRequest(msg: Message<MessageNotification>): Message<*>
}
@MessagingGateway(
    defaultRequestChannel = "acceptRequestChannel", errorChannel = "newErrorChannel",
    defaultReplyChannel = "replyChannel2"
)
interface AcceptRequest {
    fun acceptRequest(msg: Message<MessageNotification>): Message<*>
}

Right now we are not doing anything with queue channel. Its just used for placeholder purpose.

0 Answers
Related