当前位置: 首页>>代码示例>>Java>>正文


Java StanzaListener.processPacket方法代码示例

本文整理汇总了Java中org.jivesoftware.smack.StanzaListener.processPacket方法的典型用法代码示例。如果您正苦于以下问题:Java StanzaListener.processPacket方法的具体用法?Java StanzaListener.processPacket怎么用?Java StanzaListener.processPacket使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在org.jivesoftware.smack.StanzaListener的用法示例。


在下文中一共展示了StanzaListener.processPacket方法的11个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: shouldConfirmReceivedDataPacket

import org.jivesoftware.smack.StanzaListener; //导入方法依赖的package包/类
/**
 * Valid data packets should be confirmed.
 * 
 * @throws Exception should not happen
 */
@Test
public void shouldConfirmReceivedDataPacket() throws Exception {
    // verify data packet confirmation is of type RESULT
    protocol.addResponse(null, Verification.requestTypeRESULT);

    InBandBytestreamSession session = new InBandBytestreamSession(connection, initBytestream,
                    initiatorJID);
    InputStream inputStream = session.getInputStream();
    StanzaListener listener = Whitebox.getInternalState(inputStream, StanzaListener.class);

    String base64Data = Base64.encode("Data");
    DataPacketExtension dpe = new DataPacketExtension(sessionID, 0, base64Data);
    Data data = new Data(dpe);

    listener.processPacket(data);

    protocol.verifyAll();

}
 
开发者ID:TTalkIM,项目名称:Smack,代码行数:25,代码来源:InBandBytestreamSessionTest.java

示例2: shouldSendCloseRequestIfInvalidSequenceReceived

import org.jivesoftware.smack.StanzaListener; //导入方法依赖的package包/类
/**
 * If a data stanza(/packet) is received out of order the session should be closed. See XEP-0047 Section
 * 2.2.
 * 
 * @throws Exception should not happen
 */
@Test
public void shouldSendCloseRequestIfInvalidSequenceReceived() throws Exception {
    // confirm close request
    IQ resultIQ = IBBPacketUtils.createResultIQ(initiatorJID, targetJID);
    protocol.addResponse(resultIQ, Verification.requestTypeSET,
                    Verification.correspondingSenderReceiver);

    // get IBB sessions data packet listener
    InBandBytestreamSession session = new InBandBytestreamSession(connection, initBytestream,
                    initiatorJID);
    InputStream inputStream = session.getInputStream();
    StanzaListener listener = Whitebox.getInternalState(inputStream, StanzaListener.class);

    // build invalid packet with out of order sequence
    String base64Data = Base64.encode("Data");
    DataPacketExtension dpe = new DataPacketExtension(sessionID, 123, base64Data);
    Message dataMessage = new Message();
    dataMessage.addExtension(dpe);

    // add data packets
    listener.processPacket(dataMessage);

    // read until exception is thrown
    try {
        inputStream.read();
        fail("exception should be thrown");
    }
    catch (IOException e) {
        assertTrue(e.getMessage().contains("Packets out of sequence"));
    }

    protocol.verifyAll();

}
 
开发者ID:TTalkIM,项目名称:Smack,代码行数:41,代码来源:InBandBytestreamSessionMessageTest.java

示例3: shouldReadAllReceivedData1

import org.jivesoftware.smack.StanzaListener; //导入方法依赖的package包/类
/**
 * Test the input stream read(byte[], int, int) method.
 * 
 * @throws Exception should not happen
 */
@Test
public void shouldReadAllReceivedData1() throws Exception {
    // create random data
    Random rand = new Random();
    byte[] controlData = new byte[3 * blockSize];
    rand.nextBytes(controlData);

    // get IBB sessions data packet listener
    InBandBytestreamSession session = new InBandBytestreamSession(connection, initBytestream,
                    initiatorJID);
    InputStream inputStream = session.getInputStream();
    StanzaListener listener = Whitebox.getInternalState(inputStream, StanzaListener.class);

    // verify data packet and notify listener
    for (int i = 0; i < controlData.length / blockSize; i++) {
        String base64Data = Base64.encodeToString(controlData, i * blockSize, blockSize);
        DataPacketExtension dpe = new DataPacketExtension(sessionID, i, base64Data);
        Message dataMessage = new Message();
        dataMessage.addExtension(dpe);
        listener.processPacket(dataMessage);
    }

    byte[] bytes = new byte[3 * blockSize];
    int read = 0;
    read = inputStream.read(bytes, 0, blockSize);
    assertEquals(blockSize, read);
    read = inputStream.read(bytes, 10, blockSize);
    assertEquals(blockSize, read);
    read = inputStream.read(bytes, 20, blockSize);
    assertEquals(blockSize, read);

    // verify data
    for (int i = 0; i < bytes.length; i++) {
        assertEquals(controlData[i], bytes[i]);
    }

    protocol.verifyAll();

}
 
