X-Git-Url: https://git.opendaylight.org/gerrit/gitweb?a=blobdiff_plain;f=netconf%2Fnetconf-netty-util%2Fsrc%2Fmain%2Fjava%2Forg%2Fopendaylight%2Fnetconf%2Fnettyutil%2Fhandler%2FNetconfEXIToMessageDecoder.java;h=0f85d18c16964be7b72b3d94fcb504f937e1a99d;hb=791a6a25f6670a23d390bfdeb786f70588d622a5;hp=6d2508757a4e3138c5f3effe1cb7a2e08c757dd3;hpb=e85b308c5bb9978141d511d323225ba1d503810d;p=netconf.git diff --git a/netconf/netconf-netty-util/src/main/java/org/opendaylight/netconf/nettyutil/handler/NetconfEXIToMessageDecoder.java b/netconf/netconf-netty-util/src/main/java/org/opendaylight/netconf/nettyutil/handler/NetconfEXIToMessageDecoder.java index 6d2508757a..0f85d18c16 100644 --- a/netconf/netconf-netty-util/src/main/java/org/opendaylight/netconf/nettyutil/handler/NetconfEXIToMessageDecoder.java +++ b/netconf/netconf-netty-util/src/main/java/org/opendaylight/netconf/nettyutil/handler/NetconfEXIToMessageDecoder.java @@ -7,7 +7,8 @@ */ package org.opendaylight.netconf.nettyutil.handler; -import com.google.common.base.Preconditions; +import static java.util.Objects.requireNonNull; + import io.netty.buffer.ByteBuf; import io.netty.buffer.ByteBufInputStream; import io.netty.buffer.ByteBufUtil; @@ -24,9 +25,8 @@ import javax.xml.transform.dom.DOMResult; import javax.xml.transform.sax.SAXTransformerFactory; import javax.xml.transform.sax.TransformerHandler; import org.opendaylight.netconf.api.NetconfMessage; +import org.opendaylight.netconf.shaded.exificient.core.exceptions.EXIException; import org.opendaylight.yangtools.util.xml.UntrustedXML; -import org.openexi.proc.common.EXIOptionsException; -import org.openexi.sax.EXIReader; import org.slf4j.Logger; import org.slf4j.LoggerFactory; import org.w3c.dom.Document; @@ -37,10 +37,12 @@ public final class NetconfEXIToMessageDecoder extends ByteToMessageDecoder { private static final Logger LOG = LoggerFactory.getLogger(NetconfEXIToMessageDecoder.class); private static final SAXTransformerFactory FACTORY; + static { final TransformerFactory f = SAXTransformerFactory.newInstance(); if (!f.getFeature(SAXTransformerFactory.FEATURE)) { - throw new TransformerFactoryConfigurationError(String.format("Factory %s is not a SAXTransformerFactory", f)); + throw new TransformerFactoryConfigurationError( + String.format("Factory %s is not a SAXTransformerFactory", f)); } FACTORY = (SAXTransformerFactory)f; @@ -51,20 +53,21 @@ public final class NetconfEXIToMessageDecoder extends ByteToMessageDecoder { * which means that {@link #decode(ChannelHandlerContext, ByteBuf, List)} * cannot be invoked concurrently. Hence we can reuse the reader. */ - private final EXIReader reader; + private final ThreadLocalSAXDecoder reader; private final DocumentBuilder documentBuilder; - private NetconfEXIToMessageDecoder(final EXIReader reader) { - this.reader = Preconditions.checkNotNull(reader); + private NetconfEXIToMessageDecoder(final ThreadLocalSAXDecoder reader) { + this.reader = requireNonNull(reader); this.documentBuilder = UntrustedXML.newDocumentBuilder(); } - public static NetconfEXIToMessageDecoder create(final NetconfEXICodec codec) throws EXIOptionsException { + public static NetconfEXIToMessageDecoder create(final NetconfEXICodec codec) throws EXIException { return new NetconfEXIToMessageDecoder(codec.getReader()); } @Override - protected void decode(final ChannelHandlerContext ctx, final ByteBuf in, final List out) throws EXIOptionsException, IOException, SAXException, TransformerConfigurationException { + protected void decode(final ChannelHandlerContext ctx, final ByteBuf in, final List out) + throws 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 @@ -88,7 +91,7 @@ public final class NetconfEXIToMessageDecoder extends ByteToMessageDecoder { final DOMResult domResult = new DOMResult(documentBuilder.newDocument()); handler.setResult(domResult); - try (final InputStream is = new ByteBufInputStream(in)) { + try (InputStream is = new ByteBufInputStream(in)) { // Performs internal reset before doing anything reader.parse(new InputSource(is)); }