Java Code Examples for org.jivesoftware.smack.packet.StanzaError#Condition
The following examples show how to use
org.jivesoftware.smack.packet.StanzaError#Condition .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: RosterHandler.java From desktopclient-java with GNU General Public License v3.0 | 5 votes |
public void onPresenceError(JID jid, StanzaError.Type type, StanzaError.Condition condition) { if (type != StanzaError.Type.CANCEL) // it can't be that bad) return; Error error = null; switch (condition) { case remote_server_not_found: error = Error.SERVER_NOT_FOUND; } if (error == null) { LOGGER.warning("unhandled error condition: "+condition); return; } Contact contact = mModel.contacts().get(jid).orElse(null); if (contact == null) { LOGGER.info("can't find contact with jid: "+jid); return; } if (contact.getOnline() == Contact.Online.ERROR) // we already know this return; contact.setOnlineStatus(Contact.Online.ERROR); mControl.getViewControl().changed(new ViewEvent.PresenceError(contact, error)); }
Example 2
Source File: ParseStreamManagement.java From Smack with Apache License 2.0 | 5 votes |
public static Failed failed(XmlPullParser parser) throws XmlPullParserException, IOException { ParserUtils.assertAtStartTag(parser); String name; StanzaError.Condition condition = null; List<StanzaErrorTextElement> textElements = new ArrayList<>(4); outerloop: while (true) { XmlPullParser.Event event = parser.next(); switch (event) { case START_ELEMENT: name = parser.getName(); String namespace = parser.getNamespace(); if (StanzaError.ERROR_CONDITION_AND_TEXT_NAMESPACE.equals(namespace)) { if (name.equals(AbstractTextElement.ELEMENT)) { String lang = ParserUtils.getXmlLang(parser); String text = parser.nextText(); StanzaErrorTextElement stanzaErrorTextElement = new StanzaErrorTextElement(text, lang); textElements.add(stanzaErrorTextElement); } else { condition = StanzaError.Condition.fromString(name); } } break; case END_ELEMENT: name = parser.getName(); if (Failed.ELEMENT.equals(name)) { break outerloop; } break; default: // Catch all for incomplete switch (MissingCasesInEnumSwitch) statement. break; } } ParserUtils.assertAtEndTag(parser); return new Failed(condition, textElements); }
Example 3
Source File: StreamManagement.java From Smack with Apache License 2.0 | 5 votes |
public Failed(StanzaError.Condition condition, List<StanzaErrorTextElement> textElements) { this.condition = condition; if (textElements == null) { this.textElements = Collections.emptyList(); } else { this.textElements = Collections.unmodifiableList(textElements); } }
Example 4
Source File: ParseStreamManagementTest.java From Smack with Apache License 2.0 | 5 votes |
@Test public void testParseFailedError() throws Exception { StanzaError.Condition errorCondition = StanzaError.Condition.unexpected_request; String failedStanza = XMLBuilder.create("failed") .a("xmlns", "urn:xmpp:sm:3") .element(errorCondition.toString(), StanzaError.ERROR_CONDITION_AND_TEXT_NAMESPACE) .asString(outputProperties); StreamManagement.Failed failedPacket = ParseStreamManagement.failed( PacketParserUtils.getParserFor(failedStanza)); assertNotNull(failedPacket); assertTrue(failedPacket.getStanzaErrorCondition() == errorCondition); }
Example 5
Source File: PingManager.java From Smack with Apache License 2.0 | 5 votes |
private boolean isValidErrorPong(Jid destinationJid, XMPPErrorException xmppErrorException) { // If it is an error error response and the destination was our own service, then this must mean that the // service responded, i.e. is up and pingable. if (destinationJid.equals(connection().getXMPPServiceDomain())) { return true; } final StanzaError xmppError = xmppErrorException.getStanzaError(); // We may received an error response from an intermediate service returning an error like // 'remote-server-not-found' or 'remote-server-timeout' to us (which would fake the 'from' address, // see RFC 6120 § 8.3.1 2.). Or the recipient could became unavailable. // Sticking with the current rules of RFC 6120/6121, it is undecidable at this point whether we received an // error response from the pinged entity or not. This is because a service-unavailable error condition is // *required* (as per the RFCs) to be send back in both relevant cases: // 1. When the receiving entity is unaware of the IQ request type. RFC 6120 § 8.4.: // "If an intended recipient receives an IQ stanza of type "get" or // "set" containing a child element qualified by a namespace it does // not understand, then the entity MUST return an IQ stanza of type // "error" with an error condition of <service-unavailable/>. // 2. When the receiving resource is not available. RFC 6121 § 8.5.3.2.3. // Some clients don't obey the first rule and instead send back a feature-not-implement condition with type 'cancel', // which allows us to consider this response as valid "error response" pong. StanzaError.Type type = xmppError.getType(); StanzaError.Condition condition = xmppError.getCondition(); return type == StanzaError.Type.CANCEL && condition == StanzaError.Condition.feature_not_implemented; }
Example 6
Source File: IBBPacketUtils.java From Smack with Apache License 2.0 | 5 votes |
/** * Returns an error IQ. * * @param from the senders JID * @param to the recipients JID * @param condition the XMPP error condition * @return an error IQ */ public static IQ createErrorIQ(Jid from, Jid to, StanzaError.Condition condition) { StanzaError xmppError = StanzaError.getBuilder(condition).build(); IQ errorIQ = new ErrorIQ(xmppError); errorIQ.setType(IQ.Type.error); errorIQ.setFrom(from); errorIQ.setTo(to); return errorIQ; }
Example 7
Source File: AccountCreationWizard.java From Spark with Apache License 2.0 | 5 votes |
/** * Called if the account creation failed. * * @param condition the error code. */ private void accountCreationFailed( StanzaError.Condition condition ) { String message = Res.getString("message.create.account"); if (condition == StanzaError.Condition.conflict) { message = Res.getString("message.already.exists"); usernameField.setText(""); usernameField.requestFocus(); } UIManager.put("OptionPane.okButtonText", Res.getString("ok")); JOptionPane.showMessageDialog(this, message, Res.getString("title.create.problem"), JOptionPane.ERROR_MESSAGE); createAccountButton.setEnabled(true); }
Example 8
Source File: Control.java From desktopclient-java with GNU General Public License v3.0 | 4 votes |
public void onMessageError(MessageIDs ids, StanzaError.Condition condition, String errorText) { OutMessage message = this.findMessage(ids).orElse(null); if (message == null) return ; message.setServerError(condition.toString(), errorText); }
Example 9
Source File: StreamManagement.java From Smack with Apache License 2.0 | 4 votes |
public StanzaError.Condition getStanzaErrorCondition() { return condition; }
Example 10
Source File: XMPPException.java From Smack with Apache License 2.0 | 4 votes |
public FailedNonzaException(Nonza nonza, StanzaError.Condition condition) { this.condition = condition; this.nonza = nonza; }
Example 11
Source File: XMPPException.java From Smack with Apache License 2.0 | 4 votes |
public StanzaError.Condition getCondition() { return condition; }
Example 12
Source File: AdHocCommandManager.java From Smack with Apache License 2.0 | 3 votes |
/** * 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 if the XMPP connection is not connected. */ private static IQ respondError(AdHocCommandData response, StanzaError.Condition condition, AdHocCommand.SpecificErrorCondition specificCondition) { StanzaError error = StanzaError.getBuilder(condition) .addExtension(new AdHocCommandData.SpecificError(specificCondition)) .build(); return respondError(response, error); }
Example 13
Source File: AdHocCommandManager.java From Smack with Apache License 2.0 | 2 votes |
/** * Responds an error with an specific condition. * * @param response the response to send. * @param condition the condition of the error. * @throws NotConnectedException if the XMPP connection is not connected. */ private static IQ respondError(AdHocCommandData response, StanzaError.Condition condition) { return respondError(response, StanzaError.getBuilder(condition).build()); }