public class XmlMessageProtocol extends AbstractByteProtocol
The XmlMessageProtocol is an application level tcp protocol that can be used to read streaming xml documents. The only requirement is that each document include an xml declaration at the beginning of the document of the form "SHOULD begin with an XML declaration which specifies the version of XML being used" while the xml 1.1 standard contains "Definition: XML 1.1 documents MUST begin with an XML declaration which specifies the version of XML being used". The SHOULD indicates a recommendation that, if not followed, needs to be carefully checked for unintended consequences. MUST indicates a mandatory requirement for a well-formed document. Please make sure that the xml documents being streamed begin with an xml declaration when using this class.
Data are read until a new document is found or there are no more data
(momentarily). For slower networks,
XmlMessageEOFProtocol
may be more reliable.
Also, the default character encoding for the platform is used to decode the message bytes when looking for the XML declaration. Some caution with message character encodings is warranted.
Finally, this class uses a PushbackInputStream to enable parsing of individual messages. The stream stores any pushed-back bytes into it's own internal buffer and not the original stream. Therefore, the read buffer size is intentionally limited to insure that unread characters remain on the stream so that all data may be read later.
EOF, NO_STREAM, STREAM_OK
Constructor and Description |
---|
XmlMessageProtocol() |
Modifier and Type | Method and Description |
---|---|
protected boolean |
isRepeat(int patternIndex,
int len,
int available)
Show we continue reading? This class, following previous implementations, only
reads while input is saturated.
|
Object |
read(InputStream is)
Reads the input stream and returns a whole message.
|
copy, copy, createResponse, isRethrowExceptionOnRead, nullEmptyArray, safeRead, safeRead, setObjectSerializer, setRethrowExceptionOnRead, write, writeByteArray
public Object read(InputStream is) throws IOException
TcpProtocol
is
- the input streamIOException
- if an exception occursprotected boolean isRepeat(int patternIndex, int len, int available)
patternIndex
- The index of the xml tag (or -1 if the next message not found)len
- The amount of data read this loop (or -1 if EOF)available
- The amount of data available to readXmlMessageEOFProtocol
Copyright © 2003–2016 MuleSoft, Inc.. All rights reserved.