@Override public ResourceDocument sendRestDocument(XmppURI uri, ResourceDocument document) throws XMPPException, IOException, SmackException { AbstractXMPPConnection connection = this.connectionManager.getConnection(); // create an set IQ stanza to uri RestIQ setIQ = new RestIQ(uri, document); // send stanza connection.sendStanza(setIQ); // wait for response StanzaFilter filter = new AndFilter(new IQReplyFilter(setIQ, connection)); PacketCollector collector = connection.createPacketCollector(filter); IQ resultIQ = collector.nextResultOrThrow(); if(resultIQ instanceof RestIQ) { // create rest doc return ((RestIQ) resultIQ).getResourceDocument(); } else { throw new SmackException("Wrong RestIQ has been passed"); } }
@Override public ResourceTypeDocument getXwadlDocument(XmppURI uri) throws XMPPException, IOException, SmackException { AbstractXMPPConnection connection = this.connectionManager.getConnection(); // create an get IQ stanza to uri IQ getIQ = new GetXwadlIQ(uri); // send stanza connection.sendStanza(getIQ); // wait for response StanzaFilter filter = new AndFilter(new IQReplyFilter(getIQ, connection)); PacketCollector collector = connection.createPacketCollector(filter); IQ resultIQ = collector.nextResultOrThrow(); if (resultIQ instanceof XwadlIQ) { // create xwadl return ((XwadlIQ) resultIQ).getXwadl(); } else { throw new SmackException("Wrong IQ has been passed"); } }
@Override public PacketCollector createPacketCollectorAndSend(IQ packet) throws NotConnectedException { StanzaFilter packetFilter = new IQReplyFilter(packet, this); // Create the packet collector before sending the packet PacketCollector packetCollector = createPacketCollectorAndSend(packetFilter, packet); return packetCollector; }
@Override public void sendIqWithResponseCallback(IQ iqRequest, final StanzaListener callback, final ExceptionCallback exceptionCallback, long timeout) throws NotConnectedException { StanzaFilter replyFilter = new IQReplyFilter(iqRequest, this); sendStanzaWithResponseCallback(iqRequest, replyFilter, callback, exceptionCallback, timeout); }
public static XmppRestClient build(XMPPConnection connection, XmppURI uri) throws XMPPErrorException, XmlException, SmackException { logger.info("building rest client for uri=" + uri.toString()); // create an get IQ stanza to uri IQ getIQ = new GetXwadlIQ(uri); // send stanza connection.sendStanza(getIQ); logger.info("the following stanza had been send: " + getIQ.toString()); // wait for response StanzaFilter filter = new AndFilter(new IQReplyFilter(getIQ, connection)); PacketCollector collector = connection .createPacketCollector(filter); IQ resultIQ = collector.nextResultOrThrow(); ResourceTypeDocument xwadl = null; if(resultIQ instanceof XwadlIQ) { // create xwadl xwadl = ((XwadlIQ) resultIQ).getXwadl(); } else throw new SmackException("Wrong IQ has been passed"); logger.info("the following stanza had been received: " + xwadl.toString()); // create client return new XmppRestClient(connection, uri, xwadl); }
public Representation invoke() throws XMPPErrorException, XmlException, SmackException { // create an set IQ stanza to uri RestIQ setIQ = new RestIQ(this.uri, this.getXmlDocument()); // logger.info("invoke: the following stanza will be send: " + this.getXmlDocument().toString()); // send stanza this.connection.sendStanza(setIQ); // wait for response StanzaFilter filter = new AndFilter(new IQReplyFilter(setIQ, connection)); PacketCollector collector = connection .createPacketCollector(filter); IQ resultIQ = collector.nextResultOrThrow(); ResourceDocument doc = null; if(resultIQ instanceof RestIQ) { // create rest doc doc = ((RestIQ) resultIQ).getResourceDocument(); } else throw new SmackException("Wrong RestIQ has been passed"); // logger.info("the following resource stanza had been received: " + doc.toString()); // create representation return getPresentation(doc); }