Merge "Changed model versions to dependencies"
[controller.git] / opendaylight / netconf / netconf-util / src / main / java / org / opendaylight / controller / netconf / util / AbstractChannelInitializer.java
index 317a126bbae392c46b8bd699f8023a03f858d4d0..5b4b3d02ea8839b1dddbf5132d16157d0d325324 100644 (file)
@@ -8,69 +8,26 @@
 
 package org.opendaylight.controller.netconf.util;
 
-import javax.net.ssl.SSLContext;
-import javax.net.ssl.SSLEngine;
-
-import org.opendaylight.controller.netconf.api.NetconfMessage;
-import org.opendaylight.controller.netconf.api.NetconfSession;
-import org.opendaylight.controller.netconf.util.messages.NetconfMessageFactory;
-import org.opendaylight.protocol.framework.ProtocolHandlerFactory;
-import org.opendaylight.protocol.framework.ProtocolMessageDecoder;
-import org.opendaylight.protocol.framework.ProtocolMessageEncoder;
-
-import com.google.common.base.Optional;
-
-import io.netty.channel.ChannelHandler;
 import io.netty.channel.socket.SocketChannel;
-import io.netty.handler.ssl.SslHandler;
 import io.netty.util.concurrent.Promise;
 
-public abstract class AbstractChannelInitializer {
-
-    private final Optional<SSLContext> maybeContext;
-    private final NetconfHandlerFactory handlerFactory;
-
-    public AbstractChannelInitializer(Optional<SSLContext> maybeContext) {
-        this.maybeContext = maybeContext;
-        this.handlerFactory = new NetconfHandlerFactory(new NetconfMessageFactory());
-    }
+import org.opendaylight.controller.netconf.api.NetconfSession;
+import org.opendaylight.controller.netconf.util.handler.FramingMechanismHandlerFactory;
+import org.opendaylight.controller.netconf.util.handler.NetconfMessageAggregator;
+import org.opendaylight.controller.netconf.util.handler.NetconfMessageToXMLEncoder;
+import org.opendaylight.controller.netconf.util.handler.NetconfXMLToMessageDecoder;
+import org.opendaylight.controller.netconf.util.messages.FramingMechanism;
 
-    public void initialize(SocketChannel ch, Promise<? extends NetconfSession> promise) {
-        if (maybeContext.isPresent()) {
-            initSsl(ch);
-        }
+public abstract class AbstractChannelInitializer {
 
-        ch.pipeline().addLast("frameDecoder", NetconfMessageFactory.getDelimiterFrameDecoder());
-        ch.pipeline().addLast(handlerFactory.getDecoders());
+    public void initialize(SocketChannel ch, Promise<? extends NetconfSession> promise){
+        ch.pipeline().addLast("aggregator", new NetconfMessageAggregator(FramingMechanism.EOM));
+        ch.pipeline().addLast(new NetconfXMLToMessageDecoder());
         initializeAfterDecoder(ch, promise);
-        ch.pipeline().addLast(handlerFactory.getEncoders());
+        ch.pipeline().addLast("frameEncoder", FramingMechanismHandlerFactory.createHandler(FramingMechanism.EOM));
+        ch.pipeline().addLast(new NetconfMessageToXMLEncoder());
     }
 
     protected abstract void initializeAfterDecoder(SocketChannel ch, Promise<? extends NetconfSession> promise);
 
-    private void initSsl(SocketChannel ch) {
-        SSLEngine sslEngine = maybeContext.get().createSSLEngine();
-        initSslEngine(sslEngine);
-        final SslHandler handler = new SslHandler(sslEngine);
-        ch.pipeline().addLast("ssl", handler);
-    }
-
-    protected abstract void initSslEngine(SSLEngine sslEngine);
-
-    private static final class NetconfHandlerFactory extends ProtocolHandlerFactory<NetconfMessage> {
-
-        public NetconfHandlerFactory(final NetconfMessageFactory msgFactory) {
-            super(msgFactory);
-        }
-
-        @Override
-        public ChannelHandler[] getEncoders() {
-            return new ChannelHandler[] { new ProtocolMessageEncoder(this.msgFactory) };
-        }
-
-        @Override
-        public ChannelHandler[] getDecoders() {
-            return new ChannelHandler[] { new ProtocolMessageDecoder(this.msgFactory) };
-        }
-    }
 }