Search in sources :

Example 1 with HeadersExtension

use of org.jivesoftware.smackx.shim.packet.HeadersExtension in project Smack by igniterealtime.

the class HeadersProviderTest method headersInMessageTest.

@Test
public void headersInMessageTest() throws Exception {
    // @formatter:off
    final String messageStanza = "<message from='romeo@shakespeare.lit/orchard' to='juliet@capulet.com' type='chat'>" + "<body>Wherefore are thou?!?</body>" + "<headers xmlns='http://jabber.org/protocol/shim'>" + "<header name='Urgency'>high</header>" + "</headers>" + "</message>";
    // @formatter:on
    XmlPullParser parser = TestUtils.getMessageParser(messageStanza);
    Message message = PacketParserUtils.parseMessage(parser);
    HeadersExtension headers = HeadersExtension.from(message);
    Header header = headers.getHeaders().get(0);
    assertEquals("Urgency", header.getName());
    assertEquals("high", header.getValue());
}
Also used : HeadersExtension(org.jivesoftware.smackx.shim.packet.HeadersExtension) Message(org.jivesoftware.smack.packet.Message) Header(org.jivesoftware.smackx.shim.packet.Header) XmlPullParser(org.xmlpull.v1.XmlPullParser) Test(org.junit.Test)

Example 2 with HeadersExtension

use of org.jivesoftware.smackx.shim.packet.HeadersExtension in project Smack by igniterealtime.

the class AbstractHttpOverXmppProvider method parseHeaders.

/**
     * Parses HeadersExtension element if any.
     *
     * @param parser parser
     * @return HeadersExtension or null if no headers
     * @throws Exception
     */
protected HeadersExtension parseHeaders(XmlPullParser parser) throws Exception {
    HeadersExtension headersExtension = null;
    /* We are either at start of headers, start of data or end of req/res */
    if (parser.next() == XmlPullParser.START_TAG && parser.getName().equals(HeadersExtension.ELEMENT)) {
        headersExtension = HeadersProvider.INSTANCE.parse(parser);
        parser.next();
    }
    return headersExtension;
}
Also used : HeadersExtension(org.jivesoftware.smackx.shim.packet.HeadersExtension)

Example 3 with HeadersExtension

use of org.jivesoftware.smackx.shim.packet.HeadersExtension in project Smack by igniterealtime.

the class HttpOverXmppRespProvider method parse.

@Override
public HttpOverXmppResp parse(XmlPullParser parser, int initialDepth) throws Exception {
    String version = parser.getAttributeValue("", ATTRIBUTE_VERSION);
    String statusMessage = parser.getAttributeValue("", ATTRIBUTE_STATUS_MESSAGE);
    String statusCodeString = parser.getAttributeValue("", ATTRIBUTE_STATUS_CODE);
    int statusCode = Integer.parseInt(statusCodeString);
    HeadersExtension headers = parseHeaders(parser);
    AbstractHttpOverXmpp.Data data = parseData(parser);
    return HttpOverXmppResp.builder().setHeaders(headers).setData(data).setStatusCode(statusCode).setStatusMessage(statusMessage).setVersion(version).build();
}
Also used : AbstractHttpOverXmpp(org.jivesoftware.smackx.hoxt.packet.AbstractHttpOverXmpp) HeadersExtension(org.jivesoftware.smackx.shim.packet.HeadersExtension)

Example 4 with HeadersExtension

use of org.jivesoftware.smackx.shim.packet.HeadersExtension in project Smack by igniterealtime.

the class Node method getSubscriptionIds.

private static List<String> getSubscriptionIds(Stanza packet) {
    HeadersExtension headers = (HeadersExtension) packet.getExtension("headers", "http://jabber.org/protocol/shim");
    List<String> values = null;
    if (headers != null) {
        values = new ArrayList<String>(headers.getHeaders().size());
        for (Header header : headers.getHeaders()) {
            values.add(header.getValue());
        }
    }
    return values;
}
Also used : HeadersExtension(org.jivesoftware.smackx.shim.packet.HeadersExtension) Header(org.jivesoftware.smackx.shim.packet.Header)

Aggregations

HeadersExtension (org.jivesoftware.smackx.shim.packet.HeadersExtension)4 Header (org.jivesoftware.smackx.shim.packet.Header)2 Message (org.jivesoftware.smack.packet.Message)1 AbstractHttpOverXmpp (org.jivesoftware.smackx.hoxt.packet.AbstractHttpOverXmpp)1 Test (org.junit.Test)1 XmlPullParser (org.xmlpull.v1.XmlPullParser)1