X-Git-Url: https://git.opendaylight.org/gerrit/gitweb?p=controller.git;a=blobdiff_plain;f=opendaylight%2Fnetconf%2Fnetconf-client%2Fsrc%2Fmain%2Fjava%2Forg%2Fopendaylight%2Fcontroller%2Fnetconf%2Fclient%2FNetconfClientSessionNegotiatorFactory.java;h=ac13729d885fbf5b83ff21d4e9a90e91ab2dfa64;hp=07e088e117d636502be739aabff6952eeac62fb9;hb=d762fe6c823ad1ba21db1cad627a1cbd6d7c6d8e;hpb=f330b481b7f70fb165f423cc566214d1efddade8 diff --git a/opendaylight/netconf/netconf-client/src/main/java/org/opendaylight/controller/netconf/client/NetconfClientSessionNegotiatorFactory.java b/opendaylight/netconf/netconf-client/src/main/java/org/opendaylight/controller/netconf/client/NetconfClientSessionNegotiatorFactory.java index 07e088e117..ac13729d88 100644 --- a/opendaylight/netconf/netconf-client/src/main/java/org/opendaylight/controller/netconf/client/NetconfClientSessionNegotiatorFactory.java +++ b/opendaylight/netconf/netconf-client/src/main/java/org/opendaylight/controller/netconf/client/NetconfClientSessionNegotiatorFactory.java @@ -8,50 +8,68 @@ package org.opendaylight.controller.netconf.client; +import com.google.common.base.Optional; +import com.google.common.base.Preconditions; +import com.google.common.collect.ImmutableSet; +import io.netty.channel.Channel; +import io.netty.util.Timer; +import io.netty.util.concurrent.Promise; +import java.util.Set; import org.opendaylight.controller.netconf.api.NetconfClientSessionPreferences; +import org.opendaylight.controller.netconf.api.NetconfDocumentedException; import org.opendaylight.controller.netconf.api.NetconfMessage; +import org.opendaylight.controller.netconf.api.xml.XmlNetconfConstants; +import org.opendaylight.controller.netconf.nettyutil.handler.exi.NetconfStartExiMessage; import org.opendaylight.controller.netconf.util.messages.NetconfHelloMessage; import org.opendaylight.controller.netconf.util.messages.NetconfHelloMessageAdditionalHeader; -import org.opendaylight.controller.netconf.util.messages.NetconfStartExiMessage; -import org.opendaylight.controller.netconf.util.xml.XmlNetconfConstants; import org.opendaylight.protocol.framework.SessionListenerFactory; import org.opendaylight.protocol.framework.SessionNegotiator; import org.opendaylight.protocol.framework.SessionNegotiatorFactory; import org.openexi.proc.common.AlignmentType; import org.openexi.proc.common.EXIOptions; import org.openexi.proc.common.EXIOptionsException; - -import com.google.common.base.Optional; -import com.google.common.base.Preconditions; -import com.google.common.collect.Sets; - -import io.netty.channel.Channel; -import io.netty.util.Timer; -import io.netty.util.concurrent.Promise; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; public class NetconfClientSessionNegotiatorFactory implements SessionNegotiatorFactory { - public static final java.util.Set CLIENT_CAPABILITIES = Sets.newHashSet( - XmlNetconfConstants.URN_IETF_PARAMS_XML_NS_NETCONF_BASE_1_0, - XmlNetconfConstants.URN_IETF_PARAMS_XML_NS_NETCONF_BASE_1_1, + public static final Set CLIENT_CAPABILITIES = ImmutableSet.of( + XmlNetconfConstants.URN_IETF_PARAMS_NETCONF_BASE_1_0, + XmlNetconfConstants.URN_IETF_PARAMS_NETCONF_BASE_1_1, XmlNetconfConstants.URN_IETF_PARAMS_NETCONF_CAPABILITY_EXI_1_0); + private static final Logger LOG = LoggerFactory.getLogger(NetconfClientSessionNegotiatorFactory.class); private static final String START_EXI_MESSAGE_ID = "default-start-exi"; + private static final EXIOptions DEFAULT_OPTIONS; private final Optional additionalHeader; private final long connectionTimeoutMillis; private final Timer timer; private final EXIOptions options; - public NetconfClientSessionNegotiatorFactory(Timer timer, - Optional additionalHeader, - long connectionTimeoutMillis) { + static { + final EXIOptions opts = new EXIOptions(); + try { + opts.setPreserveDTD(true); + opts.setPreserveNS(true); + opts.setPreserveLexicalValues(true); + opts.setAlignmentType(AlignmentType.byteAligned); + } catch (EXIOptionsException e) { + throw new ExceptionInInitializerError(e); + } + + DEFAULT_OPTIONS = opts; + } + + public NetconfClientSessionNegotiatorFactory(final Timer timer, + final Optional additionalHeader, + final long connectionTimeoutMillis) { this(timer, additionalHeader, connectionTimeoutMillis, DEFAULT_OPTIONS); } - public NetconfClientSessionNegotiatorFactory(Timer timer, - Optional additionalHeader, - long connectionTimeoutMillis, EXIOptions exiOptions) { + public NetconfClientSessionNegotiatorFactory(final Timer timer, + final Optional additionalHeader, + final long connectionTimeoutMillis, final EXIOptions exiOptions) { this.timer = Preconditions.checkNotNull(timer); this.additionalHeader = additionalHeader; this.connectionTimeoutMillis = connectionTimeoutMillis; @@ -59,28 +77,21 @@ public class NetconfClientSessionNegotiatorFactory implements SessionNegotiatorF } @Override - public SessionNegotiator getSessionNegotiator(SessionListenerFactory sessionListenerFactory, - Channel channel, - Promise promise) { + public SessionNegotiator getSessionNegotiator(final SessionListenerFactory sessionListenerFactory, + final Channel channel, + final Promise promise) { NetconfMessage startExiMessage = NetconfStartExiMessage.create(options, START_EXI_MESSAGE_ID); - NetconfHelloMessage helloMessage = NetconfHelloMessage.createClientHello(CLIENT_CAPABILITIES, additionalHeader); + NetconfHelloMessage helloMessage = null; + try { + helloMessage = NetconfHelloMessage.createClientHello(CLIENT_CAPABILITIES, additionalHeader); + } catch (NetconfDocumentedException e) { + LOG.error("Unable to create client hello message with capabilities {} and additional handler {}",CLIENT_CAPABILITIES,additionalHeader); + throw new IllegalStateException(e); + } - NetconfClientSessionPreferences proposal = new NetconfClientSessionPreferences(helloMessage,startExiMessage); + NetconfClientSessionPreferences proposal = new NetconfClientSessionPreferences(helloMessage, startExiMessage); return new NetconfClientSessionNegotiator(proposal, promise, channel, timer, sessionListenerFactory.getSessionListener(),connectionTimeoutMillis); } - - private static final EXIOptions DEFAULT_OPTIONS = new EXIOptions(); - static { - try { - DEFAULT_OPTIONS.setPreserveDTD(true); - DEFAULT_OPTIONS.setPreserveNS(true); - DEFAULT_OPTIONS.setPreserveLexicalValues(true); - DEFAULT_OPTIONS.setAlignmentType(AlignmentType.preCompress); - } catch (EXIOptionsException e) { - // Should not happen since DEFAULT_OPTIONS are still the same - throw new IllegalStateException("Unable to create EXI DEFAULT_OPTIONS"); - } - } }