import org.slf4j.LoggerFactory;
import org.w3c.dom.Document;
import org.w3c.dom.Node;
-import org.w3c.dom.NodeList;
// Non-final for mocking
class NetconfClientSessionNegotiator
new ExiConfirmationInboundHandler(session, startExiMessage));
session.sendMessage(startExiMessage).addListener(channelFuture -> {
- if (!channelFuture.isSuccess()) {
- LOG.warn("Failed to send start-exi message {} on session {}", startExiMessage, session,
- channelFuture.cause());
+ final var cause = channelFuture.cause();
+ if (cause != null) {
+ LOG.warn("Failed to send start-exi message {} on session {}", startExiMessage, session, cause);
channel.pipeline().remove(ExiConfirmationInboundHandler.EXI_CONFIRMED_HANDLER);
} else {
LOG.trace("Start-exi message {} sent to socket on session {}", startExiMessage, session);
}
private static boolean containsExi10Capability(final Document doc) {
- final NodeList nList = doc.getElementsByTagName(XmlNetconfConstants.CAPABILITY);
- for (int i = 0; i < nList.getLength(); i++) {
- if (nList.item(i).getTextContent().contains(EXI_1_0_CAPABILITY_MARKER)) {
+ final var nodeList = doc.getElementsByTagName(XmlNetconfConstants.CAPABILITY);
+ for (int i = 0; i < nodeList.getLength(); i++) {
+ if (nodeList.item(i).getTextContent().contains(EXI_1_0_CAPABILITY_MARKER)) {
return true;
}
}
@Override
public void operationComplete(final ChannelFuture channelFuture) {
- checkState(channelFuture.isSuccess(), "Unable to send exception %s", sendErrorException,
- channelFuture.cause());
+ final var cause = channelFuture.cause();
+ if (cause != null) {
+ throw new IllegalStateException("Unable to send exception " + sendErrorException, cause);
+ }
}
}
}
socketAddressOf(connectParams.requireRemoteAddress(), connectParams.requireRemotePort()),
socketAddressOf(connectParams.getLocalAddress(), connectParams.getLocalPort()))
.addListener((ChannelFutureListener) future -> {
- if (future.isSuccess()) {
+ final var cause = future.cause();
+ if (cause == null) {
// Order of operations is important here: the stack should be visible before the underlying channel
final var stack = new TCPClient(listener);
ret.set(stack);
stack.addTransportChannel(new TCPTransportChannel(future.channel()));
} else {
- ret.setException(future.cause());
+ ret.setException(cause);
}
});
return ret;
.childHandler(initializer)
.bind(socketAddressOf(listenParams.requireLocalAddress(), listenParams.requireLocalPort()))
.addListener((ChannelFutureListener) future -> {
- if (future.isSuccess()) {
+ final var cause = future.cause();
+ if (cause == null) {
stack.setListenChannel(future.channel());
ret.set(stack);
} else {
- ret.setException(future.cause());
+ ret.setException(cause);
}
});
return ret;