membersound
membersound

Reputation: 86637

How to catch socket exceptions on TcpInboundGateway?

I'm using TcpInboundGateway from spring-integration for a socket client.

In TcpInboundGateway.doOnMessage() the stream is send via the socket connection. If an exception occurs eg because the socket is closed, there is just a spring error log "Failed to send reply".

BUT I'd like to handle those socket errors explicit. How could I catch those errors in the desired class?

Upvotes: 0

Views: 136

Answers (1)

Gary Russell
Gary Russell

Reputation: 174494

We should probably change that to propagate the exception, but it would be a behavior change so we'd probably have to do it in 4.2 only, unless we make it an option.

Actually, after further review; this can't be accommodated - you have to handle the exception via the connection exception event.

The send is performed on the inbound thread, not your send thread.

We could enhance the exception event to include the failed outbound message.

EDIT:

Alternatively, use a pair of collaborating channel adapters instead of the inbound gateway.

That way, the send is performed on the thread that sends the reply and you can catch exceptions.

Upvotes: 2

Related Questions