开发者ID:TTalkIM,项目名称:Smack,代码行数:45,代码来源:InBandBytestreamSessionMessageTest.java

示例4: shouldReadAllReceivedData2

import org.jivesoftware.smack.StanzaListener; //导入方法依赖的package包/类
/**
 * Test the input stream read() method.
 * 
 * @throws Exception should not happen
 */
@Test
public void shouldReadAllReceivedData2() throws Exception {
    // create random data
    Random rand = new Random();
    byte[] controlData = new byte[3 * blockSize];
    rand.nextBytes(controlData);

    // get IBB sessions data packet listener
    InBandBytestreamSession session = new InBandBytestreamSession(connection, initBytestream,
                    initiatorJID);
    InputStream inputStream = session.getInputStream();
    StanzaListener listener = Whitebox.getInternalState(inputStream, StanzaListener.class);

    // verify data packet and notify listener
    for (int i = 0; i < controlData.length / blockSize; i++) {
        String base64Data = Base64.encodeToString(controlData, i * blockSize, blockSize);
        DataPacketExtension dpe = new DataPacketExtension(sessionID, i, base64Data);
        Message dataMessage = new Message();
        dataMessage.addExtension(dpe);
        listener.processPacket(dataMessage);
    }

    // read data
    byte[] bytes = new byte[3 * blockSize];
    for (int i = 0; i < bytes.length; i++) {
        bytes[i] = (byte) inputStream.read();
    }

    // verify data
    for (int i = 0; i < bytes.length; i++) {
        assertEquals(controlData[i], bytes[i]);
    }

    protocol.verifyAll();

}
 
开发者ID:TTalkIM,项目名称:Smack,代码行数:42,代码来源:InBandBytestreamSessionMessageTest.java

示例5: shouldNotCloseBothStreamsIfOutputStreamIsClosed

import org.jivesoftware.smack.StanzaListener; //导入方法依赖的package包/类
/**
 * If the input stream is closed the output stream should not be closed as well.
 * 
 * @throws Exception should not happen
 */
@Test
public void shouldNotCloseBothStreamsIfOutputStreamIsClosed() throws Exception {

    InBandBytestreamSession session = new InBandBytestreamSession(connection, initBytestream,
                    initiatorJID);
    OutputStream outputStream = session.getOutputStream();
    outputStream.close();

    // verify data packet confirmation is of type RESULT
    protocol.addResponse(null, Verification.requestTypeRESULT);

    // insert data to read
    InputStream inputStream = session.getInputStream();
    StanzaListener listener = Whitebox.getInternalState(inputStream, StanzaListener.class);
    String base64Data = Base64.encode("Data");
    DataPacketExtension dpe = new DataPacketExtension(sessionID, 0, base64Data);
    Data data = new Data(dpe);
    listener.processPacket(data);

    // verify no packet send
    protocol.verifyAll();

    try {
        outputStream.flush();
        fail("should throw an exception");
    }
    catch (IOException e) {
        assertTrue(e.getMessage().contains("closed"));
    }

    assertTrue(inputStream.read() != 0);

}
 
开发者ID:TTalkIM,项目名称:Smack,代码行数:39,代码来源:InBandBytestreamSessionTest.java

示例6: shouldReplyWithErrorIfAlreadyUsedSequenceIsReceived

import org.jivesoftware.smack.StanzaListener; //导入方法依赖的package包/类
/**
 * If the data stanza(/packet) has a sequence that is already used an 'unexpected-request' error should
 * be returned. See XEP-0047 Section 2.2.
 * 
 * @throws Exception should not happen
 */
