use of org.apache.mina.core.buffer.IoBuffer in project Openfire by igniterealtime.
the class XMLLightweightParserTest method testOF2329SelfTerminatingWithNewline.
/**
* Asserts that a self-terminating start-tag name can be parsed when it is followed by a newline character.
*
* This test checks for a variation of the issue described in OF-2329.
*
* @see <a href="https://igniterealtime.atlassian.net/browse/OF-2329">OF-2329: XML parsing bug when tag-name is not followed by space or '>'</a>
*/
@Test
public void testOF2329SelfTerminatingWithNewline() throws Exception {
// Setup test fixture.
final String input = "<presence \n to='foo@example.org'/>";
final IoBuffer buffer = IoBuffer.allocate(input.length(), false);
buffer.putString(input, StandardCharsets.UTF_8.newEncoder());
buffer.flip();
final XMLLightweightParser parser = new XMLLightweightParser(StandardCharsets.UTF_8);
// Execute system under test.
parser.read(buffer);
final String[] result = parser.getMsgs();
// Verify results.
assertNotNull(result);
assertEquals(1, result.length);
}
use of org.apache.mina.core.buffer.IoBuffer in project Openfire by igniterealtime.
the class XMLLightweightParserTest method testOF2329SelfTerminatingWithSpaceAndNewline.
/**
* Asserts that a self-terminating start-tag name can be parsed when it is followed by a space and a newline character.
*
* This test checks for a variation of the issue described in OF-2329.
*
* @see <a href="https://igniterealtime.atlassian.net/browse/OF-2329">OF-2329: XML parsing bug when tag-name is not followed by space or '>'</a>
*/
@Test
public void testOF2329SelfTerminatingWithSpaceAndNewline() throws Exception {
// Setup test fixture.
final String input = "<presence\n to='foo@example.org'/>";
final IoBuffer buffer = IoBuffer.allocate(input.length(), false);
buffer.putString(input, StandardCharsets.UTF_8.newEncoder());
buffer.flip();
final XMLLightweightParser parser = new XMLLightweightParser(StandardCharsets.UTF_8);
// Execute system under test.
parser.read(buffer);
final String[] result = parser.getMsgs();
// Verify results.
assertNotNull(result);
assertEquals(1, result.length);
}
use of org.apache.mina.core.buffer.IoBuffer in project Openfire by igniterealtime.
the class XMLLightweightParserTest method testOF2329OpenAndCloseWithSpace.
/**
* Asserts that a start-tag name can be parsed when it is followed by a space character.
*
* This test checks for a variation of the issue described in OF-2329.
*
* @see <a href="https://igniterealtime.atlassian.net/browse/OF-2329">OF-2329: XML parsing bug when tag-name is not followed by space or '>'</a>
*/
@Test
public void testOF2329OpenAndCloseWithSpace() throws Exception {
// Setup test fixture.
final String input = "<presence to='foo@example.org'></presence>";
final IoBuffer buffer = IoBuffer.allocate(input.length(), false);
buffer.putString(input, StandardCharsets.UTF_8.newEncoder());
buffer.flip();
final XMLLightweightParser parser = new XMLLightweightParser(StandardCharsets.UTF_8);
// Execute system under test.
parser.read(buffer);
final String[] result = parser.getMsgs();
// Verify results.
assertNotNull(result);
assertEquals(1, result.length);
}
use of org.apache.mina.core.buffer.IoBuffer in project Openfire by igniterealtime.
the class XMLLightweightParserTest method testOF2329OpenAndCloseWithSpaceAndNewline.
/**
* Asserts that a start-tag name can be parsed when it is followed by a space and a newline character.
*
* This test checks for a variation of the issue described in OF-2329.
*
* @see <a href="https://igniterealtime.atlassian.net/browse/OF-2329">OF-2329: XML parsing bug when tag-name is not followed by space or '>'</a>
*/
@Test
public void testOF2329OpenAndCloseWithSpaceAndNewline() throws Exception {
// Setup test fixture.
final String input = "<presence \n to='foo@example.org'></presence>";
final IoBuffer buffer = IoBuffer.allocate(input.length(), false);
buffer.putString(input, StandardCharsets.UTF_8.newEncoder());
buffer.flip();
final XMLLightweightParser parser = new XMLLightweightParser(StandardCharsets.UTF_8);
// Execute system under test.
parser.read(buffer);
final String[] result = parser.getMsgs();
// Verify results.
assertNotNull(result);
assertEquals(1, result.length);
}
use of org.apache.mina.core.buffer.IoBuffer in project Openfire by igniterealtime.
the class NIOConnection method deliverRawText.
@Override
public void deliverRawText(String text) {
if (!isClosed()) {
boolean errorDelivering = false;
IoBuffer buffer = IoBuffer.allocate(text.length());
buffer.setAutoExpand(true);
try {
//Charset charset = Charset.forName(CHARSET);
//buffer.putString(text, charset.newEncoder());
buffer.put(text.getBytes(StandardCharsets.UTF_8));
if (flashClient) {
buffer.put((byte) '\0');
}
buffer.flip();
ioSessionLock.lock();
try {
ioSession.write(buffer);
} finally {
ioSessionLock.unlock();
}
} catch (Exception e) {
Log.debug("Error delivering raw text:\n" + text, e);
errorDelivering = true;
}
// Attempt to close the connection if delivering text fails.
if (errorDelivering) {
close();
}
}
}
Aggregations