From: Tony Tkacik Date: Mon, 8 Dec 2014 09:01:42 +0000 (+0000) Subject: Merge "Remove duplicate dependency declaration" X-Git-Tag: release/lithium~795 X-Git-Url: https://git.opendaylight.org/gerrit/gitweb?p=controller.git;a=commitdiff_plain;h=d762fe6c823ad1ba21db1cad627a1cbd6d7c6d8e;hp=589bf833089d2aef2113bb5e493ee8c6816df19f Merge "Remove duplicate dependency declaration" --- diff --git a/opendaylight/adsal/commons/integrationtest/pom.xml b/opendaylight/adsal/commons/integrationtest/pom.xml index 1701964bf1..e4d795d563 100644 --- a/opendaylight/adsal/commons/integrationtest/pom.xml +++ b/opendaylight/adsal/commons/integrationtest/pom.xml @@ -122,7 +122,6 @@ org.ops4j.pax.exam maven-paxexam-plugin - 1.2.4 generate-config diff --git a/opendaylight/netconf/netconf-api/pom.xml b/opendaylight/netconf/netconf-api/pom.xml index c5fd8f1894..11aed2990e 100644 --- a/opendaylight/netconf/netconf-api/pom.xml +++ b/opendaylight/netconf/netconf-api/pom.xml @@ -46,20 +46,6 @@ - javax.management, - javax.xml.parsers, - org.opendaylight.controller.config.api, - org.opendaylight.controller.config.api.jmx, - org.opendaylight.protocol.framework, - io.netty.channel, - io.netty.util.concurrent, - org.w3c.dom, - org.slf4j, - org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev100924, - org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.yang.types.rev100924, - org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.netconf.monitoring.rev101004.netconf.state, - org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.netconf.monitoring.rev101004.netconf.state.sessions, - com.google.common.base, org.opendaylight.controller.netconf.api, org.opendaylight.controller.netconf.api.jmx, org.opendaylight.controller.netconf.api.xml, diff --git a/opendaylight/netconf/netconf-api/src/main/java/org/opendaylight/controller/netconf/api/NetconfMessage.java b/opendaylight/netconf/netconf-api/src/main/java/org/opendaylight/controller/netconf/api/NetconfMessage.java index 78586a3fec..d8c80e56eb 100644 --- a/opendaylight/netconf/netconf-api/src/main/java/org/opendaylight/controller/netconf/api/NetconfMessage.java +++ b/opendaylight/netconf/netconf-api/src/main/java/org/opendaylight/controller/netconf/api/NetconfMessage.java @@ -8,6 +8,15 @@ package org.opendaylight.controller.netconf.api; +import java.io.StringWriter; +import javax.xml.transform.OutputKeys; +import javax.xml.transform.Transformer; +import javax.xml.transform.TransformerConfigurationException; +import javax.xml.transform.TransformerException; +import javax.xml.transform.TransformerFactory; +import javax.xml.transform.TransformerFactoryConfigurationError; +import javax.xml.transform.dom.DOMSource; +import javax.xml.transform.stream.StreamResult; import org.w3c.dom.Document; /** @@ -15,6 +24,21 @@ import org.w3c.dom.Document; * implementing ProtocolMessage interface. */ public class NetconfMessage { + private static final Transformer TRANSFORMER; + + static { + final Transformer t; + try { + t = TransformerFactory.newInstance().newTransformer(); + } catch (TransformerConfigurationException | TransformerFactoryConfigurationError e) { + throw new ExceptionInInitializerError(e); + } + t.setOutputProperty(OutputKeys.INDENT, "yes"); + t.setOutputProperty(OutputKeys.OMIT_XML_DECLARATION, "yes"); + + TRANSFORMER = t; + } + private final Document doc; public NetconfMessage(final Document doc) { @@ -24,4 +48,21 @@ public class NetconfMessage { public Document getDocument() { return this.doc; } + + @Override + public String toString() { + final StreamResult result = new StreamResult(new StringWriter()); + final DOMSource source = new DOMSource(doc.getDocumentElement()); + + try { + // Slight critical section is a tradeoff. This should be reasonably fast. + synchronized (TRANSFORMER) { + TRANSFORMER.transform(source, result); + } + } catch (TransformerException e) { + throw new IllegalStateException("Failed to encode document", e); + } + + return result.getWriter().toString(); + } } diff --git a/opendaylight/netconf/netconf-client/src/main/java/org/opendaylight/controller/netconf/client/NetconfClientSessionNegotiator.java b/opendaylight/netconf/netconf-client/src/main/java/org/opendaylight/controller/netconf/client/NetconfClientSessionNegotiator.java index a8c9a6526d..06c695c25a 100644 --- a/opendaylight/netconf/netconf-client/src/main/java/org/opendaylight/controller/netconf/client/NetconfClientSessionNegotiator.java +++ b/opendaylight/netconf/netconf-client/src/main/java/org/opendaylight/controller/netconf/client/NetconfClientSessionNegotiator.java @@ -169,14 +169,13 @@ public class NetconfClientSessionNegotiator extends } else if(NetconfMessageUtil.isErrorMessage(netconfMessage)) { LOG.warn( "Error response to start-exi message {}, Communication will continue without exi on session {}", - XmlUtil.toString(netconfMessage.getDocument()), session); + netconfMessage, session); // Unexpected response to start-exi, throwing message away, continue without exi } else { - LOG.warn( - "Unexpected response to start-exi message, should be ok, was {}, ",XmlUtil.toString(netconfMessage.getDocument()), - "Communication will continue without exi and response message will be thrown away on session {}", - 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); 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 7efb28b467..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 @@ -10,10 +10,11 @@ package org.opendaylight.controller.netconf.client; import com.google.common.base.Optional; import com.google.common.base.Preconditions; -import com.google.common.collect.Sets; +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; @@ -32,28 +33,43 @@ import org.slf4j.LoggerFactory; public class NetconfClientSessionNegotiatorFactory implements SessionNegotiatorFactory { - public static final java.util.Set CLIENT_CAPABILITIES = Sets.newHashSet( + 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; - private static final Logger LOG = LoggerFactory.getLogger(NetconfClientSessionNegotiatorFactory.class); - 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; @@ -61,9 +77,9 @@ 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 = null; @@ -78,17 +94,4 @@ public class NetconfClientSessionNegotiatorFactory implements SessionNegotiatorF 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"); - } - } } diff --git a/opendaylight/netconf/netconf-impl/src/main/java/org/opendaylight/controller/netconf/impl/NetconfServerSessionListener.java b/opendaylight/netconf/netconf-impl/src/main/java/org/opendaylight/controller/netconf/impl/NetconfServerSessionListener.java index b2b8c50029..951d0dd98d 100644 --- a/opendaylight/netconf/netconf-impl/src/main/java/org/opendaylight/controller/netconf/impl/NetconfServerSessionListener.java +++ b/opendaylight/netconf/netconf-impl/src/main/java/org/opendaylight/controller/netconf/impl/NetconfServerSessionListener.java @@ -35,25 +35,25 @@ public class NetconfServerSessionListener implements NetconfSessionListener allNetconfOperations; - private NetconfOperationRouterImpl(NetconfOperationServiceSnapshot netconfOperationServiceSnapshot) { + private NetconfOperationRouterImpl(final NetconfOperationServiceSnapshot netconfOperationServiceSnapshot) { this.netconfOperationServiceSnapshot = netconfOperationServiceSnapshot; } - private synchronized void initNetconfOperations(Set allOperations) { + private synchronized void initNetconfOperations(final Set allOperations) { allNetconfOperations = allOperations; } /** * Factory method to produce instance of NetconfOperationRouter */ - public static NetconfOperationRouter createOperationRouter(NetconfOperationServiceSnapshot netconfOperationServiceSnapshot, - CapabilityProvider capabilityProvider, DefaultCommitNotificationProducer commitNotifier) { + public static NetconfOperationRouter createOperationRouter(final NetconfOperationServiceSnapshot netconfOperationServiceSnapshot, + final CapabilityProvider capabilityProvider, final DefaultCommitNotificationProducer commitNotifier) { NetconfOperationRouterImpl router = new NetconfOperationRouterImpl(netconfOperationServiceSnapshot); Preconditions.checkNotNull(netconfOperationServiceSnapshot); @@ -75,8 +75,8 @@ public class NetconfOperationRouterImpl implements NetconfOperationRouter { return router; } - private static Set getAllNetconfOperations(Set defaultNetconfOperations, - NetconfOperationServiceSnapshot netconfOperationServiceSnapshot) { + private static Set getAllNetconfOperations(final Set defaultNetconfOperations, + final NetconfOperationServiceSnapshot netconfOperationServiceSnapshot) { Set result = new HashSet<>(); result.addAll(defaultNetconfOperations); @@ -92,8 +92,8 @@ public class NetconfOperationRouterImpl implements NetconfOperationRouter { } @Override - public synchronized Document onNetconfMessage(Document message, - NetconfServerSession session) throws NetconfDocumentedException { + public synchronized Document onNetconfMessage(final Document message, + final NetconfServerSession session) throws NetconfDocumentedException { Preconditions.checkNotNull(allNetconfOperations, "Operation router was not initialized properly"); NetconfOperationExecution netconfOperationExecution; @@ -135,7 +135,7 @@ public class NetconfOperationRouterImpl implements NetconfOperationRouter { netconfOperationServiceSnapshot.close(); } - private NetconfDocumentedException handleUnexpectedEx(String s, Exception e) throws NetconfDocumentedException { + private NetconfDocumentedException handleUnexpectedEx(final String s, final Exception e) throws NetconfDocumentedException { LOG.error(s, e); Map info = Maps.newHashMap(); @@ -146,28 +146,29 @@ public class NetconfOperationRouterImpl implements NetconfOperationRouter { NetconfDocumentedException.ErrorSeverity.error, info); } - private Document executeOperationWithHighestPriority(Document message, - NetconfOperationExecution netconfOperationExecution, String messageAsString) + private Document executeOperationWithHighestPriority(final Document message, + final NetconfOperationExecution netconfOperationExecution, final String messageAsString) throws NetconfDocumentedException { LOG.debug("Forwarding netconf message {} to {}", messageAsString, netconfOperationExecution.netconfOperation); return netconfOperationExecution.execute(message); } private NetconfOperationExecution getNetconfOperationWithHighestPriority( - Document message, NetconfServerSession session) throws NetconfDocumentedException { + final Document message, final NetconfServerSession session) throws NetconfDocumentedException { NavigableMap sortedByPriority = getSortedNetconfOperationsWithCanHandle( message, session); - Preconditions.checkArgument(sortedByPriority.isEmpty() == false, - "No %s available to handle message %s", NetconfOperation.class.getName(), - XmlUtil.toString(message)); + if (sortedByPriority.isEmpty()) { + throw new IllegalArgumentException(String.format("No %s available to handle message %s", + NetconfOperation.class.getName(), XmlUtil.toString(message))); + } return NetconfOperationExecution.createExecutionChain(sortedByPriority, sortedByPriority.lastKey()); } - private TreeMap getSortedNetconfOperationsWithCanHandle(Document message, - NetconfServerSession session) throws NetconfDocumentedException { + private TreeMap getSortedNetconfOperationsWithCanHandle(final Document message, + final NetconfServerSession session) throws NetconfDocumentedException { TreeMap sortedPriority = Maps.newTreeMap(); for (NetconfOperation netconfOperation : allNetconfOperations) { @@ -193,7 +194,7 @@ public class NetconfOperationRouterImpl implements NetconfOperationRouter { } @Override - public Document execute(Document requestMessage) throws NetconfDocumentedException { + public Document execute(final Document requestMessage) throws NetconfDocumentedException { throw new NetconfDocumentedException("This execution represents the termination point in operation execution and cannot be executed itself", NetconfDocumentedException.ErrorType.application, NetconfDocumentedException.ErrorTag.operation_failed, @@ -203,9 +204,9 @@ public class NetconfOperationRouterImpl implements NetconfOperationRouter { private static class NetconfOperationExecution implements NetconfOperationChainedExecution { private final NetconfOperation netconfOperation; - private NetconfOperationChainedExecution subsequentExecution; + private final NetconfOperationChainedExecution subsequentExecution; - private NetconfOperationExecution(NetconfOperation netconfOperation, NetconfOperationChainedExecution subsequentExecution) { + private NetconfOperationExecution(final NetconfOperation netconfOperation, final NetconfOperationChainedExecution subsequentExecution) { this.netconfOperation = netconfOperation; this.subsequentExecution = subsequentExecution; } @@ -216,12 +217,12 @@ public class NetconfOperationRouterImpl implements NetconfOperationRouter { } @Override - public Document execute(Document message) throws NetconfDocumentedException { + public Document execute(final Document message) throws NetconfDocumentedException { return netconfOperation.handle(message, subsequentExecution); } public static NetconfOperationExecution createExecutionChain( - NavigableMap sortedByPriority, HandlingPriority handlingPriority) { + final NavigableMap sortedByPriority, final HandlingPriority handlingPriority) { NetconfOperation netconfOperation = sortedByPriority.get(handlingPriority); HandlingPriority subsequentHandlingPriority = sortedByPriority.lowerKey(handlingPriority); diff --git a/opendaylight/netconf/netconf-it/pom.xml b/opendaylight/netconf/netconf-it/pom.xml index b2c5c4c8f7..7218ac7872 100644 --- a/opendaylight/netconf/netconf-it/pom.xml +++ b/opendaylight/netconf/netconf-it/pom.xml @@ -145,21 +145,4 @@ test - - - - - org.ops4j.pax.exam - maven-paxexam-plugin - - - generate-config - - generate-depends-file - - - - - - diff --git a/opendaylight/netconf/netconf-netty-util/src/main/java/org/opendaylight/controller/netconf/nettyutil/AbstractNetconfSession.java b/opendaylight/netconf/netconf-netty-util/src/main/java/org/opendaylight/controller/netconf/nettyutil/AbstractNetconfSession.java index 4eaeee9d78..efa1c731c8 100644 --- a/opendaylight/netconf/netconf-netty-util/src/main/java/org/opendaylight/controller/netconf/nettyutil/AbstractNetconfSession.java +++ b/opendaylight/netconf/netconf-netty-util/src/main/java/org/opendaylight/controller/netconf/nettyutil/AbstractNetconfSession.java @@ -19,7 +19,6 @@ import org.opendaylight.controller.netconf.api.NetconfTerminationReason; import org.opendaylight.controller.netconf.nettyutil.handler.NetconfEXICodec; import org.opendaylight.controller.netconf.nettyutil.handler.exi.EXIParameters; import org.opendaylight.controller.netconf.util.xml.XmlElement; -import org.opendaylight.controller.netconf.util.xml.XmlUtil; import org.opendaylight.protocol.framework.AbstractProtocolSession; import org.openexi.proc.common.EXIOptionsException; import org.slf4j.Logger; @@ -114,8 +113,8 @@ public abstract class AbstractNetconfSession promise, Channel channel, Timer timer, - L sessionListener, long connectionTimeoutMillis) { + protected AbstractNetconfSessionNegotiator(final P sessionPreferences, final Promise promise, final Channel channel, final Timer timer, + final L sessionListener, final long connectionTimeoutMillis) { super(promise, channel); this.sessionPreferences = sessionPreferences; this.promise = promise; @@ -83,7 +82,7 @@ public abstract class AbstractNetconfSessionNegotiator

