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;
}
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);
}
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());
}
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());
}
Aggregations