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


Java PacketParserUtils类代码示例

本文整理汇总了Java中org.jivesoftware.smack.util.PacketParserUtils的典型用法代码示例。如果您正苦于以下问题:Java PacketParserUtils类的具体用法?Java PacketParserUtils怎么用?Java PacketParserUtils使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。


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

示例1: checkProvider

import org.jivesoftware.smack.util.PacketParserUtils; //导入依赖的package包/类
@Test
public void checkProvider() throws Exception {
    // @formatter:off
    String control = "<iq from='capulet.lit' to='[email protected]/balcony' id='s2c1' type='get'>"
            + "<ping xmlns='urn:xmpp:ping'/>" 
            + "</iq>";
    // @formatter:on
    DummyConnection con = new DummyConnection();
    con.connect();
    // Enable ping for this connection
    PingManager.getInstanceFor(con);
    IQ pingRequest = (IQ) PacketParserUtils.parseStanza(control);

    assertTrue(pingRequest instanceof Ping);

    con.processPacket(pingRequest);

    Stanza pongPacket = con.getSentPacket();
    assertTrue(pongPacket instanceof IQ);

    IQ pong = (IQ) pongPacket;
    assertEquals("capulet.lit", pong.getTo());
    assertEquals("s2c1", pong.getStanzaId());
    assertEquals(IQ.Type.result, pong.getType());
}
 
开发者ID:TTalkIM,项目名称:Smack,代码行数:26,代码来源:PingTest.java

示例2: openStream

import org.jivesoftware.smack.util.PacketParserUtils; //导入依赖的package包/类
/**
 * Resets the parser using the latest connection's reader. Reseting the parser is necessary
 * when the plain connection has been secured or when a new opening stream element is going
 * to be sent by the server.
 *
 * @throws SmackException if the parser could not be reset.
 */
void openStream() throws SmackException {
    // If possible, provide the receiving entity of the stream open tag, i.e. the server, as much information as
    // possible. The 'to' attribute is *always* available. The 'from' attribute if set by the user and no external
    // mechanism is used to determine the local entity (user). And the 'id' attribute is available after the first
    // response from the server (see e.g. RFC 6120 § 9.1.1 Step 2.)
    CharSequence to = getServiceName();
    CharSequence from = null;
    CharSequence localpart = config.getUsername();
    if (localpart != null) {
        from = XmppStringUtils.completeJidFrom(localpart, to);
    }
    String id = getStreamId();
    // 发送一个SteamOpen
    send(new StreamOpen(to, from, id));
    try {
        packetReader.parser = PacketParserUtils.newXmppParser(reader);
    }
    catch (XmlPullParserException e) {
        throw new SmackException(e);
    }
}
 
开发者ID:TTalkIM,项目名称:Smack,代码行数:29,代码来源:XMPPTCPConnection.java

示例3: testParseEnabled

import org.jivesoftware.smack.util.PacketParserUtils; //导入依赖的package包/类
@Test
public void testParseEnabled() throws Exception {
    String stanzaID = "zid615d9";
    boolean resume = true;
    String location = "test";
    int max = 42;

    String enabledStanza = XMLBuilder.create("enabled")
            .a("xmlns", "urn:xmpp:sm:3")
            .a("id", "zid615d9")
            .a("resume", String.valueOf(resume))
            .a("location", location)
            .a("max", String.valueOf(max))
            .asString(outputProperties);

    StreamManagement.Enabled enabledPacket = ParseStreamManagement.enabled(
            PacketParserUtils.getParserFor(enabledStanza));

    assertThat(enabledPacket, is(notNullValue()));
    assertThat(enabledPacket.getId(), equalTo(stanzaID));
    assertThat(enabledPacket.getLocation(), equalTo(location));
    assertThat(enabledPacket.isResumeSet(), equalTo(resume));
    assertThat(enabledPacket.getMaxResumptionTime(), equalTo(max));
}
 
开发者ID:TTalkIM,项目名称:Smack,代码行数:25,代码来源:ParseStreamManagementTest.java

示例4: testParseFailedError

import org.jivesoftware.smack.util.PacketParserUtils; //导入依赖的package包/类
@Test
public void testParseFailedError() throws Exception {
    XMPPError.Condition errorCondition = XMPPError.Condition.unexpected_request;

    String failedStanza = XMLBuilder.create("failed")
            .a("xmlns", "urn:xmpp:sm:3")
            .element(errorCondition.toString(), XMPPError.NAMESPACE)
            .asString(outputProperties);

    System.err.println(failedStanza);

    StreamManagement.Failed failedPacket = ParseStreamManagement.failed(
            PacketParserUtils.getParserFor(failedStanza));

    assertThat(failedPacket, is(notNullValue()));
    assertTrue(failedPacket.getXMPPErrorCondition() == errorCondition);
}
 
