Package rocks.xmpp.core.stanza.model

Examples of rocks.xmpp.core.stanza.model.StanzaError


                if (e.isIncoming() && isEnabled() && !e.isConsumed() && iq.getType() == IQ.Type.SET) {
                    ContactExchange contactExchange = iq.getExtension(ContactExchange.class);
                    if (contactExchange != null) {
                        if (xmppSession.getRosterManager().getContact(iq.getFrom().asBareJid()) == null) {
                            // If the receiving entity will not process the suggested action(s) because the sending entity is not in the receiving entity's roster, the receiving entity MUST return an error to the sending entity, which error SHOULD be <not-authorized/>.
                            xmppSession.send(iq.createError(new StanzaError(new NotAuthorized())));
                        } else {
                            List<ContactExchange.Item> items = getItemsToProcess(contactExchange.getItems());
                            if (!items.isEmpty()) {
                                processItems(items, iq.getFrom(), null, new Date());
                            }
View Full Code Here


                    Socks5ByteStream socks5ByteStream = iq.getExtension(Socks5ByteStream.class);
                    if (socks5ByteStream != null) {
                        if (socks5ByteStream.getSessionId() == null) {
                            // If the request is malformed (e.g., the <query/> element does not include the 'sid' attribute), the Target MUST return an error of <bad-request/>.
                            xmppSession.send(iq.createError(new StanzaError(new BadRequest())));
                        } else {
                            notifyByteStreamEvent(new S5bEvent(Socks5ByteStreamManager.this, socks5ByteStream.getSessionId(), xmppSession, iq, socks5ByteStream.getStreamHosts()));
                        }
                        e.consume();
                    }
View Full Code Here

                        if (ibbSession != null) {
                            if (ibbSession.dataReceived(data)) {
                                xmppSession.send(iq.createResult());
                            } else {
                                // 2. Because the sequence number has already been used, the recipient returns an <unexpected-request/> error with a type of 'cancel'.
                                xmppSession.send(iq.createError(new StanzaError(StanzaError.Type.CANCEL, new UnexpectedRequest())));
                            }
                        }
                        e.consume();
                    } else {
                        InBandByteStream.Open open = iq.getExtension(InBandByteStream.Open.class);
                        if (open != null) {
                            if (open.getBlockSize() > 65535) {
                                xmppSession.send(iq.createError(new StanzaError(StanzaError.Type.MODIFY, new ResourceConstraint())));
                            } else {
                                // Somebody wants to create a IBB session with me.
                                // Notify the listeners.
                                notifyByteStreamEvent(new IbbEvent(InBandByteStreamManager.this, open.getSessionId(), xmppSession, iq, open.getBlockSize()));
                            }
                            e.consume();
                        } else {
                            InBandByteStream.Close close = iq.getExtension(InBandByteStream.Close.class);
                            // The session got closed.
                            if (close != null) {
                                IbbSession ibbSession = getIbbSession(iq, close.getSessionId());
                                if (ibbSession != null) {
                                    try {
                                        ibbSessionMap.remove(close.getSessionId());
                                        ibbSession.closedByPeer();
                                    } catch (IOException e1) {
                                        logger.log(Level.WARNING, e1.getMessage(), e1);
                                    } finally {
                                        xmppSession.send(iq.createResult());
                                    }
                                }
                                e.consume();
                            }
                        }
                    }
                }
            }
        });

        // 4. Use of Message Stanzas
        // an application MAY use message stanzas instead.
        xmppSession.addMessageListener(new MessageListener() {
            @Override
            public void handle(MessageEvent e) {
                if (e.isIncoming() && isEnabled()) {
                    InBandByteStream.Data data = e.getMessage().getExtension(InBandByteStream.Data.class);
                    if (data != null) {
                        IbbSession ibbSession = ibbSessionMap.get(data.getSessionId());
                        if (ibbSession != null) {
                            if (!ibbSession.dataReceived(data)) {
                                // 2. Because the sequence number has already been used, the recipient returns an <unexpected-request/> error with a type of 'cancel'.
                                xmppSession.send(e.getMessage().createError(new StanzaError(StanzaError.Type.CANCEL, new UnexpectedRequest())));
                            }
                        } else {
                            xmppSession.send(e.getMessage().createError(new StanzaError(new ItemNotFound())));
                        }
                    }
                }
            }
        });
View Full Code Here

    private IbbSession getIbbSession(IQ iq, String sessionId) {
        // Check, if the session id is known.
        IbbSession ibbSession = ibbSessionMap.get(sessionId);
        if (ibbSession == null) {
            // 1. Because the session ID is unknown, the recipient returns an <item-not-found/> error with a type of 'cancel'.
            xmppSession.send(iq.createError(new StanzaError(new ItemNotFound())));
        }
        return ibbSession;
    }
View Full Code Here

    }

    @Override
    public void reject() {
        // If the responder supports IBB but does not wish to proceed with the session, it returns a <not-acceptable/> error.
        xmppSession.send(iq.createError(new StanzaError(StanzaError.Type.CANCEL, new NotAcceptable())));
    }
View Full Code Here

                        if (cachedData != null) {
                            IQ result = iq.createResult();
                            result.setExtension(cachedData);
                            xmppSession.send(result);
                        } else {
                            xmppSession.send(iq.createError(new StanzaError(new ItemNotFound())));
                        }
                        e.consume();
                    }
                }
            }
View Full Code Here

            result.setExtension(Socks5ByteStream.streamHostUsed(s5bSession.getStreamHost()));
            xmppSession.send(result);
            return s5bSession;
        } catch (IOException e) {
            // If the Target tries but is unable to connect to any of the StreamHosts and it does not wish to attempt a connection from its side, it MUST return an <item-not-found/> error to the Requester.
            xmppSession.send(iq.createError(new StanzaError(new ItemNotFound())));
            throw e;
        }
    }
