*/
package org.opendaylight.netconf.client;
+import com.google.common.annotations.VisibleForTesting;
import com.google.common.base.Strings;
import com.google.common.collect.ImmutableSet;
import com.google.common.collect.Interner;
import io.netty.channel.Channel;
import io.netty.channel.ChannelHandlerContext;
import io.netty.channel.ChannelInboundHandlerAdapter;
-import io.netty.util.Timer;
import io.netty.util.concurrent.Promise;
import java.util.Set;
import javax.xml.xpath.XPathConstants;
import javax.xml.xpath.XPathExpression;
+import javax.xml.xpath.XPathExpressionException;
import org.checkerframework.checker.index.qual.NonNegative;
import org.eclipse.jdt.annotation.NonNull;
import org.opendaylight.netconf.api.NetconfDocumentedException;
import org.opendaylight.netconf.api.messages.RpcMessage;
import org.opendaylight.netconf.api.xml.XmlNetconfConstants;
import org.opendaylight.netconf.api.xml.XmlUtil;
+import org.opendaylight.netconf.common.NetconfTimer;
import org.opendaylight.netconf.nettyutil.AbstractChannelInitializer;
-import org.opendaylight.netconf.nettyutil.AbstractNetconfSessionNegotiator;
+import org.opendaylight.netconf.nettyutil.NetconfSessionNegotiator;
import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.netconf.base._1._0.rev110601.SessionIdType;
import org.opendaylight.yangtools.yang.common.Uint32;
import org.slf4j.Logger;
// Non-final for mocking
class NetconfClientSessionNegotiator
- extends AbstractNetconfSessionNegotiator<NetconfClientSession, NetconfClientSessionListener> {
+ extends NetconfSessionNegotiator<NetconfClientSession, NetconfClientSessionListener> {
private static final Logger LOG = LoggerFactory.getLogger(NetconfClientSessionNegotiator.class);
private static final XPathExpression SESSION_ID_X_PATH = XMLNetconfUtil
private final RpcMessage startExi;
NetconfClientSessionNegotiator(final HelloMessage hello, final RpcMessage startExi,
- final Promise<NetconfClientSession> promise, final Channel channel, final Timer timer,
+ final Promise<NetconfClientSession> promise, final Channel channel, final NetconfTimer timer,
final NetconfClientSessionListener sessionListener, final long connectionTimeoutMillis,
final @NonNegative int maximumIncomingChunkSize) {
super(hello, promise, channel, timer, sessionListener, connectionTimeoutMillis, maximumIncomingChunkSize);
}
private static String getSessionIdWithXPath(final Document doc, final XPathExpression sessionIdXPath) {
- final Node sessionIdNode = (Node) XmlUtil.evaluateXPath(sessionIdXPath, doc, XPathConstants.NODE);
+ final var sessionIdNode = evaluateXPath(sessionIdXPath, doc);
return sessionIdNode != null ? sessionIdNode.getTextContent() : null;
}
return new NetconfClientSession(sessionListener, channel, sessionId, capabilities);
}
+ @VisibleForTesting
+ static Node evaluateXPath(final XPathExpression expr, final Object rootNode) {
+ try {
+ return (Node) expr.evaluate(rootNode, XPathConstants.NODE);
+ } catch (final XPathExpressionException e) {
+ throw new IllegalStateException("Error while evaluating xpath expression " + expr, e);
+ }
+ }
+
/**
* Handler to process response for start-exi message.
*/
// Unexpected response to start-exi, throwing message away, continue without exi
} else {
- LOG.warn("Unexpected response to start-exi message, should be ok, was {}, "
- + "Communication will continue without exi "
- + "and response message will be thrown away on session {}",
- netconfMessage, session);
+ LOG.warn("""
+ Unexpected response to start-exi message, should be ok, was {}. Communication will continue \
+ without EXI and response message will be thrown away on session {}""", netconfMessage, session);
}
negotiationSuccessful(session);