public static void sendErrorMessage(final NetconfSession session, final DocumentedException sendErrorException, final NetconfMessage incommingMessage) { final Document errorDocument = createDocument(sendErrorException); 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)); }
public static void sendErrorMessage(final Channel channel, final DocumentedException 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 boolean isErrorMessage(NetconfMessage message) throws NetconfDocumentedException { return isErrorMessage(message.getDocument()); }
public static void sendErrorMessage(final NetconfSession session, final DocumentedException sendErrorException) { LOG.trace("Sending error {}", sendErrorException.getMessage(), sendErrorException); final Document errorDocument = createDocument(sendErrorException); ChannelFuture f = session.sendMessage(new NetconfMessage(errorDocument)); f.addListener(new SendErrorVerifyingListener(sendErrorException)); }
public static boolean isOKMessage(NetconfMessage message) throws NetconfDocumentedException { return isOKMessage(message.getDocument()); }
out.add(new NetconfMessage((Document) domResult.getNode()));
@Override @VisibleForTesting public void encode(final ChannelHandlerContext ctx, final NetconfMessage msg, final ByteBuf out) throws IOException, TransformerException { LOG.trace("Sent to encode : {}", msg); if (clientId.isPresent()) { Comment comment = msg.getDocument().createComment("clientId:" + clientId.get()); msg.getDocument().appendChild(comment); } try (OutputStream os = new ByteBufOutputStream(out)) { // Wrap OutputStreamWriter with BufferedWriter as suggested in javadoc for OutputStreamWriter // Using custom BufferedWriter that does not provide newLine method as performance improvement // see javadoc for BufferedWriter StreamResult result = new StreamResult(new BufferedWriter(new OutputStreamWriter(os))); DOMSource source = new DOMSource(msg.getDocument()); ThreadLocalTransformers.getPrettyTransformer().transform(source, result); } } }
out.add(new NetconfMessage(XmlUtil.readXmlToDocument(new ByteBufInputStream(in)))); } else { LOG.debug("No more content in incoming buffer.");
@Override protected void encode(final ChannelHandlerContext ctx, final NetconfMessage msg, final ByteBuf out) throws EXIOptionsException, IOException, TransformerException, TransmogrifierException { LOG.trace("Sent to encode : {}", msg); try (final OutputStream os = new ByteBufOutputStream(out)) { transmogrifier.setOutputStream(os); final ContentHandler handler = transmogrifier.getSAXTransmogrifier(); final Transformer transformer = ThreadLocalTransformers.getDefaultTransformer(); transformer.transform(new DOMSource(msg.getDocument()), new SAXResult(handler)); } finally { // Make sure we do not retain any reference to state by removing // the output stream reference and resetting internal state. transmogrifier.setOutputStream(null); transmogrifier.getSAXTransmogrifier(); } } }
private static NetconfMessage getNetconfMessage(final String additionalHeader, final Document doc) throws NetconfDocumentedException { NetconfMessage msg = new NetconfMessage(doc); if(NetconfHelloMessage.isHelloMessage(msg)) { if (additionalHeader != null) { return new NetconfHelloMessage(doc, NetconfHelloMessageAdditionalHeader.fromString(additionalHeader)); } else { return new NetconfHelloMessage(doc); } } return msg; }
@Override public final void startExiCommunication(final NetconfMessage startExiMessage) { final EXIParameters exiParams; try { exiParams = EXIParameters.fromXmlElement(XmlElement.fromDomDocument(startExiMessage.getDocument())); } catch (final EXIOptionsException e) { LOG.warn("Unable to parse EXI parameters from {} on session {}", startExiMessage, this, e); throw new IllegalArgumentException("Cannot parse options", e); } final NetconfEXICodec exiCodec = new NetconfEXICodec(exiParams.getOptions()); final NetconfMessageToEXIEncoder exiEncoder; try { exiEncoder = NetconfMessageToEXIEncoder.create(exiCodec); } catch (EXIOptionsException | TransmogrifierException e) { LOG.warn("Failed to instantiate EXI encoder for {} on session {}", exiCodec, this, e); throw new IllegalStateException("Cannot instantiate encoder for options", e); } final NetconfEXIToMessageDecoder exiDecoder; try { exiDecoder = NetconfEXIToMessageDecoder.create(exiCodec); } catch (EXIOptionsException e) { LOG.warn("Failed to instantiate EXI decodeer for {} on session {}", exiCodec, this, e); throw new IllegalStateException("Cannot instantiate encoder for options", e); } addExiHandlers(exiDecoder, exiEncoder); LOG.debug("Session {} EXI handlers added to pipeline", this); }