} else { StanzaError.Builder builder = PacketParserUtils.parseError(parser); throw new XMPPException.XMPPErrorException(null, builder.build());
StanzaError.Builder xmppError = StanzaError.getBuilder().setCondition(StanzaError.Condition.internal_server_error).setDescriptiveEnText(e.getMessage()); return respondError(response, xmppError);
builder.setType(StanzaError.Type.fromString(parser.getAttributeValue("", "type"))); builder.setErrorGenerator(parser.getAttributeValue("", "by")); break; default: builder.setCondition(StanzaError.Condition.fromString(name)); if (!parser.isEmptyElementTag()) { builder.setConditionText(parser.nextText()); builder.setExtensions(extensions).setDescriptiveTexts(descriptiveTexts); return builder;
builder.setType(StanzaError.Type.fromString(parser.getAttributeValue("", "type"))); builder.setErrorGenerator(parser.getAttributeValue("", "by")); break; default: builder.setCondition(StanzaError.Condition.fromString(name)); if (!parser.isEmptyElementTag()) { builder.setConditionText(parser.nextText()); builder.setExtensions(extensions).setDescriptiveTexts(descriptiveTexts); return builder;
public static Builder getBuilder(Condition condition) { return getBuilder().setCondition(condition); }
public static Builder getBuilder() { return new Builder(); }
public static Builder getBuilder(StanzaError xmppError) { return getBuilder().copyFrom(xmppError); }
/** * 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()); }
public static StanzaError.Builder from(Condition condition, String descriptiveText) { StanzaError.Builder builder = getBuilder().setCondition(condition); if (descriptiveText != null) { Map<String, String> descriptiveTexts = new HashMap<>(); descriptiveTexts.put("en", descriptiveText); builder.setDescriptiveTexts(descriptiveTexts); } return builder; }
public Builder copyFrom(StanzaError xmppError) { setCondition(xmppError.getCondition()); setType(xmppError.getType()); setConditionText(xmppError.getConditionText()); setErrorGenerator(xmppError.getErrorGenerator()); setStanza(xmppError.getStanza()); setDescriptiveTexts(xmppError.descriptiveTexts); setTextNamespace(xmppError.textNamespace); setExtensions(xmppError.extensions); return this; }
/** * Complete and send an error. Complete all the null fields in an IQ error * response, using the session information we have or some info from the * incoming packet. * * @param iq * The Jingle stanza we are responding to * @param jingleError * the IQ stanza we want to complete and send */ public IQ createJingleError(IQ iq, JingleError jingleError) { IQ errorPacket = null; if (jingleError != null) { // TODO This is wrong according to XEP-166 ยง 10, but this jingle implementation is deprecated anyways StanzaError.Builder builder = StanzaError.getBuilder(StanzaError.Condition.undefined_condition); builder.addExtension(jingleError); errorPacket = IQ.createErrorResponse(iq, builder); // errorPacket.addExtension(jingleError); // NO! Let the normal state machinery do all of the sending. // getConnection().sendStanza(perror); LOGGER.severe("Error sent: " + errorPacket.toXML(null)); } return errorPacket; }
/** * 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()); }
public static Builder getBuilder() { return new Builder(); }
public static Builder getBuilder(StanzaError xmppError) { return getBuilder().copyFrom(xmppError); }
public static Builder getBuilder(Condition condition) { return getBuilder().setCondition(condition); }
/** * Responds an error with an specific condition. * * @param response the response to send. * @param condition the condition of the error. * @param specificCondition the adhoc command error condition. * @throws NotConnectedException */ private static IQ respondError(AdHocCommandData response, StanzaError.Condition condition, AdHocCommand.SpecificErrorCondition specificCondition) { StanzaError.Builder error = StanzaError.getBuilder(condition).addExtension(new AdHocCommandData.SpecificError(specificCondition)); return respondError(response, error); }
@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()); } }