Search in sources :

Example 21 with IoBuffer

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);
}
Also used : IoBuffer(org.apache.mina.core.buffer.IoBuffer) Test(org.junit.Test)

Example 22 with IoBuffer

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);
}
Also used : IoBuffer(org.apache.mina.core.buffer.IoBuffer) Test(org.junit.Test)

Example 23 with IoBuffer

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);
}
Also used : IoBuffer(org.apache.mina.core.buffer.IoBuffer) Test(org.junit.Test)

Example 24 with IoBuffer

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);
}
Also used : IoBuffer(org.apache.mina.core.buffer.IoBuffer) Test(org.junit.Test)

Example 25 with IoBuffer

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();
        }
    }
}
Also used : UnauthorizedException(org.jivesoftware.openfire.auth.UnauthorizedException) IOException(java.io.IOException) UnknownHostException(java.net.UnknownHostException) IoBuffer(org.apache.mina.core.buffer.IoBuffer)

Aggregations

IoBuffer (org.apache.mina.core.buffer.IoBuffer)49 Test (org.junit.Test)8 VideoData (org.red5.server.net.rtmp.event.VideoData)4 UnknownHostException (java.net.UnknownHostException)3 HashMap (java.util.HashMap)3 UnauthorizedException (org.jivesoftware.openfire.auth.UnauthorizedException)3 AudioData (org.red5.server.net.rtmp.event.AudioData)3 Gson (com.google.gson.Gson)2 IOException (java.io.IOException)2 InputStream (java.io.InputStream)2 ByteBuffer (java.nio.ByteBuffer)2 CharacterCodingException (java.nio.charset.CharacterCodingException)2 Exchange (org.apache.camel.Exchange)2 DefaultCamelContext (org.apache.camel.impl.DefaultCamelContext)2 DefaultExchange (org.apache.camel.impl.DefaultExchange)2 Message (ca.uhn.hl7v2.model.Message)1 AddressedEnvelope (io.netty.channel.AddressedEnvelope)1 ChannelHandlerContext (io.netty.channel.ChannelHandlerContext)1 ChannelInboundHandlerAdapter (io.netty.channel.ChannelInboundHandlerAdapter)1 DatagramPacket (io.netty.channel.socket.DatagramPacket)1