@Test
public void shouldReplyWithErrorIfAlreadyUsedSequenceIsReceived() throws Exception {
    // verify reply to first valid data packet is of type RESULT
    protocol.addResponse(null, Verification.requestTypeRESULT);

    // verify reply to invalid data packet is an error
    protocol.addResponse(null, Verification.requestTypeERROR, new Verification<IQ, IQ>() {

        public void verify(IQ request, IQ response) {
            assertEquals(XMPPError.Condition.unexpected_request,
                            request.getError().getCondition());
        }

    });

    // get IBB sessions data packet listener
    InBandBytestreamSession session = new InBandBytestreamSession(connection, initBytestream,
                    initiatorJID);
    InputStream inputStream = session.getInputStream();
    StanzaListener listener = Whitebox.getInternalState(inputStream, StanzaListener.class);

    // build data packets
    String base64Data = Base64.encode("Data");
    DataPacketExtension dpe = new DataPacketExtension(sessionID, 0, base64Data);
    Data data1 = new Data(dpe);
    Data data2 = new Data(dpe);

    // notify listener
    listener.processPacket(data1);
    listener.processPacket(data2);

    protocol.verifyAll();

}
 
开发者ID:TTalkIM,项目名称:Smack,代码行数:41,代码来源:InBandBytestreamSessionTest.java

示例7: shouldReplyWithErrorIfDataIsInvalid

import org.jivesoftware.smack.StanzaListener; //导入方法依赖的package包/类
/**
 * If the data stanza(/packet) contains invalid Base64 encoding an 'bad-request' error should be
 * returned. See XEP-0047 Section 2.2.
 * 
 * @throws Exception should not happen
 */
@Test
public void shouldReplyWithErrorIfDataIsInvalid() throws Exception {
    // verify reply to invalid data packet is an error
    protocol.addResponse(null, Verification.requestTypeERROR, new Verification<IQ, IQ>() {

        public void verify(IQ request, IQ response) {
            assertEquals(XMPPError.Condition.bad_request,
                            request.getError().getCondition());
        }

    });

    // get IBB sessions data packet listener
    InBandBytestreamSession session = new InBandBytestreamSession(connection, initBytestream,
                    initiatorJID);
    InputStream inputStream = session.getInputStream();
    StanzaListener listener = Whitebox.getInternalState(inputStream, StanzaListener.class);

    // build data packets
    DataPacketExtension dpe = new DataPacketExtension(sessionID, 0, "AA=BB");
    Data data = new Data(dpe);

    // notify listener
    listener.processPacket(data);

    protocol.verifyAll();

}
 
开发者ID:TTalkIM,项目名称:Smack,代码行数:35,代码来源:InBandBytestreamSessionTest.java

示例8: shouldSendCloseRequestIfInvalidSequenceReceived

import org.jivesoftware.smack.StanzaListener; //导入方法依赖的package包/类
/**
 * If a data stanza(/packet) is received out of order the session should be closed. See XEP-0047 Section
 * 2.2.
 * 
 * @throws Exception should not happen
 */
@Test
public void shouldSendCloseRequestIfInvalidSequenceReceived() throws Exception {
    IQ resultIQ = IBBPacketUtils.createResultIQ(initiatorJID, targetJID);

    // confirm data packet with invalid sequence
    protocol.addResponse(resultIQ);

    // confirm close request
    protocol.addResponse(resultIQ, Verification.requestTypeSET,
                    Verification.correspondingSenderReceiver);

    // get IBB sessions data packet listener
    InBandBytestreamSession session = new InBandBytestreamSession(connection, initBytestream,
                    initiatorJID);
    InputStream inputStream = session.getInputStream();
    StanzaListener listener = Whitebox.getInternalState(inputStream, StanzaListener.class);

    // build invalid packet with out of order sequence
    String base64Data = Base64.encode("Data");
    DataPacketExtension dpe = new DataPacketExtension(sessionID, 123, base64Data);
    Data data = new Data(dpe);

    // add data packets
    listener.processPacket(data);

    // read until exception is thrown
    try {
        inputStream.read();
        fail("exception should be thrown");
    }
    catch (IOException e) {
        assertTrue(e.getMessage().contains("Packets out of sequence"));
    }

    protocol.verifyAll();

}
 
开发者ID:TTalkIM,项目名称:Smack,代码行数:44,代码来源:InBandBytestreamSessionTest.java

示例9: shouldReadAllReceivedData2

import org.jivesoftware.smack.StanzaListener; //导入方法依赖的package包/类
/**
 * Test the input stream read() method.
 * 
 * @throws Exception should not happen
 */
