/** * Returns the error as XML. * * @return the error as XML. */ public XmlStringBuilder toXML() { return toXML(null); }
/** * Append an XMPPError is this stanza has one set. * * @param xml the XmlStringBuilder to append the error to. */ protected void appendErrorIfExists(XmlStringBuilder xml, String enclosingNamespace) { StanzaError error = getError(); if (error != null) { xml.append(error.toXML(enclosingNamespace)); } } }
@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)); }
/** * 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()); }
/** * Returns the error as XML. * * @return the error as XML. */ public XmlStringBuilder toXML() { return toXML(null); }
/** * Append an XMPPError is this stanza has one set. * * @param xml the XmlStringBuilder to append the error to. */ protected void appendErrorIfExists(XmlStringBuilder xml, String enclosingNamespace) { StanzaError error = getError(); if (error != null) { xml.append(error.toXML(enclosingNamespace)); } } }