List of usage examples for io.netty.buffer ByteBufUtil hexDump
public static String hexDump(byte[] array)
From source file:org.eclipse.neoscada.protocol.iec60870.asdu.MessageManager.java
License:Open Source License
public ByteBuf receiveMessage(final InformationTransfer informationTransfer, final List<Object> out) { if (logger.isDebugEnabled()) { logger.debug("Received message: {} -> {}", informationTransfer, informationTransfer.getData() != null ? ByteBufUtil.hexDump(informationTransfer.getData()) : null);//w w w .ja va 2 s .c o m } final ByteBuf data = informationTransfer.getData(); final byte typeId = data.readByte(); final byte subTypeId = data.readByte(); final InformationStructure informationStructure = (subTypeId & 0b10000000) > 0 ? InformationStructure.SEQUENCE : InformationStructure.SINGLE; final byte length = (byte) (~0b10000000 & subTypeId); final CauseOfTransmission causeOfTransmission = CauseOfTransmission.parse(this.options, data); final ASDUAddress asduAddress = ASDUAddress.parse(this.options, data); final ASDUHeader header = new ASDUHeader(causeOfTransmission, asduAddress); final MessageCodec codec = this.codecs.get(MessageTypeId.valueOf(typeId, informationStructure)); if (codec == null) { return mirrorUnknown(data, typeId, informationStructure, length, header, StandardCause.UNKNOWN_TYPE); } out.add(codec.parse(this.options, length, header, data)); return null; }
From source file:org.eclipse.neoscada.protocol.iec60870.asdu.MessageManager.java
License:Open Source License
protected void handleUnknownMessage(final byte typeId, final ASDUHeader header, final ByteBuf data) { // FIXME: do nothing at the moment logger.info("Received unknown message - typeId: {}, header: {}, data: {}", (int) typeId, header, ByteBufUtil.hexDump(data)); }
From source file:org.fengbaoxp.netty.inaction.ch2.EchoClientHandler.java
License:Apache License
@Override public void channelRead(ChannelHandlerContext ctx, Object msg) throws Exception { ByteBuf in = (ByteBuf) msg;//from w w w.j ava2s. co m System.out.println("Client received:" + ByteBufUtil.hexDump(in.readBytes(in.readableBytes()))); }
From source file:org.opendaylight.controller.netconf.nettyutil.handler.NetconfEXIToMessageDecoder.java
License:Open Source License
@Override protected void decode(final ChannelHandlerContext ctx, final ByteBuf in, final List<Object> out) throws EXIOptionsException, IOException, SAXException, TransformerConfigurationException { /*//www .j a va 2 s . c o m * Note that we could loop here and process all the messages, but we can't do that. * The reason is <stop-exi> operation, which has the contract of immediately stopping * the use of EXI, which means the next message needs to be decoded not by us, but rather * by the XML decoder. */ // If empty Byte buffer is passed to r.parse, EOFException is thrown if (!in.isReadable()) { LOG.debug("No more content in incoming buffer."); return; } if (LOG.isTraceEnabled()) { LOG.trace("Received to decode: {}", ByteBufUtil.hexDump(in)); } final TransformerHandler handler = FACTORY.newTransformerHandler(); reader.setContentHandler(handler); final DOMResult domResult = new DOMResult(); handler.setResult(domResult); try (final InputStream is = new ByteBufInputStream(in)) { // Performs internal reset before doing anything reader.parse(new InputSource(is)); } out.add(new NetconfMessage((Document) domResult.getNode())); }
From source file:org.opendaylight.controller.netconf.nettyutil.handler.NetconfXMLToHelloMessageDecoder.java
License:Open Source License
@Override @VisibleForTesting/*from w w w . ja v a 2 s. co m*/ public void decode(final ChannelHandlerContext ctx, final ByteBuf in, final List<Object> out) throws IOException, SAXException, NetconfDocumentedException { if (in.readableBytes() == 0) { LOG.debug("No more content in incoming buffer."); return; } in.markReaderIndex(); try { if (LOG.isTraceEnabled()) { LOG.trace("Received to decode: {}", ByteBufUtil.hexDump(in)); } byte[] bytes = new byte[in.readableBytes()]; in.readBytes(bytes); logMessage(bytes); // Extract bytes containing header with additional metadata String additionalHeader = null; if (startsWithAdditionalHeader(bytes)) { // Auth information containing username, ip address... extracted for monitoring int endOfAuthHeader = getAdditionalHeaderEndIndex(bytes); if (endOfAuthHeader > -1) { byte[] additionalHeaderBytes = Arrays.copyOfRange(bytes, 0, endOfAuthHeader + 2); additionalHeader = additionalHeaderToString(additionalHeaderBytes); bytes = Arrays.copyOfRange(bytes, endOfAuthHeader + 2, bytes.length); } } Document doc = XmlUtil.readXmlToDocument(new ByteArrayInputStream(bytes)); final NetconfMessage message = getNetconfMessage(additionalHeader, doc); if (message instanceof NetconfHelloMessage) { Preconditions.checkState(helloReceived == false, "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", message); LOG.debug("Netconf message received during negotiation, caching {}", message); nonHelloMessages.add(message); } } finally { in.discardReadBytes(); } }
From source file:org.opendaylight.controller.netconf.nettyutil.handler.NetconfXMLToMessageDecoder.java
License:Open Source License
@Override public void decode(final ChannelHandlerContext ctx, final ByteBuf in, final List<Object> out) throws IOException, SAXException { if (in.isReadable()) { if (LOG.isTraceEnabled()) { LOG.trace("Received to decode: {}", ByteBufUtil.hexDump(in)); }/* w w w . ja va 2 s . c o m*/ out.add(new NetconfMessage(XmlUtil.readXmlToDocument(new ByteBufInputStream(in)))); } else { LOG.debug("No more content in incoming buffer."); } }
From source file:org.opendaylight.controller.netconf.util.handler.NetconfEXIToMessageDecoder.java
License:Open Source License
@Override protected void decode(final ChannelHandlerContext ctx, final ByteBuf in, final List<Object> out) throws Exception { /*/* ww w . ja v a 2s . co m*/ * Note that we could loop here and process all the messages, but we can't do that. * The reason is <stop-exi> operation, which has the contract of immediately stopping * the use of EXI, which means the next message needs to be decoded not by us, but rather * by the XML decoder. */ // If empty Byte buffer is passed to r.parse, EOFException is thrown if (in.readableBytes() == 0) { LOG.debug("No more content in incoming buffer."); return; } LOG.trace("Received to decode: {}", ByteBufUtil.hexDump(in)); final EXIReader r = codec.getReader(); final SAXTransformerFactory transformerFactory = (SAXTransformerFactory) TransformerFactory.newInstance(); final TransformerHandler handler = transformerFactory.newTransformerHandler(); r.setContentHandler(handler); final DOMResult domResult = new DOMResult(); handler.setResult(domResult); try (final InputStream is = new ByteBufInputStream(in)) { r.parse(new InputSource(is)); } out.add(new NetconfMessage((Document) domResult.getNode())); }
From source file:org.opendaylight.controller.netconf.util.handler.NetconfXMLToHelloMessageDecoder.java
License:Open Source License
@Override @VisibleForTesting/*from w w w . ja v a 2s. co m*/ public void decode(ChannelHandlerContext ctx, ByteBuf in, List<Object> out) throws Exception { if (in.readableBytes() == 0) { LOG.debug("No more content in incoming buffer."); return; } in.markReaderIndex(); try { LOG.trace("Received to decode: {}", ByteBufUtil.hexDump(in)); byte[] bytes = new byte[in.readableBytes()]; in.readBytes(bytes); logMessage(bytes); // Extract bytes containing header with additional metadata String additionalHeader = null; if (startsWithAdditionalHeader(bytes)) { // Auth information containing username, ip address... extracted for monitoring int endOfAuthHeader = getAdditionalHeaderEndIndex(bytes); if (endOfAuthHeader > -1) { byte[] additionalHeaderBytes = Arrays.copyOfRange(bytes, 0, endOfAuthHeader + 2); additionalHeader = additionalHeaderToString(additionalHeaderBytes); bytes = Arrays.copyOfRange(bytes, endOfAuthHeader + 2, bytes.length); } } Document doc = XmlUtil.readXmlToDocument(new ByteArrayInputStream(bytes)); final NetconfMessage message; if (additionalHeader != null) { message = new NetconfHelloMessage(doc, NetconfHelloMessageAdditionalHeader.fromString(additionalHeader)); } else { message = new NetconfHelloMessage(doc); } out.add(message); } finally { in.discardReadBytes(); } }
From source file:org.opendaylight.controller.netconf.util.handler.NetconfXMLToMessageDecoder.java
License:Open Source License
@Override @VisibleForTesting//from w w w . ja v a 2 s .co m public void decode(ChannelHandlerContext ctx, ByteBuf in, List<Object> out) throws Exception { 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."); } }
From source file:org.opendaylight.netconf.nettyutil.handler.NetconfXMLToHelloMessageDecoder.java
License:Open Source License
@Override @VisibleForTesting//from w w w. j a v a 2 s .co m public void decode(final ChannelHandlerContext ctx, final ByteBuf in, final List<Object> out) throws IOException, SAXException, NetconfDocumentedException { if (in.readableBytes() == 0) { LOG.debug("No more content in incoming buffer."); return; } in.markReaderIndex(); try { if (LOG.isTraceEnabled()) { LOG.trace("Received to decode: {}", ByteBufUtil.hexDump(in)); } byte[] bytes = new byte[in.readableBytes()]; in.readBytes(bytes); logMessage(bytes); // Extract bytes containing header with additional metadata String additionalHeader = null; if (startsWithAdditionalHeader(bytes)) { // Auth information containing username, ip address... extracted for monitoring int endOfAuthHeader = getAdditionalHeaderEndIndex(bytes); if (endOfAuthHeader > -1) { byte[] additionalHeaderBytes = Arrays.copyOfRange(bytes, 0, endOfAuthHeader); additionalHeader = additionalHeaderToString(additionalHeaderBytes); bytes = Arrays.copyOfRange(bytes, endOfAuthHeader, bytes.length); } } Document doc = XmlUtil.readXmlToDocument(new ByteArrayInputStream(bytes)); final NetconfMessage message = getNetconfMessage(additionalHeader, doc); if (message instanceof NetconfHelloMessage) { Preconditions.checkState(helloReceived == false, "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", message); LOG.debug("Netconf message received during negotiation, caching {}", message); nonHelloMessages.add(message); } } finally { in.discardReadBytes(); } }