package org.opendaylight.netconf.mdsal.connector.ops;
import com.google.common.collect.ImmutableMap;
+import java.io.IOException;
import java.net.URI;
import java.net.URISyntaxException;
import java.util.Iterator;
import java.util.Map;
import java.util.Optional;
+import javax.xml.stream.XMLStreamException;
import javax.xml.transform.dom.DOMSource;
import org.opendaylight.netconf.api.DocumentedException;
import org.opendaylight.netconf.api.DocumentedException.ErrorSeverity;
import org.slf4j.LoggerFactory;
import org.w3c.dom.Element;
import org.w3c.dom.NodeList;
+import org.xml.sax.SAXException;
abstract class AbstractEdit extends AbstractConfigOperation {
private static final Logger LOG = LoggerFactory.getLogger(AbstractEdit.class);
this.schemaContext = schemaContext;
}
- @SuppressWarnings("checkstyle:IllegalCatch")
protected void parseIntoNormalizedNode(final DataSchemaNode schemaNode, final XmlElement element,
final NormalizedNodeStreamWriter writer) throws DocumentedException {
if (!(schemaNode instanceof ContainerSchemaNode) && !(schemaNode instanceof ListSchemaNode)) {
final XmlParserStream xmlParser = XmlParserStream.create(writer, schemaContext.getCurrentContext(), schemaNode);
try {
xmlParser.traverse(new DOMSource(element.getDomElement()));
- } catch (final Exception ex) {
+ } catch (final XMLStreamException | URISyntaxException | IOException | SAXException ex) {
throw new NetconfDocumentedException("Error parsing input: " + ex.getMessage(), ex, ErrorType.PROTOCOL,
ErrorTag.MALFORMED_MESSAGE, ErrorSeverity.ERROR);
}
import java.io.IOException;
import java.net.URI;
+import java.net.URISyntaxException;
import java.util.Collection;
import java.util.Collections;
import java.util.Map;
import org.w3c.dom.Element;
import org.w3c.dom.Node;
import org.w3c.dom.NodeList;
+import org.xml.sax.SAXException;
public class RuntimeRpc extends AbstractSingletonNetconfOperation {
* @param input input container schema node, or null if rpc does not take any input
* @return parsed rpc into normalized node, or null if input schema is null
*/
- @SuppressWarnings("checkstyle:IllegalCatch")
private @Nullable ContainerNode rpcToNNode(final XmlElement element,
final @Nullable ContainerSchemaNode input) throws DocumentedException {
final NormalizedNodeResult resultHolder = new NormalizedNodeResult();
try {
xmlParser.traverse(new DOMSource(element.getDomElement()));
- } catch (final Exception ex) {
+ } catch (final XMLStreamException | URISyntaxException | IOException | SAXException ex) {
throw new NetconfDocumentedException("Error parsing input: " + ex.getMessage(), ex, ErrorType.PROTOCOL,
ErrorTag.MALFORMED_MESSAGE, ErrorSeverity.ERROR);
}
import com.google.common.io.ByteSource;
import com.google.common.util.concurrent.Futures;
import com.google.common.util.concurrent.MoreExecutors;
+import java.io.IOException;
import java.io.StringWriter;
import java.util.EnumMap;
import java.util.concurrent.ExecutorService;
+import javax.xml.parsers.ParserConfigurationException;
import javax.xml.transform.OutputKeys;
import javax.xml.transform.Transformer;
import javax.xml.transform.TransformerFactory;
import org.w3c.dom.Document;
import org.w3c.dom.Node;
import org.w3c.dom.NodeList;
+import org.xml.sax.SAXException;
public abstract class AbstractNetconfOperationTest {
private static final Logger LOG = LoggerFactory.getLogger(AbstractNetconfOperationTest.class);
return transactionProvider;
}
- @SuppressWarnings("illegalCatch")
private static Document getReplyOk() {
Document doc;
try {
doc = XmlFileLoader.xmlFileToDocument("messages/mapping/rpc-reply_ok.xml");
- } catch (final Exception e) {
+ } catch (final IOException | SAXException | ParserConfigurationException e) {
LOG.debug("unable to load rpc reply ok.", e);
doc = XmlUtil.newDocument();
}
import com.google.common.base.Preconditions;
import com.google.common.io.ByteSource;
import com.google.common.util.concurrent.FluentFuture;
+import java.io.IOException;
import java.net.URI;
import java.util.Collection;
import java.util.Collections;
+import javax.xml.parsers.ParserConfigurationException;
import org.custommonkey.xmlunit.DetailedDiff;
import org.custommonkey.xmlunit.Diff;
import org.custommonkey.xmlunit.XMLUnit;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.w3c.dom.Document;
+import org.xml.sax.SAXException;
@RunWith(MockitoJUnitRunner.StrictStubs.class)
public class RuntimeRpcTest {
private static final Logger LOG = LoggerFactory.getLogger(RuntimeRpcTest.class);
private static final String SESSION_ID_FOR_REPORTING = "netconf-test-session1";
- private static final Document RPC_REPLY_OK = RuntimeRpcTest.getReplyOk();
+ private static final Document RPC_REPLY_OK = getReplyOk();
- @SuppressWarnings("illegalCatch")
private static Document getReplyOk() {
- Document doc;
try {
- doc = XmlFileLoader.xmlFileToDocument("messages/mapping/rpcs/runtimerpc-ok-reply.xml");
- } catch (final Exception e) {
+ return XmlFileLoader.xmlFileToDocument("messages/mapping/rpcs/runtimerpc-ok-reply.xml");
+ } catch (final IOException | SAXException | ParserConfigurationException e) {
LOG.debug("unable to load rpc reply ok.", e);
- doc = XmlUtil.newDocument();
+ return XmlUtil.newDocument();
}
- return doc;
}
private static final DOMRpcService RPC_SERVICE_VOID_INVOKER = new DOMRpcService() {
package org.opendaylight.netconf.mdsal.connector.ops.get;
import static java.util.Objects.requireNonNull;
+import static org.hamcrest.CoreMatchers.startsWith;
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.fail;
+import static org.junit.Assume.assumeThat;
import static org.mockito.Mockito.doReturn;
import static org.mockito.Mockito.mock;
import java.util.Map;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
-import org.junit.Assert;
import org.junit.Before;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.junit.runners.Parameterized;
import org.junit.runners.model.InitializationError;
+import org.opendaylight.netconf.api.DocumentedException;
import org.opendaylight.netconf.api.xml.XmlElement;
import org.opendaylight.netconf.api.xml.XmlUtil;
import org.opendaylight.netconf.mdsal.connector.CurrentSchemaContext;
validator = new FilterContentValidator(currentContext);
}
- @SuppressWarnings("checkstyle:IllegalCatch")
@Test
- public void testValidate() throws Exception {
- if (expected.startsWith("success")) {
- final String expId = expected.replace("success=", "");
- final YangInstanceIdentifier actual = validator.validate(filterContent);
- Assert.assertEquals(fromString(expId), actual);
- } else if (expected.startsWith("error")) {
- try {
- validator.validate(filterContent);
- Assert.fail(XmlUtil.toString(filterContent) + " is not valid and should throw exception.");
- } catch (final Exception e) {
- final String expectedExceptionClass = expected.replace("error=", "");
- Assert.assertEquals(expectedExceptionClass, e.getClass().getName());
- }
+ public void testValidateSuccess() throws DocumentedException {
+ assumeThat(expected, startsWith("success"));
+
+ final String expId = expected.replace("success=", "");
+ final YangInstanceIdentifier actual = validator.validate(filterContent);
+ assertEquals(fromString(expId), actual);
+ }
+
+ @Test
+ public void testValidateError() {
+ assumeThat(expected, startsWith("error"));
+
+ try {
+ validator.validate(filterContent);
+ fail(XmlUtil.toString(filterContent) + " is not valid and should throw exception.");
+ } catch (final DocumentedException e) {
+ final String expectedExceptionClass = expected.replace("error=", "");
+ assertEquals(expectedExceptionClass, e.getClass().getName());
}
}
super(manager, group);
}
- @SuppressWarnings("checkstyle:IllegalCatch")
@Override
protected void doCloseImmediately() {
try {
group().shutdownNow();
group().awaitTermination(5, TimeUnit.SECONDS);
- } catch (final Exception e) {
+ } catch (final IOException | InterruptedException e) {
log.debug("Exception caught while closing channel group", e);
} finally {
super.doCloseImmediately();
* terms of the Eclipse Public License v1.0 which accompanies this distribution,
* and is available at http://www.eclipse.org/legal/epl-v10.html
*/
-
package org.opendaylight.netconf.netty;
import io.netty.bootstrap.Bootstrap;
public class EchoClient extends Thread {
private static final Logger LOG = LoggerFactory.getLogger(EchoClient.class);
-
private final ChannelInitializer<LocalChannel> channelInitializer;
-
public EchoClient(final ChannelHandler clientHandler) {
- channelInitializer = new ChannelInitializer<LocalChannel>() {
+ channelInitializer = new ChannelInitializer<>() {
@Override
- public void initChannel(LocalChannel ch) throws Exception {
+ public void initChannel(final LocalChannel ch) throws Exception {
ch.pipeline().addLast(clientHandler);
}
};
}
- public EchoClient(ChannelInitializer<LocalChannel> channelInitializer) {
+ public EchoClient(final ChannelInitializer<LocalChannel> channelInitializer) {
this.channelInitializer = channelInitializer;
}
- @SuppressWarnings("checkstyle:IllegalCatch")
@Override
public void run() {
// Configure the client.
// Wait until the connection is closed.
future.channel().closeFuture().sync();
- } catch (Exception e) {
+ } catch (InterruptedException e) {
LOG.error("Error in client", e);
throw new RuntimeException("Error in client", e);
} finally {
* terms of the Eclipse Public License v1.0 which accompanies this distribution,
* and is available at http://www.eclipse.org/legal/epl-v10.html
*/
-
package org.opendaylight.netconf.netty;
import io.netty.bootstrap.ServerBootstrap;
import io.netty.handler.logging.LogLevel;
import io.netty.handler.logging.LoggingHandler;
import java.io.BufferedReader;
+import java.io.IOException;
import java.io.InputStreamReader;
import org.opendaylight.netconf.util.NetconfConfiguration;
import org.slf4j.Logger;
public class EchoServer implements Runnable {
private static final Logger LOG = LoggerFactory.getLogger(EchoServer.class);
- @SuppressWarnings("checkstyle:IllegalCatch")
+ @Override
public void run() {
// Configure the server.
EventLoopGroup bossGroup = new NioEventLoopGroup(1);
.handler(new LoggingHandler(LogLevel.INFO))
.childHandler(new ChannelInitializer<LocalChannel>() {
@Override
- public void initChannel(LocalChannel ch) throws Exception {
+ public void initChannel(final LocalChannel ch) throws Exception {
ch.pipeline().addLast(new EchoServerHandler());
}
});
// Wait until the server socket is closed.
future.channel().closeFuture().sync();
- } catch (Exception e) {
+ } catch (InterruptedException e) {
throw new RuntimeException(e);
} finally {
// Shut down all event loops to terminate all threads.
}
}
- public static void main(String[] args) throws Exception {
+ public static void main(final String[] args) throws InterruptedException, IOException {
new Thread(new EchoServer()).start();
Thread.sleep(1000);
EchoClientHandler clientHandler = new EchoClientHandler();
* terms of the Eclipse Public License v1.0 which accompanies this distribution,
* and is available at http://www.eclipse.org/legal/epl-v10.html
*/
-
package org.opendaylight.netconf.netty;
import io.netty.bootstrap.ServerBootstrap;
public class ProxyServer implements Runnable {
private final ProxyHandlerFactory proxyHandlerFactory;
- public ProxyServer(ProxyHandlerFactory proxyHandlerFactory) {
+ public ProxyServer(final ProxyHandlerFactory proxyHandlerFactory) {
this.proxyHandlerFactory = proxyHandlerFactory;
}
- @SuppressWarnings("checkstyle:IllegalCatch")
+ @Override
public void run() {
// Configure the server.
final EventLoopGroup bossGroup = new NioEventLoopGroup();
.handler(new LoggingHandler(LogLevel.INFO))
.childHandler(new ChannelInitializer<SocketChannel>() {
@Override
- public void initChannel(SocketChannel ch) throws Exception {
+ public void initChannel(final SocketChannel ch) throws Exception {
ch.pipeline().addLast(proxyHandlerFactory.create(bossGroup, localAddress));
}
});
// Wait until the server socket is closed.
future.channel().closeFuture().sync();
- } catch (Exception e) {
+ } catch (InterruptedException e) {
throw new RuntimeException(e);
} finally {
// Shut down all event loops to terminate all threads.
ChannelHandler create(EventLoopGroup bossGroup, LocalAddress localAddress);
}
- public static void main(String[] args) {
+ public static void main(final String[] args) {
ProxyHandlerFactory proxyHandlerFactory = ProxyServerHandler::new;
start(proxyHandlerFactory);
}
- public static void start(ProxyHandlerFactory proxyHandlerFactory) {
+ public static void start(final ProxyHandlerFactory proxyHandlerFactory) {
new Thread(new EchoServer()).start();
new Thread(new ProxyServer(proxyHandlerFactory)).start();
}
public EchoClientHandler connectClient(final InetSocketAddress address) {
final EchoClientHandler echoClientHandler = new EchoClientHandler();
- final ChannelInitializer<NioSocketChannel> channelInitializer = new ChannelInitializer<NioSocketChannel>() {
+ final ChannelInitializer<NioSocketChannel> channelInitializer = new ChannelInitializer<>() {
@Override
public void initChannel(final NioSocketChannel ch) throws Exception {
ch.pipeline().addFirst(AsyncSshHandler.createForNetconfSubsystem(new LoginPasswordHandler("a", "a")));