View Full Code Here

    }

    @Override
    public void reject() {
        // Else if the Target is unwilling to accept the bytestream, it MUST return an error of <not-acceptable/> to the Requester.
        xmppSession.send(iq.createError(new StanzaError(new NotAcceptable())));
    }
View Full Code Here

                                // Gracefully send an empty result.
                                xmppSession.send(iq.createResult());
                                updateRoster(roster, true);
                            } else {
                                // If the client receives a roster push from an unauthorized entity, it MUST NOT process the pushed data; in addition, the client can either return a stanza error of <service-unavailable/> error
                                xmppSession.send(iq.createError(new StanzaError(new ServiceUnavailable())));
                            }
                        } else if (iq.getType() == IQ.Type.RESULT) {
                            updateRoster(roster, false);
                        }
                        e.consume();
View Full Code Here

                        // The value of the 'action' attribute MUST be one of the following.
                        // If an entity receives a value not defined here, it MUST ignore the attribute and MUST return a <bad-request/> error to the sender.
                        // There is no default value for the 'action' attribute.
                        if (jingle.getAction() == null) {
                            xmppSession.send(iq.createError(new StanzaError(new BadRequest(), "No valid action attribute set.")));
                        } else if (jingle.getSessionId() == null) {
                            xmppSession.send(iq.createError(new StanzaError(new BadRequest(), "No session id set.")));
                        } else if (jingle.getAction() == Jingle.Action.SESSION_INITIATE) {

                            // Check if the Jingle request is not mal-formed, otherwise return a bad-request error.
                            // See 6.3.2 Errors
                            if (jingle.getContents().isEmpty()) {
                                xmppSession.send(iq.createError(new StanzaError(new BadRequest(), "No contents found.")));
                            } else {
                                boolean hasContentWithDispositionSession = false;
                                boolean hasSupportedApplications = false;
                                boolean hasSupportedTransports = false;
                                // Check if we support the application format and transport method and at least one content element has a disposition of "session".
                                for (Jingle.Content content : jingle.getContents()) {
                                    // Check if the content disposition is "session" (default value is "session").
                                    if (!hasContentWithDispositionSession && ("session".equals(content.getDisposition()) || content.getDisposition() == null)) {
                                        hasContentWithDispositionSession = true;
                                    }

                                    if (!hasSupportedApplications && content.getApplicationFormat() != null) {
                                        hasSupportedApplications = true;
                                    }

                                    if (!hasSupportedTransports && content.getTransportMethod() != null) {
                                        hasSupportedTransports = true;
                                    }
                                }

                                if (!hasContentWithDispositionSession) {
                                    // When sending a session-initiate with one <content/> element,
                                    // the value of the <content/> element's 'disposition' attribute MUST be "session"
                                    // (if there are multiple <content/> elements then at least one MUST have a disposition of "session");
                                    // if this rule is violated, the responder MUST return a <bad-request/> error to the initiator.
                                    xmppSession.send(iq.createError(new StanzaError(new BadRequest(), "No content with disposition 'session' found.")));
                                } else {
                                    // If the request was ok, immediately acknowledge the initiation request.
                                    // See 6.3.1 Acknowledgement
                                    xmppSession.send(iq.createResult());

                                    // However, after acknowledging the session initiation request,
                                    // the responder might subsequently determine that it cannot proceed with negotiation of the session
                                    // (e.g., because it does not support any of the offered application formats or transport methods,
                                    // because a human user is busy or unable to accept the session, because a human user wishes to formally decline
                                    // the session, etc.). In these cases, the responder SHOULD immediately acknowledge the session initiation request
                                    // but then terminate the session with an appropriate reason as described in the Termination section of this document.

                                    if (!hasSupportedApplications) {
                                        // Terminate the session with <unsupported-applications/>.
                                        xmppSession.send(new IQ(iq.getFrom(), IQ.Type.SET, new Jingle(jingle.getSessionId(), Jingle.Action.SESSION_TERMINATE, new Jingle.Reason(new Jingle.Reason.UnsupportedApplications()))));
                                    } else if (!hasSupportedTransports) {
                                        // Terminate the session with <unsupported-transports/>.
                                        xmppSession.send(new IQ(iq.getFrom(), IQ.Type.SET, new Jingle(jingle.getSessionId(), Jingle.Action.SESSION_TERMINATE, new Jingle.Reason(new Jingle.Reason.UnsupportedTransports()))));
                                    } else {
                                        // Everything is fine, create the session and notify the listeners.
                                        JingleSession jingleSession = new JingleSession(jingle.getSessionId(), iq.getFrom(), false, xmppSession, JingleManager.this, jingle.getContents());
                                        jingleSessionMap.put(jingle.getSessionId(), jingleSession);
                                        notifyJingleListeners(new JingleEvent(JingleManager.this, xmppSession, iq, jingle));
                                    }
                                }
                            }
                        } else {

                            // Another action (!= session-initiate) has been sent.
                            // Check if we know the session.
                            JingleSession jingleSession = jingleSessionMap.get(jingle.getSessionId());

                            if (jingleSession == null) {
                                // If we receive a non-session-initiate Jingle action with an unknown session id,
                                // return <item-not-found/> and <unknown-session/>
                                StanzaError stanzaError = new StanzaError(new ItemNotFound());
                                stanzaError.setExtension(new UnknownSession());
                                xmppSession.send(iq.createError(stanzaError));
                            } else {
                                jingleSession.notifyJingleListeners(new JingleEvent(JingleManager.this, xmppSession, iq, jingle));
                                xmppSession.send(iq.createResult());
                            }
View Full Code Here

TOP

Related Classes of rocks.xmpp.core.stanza.model.StanzaError

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.