Examples of StanzaError


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

    @Test
    public void marshalErrorMessage() throws JAXBException, XMLStreamException {
        Message message = new Message(Jid.valueOf("juliet@example.com"), Message.Type.ERROR);
        message.setBody("test");
        message.setError(new StanzaError(new Conflict()));
        String xml = marshal(message);
        Assert.assertEquals(xml, "<message to=\"juliet@example.com\" type=\"error\"><body>test</body><error type=\"cancel\"><conflict xmlns=\"urn:ietf:params:xml:ns:xmpp-stanzas\"></conflict></error></message>");
    }
View Full Code Here

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

    public void marshalIQWithError() throws JAXBException, XMLStreamException {
        IQ iq = new IQ(IQ.Type.GET);
        iq.setId("id");
        iq.setTo(new Jid("to", "domain"));
        iq.setFrom(new Jid("from", "domain"));
        iq.setError(new StanzaError(StanzaError.Type.MODIFY, new ServiceUnavailable()));
        String xml = marshal(iq);
        Assert.assertEquals(xml, "<iq from=\"from@domain\" id=\"id\" to=\"to@domain\" type=\"get\"><error type=\"modify\"><service-unavailable xmlns=\"urn:ietf:params:xml:ns:xmpp-stanzas\"></service-unavailable></error></iq>");
    }
View Full Code Here

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

    public void testErrorIQ() throws JAXBException, XMLStreamException {
        IQ iq = new IQ(IQ.Type.GET);
        iq.setId("id");
        iq.setTo(new Jid("to", "domain"));
        iq.setFrom(new Jid("from", "domain"));
        IQ error = iq.createError(new StanzaError(new UndefinedCondition()));
        Assert.assertEquals(error.getType(), IQ.Type.ERROR);
        Assert.assertEquals(error.getId(), iq.getId());
        Assert.assertEquals(error.getTo(), iq.getFrom());
        Assert.assertEquals(error.getFrom(), iq.getTo());
        Assert.assertEquals(error.getError().getBy(), error.getFrom());
View Full Code Here

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

    }

    @Test
    public void marshalCondition() throws JAXBException, XMLStreamException {
        String xml = "<iq id=\"1\" type=\"error\"><error type=\"wait\"><unexpected-request xmlns=\"urn:ietf:params:xml:ns:xmpp-stanzas\"></unexpected-request></error></iq>";
        StanzaError error = new StanzaError(new UnexpectedRequest());
        IQ iq = new IQ("1", AbstractIQ.Type.ERROR);
        iq.setError(error);
        Assert.assertEquals(marshal(iq), xml);
    }
View Full Code Here

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

    }

    @Test
    public void marshalBadProfile() throws JAXBException, XMLStreamException {
        IQ result = new IQ("1", IQ.Type.ERROR);
        result.setError(new StanzaError(new BadRequest()));
        result.getError().setExtension(new BadProfile());
        String xml = marshal(result);
        Assert.assertEquals(xml, "<iq id=\"1\" type=\"error\"><error type=\"modify\"><bad-request xmlns=\"urn:ietf:params:xml:ns:xmpp-stanzas\"></bad-request><bad-profile xmlns=\"http://jabber.org/protocol/si\"></bad-profile></error></iq>");

    }
View Full Code Here

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

    }

    @Test
    public void marshalNoValidStreams() throws JAXBException, XMLStreamException {
        IQ result = new IQ("1", IQ.Type.ERROR);
        result.setError(new StanzaError(new BadRequest()));
        result.getError().setExtension(new NoValidStreams());
        String xml = marshal(result);
        Assert.assertEquals(xml, "<iq id=\"1\" type=\"error\"><error type=\"modify\"><bad-request xmlns=\"urn:ietf:params:xml:ns:xmpp-stanzas\"></bad-request><no-valid-streams xmlns=\"http://jabber.org/protocol/si\"></no-valid-streams></error></iq>");

    }
View Full Code Here

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

                                            IQ result = iq.createResult();
                                            result.setExtension(new Rpc(new Rpc.MethodResponse.Fault(e1.getFaultCode(), e1.getFaultString())));
                                            xmppSession.send(result);
                                        } catch (Throwable e1) {
                                            logger.log(Level.WARNING, e1.getMessage(), e1);
                                            xmppSession.send(iq.createError(new StanzaError(new InternalServerError())));
                                        }
                                    }
                                });
                                e.consume();
                            }
View Full Code Here

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

                                IQ result = iq.createResult();
                                result.setExtension(new InfoDiscovery(infoNode.getNode(), infoNode.getIdentities(), infoNode.getFeatures(), infoNode.getExtensions()));
                                xmppSession.send(result);
                                e.consume();
                            } else {
                                xmppSession.send(iq.createError(new StanzaError(new ItemNotFound())));
                                e.consume();
                            }
                        }
                    } else {
                        ItemDiscovery itemDiscovery = iq.getExtension(ItemDiscovery.class);
                        if (itemDiscovery != null) {
                            if (itemDiscovery.getNode() == null) {
                                IQ result = iq.createResult();
                                result.setExtension(new ItemDiscovery(items));
                                xmppSession.send(result);
                                e.consume();
                            } else {
                                ItemNode itemNode = itemNodeMap.get(itemDiscovery.getNode());
                                if (itemNode != null) {
                                    IQ result = iq.createResult();
                                    result.setExtension(new ItemDiscovery(itemNode.getNode(), items));
                                    xmppSession.send(result);
                                    e.consume();
                                } else {
                                    xmppSession.send(iq.createError(new StanzaError(new ItemNotFound())));
                                    e.consume();
                                }
                            }
                        }
                    }
View Full Code Here

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

                    logger.log(Level.WARNING, e.getMessage(), e);
                }
            }
            if (incoming && (iq.getType() == IQ.Type.GET || iq.getType() == IQ.Type.SET) && !iqEvent.isConsumed()) {
                // return <service-unavailble/> if the <iq/> is not understood or has not been handles by an event listener.
                IQ error = iq.createError(new StanzaError(new ServiceUnavailable()));
                send(error);
            }
        }
    }
View Full Code Here

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

                                        EntityTime entityTime = entityTimeManager.getEntityTime(Jid.valueOf("juliet@example.net/balcony"));
                                    } catch (XmppException e) {
                                        if (e instanceof NoResponseException) {
                                            // The entity did not respond
                                        } else if (e instanceof StanzaException) {
                                            StanzaError stanzaError = ((StanzaException) e).getStanza().getError();
                                            if (stanzaError.getCondition() instanceof ServiceUnavailable) {
                                                // The entity returned a <service-unavailable/> stanza error.
                                            }
                                        }
                                    }
                                }
View Full Code Here
TOP
Copyright © 2018 www.massapi.com. 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.