Search in sources :

Example 1 with BoBIQ

use of org.jivesoftware.smackx.bob.element.BoBIQ in project Smack by igniterealtime.

the class BoBManager method requestBoB.

/**
     * Request BoB data.
     * 
     * @param to
     * @param bobHash
     * @return the BoB data
     * @throws NotLoggedInException
     * @throws NoResponseException
     * @throws XMPPErrorException
     * @throws NotConnectedException
     * @throws InterruptedException
     */
public BoBData requestBoB(Jid to, BoBHash bobHash) throws NotLoggedInException, NoResponseException, XMPPErrorException, NotConnectedException, InterruptedException {
    BoBData bobData = BOB_CACHE.lookup(bobHash);
    if (bobData != null) {
        return bobData;
    }
    BoBIQ requestBoBIQ = new BoBIQ(bobHash);
    requestBoBIQ.setType(Type.get);
    requestBoBIQ.setTo(to);
    XMPPConnection connection = getAuthenticatedConnectionOrThrow();
    BoBIQ responseBoBIQ = connection.createStanzaCollectorAndSend(requestBoBIQ).nextResultOrThrow();
    bobData = responseBoBIQ.getBoBData();
    BOB_CACHE.put(bobHash, bobData);
    return bobData;
}
Also used : BoBIQ(org.jivesoftware.smackx.bob.element.BoBIQ) XMPPConnection(org.jivesoftware.smack.XMPPConnection)

Example 2 with BoBIQ

use of org.jivesoftware.smackx.bob.element.BoBIQ in project Smack by igniterealtime.

the class BoBIQProvider method parse.

@Override
public BoBIQ parse(XmlPullParser parser, int initialDepth) throws Exception {
    String cid = parser.getAttributeValue("", "cid");
    BoBHash bobHash = BoBHash.fromCid(cid);
    String dataType = parser.getAttributeValue("", "type");
    int maxAge = ParserUtils.getIntegerAttribute(parser, "max-age", -1);
    String base64EncodedData = parser.nextText();
    BoBData bobData;
    if (dataType != null) {
        bobData = new BoBData(dataType, base64EncodedData, maxAge);
    } else {
        bobData = null;
    }
    return new BoBIQ(bobHash, bobData);
}
Also used : BoBData(org.jivesoftware.smackx.bob.BoBData) BoBIQ(org.jivesoftware.smackx.bob.element.BoBIQ) BoBHash(org.jivesoftware.smackx.bob.BoBHash)

Example 3 with BoBIQ

use of org.jivesoftware.smackx.bob.element.BoBIQ in project Smack by igniterealtime.

the class BoBIQTest method checkBoBIQResponse.

@Test
public void checkBoBIQResponse() throws Exception {
    BoBIQ bobIQ = PacketParserUtils.parseStanza(sampleBoBIQResponse);
    BoBHash bobHash = new BoBHash("8f35fef110ffc5df08d579a50083ff9308fb6242", "sha1");
    BoBData bobData = new BoBData("image/png", "sarasade2354j2".getBytes(StringUtils.UTF8), 86400);
    BoBIQ createdBoBIQ = new BoBIQ(bobHash, bobData);
    createdBoBIQ.setStanzaId("sarasa");
    createdBoBIQ.setTo(JidCreate.from("doctor@shakespeare.lit/pda"));
    createdBoBIQ.setType(Type.result);
    Assert.assertEquals(bobIQ.getBoBHash().getHash(), createdBoBIQ.getBoBHash().getHash());
    Assert.assertEquals(bobIQ.getBoBHash().getHashType(), createdBoBIQ.getBoBHash().getHashType());
    Assert.assertEquals(bobIQ.getBoBData().getMaxAge(), createdBoBIQ.getBoBData().getMaxAge());
    Assert.assertEquals(bobIQ.getBoBData().getType(), createdBoBIQ.getBoBData().getType());
    Assert.assertEquals(bobIQ.getBoBData().getContentBase64Encoded(), createdBoBIQ.getBoBData().getContentBase64Encoded());
    Assert.assertEquals(bobIQ.toXML().toString(), createdBoBIQ.toXML().toString());
}
Also used : BoBIQ(org.jivesoftware.smackx.bob.element.BoBIQ) Test(org.junit.Test)

Example 4 with BoBIQ

use of org.jivesoftware.smackx.bob.element.BoBIQ in project Smack by igniterealtime.

the class BoBIQTest method checkBoBIQRequest.

@Test
public void checkBoBIQRequest() throws Exception {
    BoBHash bobHash = new BoBHash("8f35fef110ffc5df08d579a50083ff9308fb6242", "sha1");
    BoBIQ createdBoBIQ = new BoBIQ(bobHash);
    createdBoBIQ.setStanzaId("sarasa");
    createdBoBIQ.setTo(JidCreate.from("ladymacbeth@shakespeare.lit/castle"));
    createdBoBIQ.setType(Type.get);
    Assert.assertEquals(sampleBoBIQRequest, createdBoBIQ.toXML().toString());
}
Also used : BoBIQ(org.jivesoftware.smackx.bob.element.BoBIQ) Test(org.junit.Test)

Aggregations

BoBIQ (org.jivesoftware.smackx.bob.element.BoBIQ)4 Test (org.junit.Test)2 XMPPConnection (org.jivesoftware.smack.XMPPConnection)1 BoBData (org.jivesoftware.smackx.bob.BoBData)1 BoBHash (org.jivesoftware.smackx.bob.BoBHash)1