Java Code Examples for org.jivesoftware.smack.packet.StanzaError#getCondition()
The following examples show how to use
org.jivesoftware.smack.packet.StanzaError#getCondition() .
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: JidPrepManager.java From Smack with Apache License 2.0 | 6 votes |
public String requestJidPrep(Jid jidPrepService, String jidToBePrepped) throws NoResponseException, NotConnectedException, InterruptedException, XMPPErrorException { JidPrepIq jidPrepRequest = new JidPrepIq(jidToBePrepped); jidPrepRequest.setTo(jidPrepService); JidPrepIq jidPrepResponse; try { jidPrepResponse = connection().sendIqRequestAndWaitForResponse(jidPrepRequest); } catch (XMPPErrorException e) { StanzaError stanzaError = e.getStanzaError(); if (stanzaError.getCondition() == StanzaError.Condition.jid_malformed) { // jid-malformed is, sadly, returned if the jid can not be normalized. This means we can not distinguish // if the error is returned because e.g. the IQ's 'to' address was malformed (c.f. RFC 6120 § 8.3.3.8) // or if the JID to prep was malformed. Assume the later is the case and return 'null'. return null; } throw e; } return jidPrepResponse.getJid(); }
Example 2
Source File: OutgoingFileTransfer.java From Smack with Apache License 2.0 | 6 votes |
private void handleXMPPException(XMPPErrorException e) { StanzaError error = e.getStanzaError(); if (error != null) { switch (error.getCondition()) { case forbidden: setStatus(Status.refused); return; case bad_request: setStatus(Status.error); setError(Error.not_acceptable); break; default: setStatus(FileTransfer.Status.error); } } setException(e); }
Example 3
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 4
Source File: ConferenceUtils.java From Spark with Apache License 2.0 | 5 votes |
/** * Returns an explanation for the exception. * * @param error The XMPP error * @return the reason for the exception. * @see <a href="http://xmpp.org/extensions/xep-0045.html#enter-errorcodes">XEP-0045 Error Conditions</a> */ public static String getReason(StanzaError error) { if (error == null) { return Res.getString("message.error.no.response"); } switch ( error.getCondition() ) { case conflict: return Res.getString("message.error.nickname.in.use"); case forbidden: return Res.getString("message.you.have.been.banned"); case item_not_found: return Res.getString("message.error.room.not.exist"); case not_acceptable: return Res.getString("message.error.must.use.reserved.nick"); case not_allowed: return Res.getString("message.error.no.permission.create.room"); case not_authorized: return Res.getString("message.error.room.password.incorrect"); case registration_required: return Res.getString("message.error.not.member"); default: return Res.getString("message.default.error") + ": " + error.getConditionText(); } }