开发者ID:TTalkIM,项目名称:Smack,代码行数:18,代码来源:ParseStreamManagementTest.java

示例5: testParseResumed

import org.jivesoftware.smack.util.PacketParserUtils; //导入依赖的package包/类
@Test
public void testParseResumed() throws Exception {
    long handledPackets = 42;
    String previousID = "zid615d9";

    String resumedStanza = XMLBuilder.create("resumed")
            .a("xmlns", "urn:xmpp:sm:3")
            .a("h", String.valueOf(handledPackets))
            .a("previd", previousID)
            .asString(outputProperties);

    StreamManagement.Resumed resumedPacket = ParseStreamManagement.resumed(
            PacketParserUtils.getParserFor(resumedStanza));

    assertThat(resumedPacket, is(notNullValue()));
    assertThat(resumedPacket.getHandledCount(), equalTo(handledPackets));
    assertThat(resumedPacket.getPrevId(), equalTo(previousID));
}
 
开发者ID:TTalkIM,项目名称:Smack,代码行数:19,代码来源:ParseStreamManagementTest.java

示例6: isNonLatsChunkParsedCorrectly

import org.jivesoftware.smack.util.PacketParserUtils; //导入依赖的package包/类
@Test
public void isNonLatsChunkParsedCorrectly() throws Exception {
    String base64Text = "iVBORw0KGgoAAAANSUhEUgAAASwAAAGQCAYAA";
    String string = "<chunk xmlns='urn:xmpp:http' streamId='Stream0001' nr='0'>" + base64Text + "</chunk>";

    Base64BinaryChunkProvider provider = new Base64BinaryChunkProvider();
    XmlPullParser parser = PacketParserUtils.getParserFor(string);

    ExtensionElement extension = provider.parse(parser);
    assertTrue(extension instanceof Base64BinaryChunk);

    Base64BinaryChunk chunk = (Base64BinaryChunk) extension;
    assertEquals("Stream0001", chunk.getStreamId());
    assertFalse(chunk.isLast());
    assertEquals(base64Text, chunk.getText());
    assertEquals(0, chunk.getNr());
}
 
开发者ID:TTalkIM,项目名称:Smack,代码行数:18,代码来源:Base64BinaryChunkProviderTest.java

示例7: isLatsChunkParsedCorrectly

import org.jivesoftware.smack.util.PacketParserUtils; //导入依赖的package包/类
@Test
public void isLatsChunkParsedCorrectly() throws Exception {
    String base64Text = "2uPzi9u+tVWJd+e+y1AAAAABJRU5ErkJggg==";
    String string = "<chunk xmlns='urn:xmpp:http' streamId='Stream0001' nr='1' last='true'>" + base64Text + "</chunk>";

    Base64BinaryChunkProvider provider = new Base64BinaryChunkProvider();
    XmlPullParser parser = PacketParserUtils.getParserFor(string);

    ExtensionElement extension = provider.parse(parser);
    assertTrue(extension instanceof Base64BinaryChunk);

    Base64BinaryChunk chunk = (Base64BinaryChunk) extension;
    assertEquals("Stream0001", chunk.getStreamId());
    assertTrue(chunk.isLast());
    assertEquals(base64Text, chunk.getText());
    assertEquals(1, chunk.getNr());
}
 
开发者ID:TTalkIM,项目名称:Smack,代码行数:18,代码来源:Base64BinaryChunkProviderTest.java

示例8: areRespHeadersParsedCorrectly

