use of org.jivesoftware.smackx.pubsub.packet.PubSub in project Smack by igniterealtime.
the class PubSubProviderTest method subscriptionsOwnerResultTest.
@Test
public void subscriptionsOwnerResultTest() throws Exception {
// @formatter:off
final String resultStanza = "<iq from='pubsub.example.org' to='julia@example.org/Smack' id='HaT4m-13' type='result'>" + "<pubsub xmlns='http://jabber.org/protocol/pubsub#owner'>" + "<subscriptions node='test'>" + "<subscription jid='foo@example.org/Smack' subscription='subscribed' subid='58C1A6F99F2A7'/>" + "<subscription jid='julia@example.org/Smack' subscription='subscribed' subid='58C18F8917321'/>" + "</subscriptions>" + "</pubsub>" + "</iq>";
// @formatter:on
XmlPullParser parser = TestUtils.getIQParser(resultStanza);
PubSub pubsubResult = (PubSub) PacketParserUtils.parseIQ(parser);
SubscriptionsExtension subElem = pubsubResult.getExtension(PubSubElementType.SUBSCRIPTIONS_OWNER);
List<Subscription> subscriptions = subElem.getSubscriptions();
assertEquals(2, subscriptions.size());
Subscription sub1 = subscriptions.get(0);
assertThat("foo@example.org/Smack", equalsCharSequence(sub1.getJid()));
assertEquals(Subscription.State.subscribed, sub1.getState());
assertEquals("58C1A6F99F2A7", sub1.getId());
Subscription sub2 = subscriptions.get(1);
assertThat("julia@example.org/Smack", equalsCharSequence(sub2.getJid()));
assertEquals(Subscription.State.subscribed, sub2.getState());
assertEquals("58C18F8917321", sub2.getId());
}
use of org.jivesoftware.smackx.pubsub.packet.PubSub in project camel by apache.
the class XmppBinding method extractHeadersFromXmpp.
public Map<String, Object> extractHeadersFromXmpp(Packet xmppPacket, Exchange exchange) {
Map<String, Object> answer = new HashMap<String, Object>();
PacketExtension jpe = xmppPacket.getExtension(JivePropertiesExtension.NAMESPACE);
if (jpe != null && jpe instanceof JivePropertiesExtension) {
extractHeadersFrom((JivePropertiesExtension) jpe, exchange, answer);
}
if (jpe != null && jpe instanceof DefaultPacketExtension) {
extractHeadersFrom((DefaultPacketExtension) jpe, exchange, answer);
}
if (xmppPacket instanceof Message) {
Message xmppMessage = (Message) xmppPacket;
answer.put(XmppConstants.MESSAGE_TYPE, xmppMessage.getType());
answer.put(XmppConstants.SUBJECT, xmppMessage.getSubject());
answer.put(XmppConstants.THREAD_ID, xmppMessage.getThread());
} else if (xmppPacket instanceof PubSub) {
PubSub pubsubPacket = (PubSub) xmppPacket;
answer.put(XmppConstants.MESSAGE_TYPE, pubsubPacket.getType());
}
answer.put(XmppConstants.FROM, xmppPacket.getFrom());
answer.put(XmppConstants.PACKET_ID, xmppPacket.getPacketID());
answer.put(XmppConstants.TO, xmppPacket.getTo());
return answer;
}
use of org.jivesoftware.smackx.pubsub.packet.PubSub in project camel by apache.
the class XmppPubSubProducer method process.
public void process(Exchange exchange) throws Exception {
try {
if (connection == null) {
connection = endpoint.createConnection();
}
// make sure we are connected
if (!connection.isConnected()) {
if (LOG.isDebugEnabled()) {
LOG.debug("Reconnecting to: " + XmppEndpoint.getConnectionMessage(connection));
}
connection.connect();
}
} catch (XMPPException e) {
throw new RuntimeExchangeException("Cannot connect to XMPP Server: " + ((connection != null) ? XmppEndpoint.getConnectionMessage(connection) : endpoint.getHost()), exchange, e);
}
try {
Object body = exchange.getIn().getBody(Object.class);
if (body instanceof PubSub) {
PubSub pubsubpacket = (PubSub) body;
endpoint.getBinding().populateXmppPacket(pubsubpacket, exchange);
exchange.getIn().setHeader(XmppConstants.DOC_HEADER, pubsubpacket);
connection.sendPacket(pubsubpacket);
} else {
throw new Exception("Message does not contain a pubsub packet");
}
} catch (XMPPException xmppe) {
throw new RuntimeExchangeException("Cannot send XMPP pubsub: from " + endpoint.getUser() + " to: " + XmppEndpoint.getConnectionMessage(connection), exchange, xmppe);
} catch (Exception e) {
throw new RuntimeExchangeException("Cannot send XMPP pubsub: from " + endpoint.getUser() + " to: " + XmppEndpoint.getConnectionMessage(connection), exchange, e);
}
}
use of org.jivesoftware.smackx.pubsub.packet.PubSub in project Smack by igniterealtime.
the class Node method subscribe.
/**
* The user subscribes to the node using the supplied jid. The
* bare jid portion of this one must match the jid for the connection.
*
* Please note that the {@link Subscription.State} should be checked
* on return since more actions may be required by the caller.
* {@link Subscription.State#pending} - The owner must approve the subscription
* request before messages will be received.
* {@link Subscription.State#unconfigured} - If the {@link Subscription#isConfigRequired()} is true,
* the caller must configure the subscription before messages will be received. If it is false
* the caller can configure it but is not required to do so.
* @param jid The jid to subscribe as.
* @return The subscription
* @throws XMPPErrorException
* @throws NoResponseException
* @throws NotConnectedException
* @throws InterruptedException
*/
public Subscription subscribe(String jid) throws NoResponseException, XMPPErrorException, NotConnectedException, InterruptedException {
PubSub pubSub = createPubsubPacket(Type.set, new SubscribeExtension(jid, getId()));
PubSub reply = sendPubsubPacket(pubSub);
return reply.getExtension(PubSubElementType.SUBSCRIPTION);
}
use of org.jivesoftware.smackx.pubsub.packet.PubSub in project Smack by igniterealtime.
the class Node method sendConfigurationForm.
/**
* Update the configuration with the contents of the new {@link Form}.
*
* @param submitForm
* @throws XMPPErrorException
* @throws NoResponseException
* @throws NotConnectedException
* @throws InterruptedException
*/
public void sendConfigurationForm(Form submitForm) throws NoResponseException, XMPPErrorException, NotConnectedException, InterruptedException {
PubSub packet = createPubsubPacket(Type.set, new FormNode(FormNodeType.CONFIGURE_OWNER, getId(), submitForm), PubSubNamespace.OWNER);
pubSubManager.getConnection().createStanzaCollectorAndSend(packet).nextResultOrThrow();
}
Aggregations