Package org.apache.vysper.xmpp.stanza

Examples of org.apache.vysper.xmpp.stanza.StanzaBuilder


        return stanzaBuilder.build();
    }

    private Stanza bindError(IQStanza stanza, SessionContext sessionContext) {
        StanzaBuilder stanzaBuilder =
            StanzaBuilder.createIQStanza(null, null, IQStanzaType.ERROR, stanza.getID()).
            startInnerElement("error").
                    addAttribute("type", "cancel").
                    startInnerElement("not-allowed", NamespaceURIs.URN_IETF_PARAMS_XML_NS_XMPP_STANZAS).
            endInnerElement();

        return stanzaBuilder.build();
    }
View Full Code Here


        }

        //TODO check that elementSet contains at least one identity element and on feature element!

        // render the stanza with information collected
        StanzaBuilder stanzaBuilder = StanzaBuilder.createIQStanza(to, stanza.getFrom(), IQStanzaType.RESULT, stanza.getID()).
            startInnerElement("query", NamespaceURIs.XEP0030_SERVICE_DISCOVERY_INFO);
            if (node != null) {
                stanzaBuilder.addAttribute("node", node);
            }
            for (InfoElement infoElement : elements) {
                infoElement.insertElement(stanzaBuilder);
            }

        stanzaBuilder.endInnerElement();

        return stanzaBuilder.build();
    }
View Full Code Here

        }

        String queryKey = getKey(x);
        String privateDataXML = persistenceManager.getPrivateData(from, queryKey);

        StanzaBuilder stanzaBuilder = StanzaBuilder.createIQStanza(stanza.getTo(), stanza.getFrom(), IQStanzaType.RESULT, stanza.getID());
        if (privateDataXML == null) {
            stanzaBuilder.startInnerElement(x.getName());
            for (Attribute a : x.getAttributes()) {
                stanzaBuilder.addAttribute(a);
            }
            stanzaBuilder.endInnerElement();
        } else {
            stanzaBuilder.addText(privateDataXML);
        }
        return stanzaBuilder.build();
    }
View Full Code Here

                    "disco info request failed.",
                    getErrorLanguage(serverRuntimeContext, sessionContext), null);
        }

        // render the stanza with information collected
        StanzaBuilder stanzaBuilder = StanzaBuilder.createIQStanza(to, stanza.getFrom(), IQStanzaType.RESULT, stanza.getID()).
            startInnerElement("query", NamespaceURIs.XEP0030_SERVICE_DISCOVERY_ITEMS);
            if (node != null) {
                stanzaBuilder.addAttribute("node", node);
            }
            for (Item item : items) {
                item.insertElement(stanzaBuilder);
            }
        stanzaBuilder.endInnerElement();

        return stanzaBuilder.build();
    }
View Full Code Here

        // from XEP-0054 3.1:
        // If no vCard exists, the server MUST return a stanza error (which SHOULD be <item-not-found/>)
        // or an IQ-result containing an empty <vCard/> element.
        if (vcardXml == null) {
            IQStanzaType iqStanzaType = returnEmptyVCardWhenNonExistent ? IQStanzaType.RESULT : IQStanzaType.ERROR;
            StanzaBuilder stanzaBuilder = StanzaBuilder.createIQStanza(stanza.getTo(), stanza.getFrom(), iqStanzaType, stanza.getID());
            stanzaBuilder.startInnerElement("vCard", NamespaceURIs.VCARD_TEMP).endInnerElement();
            if (returnEmptyVCardWhenNonExistent) {
                // keep it like it is
            } else {
                stanzaBuilder.
                    startInnerElement("error").addAttribute("type", "cancel").
                        startInnerElement("item-not-found", NamespaceURIs.URN_IETF_PARAMS_XML_NS_XMPP_STANZAS).
                        endInnerElement().
                    endInnerElement();
            }
            return stanzaBuilder.build();
        }

        StanzaBuilder stanzaBuilder = StanzaBuilder.createIQStanza(stanza.getTo(), stanza.getFrom(), IQStanzaType.RESULT, stanza.getID());
        stanzaBuilder.addText(vcardXml);
        return stanzaBuilder.build();
    }
View Full Code Here

* @author The Apache MINA Project (dev@mina.apache.org)
*/
public class RosterStanzaUtils {

    public static StanzaBuilder createRosterItemsIQ(Entity to, String id, IQStanzaType type, Iterable<RosterItem> rosterItems) {
        StanzaBuilder stanzaBuilder = StanzaBuilder.createIQStanza(null, to, type, id).
            startInnerElement("query", NamespaceURIs.JABBER_IQ_ROSTER);

            for (RosterItem rosterItem : rosterItems) {
                createRosterItem(stanzaBuilder, rosterItem);
            }

        stanzaBuilder.endInnerElement();

        return stanzaBuilder;
    }
View Full Code Here

        Entity sender = extractSenderJID(stanza, sessionContext);
        Entity subJID = null;