import org.jivesoftware.smack.util.PacketParserUtils; //导入依赖的package包/类
@Test
public void areRespHeadersParsedCorrectly() throws Exception {
    String string = "<resp xmlns='urn:xmpp:http' version='1.1' statusCode='200' statusMessage='OK'>"
            + "<headers xmlns='http://jabber.org/protocol/shim'>"
            + "<header name='Date'>Fri, 03 May 2013 13:52:10 GMT-4</header>"
            + "<header name='Allow'>OPTIONS, GET, HEAD, POST, PUT, DELETE, TRACE</header>"
            + "<header name='Content-Length'>0</header>"
            + "</headers>"
            + "</resp>";
    Map<String, String> expectedHeaders = new HashMap<String, String>();
    expectedHeaders.put("Date", "Fri, 03 May 2013 13:52:10 GMT-4");
    expectedHeaders.put("Allow", "OPTIONS, GET, HEAD, POST, PUT, DELETE, TRACE");
    expectedHeaders.put("Content-Length", "0");

    HttpOverXmppRespProvider provider = new HttpOverXmppRespProvider();
    XmlPullParser parser = PacketParserUtils.getParserFor(string);

    IQ iq = provider.parse(parser);
    assertTrue(iq instanceof HttpOverXmppResp);
    HttpOverXmppResp body = ((HttpOverXmppResp) iq);

    checkHeaders(body.getHeaders(), expectedHeaders);
}
 
开发者ID:TTalkIM,项目名称:Smack,代码行数:24,代码来源:AbstractHttpOverXmppProviderTest.java

示例9: areReqHeadersParsedCorrectly

import org.jivesoftware.smack.util.PacketParserUtils; //导入依赖的package包/类
@Test
public void areReqHeadersParsedCorrectly() throws Exception {
    String string = "<req xmlns='urn:xmpp:http' method='GET' resource='/rdf/xep' version='1.1'>"
            + "<headers xmlns='http://jabber.org/protocol/shim'>"
            + "<header name='Host'>clayster.com</header>"
            + "</headers>"
            + "</req>";
    Map<String, String> expectedHeaders = new HashMap<String, String>();
    expectedHeaders.put("Host", "clayster.com");

    HttpOverXmppReqProvider provider = new HttpOverXmppReqProvider();
    XmlPullParser parser = PacketParserUtils.getParserFor(string);

    IQ iq = provider.parse(parser);
    assertTrue(iq instanceof HttpOverXmppReq);
    HttpOverXmppReq body = ((HttpOverXmppReq) iq);

    checkHeaders(body.getHeaders(), expectedHeaders);
}
 
开发者ID:TTalkIM,项目名称:Smack,代码行数:20,代码来源:AbstractHttpOverXmppProviderTest.java

示例10: parseAndProcessStanza

import org.jivesoftware.smack.util.PacketParserUtils; //导入依赖的package包/类
protected void parseAndProcessStanza(XmlPullParser parser) throws Exception {
    ParserUtils.assertAtStartTag(parser);
    int parserDepth = parser.getDepth();
    Stanza stanza = null;
    try {
        stanza = PacketParserUtils.parseStanza(parser);
    }
    catch (Exception e) {
        CharSequence content = PacketParserUtils.parseContentDepth(parser,
                        parserDepth);
        UnparsablePacket message = new UnparsablePacket(content, e);
        ParsingExceptionCallback callback = getParsingExceptionCallback();
        if (callback != null) {
            callback.handleUnparsablePacket(message);
        }
    }
    ParserUtils.assertAtEndTag(parser);
    if (stanza != null) {
        processPacket(stanza);
    }
}
 
开发者ID:TTalkIM,项目名称:Smack,代码行数:22,代码来源:AbstractXMPPConnection.java

示例11: parse

import org.jivesoftware.smack.util.PacketParserUtils; //导入依赖的package包/类
@Override
public final PE parse(XmlPullParser parser, int initialDepth) throws XmlPullParserException, IOException,
                SmackException {
    final String namespace = parser.getNamespace();
    final String name = parser.getName();
    final int attributeCount = parser.getAttributeCount();
    Map<String, String> attMap = new HashMap<>(attributeCount);

    for (int i = 0; i < attributeCount; i++) {
        attMap.put(parser.getAttributeName(i), parser.getAttributeValue(i));
    }

    List<ExtensionElement> extensions = new ArrayList<>();
    int event;
    do {
        event = parser.next();

        if (event == XmlPullParser.START_TAG)
            PacketParserUtils.addExtensionElement(extensions, parser);
    }
    while (!(event == XmlPullParser.END_TAG && parser.getDepth() == initialDepth));

    return createReturnExtension(name, namespace, attMap, extensions);
}
 
开发者ID:TTalkIM,项目名称:Smack,代码行数:25,代码来源:EmbeddedExtensionProvider.java

示例12: consumeUnparsedInput