future = sslHandler.get().handshakeFuture(); future.addListener(new GenericFutureListener>() { @Override - public void operationComplete(Future future) { + public void operationComplete(final Future future) { Preconditions.checkState(future.isSuccess(), "Ssl handshake was not successful"); LOG.debug("Ssl handshake complete"); start(); @@ -94,7 +93,7 @@ public abstract class AbstractNetconfSessionNegotiator

getSslHandler(Channel channel) { + private static Optional getSslHandler(final Channel channel) { final SslHandler sslHandler = channel.pipeline().get(SslHandler.class); return sslHandler == null ? Optional. absent() : Optional.of(sslHandler); } @@ -105,7 +104,7 @@ public abstract class AbstractNetconfSessionNegotiator

() { @Override - public void operationComplete(ChannelFuture future) throws Exception { + public void operationComplete(final ChannelFuture future) throws Exception { if(future.isSuccess()) { LOG.debug("Channel {} closed: success", future.channel()); } else { @@ -159,7 +158,7 @@ public abstract class AbstractNetconfSessionNegotiator

out) throws Exception { + protected void decode(final ChannelHandlerContext ctx, final ByteBuf in, final List out) throws EXIOptionsException, IOException, SAXException, TransformerConfigurationException { /* * Note that we could loop here and process all the messages, but we can't do that. * The reason is operation, which has the contract of immediately stopping @@ -46,12 +50,14 @@ public final class NetconfEXIToMessageDecoder extends ByteToMessageDecoder { */ // If empty Byte buffer is passed to r.parse, EOFException is thrown - if (in.isReadable() == false) { + if (!in.isReadable()) { LOG.debug("No more content in incoming buffer."); return; } - LOG.trace("Received to decode: {}", ByteBufUtil.hexDump(in)); + if (LOG.isTraceEnabled()) { + LOG.trace("Received to decode: {}", ByteBufUtil.hexDump(in)); + } final EXIReader r = codec.getReader(); diff --git a/opendaylight/netconf/netconf-netty-util/src/main/java/org/opendaylight/controller/netconf/nettyutil/handler/NetconfMessageToEXIEncoder.java b/opendaylight/netconf/netconf-netty-util/src/main/java/org/opendaylight/controller/netconf/nettyutil/handler/NetconfMessageToEXIEncoder.java index 0a866fffaa..55dcd9daba 100644 --- a/opendaylight/netconf/netconf-netty-util/src/main/java/org/opendaylight/controller/netconf/nettyutil/handler/NetconfMessageToEXIEncoder.java +++ b/opendaylight/netconf/netconf-netty-util/src/main/java/org/opendaylight/controller/netconf/nettyutil/handler/NetconfMessageToEXIEncoder.java @@ -12,13 +12,15 @@ import io.netty.buffer.ByteBuf; import io.netty.buffer.ByteBufOutputStream; import io.netty.channel.ChannelHandlerContext; import io.netty.handler.codec.MessageToByteEncoder; +import java.io.IOException; import java.io.OutputStream; import javax.xml.transform.Transformer; +import javax.xml.transform.TransformerException; import javax.xml.transform.dom.DOMSource; import javax.xml.transform.sax.SAXResult; import javax.xml.transform.sax.SAXTransformerFactory; import org.opendaylight.controller.netconf.api.NetconfMessage; -import org.opendaylight.controller.netconf.util.xml.XmlUtil; +import org.openexi.proc.common.EXIOptionsException; import org.openexi.sax.Transmogrifier; import org.slf4j.Logger; import org.slf4j.LoggerFactory; @@ -35,8 +37,8 @@ public final class NetconfMessageToEXIEncoder extends MessageToByteEncoder nonHelloMessages = Lists.newArrayList(); + private final List nonHelloMessages = Lists.newArrayList(); private boolean helloReceived = false; @Override @VisibleForTesting - public void decode(ChannelHandlerContext ctx, ByteBuf in, List out) throws IOException, SAXException, NetconfDocumentedException { + public void decode(final ChannelHandlerContext ctx, final ByteBuf in, final List out) throws IOException, SAXException, NetconfDocumentedException { if (in.readableBytes() == 0) { LOG.debug("No more content in incoming buffer."); return; @@ -69,7 +69,10 @@ public final class NetconfXMLToHelloMessageDecoder extends ByteToMessageDecoder in.markReaderIndex(); try { - LOG.trace("Received to decode: {}", ByteBufUtil.hexDump(in)); + if (LOG.isTraceEnabled()) { + LOG.trace("Received to decode: {}", ByteBufUtil.hexDump(in)); + } + byte[] bytes = new byte[in.readableBytes()]; in.readBytes(bytes); @@ -92,16 +95,13 @@ public final class NetconfXMLToHelloMessageDecoder extends ByteToMessageDecoder final NetconfMessage message = getNetconfMessage(additionalHeader, doc); if (message instanceof NetconfHelloMessage) { Preconditions.checkState(helloReceived == false, - "Multiple hello messages received, unexpected hello: %s", - XmlUtil.toString(message.getDocument())); + "Multiple hello messages received, unexpected hello: %s", message); out.add(message); helloReceived = true; // Non hello message, suspend the message and insert into cache } else { - Preconditions.checkState(helloReceived, "Hello message not received, instead received: %s", - XmlUtil.toString(message.getDocument())); - LOG.debug("Netconf message received during negotiation, caching {}", - XmlUtil.toString(message.getDocument())); + Preconditions.checkState(helloReceived, "Hello message not received, instead received: %s", message); + LOG.debug("Netconf message received during negotiation, caching {}", message); nonHelloMessages.add(message); } } finally { @@ -122,7 +122,7 @@ public final class NetconfXMLToHelloMessageDecoder extends ByteToMessageDecoder return msg; } - private int getAdditionalHeaderEndIndex(byte[] bytes) { + private int getAdditionalHeaderEndIndex(final byte[] bytes) { for (byte[] possibleEnd : POSSIBLE_ENDS) { int idx = findByteSequence(bytes, possibleEnd); @@ -160,12 +160,12 @@ public final class NetconfXMLToHelloMessageDecoder extends ByteToMessageDecoder } - private void logMessage(byte[] bytes) { + private void logMessage(final byte[] bytes) { String s = Charsets.UTF_8.decode(ByteBuffer.wrap(bytes)).toString(); LOG.debug("Parsing message \n{}", s); } - private boolean startsWithAdditionalHeader(byte[] bytes) { + private boolean startsWithAdditionalHeader(final byte[] bytes) { for (byte[] possibleStart : POSSIBLE_STARTS) { int i = 0; for (byte b : possibleStart) { @@ -182,7 +182,7 @@ public final class NetconfXMLToHelloMessageDecoder extends ByteToMessageDecoder return false; } - private String additionalHeaderToString(byte[] bytes) { + private String additionalHeaderToString(final byte[] bytes) { return Charsets.UTF_8.decode(ByteBuffer.wrap(bytes)).toString(); } diff --git a/opendaylight/netconf/netconf-netty-util/src/main/java/org/opendaylight/controller/netconf/nettyutil/handler/NetconfXMLToMessageDecoder.java b/opendaylight/netconf/netconf-netty-util/src/main/java/org/opendaylight/controller/netconf/nettyutil/handler/NetconfXMLToMessageDecoder.java index bfc8d77e17..1dc8e0233b 100644 --- a/opendaylight/netconf/netconf-netty-util/src/main/java/org/opendaylight/controller/netconf/nettyutil/handler/NetconfXMLToMessageDecoder.java +++ b/opendaylight/netconf/netconf-netty-util/src/main/java/org/opendaylight/controller/netconf/nettyutil/handler/NetconfXMLToMessageDecoder.java @@ -12,20 +12,24 @@ import io.netty.buffer.ByteBufInputStream; import io.netty.buffer.ByteBufUtil; import io.netty.channel.ChannelHandlerContext; import io.netty.handler.codec.ByteToMessageDecoder; +import java.io.IOException; import java.util.List; import org.opendaylight.controller.netconf.api.NetconfMessage; import org.opendaylight.controller.netconf.util.xml.XmlUtil; import org.slf4j.Logger; import org.slf4j.LoggerFactory; +import org.xml.sax.SAXException; public final class NetconfXMLToMessageDecoder extends ByteToMessageDecoder { private static final Logger LOG = LoggerFactory.getLogger(NetconfXMLToMessageDecoder.class); @Override - public void decode(ChannelHandlerContext ctx, ByteBuf in, List out) throws Exception { + public void decode(final ChannelHandlerContext ctx, final ByteBuf in, final List out) throws IOException, SAXException { + if (in.isReadable()) { + if (LOG.isTraceEnabled()) { + LOG.trace("Received to decode: {}", ByteBufUtil.hexDump(in)); + } - if (in.readableBytes() != 0) { - LOG.trace("Received to decode: {}", ByteBufUtil.hexDump(in)); out.add(new NetconfMessage(XmlUtil.readXmlToDocument(new ByteBufInputStream(in)))); } else { LOG.debug("No more content in incoming buffer."); diff --git a/opendaylight/netconf/netconf-util/src/main/java/org/opendaylight/controller/netconf/util/messages/SendErrorExceptionUtil.java b/opendaylight/netconf/netconf-util/src/main/java/org/opendaylight/controller/netconf/util/messages/SendErrorExceptionUtil.java index fe5ed03320..490eb95b82 100644 --- a/opendaylight/netconf/netconf-util/src/main/java/org/opendaylight/controller/netconf/util/messages/SendErrorExceptionUtil.java +++ b/opendaylight/netconf/netconf-util/src/main/java/org/opendaylight/controller/netconf/util/messages/SendErrorExceptionUtil.java @@ -37,17 +37,20 @@ public final class SendErrorExceptionUtil { f.addListener(new SendErrorVerifyingListener(sendErrorException)); } - public static void sendErrorMessage(Channel channel, NetconfDocumentedException sendErrorException) { + public static void sendErrorMessage(final Channel channel, final NetconfDocumentedException sendErrorException) { LOG.trace("Sending error {}", sendErrorException.getMessage(), sendErrorException); final Document errorDocument = createDocument(sendErrorException); ChannelFuture f = channel.writeAndFlush(new NetconfMessage(errorDocument)); f.addListener(new SendErrorVerifyingListener(sendErrorException)); } - public static void sendErrorMessage(NetconfSession session, NetconfDocumentedException sendErrorException, - NetconfMessage incommingMessage) { + public static void sendErrorMessage(final NetconfSession session, final NetconfDocumentedException sendErrorException, + final NetconfMessage incommingMessage) { final Document errorDocument = createDocument(sendErrorException); - LOG.trace("Sending error {}", XmlUtil.toString(errorDocument)); + if (LOG.isTraceEnabled()) { + LOG.trace("Sending error {}", XmlUtil.toString(errorDocument)); + } + tryToCopyAttributes(incommingMessage.getDocument(), errorDocument, sendErrorException); ChannelFuture f = session.sendMessage(new NetconfMessage(errorDocument)); f.addListener(new SendErrorVerifyingListener(sendErrorException));