        String iqStanzaID = stanza.getAttributeValue("id");

        StanzaBuilder sb = StanzaBuilder.createIQStanza(serverJID, sender, IQStanzaType.RESULT, iqStanzaID);
        sb.startInnerElement("pubsub", NamespaceURIs.XEP0060_PUBSUB);

        XMLElement sub = stanza.getFirstInnerElement().getFirstInnerElement(); // pubsub/subscribe
        String strSubJID = sub.getAttributeValue("jid"); // MUST

        try {
            subJID = EntityImpl.parse(strSubJID);
        } catch (EntityFormatException e) {
            return errorStanzaGenerator.generateJIDMalformedErrorStanza(sender, serverJID, stanza);
        }

        if(!sender.getBareJID().equals(subJID.getBareJID())) {
            // error condition 1 (6.1.3)
            return errorStanzaGenerator.generateJIDDontMatchErrorStanza(sender, serverJID, stanza);
        }

        String nodeName = extractNodeName(stanza);
        LeafNode node = root.find(nodeName);

        if(node == null) {
            // no such node (error condition 11 (6.1.3))
            return errorStanzaGenerator.generateNoNodeErrorStanza(sender, serverJID, stanza);
        }

        String id = idGenerator.create();
        node.subscribe(id, subJID);

        buildSuccessStanza(sb, nodeName, strSubJID, id);

        sb.endInnerElement(); // pubsub
        return new IQStanza(sb.build());
    }
View Full Code Here

    }
   
    public void testHandshake() {
        StanzaSession session = sessionFactory.createNewSession();
        session.send(
                new StanzaBuilder("stream", "http://etherx.jabber.org/streams", "stream")
                    .addAttribute("from", "me@vysper.org")
                    .addAttribute("to", "vysper.org")
                    .addNamespaceAttribute("jabber:client")
                .build()
        );
        Stanza stanza = waitForStanza(session);
        assertNotNull(stanza);
        System.out.println(DenseStanzaLogRenderer.render(stanza));
        session.send(
                new StanzaBuilder("starttls", "urn:ietf:params:xml:ns:xmpp-tls")
                    .addAttribute("from", "me@vysper.org")
                .build()
        );
        stanza = waitForStanza(session);
        assertNotNull(stanza);
        System.out.println(DenseStanzaLogRenderer.render(stanza));
        session.setIsSecure();
        session.send(
                new StanzaBuilder("stream", "http://etherx.jabber.org/streams", "stream")
                    .addAttribute("from", "me@vysper.org")
                    .addAttribute("to", "vysper.org")
                    .addNamespaceAttribute("jabber:client")
                .build()
        );
View Full Code Here

            if (from == null || !from.isResourceSet()) {
                // rewrite stanza with new from
                String resource = serverRuntimeContext.getResourceRegistry().getUniqueResourceForSession(sessionContext);
                if (resource == null) throw new IllegalStateException("could not determine unique resource");
                from = new EntityImpl(sessionContext.getInitiatingEntity(), resource);
                StanzaBuilder stanzaBuilder = new StanzaBuilder(stanza.getName());
                for (Attribute attribute : stanza.getAttributes()) {
                    if ("from".equals(attribute.getName())) continue;
                    stanzaBuilder.addAttribute(attribute);
                }
                stanzaBuilder.addAttribute("from", from.getFullQualifiedName());
                for (XMLElement preparedElement : stanza.getInnerElements()) {
                    stanzaBuilder.addPreparedElement(preparedElement);
                }
                stanza = XMPPCoreStanza.getWrapper(stanzaBuilder.build());
            }

            StanzaRelay stanzaRelay = serverRuntimeContext.getStanzaRelay();
            try {
                stanzaRelay.relay(stanza.getTo(), stanza, new ReturnErrorToSenderFailureStrategy(stanzaRelay));
View Full Code Here

        String timeZone = TimeZone.getDefault().getDisplayName(TimeZone.getDefault().inDaylightTime(now), TimeZone.SHORT);
        String utcTime = utcDateFormatter.format(now);
        String displayTime = localDateFormatter.format(now);

        StanzaBuilder stanzaBuilder = StanzaBuilder.createIQStanza(stanza.getTo(), stanza.getFrom(), IQStanzaType.RESULT, stanza.getID()).
            startInnerElement("query", NamespaceURIs.JABBER_IQ_TIME).

            startInnerElement("utc", NamespaceURIs.JABBER_IQ_TIME).addText(utcTime).endInnerElement().
            startInnerElement("tz", NamespaceURIs.JABBER_IQ_TIME).addText(timeZone).endInnerElement().
            startInnerElement("display", NamespaceURIs.JABBER_IQ_TIME).addText(displayTime).endInnerElement().

        endInnerElement();

        return stanzaBuilder.build();
    }
View Full Code Here

TOP

Related Classes of org.apache.vysper.xmpp.stanza.StanzaBuilder

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.