import org.jivesoftware.smack.util.PacketParserUtils; //导入依赖的package包/类
@Test
public void consumeUnparsedInput() throws Exception {
    final String MESSAGE_EXCEPTION_ELEMENT = 
                    "<" + ThrowException.ELEMENT + " xmlns='" + ThrowException.NAMESPACE + "'>" +
                        "<nothingInHere>" +
                        "</nothingInHere>" +
                    "</" + ThrowException.ELEMENT + ">";
    XmlPullParser parser = TestUtils.getMessageParser(
            "<message from='[email protected]' to='[email protected]' id='foo'>" +
                MESSAGE_EXCEPTION_ELEMENT +
                EXTENSION2 +
            "</message>");
    int parserDepth = parser.getDepth();
    CharSequence content = null;
    try {
        PacketParserUtils.parseMessage(parser);
    } catch (Exception e) {
        content = PacketParserUtils.parseContentDepth(parser, parserDepth, false);
    }
    assertThat(MESSAGE_EXCEPTION_ELEMENT + EXTENSION2 + "</message>", equalsCharSequence(content));
}
 
开发者ID:TTalkIM,项目名称:Smack,代码行数:22,代码来源:ParsingExceptionTest.java

示例13: testParsingOfSimpleStreamError

import org.jivesoftware.smack.util.PacketParserUtils; //导入依赖的package包/类
@Test
public void testParsingOfSimpleStreamError() {
    StreamError error = null;
    final String xml =
            // Usually the stream:stream element has more attributes (to, version, ...)
            // We omit those, since they are not relevant for testing
            "<stream:stream from='im.example.com' id='++TR84Sm6A3hnt3Q065SnAbbk3Y=' xmlns:stream='http://etherx.jabber.org/streams'>" +
            "<stream:error>" +
            "<conflict xmlns='urn:ietf:params:xml:ns:xmpp-streams' /> +" +
            "</stream:error>" +
            "</stream:stream>";
    try {
        XmlPullParser parser = PacketParserUtils.getParserFor(xml, "error");
        error = PacketParserUtils.parseStreamError(parser);
    } catch (Exception e) {
        fail(e.getMessage());
    }
    assertNotNull(error);
    assertEquals(Condition.conflict, error.getCondition());
}
 
开发者ID:TTalkIM,项目名称:Smack,代码行数:21,代码来源:StreamErrorTest.java

示例14: testParsingOfStreamErrorWithText

import org.jivesoftware.smack.util.PacketParserUtils; //导入依赖的package包/类
@Test
public void testParsingOfStreamErrorWithText() {
    StreamError error = null;
    final String xml =
            // Usually the stream:stream element has more attributes (to, version, ...)
            // We omit those, since they are not relevant for testing
            "<stream:stream from='im.example.com' id='++TR84Sm6A3hnt3Q065SnAbbk3Y=' xmlns:stream='http://etherx.jabber.org/streams'>" +
            "<stream:error>" +
            "<conflict xmlns='urn:ietf:params:xml:ns:xmpp-streams' />" +
            "<text xml:lang='' xmlns='urn:ietf:params:xml:ns:xmpp-streams'>" +
                "Replaced by new connection" +
            "</text>" +
            "</stream:error>" +
            "</stream:stream>";
    try {
        XmlPullParser parser = PacketParserUtils.getParserFor(xml, "error");
        error = PacketParserUtils.parseStreamError(parser);
    } catch (Exception e) {
        fail(e.getMessage());
    }
    assertNotNull(error);
    assertEquals(Condition.conflict, error.getCondition());
    assertEquals("Replaced by new connection", error.getDescriptiveText());
}
 
开发者ID:TTalkIM,项目名称:Smack,代码行数:25,代码来源:StreamErrorTest.java

示例15: parse

import org.jivesoftware.smack.util.PacketParserUtils; //导入依赖的package包/类
@Override
public TranscriptSearch parse(XmlPullParser parser, int initialDepth) throws XmlPullParserException, IOException, SmackException {
    TranscriptSearch answer = new TranscriptSearch();

    boolean done = false;
    while (!done) {
        int eventType = parser.next();
        if (eventType == XmlPullParser.START_TAG) {
            // Parse the packet extension
            PacketParserUtils.addExtensionElement(answer, parser);
        }
        else if (eventType == XmlPullParser.END_TAG) {
            if (parser.getName().equals(ELEMENT_NAME)) {
                done = true;
            }
        }
    }

    return answer;
}
 
开发者ID:TTalkIM,项目名称:Smack,代码行数:21,代码来源:TranscriptSearch.java


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