/** * Creates a new XMPPErrorException with the given builder. * * @param xmppErrorBuilder * @deprecated Use {@link #XMPPErrorException(Stanza, StanzaError)} instead. */ @Deprecated public XMPPErrorException(StanzaError.Builder xmppErrorBuilder) { this(null, xmppErrorBuilder.build()); }
@Test(expected = IllegalArgumentException.class) public void descriptiveTextNullLangPassedMap() throws Exception { final String text = "Dummy descriptive text"; Map<String, String> texts = new HashMap<>(); texts.put(null, text); StanzaError .getBuilder(StanzaError.Condition.internal_server_error) .setDescriptiveTexts(texts) .build(); }
} else { StanzaError.Builder builder = PacketParserUtils.parseError(parser); throw new XMPPException.XMPPErrorException(null, builder.build());
/** * Creates a new XMPPErrorException with the given builder. * * @param xmppErrorBuilder * @deprecated Use {@link #XMPPErrorException(Stanza, StanzaError)} instead. */ @Deprecated public XMPPErrorException(StanzaError.Builder xmppErrorBuilder) { this(null, xmppErrorBuilder.build()); }
/** * Sets the error for this stanza. * * @param xmppErrorBuilder the error to associate with this stanza. */ public void setError(StanzaError.Builder xmppErrorBuilder) { if (xmppErrorBuilder == null) { return; } xmppErrorBuilder.setStanza(this); error = xmppErrorBuilder.build(); }
/** * Test creating a error response based on an IQ request. * @throws XmppStringprepException */ @Test public void testGeneratingValidErrorResponse() throws XmppStringprepException { final StanzaError.Builder error = StanzaError.getBuilder(StanzaError.Condition.bad_request); final IQ request = new TestIQ(ELEMENT, NAMESPACE); request.setType(IQ.Type.set); request.setFrom(JidCreate.from("sender@test/Smack")); request.setTo(JidCreate.from("receiver@test/Smack")); final IQ result = IQ.createErrorResponse(request, error); assertEquals(IQ.Type.error, result.getType()); assertNotNull(result.getStanzaId()); assertEquals(request.getStanzaId(), result.getStanzaId()); assertEquals(request.getFrom(), result.getTo()); assertEquals(error.build().toXML(), result.getError().toXML()); // TODO this test was never valid // assertEquals(CHILD_ELEMENT, result.getChildElementXML()); }
@Test public void ensureNoEmptyLangInDescriptiveText() throws Exception { final String text = "Dummy descriptive text"; Map<String, String> texts = new HashMap<>(); texts.put("", text); StanzaError error = StanzaError .getBuilder(StanzaError.Condition.internal_server_error) .setDescriptiveTexts(texts) .build(); final String errorXml = XMLBuilder .create(StanzaError.ERROR).a("type", "cancel").up() .element("internal-server-error", StanzaError.ERROR_CONDITION_AND_TEXT_NAMESPACE).up() .element("text", StanzaError.ERROR_CONDITION_AND_TEXT_NAMESPACE).t(text).up() .asString(); XmlUnitUtils.assertSimilar(errorXml, error.toXML(StreamOpen.CLIENT_NAMESPACE)); }
/** * Cancels the SOCKS5 Bytestream request by sending an error to the initiator and building a * XMPP exception. * @throws XMPPErrorException * @throws NotConnectedException * @throws InterruptedException */ private void cancelRequest() throws XMPPErrorException, NotConnectedException, InterruptedException { String errorMessage = "Could not establish socket with any provided host"; StanzaError.Builder error = StanzaError.from(StanzaError.Condition.item_not_found, errorMessage); IQ errorIQ = IQ.createErrorResponse(this.bytestreamRequest, error); this.manager.getConnection().sendStanza(errorIQ); throw new XMPPErrorException(errorIQ, error.build()); }
@Test public void ensureNoNullLangInParsedDescriptiveTexts() throws Exception { final String text = "Dummy descriptive text"; final String errorXml = XMLBuilder .create(StanzaError.ERROR).a("type", "cancel").up() .element("internal-server-error", StanzaError.ERROR_CONDITION_AND_TEXT_NAMESPACE).up() .element("text", StanzaError.ERROR_CONDITION_AND_TEXT_NAMESPACE).t(text).up() .asString(); XmlPullParser parser = TestUtils.getParser(errorXml); StanzaError error = PacketParserUtils.parseError(parser).build(); assertEquals(text, error.getDescriptiveText()); } }
@SmackIntegrationTest public void throwRuntimeExceptionTest() throws XMPPErrorException { Message message = new Message(); throw new XMPPException.XMPPErrorException(message, StanzaError.from(StanzaError.Condition.bad_request, DESCRIPTIVE_TEXT).build()); } }
/** * Sets the error for this stanza. * * @param xmppErrorBuilder the error to associate with this stanza. */ public void setError(StanzaError.Builder xmppErrorBuilder) { if (xmppErrorBuilder == null) { return; } xmppErrorBuilder.setStanza(this); error = xmppErrorBuilder.build(); }