@Test
public void shouldReadAllReceivedData2() throws Exception {
    // create random data
    Random rand = new Random();
    byte[] controlData = new byte[3 * blockSize];
    rand.nextBytes(controlData);

    IQ resultIQ = IBBPacketUtils.createResultIQ(initiatorJID, targetJID);

    // get IBB sessions data packet listener
    InBandBytestreamSession session = new InBandBytestreamSession(connection, initBytestream,
                    initiatorJID);
    InputStream inputStream = session.getInputStream();
    StanzaListener listener = Whitebox.getInternalState(inputStream, StanzaListener.class);

    // set data packet acknowledgment and notify listener
    for (int i = 0; i < controlData.length / blockSize; i++) {
        protocol.addResponse(resultIQ);
        String base64Data = Base64.encodeToString(controlData, i * blockSize, blockSize);
        DataPacketExtension dpe = new DataPacketExtension(sessionID, i, base64Data);
        Data data = new Data(dpe);
        listener.processPacket(data);
    }

    // read data
    byte[] bytes = new byte[3 * blockSize];
    for (int i = 0; i < bytes.length; i++) {
        bytes[i] = (byte) inputStream.read();
    }

    // verify data
    for (int i = 0; i < bytes.length; i++) {
        assertEquals(controlData[i], bytes[i]);
    }

    protocol.verifyAll();

}
 
开发者ID:TTalkIM,项目名称:Smack,代码行数:44,代码来源:InBandBytestreamSessionTest.java

示例10: shouldNotCloseBothStreamsIfInputStreamIsClosed

import org.jivesoftware.smack.StanzaListener; //导入方法依赖的package包/类
/**
 * If the output stream is closed the input stream should not be closed as well.
 * 
 * @throws Exception should not happen
 */
@Test
public void shouldNotCloseBothStreamsIfInputStreamIsClosed() throws Exception {
    // acknowledgment for data packet
    IQ resultIQ = IBBPacketUtils.createResultIQ(initiatorJID, targetJID);
    protocol.addResponse(resultIQ);

    // get IBB sessions data packet listener
    InBandBytestreamSession session = new InBandBytestreamSession(connection, initBytestream,
                    initiatorJID);
    InputStream inputStream = session.getInputStream();
    StanzaListener listener = Whitebox.getInternalState(inputStream, StanzaListener.class);

    // build data packet
    String base64Data = Base64.encode("Data");
    DataPacketExtension dpe = new DataPacketExtension(sessionID, 0, base64Data);
    Data data = new Data(dpe);

    // add data packets
    listener.processPacket(data);

    inputStream.close();

    protocol.verifyAll();

    try {
        while (inputStream.read() != -1) {
        }
        inputStream.read();
        fail("should throw an exception");
    }
    catch (IOException e) {
        assertTrue(e.getMessage().contains("closed"));
    }

    session.getOutputStream().flush();

}
 
开发者ID:TTalkIM,项目名称:Smack,代码行数:43,代码来源:InBandBytestreamSessionTest.java

示例11: shouldReadAllReceivedData1

import org.jivesoftware.smack.StanzaListener; //导入方法依赖的package包/类
/**
 * Test the input stream read(byte[], int, int) method.
 * 
 * @throws Exception should not happen
 */
@Test
public void shouldReadAllReceivedData1() throws Exception {
    // create random data
    Random rand = new Random();
    byte[] controlData = new byte[3 * blockSize];
    rand.nextBytes(controlData);

    IQ resultIQ = IBBPacketUtils.createResultIQ(initiatorJID, targetJID);

    // get IBB sessions data packet listener
    InBandBytestreamSession session = new InBandBytestreamSession(connection, initBytestream,
                    initiatorJID);
    InputStream inputStream = session.getInputStream();
    StanzaListener listener = Whitebox.getInternalState(inputStream, StanzaListener.class);

    // set data packet acknowledgment and notify listener
    for (int i = 0; i < controlData.length / blockSize; i++) {
        protocol.addResponse(resultIQ);
        String base64Data = Base64.encodeToString(controlData, i * blockSize, blockSize);
        DataPacketExtension dpe = new DataPacketExtension(sessionID, i, base64Data);
        Data data = new Data(dpe);
        listener.processPacket(data);
    }

    byte[] bytes = new byte[3 * blockSize];
    int read = 0;
    read = inputStream.read(bytes, 0, blockSize);
    assertEquals(blockSize, read);
    read = inputStream.read(bytes, 10, blockSize);
    assertEquals(blockSize, read);
    read = inputStream.read(bytes, 20, blockSize);
    assertEquals(blockSize, read);

    // verify data
    for (int i = 0; i < bytes.length; i++) {
        assertEquals(controlData[i], bytes[i]);
    }

    protocol.verifyAll();

}
 
开发者ID:TTalkIM,项目名称:Smack,代码行数:47,代码来源:InBandBytestreamSessionTest.java


注:本文中的org.jivesoftware.smack.StanzaListener.processPacket方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。