Java Code Examples for org.jivesoftware.smack.packet.IQ#createErrorResponse()
The following examples show how to use
org.jivesoftware.smack.packet.IQ#createErrorResponse() .
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: JingleSession.java From Smack with Apache License 2.0 | 6 votes |
/** * 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 * @return the jingle error IQ. */ 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 = StanzaError.getBuilder() .setCondition(StanzaError.Condition.undefined_condition) .addExtension(jingleError) .build(); 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()); } return errorPacket; }
Example 2
Source File: DnsOverXmppManager.java From Smack with Apache License 2.0 | 5 votes |
@Override public IQ handleIQRequest(IQ iqRequest) { DnsOverXmppResolver resolver = DnsOverXmppManager.this.resolver; if (resolver == null) { LOGGER.info("Resolver was null while attempting to handle " + iqRequest); return null; } DnsIq dnsIqRequest = (DnsIq) iqRequest; DnsMessage query = dnsIqRequest.getDnsMessage(); DnsMessage response; try { response = resolver.resolve(query); } catch (IOException exception) { StanzaError errorBuilder = StanzaError.getBuilder() .setType(Type.CANCEL) .setCondition(Condition.internal_server_error) .setDescriptiveEnText("Exception while resolving your DNS query", exception) .build() ; IQ errorResponse = IQ.createErrorResponse(iqRequest, errorBuilder); return errorResponse; } if (query.id != response.id) { // The ID may not match because the resolver returned a cached result. response = response.asBuilder().setId(query.id).build(); } DnsIq dnsIqResult = new DnsIq(response); dnsIqResult.setType(IQ.Type.result); return dnsIqResult; }
Example 3
Source File: Socks5BytestreamRequest.java From Smack with Apache License 2.0 | 5 votes |
/** * Cancels the SOCKS5 Bytestream request by sending an error to the initiator and building a * XMPP exception. * * @param streamHosts the stream hosts. * @throws NotConnectedException if the XMPP connection is not connected. * @throws InterruptedException if the calling thread was interrupted. * @throws CouldNotConnectToAnyProvidedSocks5Host as expected result. * @throws NoSocks5StreamHostsProvided if no stream host was provided. */ private void cancelRequest(Map<StreamHost, Exception> streamHostsExceptions) throws NotConnectedException, InterruptedException, CouldNotConnectToAnyProvidedSocks5Host, NoSocks5StreamHostsProvided { final Socks5Exception.NoSocks5StreamHostsProvided noHostsProvidedException; final Socks5Exception.CouldNotConnectToAnyProvidedSocks5Host couldNotConnectException; final String errorMessage; if (streamHostsExceptions.isEmpty()) { noHostsProvidedException = new Socks5Exception.NoSocks5StreamHostsProvided(); couldNotConnectException = null; errorMessage = noHostsProvidedException.getMessage(); } else { noHostsProvidedException = null; couldNotConnectException = Socks5Exception.CouldNotConnectToAnyProvidedSocks5Host.construct(streamHostsExceptions); errorMessage = couldNotConnectException.getMessage(); } StanzaError error = StanzaError.from(StanzaError.Condition.item_not_found, errorMessage).build(); IQ errorIQ = IQ.createErrorResponse(this.bytestreamRequest, error); this.manager.getConnection().sendStanza(errorIQ); if (noHostsProvidedException != null) { throw noHostsProvidedException; } else { throw couldNotConnectException; } }
Example 4
Source File: FileTransferManager.java From Smack with Apache License 2.0 | 5 votes |
/** * Reject an incoming file transfer. * <p> * Specified in XEP-95 4.2 and 3.2 Example 8 * </p> * @param request TODO javadoc me please * @throws NotConnectedException if the XMPP connection is not connected. * @throws InterruptedException if the calling thread was interrupted. */ protected void rejectIncomingFileTransfer(FileTransferRequest request) throws NotConnectedException, InterruptedException { StreamInitiation initiation = request.getStreamInitiation(); // Reject as specified in XEP-95 4.2. Note that this is not to be confused with the Socks 5 // Bytestream rejection as specified in XEP-65 5.3.1 Example 13, which says that // 'not-acceptable' should be returned. This is done by Smack in // Socks5BytestreamManager.replyRejectPacket(IQ). IQ rejection = IQ.createErrorResponse(initiation, StanzaError.getBuilder( StanzaError.Condition.forbidden).build()); connection().sendStanza(rejection); }
Example 5
Source File: JingleUtil.java From Smack with Apache License 2.0 | 5 votes |
public IQ createErrorUnknownSession(Jingle request) { StanzaError error = StanzaError.getBuilder() .setCondition(StanzaError.Condition.item_not_found) .addExtension(JingleError.UNKNOWN_SESSION) .build(); return IQ.createErrorResponse(request, error); }
Example 6
Source File: JingleUtil.java From Smack with Apache License 2.0 | 5 votes |
public IQ createErrorUnsupportedInfo(Jingle request) { StanzaError error = StanzaError.getBuilder() .setCondition(StanzaError.Condition.feature_not_implemented) .addExtension(JingleError.UNSUPPORTED_INFO) .build(); return IQ.createErrorResponse(request, error); }
Example 7
Source File: JingleUtil.java From Smack with Apache License 2.0 | 5 votes |
public IQ createErrorTieBreak(Jingle request) { StanzaError error = StanzaError.getBuilder() .setCondition(StanzaError.Condition.conflict) .addExtension(JingleError.TIE_BREAK) .build(); return IQ.createErrorResponse(request, error); }
Example 8
Source File: JingleUtil.java From Smack with Apache License 2.0 | 5 votes |
public IQ createErrorOutOfOrder(Jingle request) { StanzaError error = StanzaError.getBuilder() .setCondition(StanzaError.Condition.unexpected_request) .addExtension(JingleError.OUT_OF_ORDER) .build(); return IQ.createErrorResponse(request, error); }
Example 9
Source File: Roster.java From Smack with Apache License 2.0 | 4 votes |
@Override public IQ handleIQRequest(IQ iqRequest) { final XMPPConnection connection = connection(); RosterPacket rosterPacket = (RosterPacket) iqRequest; EntityFullJid ourFullJid = connection.getUser(); if (ourFullJid == null) { LOGGER.warning("Ignoring roster push " + iqRequest + " while " + connection + " has no bound resource. This may be a server bug."); return null; } // Roster push (RFC 6121, 2.1.6) // A roster push with a non-empty from not matching our address MUST be ignored EntityBareJid ourBareJid = ourFullJid.asEntityBareJid(); Jid from = rosterPacket.getFrom(); if (from != null) { if (from.equals(ourFullJid)) { // Since RFC 6121 roster pushes are no longer allowed to // origin from the full JID as it was the case with RFC // 3921. Log a warning an continue processing the push. // See also SMACK-773. LOGGER.warning( "Received roster push from full JID. This behavior is since RFC 6121 not longer standard compliant. " + "Please ask your server vendor to fix this and comply to RFC 6121 § 2.1.6. IQ roster push stanza: " + iqRequest); } else if (!from.equals(ourBareJid)) { LOGGER.warning("Ignoring roster push with a non matching 'from' ourJid='" + ourBareJid + "' from='" + from + "'"); return IQ.createErrorResponse(iqRequest, Condition.service_unavailable); } } // A roster push must contain exactly one entry Collection<Item> items = rosterPacket.getRosterItems(); if (items.size() != 1) { LOGGER.warning("Ignoring roster push with not exactly one entry. size=" + items.size()); return IQ.createErrorResponse(iqRequest, Condition.bad_request); } Collection<Jid> addedEntries = new ArrayList<>(); Collection<Jid> updatedEntries = new ArrayList<>(); Collection<Jid> deletedEntries = new ArrayList<>(); Collection<Jid> unchangedEntries = new ArrayList<>(); // We assured above that the size of items is exactly 1, therefore we are able to // safely retrieve this single item here. Item item = items.iterator().next(); RosterEntry entry = new RosterEntry(item, Roster.this, connection); String version = rosterPacket.getVersion(); if (item.getItemType().equals(RosterPacket.ItemType.remove)) { deleteEntry(deletedEntries, entry); if (rosterStore != null) { rosterStore.removeEntry(entry.getJid(), version); } } else if (hasValidSubscriptionType(item)) { addUpdateEntry(addedEntries, updatedEntries, unchangedEntries, item, entry); if (rosterStore != null) { rosterStore.addEntry(item, version); } } removeEmptyGroups(); // Fire event for roster listeners. fireRosterChangedEvent(addedEntries, updatedEntries, deletedEntries); return IQ.createResultIQ(rosterPacket); }
Example 10
Source File: InBandBytestreamSession.java From Smack with Apache License 2.0 | 4 votes |
@Override protected StanzaListener getDataPacketListener() { return new StanzaListener() { private long lastSequence = -1; @Override public void processStanza(Stanza packet) throws NotConnectedException, InterruptedException { // get data packet extension DataPacketExtension data = ((Data) packet).getDataPacketExtension(); /* * check if sequence was not used already (see XEP-0047 Section 2.2) */ if (data.getSeq() <= this.lastSequence) { IQ unexpectedRequest = IQ.createErrorResponse((IQ) packet, StanzaError.Condition.unexpected_request); connection.sendStanza(unexpectedRequest); return; } // check if encoded data is valid (see XEP-0047 Section 2.2) if (data.getDecodedData() == null) { // data is invalid; respond with bad-request error IQ badRequest = IQ.createErrorResponse((IQ) packet, StanzaError.Condition.bad_request); connection.sendStanza(badRequest); return; } // data is valid; add to data queue dataQueue.offer(data); // confirm IQ IQ confirmData = IQ.createResultIQ((IQ) packet); connection.sendStanza(confirmData); // set last seen sequence this.lastSequence = data.getSeq(); if (this.lastSequence == 65535) { this.lastSequence = -1; } } }; }
Example 11
Source File: JingleUtil.java From Smack with Apache License 2.0 | 4 votes |
public IQ createErrorUnknownInitiator(Jingle request) { return IQ.createErrorResponse(request, StanzaError.Condition.service_unavailable); }
Example 12
Source File: JingleUtil.java From Smack with Apache License 2.0 | 4 votes |
public IQ createErrorMalformedRequest(Jingle request) { return IQ.createErrorResponse(request, StanzaError.Condition.bad_request); }
Example 13
Source File: InBandBytestreamManager.java From Smack with Apache License 2.0 | 2 votes |
/** * Responses to the given IQ packet's sender with an XMPP error that an In-Band Bytestream is * not accepted. * * @param request IQ stanza that should be answered with a not-acceptable error * @throws NotConnectedException if the XMPP connection is not connected. * @throws InterruptedException if the calling thread was interrupted. */ protected void replyRejectPacket(IQ request) throws NotConnectedException, InterruptedException { IQ error = IQ.createErrorResponse(request, StanzaError.Condition.not_acceptable); connection().sendStanza(error); }
Example 14
Source File: InBandBytestreamManager.java From Smack with Apache License 2.0 | 2 votes |
/** * Responses to the given IQ packet's sender with an XMPP error that an In-Band Bytestream open * request is rejected because its block size is greater than the maximum allowed block size. * * @param request IQ stanza that should be answered with a resource-constraint error * @throws NotConnectedException if the XMPP connection is not connected. * @throws InterruptedException if the calling thread was interrupted. */ protected void replyResourceConstraintPacket(IQ request) throws NotConnectedException, InterruptedException { IQ error = IQ.createErrorResponse(request, StanzaError.Condition.resource_constraint); connection().sendStanza(error); }
Example 15
Source File: InBandBytestreamManager.java From Smack with Apache License 2.0 | 2 votes |
/** * Responses to the given IQ packet's sender with an XMPP error that an In-Band Bytestream * session could not be found. * * @param request IQ stanza that should be answered with a item-not-found error * @throws NotConnectedException if the XMPP connection is not connected. * @throws InterruptedException if the calling thread was interrupted. */ protected void replyItemNotFoundPacket(IQ request) throws NotConnectedException, InterruptedException { IQ error = IQ.createErrorResponse(request, StanzaError.Condition.item_not_found); connection().sendStanza(error); }
Example 16
Source File: Socks5BytestreamManager.java From Smack with Apache License 2.0 | 2 votes |
/** * Responses to the given packet's sender with an XMPP error that a SOCKS5 Bytestream is not * accepted. * <p> * Specified in XEP-65 5.3.1 (Example 13) * </p> * * @param packet Stanza that should be answered with a not-acceptable error * @throws NotConnectedException if the XMPP connection is not connected. * @throws InterruptedException if the calling thread was interrupted. */ protected void replyRejectPacket(IQ packet) throws NotConnectedException, InterruptedException { StanzaError xmppError = StanzaError.getBuilder(StanzaError.Condition.not_acceptable).build(); IQ errorIQ = IQ.createErrorResponse(packet, xmppError); connection().sendStanza(errorIQ); }