public IQ createErrorMalformedRequest(Jingle request) { return IQ.createErrorResponse(request, StanzaError.Condition.bad_request); }
public IQ createErrorUnknownInitiator(Jingle request) { return IQ.createErrorResponse(request, StanzaError.Condition.service_unavailable); }
@Override public IQ handleIQRequest(IQ iqRequest) { if (ourVersion == null) { return IQ.createErrorResponse(iqRequest, Condition.not_acceptable); } return Version.createResultFor(iqRequest, ourVersion); } });
@Override public IQ handleIQRequest(IQ iqRequest) { if (enabled) { return Time.createResponse(iqRequest); } else { return IQ.createErrorResponse(iqRequest, Condition.not_acceptable); } } });
public static ErrorIQ createErrorResponse(final IQ request, final StanzaError.Condition condition) { return createErrorResponse(request, StanzaError.getBuilder(condition)); }
/** * Convenience method to create a new {@link Type#error IQ.Type.error} IQ * based on a {@link Type#get IQ.Type.get} or {@link Type#set IQ.Type.set} * IQ. The new stanza will be initialized with:<ul> * <li>The sender set to the recipient of the originating IQ. * <li>The recipient set to the sender of the originating IQ. * <li>The type set to {@link Type#error IQ.Type.error}. * <li>The id set to the id of the originating IQ. * <li>The child element contained in the associated originating IQ. * <li>The provided {@link StanzaError XMPPError}. * </ul> * * @param request the {@link Type#get IQ.Type.get} or {@link Type#set IQ.Type.set} IQ packet. * @param error the error to associate with the created IQ packet. * @throws IllegalArgumentException if the IQ stanza does not have a type of * {@link Type#get IQ.Type.get} or {@link Type#set IQ.Type.set}. * @return a new {@link Type#error IQ.Type.error} IQ based on the originating IQ. */ public static ErrorIQ createErrorResponse(final IQ request, final StanzaError error) { return createErrorResponse(request, StanzaError.getBuilder(error)); }
/** * 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 * @throws InterruptedException */ protected void replyResourceConstraintPacket(IQ request) throws NotConnectedException, InterruptedException { IQ error = IQ.createErrorResponse(request, StanzaError.Condition.resource_constraint); connection().sendStanza(error); }
/** * 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 * @throws InterruptedException */ protected void replyItemNotFoundPacket(IQ request) throws NotConnectedException, InterruptedException { IQ error = IQ.createErrorResponse(request, StanzaError.Condition.item_not_found); connection().sendStanza(error); }
/** * 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 * @throws InterruptedException */ protected void replyRejectPacket(IQ request) throws NotConnectedException, InterruptedException { IQ error = IQ.createErrorResponse(request, StanzaError.Condition.not_acceptable); connection().sendStanza(error); }
public IQ createErrorUnsupportedInfo(Jingle request) { StanzaError.Builder error = StanzaError.getBuilder(); error.setCondition(StanzaError.Condition.feature_not_implemented) .addExtension(JingleError.UNSUPPORTED_INFO); return IQ.createErrorResponse(request, error); }
public IQ createErrorOutOfOrder(Jingle request) { StanzaError.Builder error = StanzaError.getBuilder(); error.setCondition(StanzaError.Condition.unexpected_request) .addExtension(JingleError.OUT_OF_ORDER); return IQ.createErrorResponse(request, error); }
public IQ createErrorTieBreak(Jingle request) { StanzaError.Builder error = StanzaError.getBuilder(); error.setCondition(StanzaError.Condition.conflict) .addExtension(JingleError.TIE_BREAK); return IQ.createErrorResponse(request, error); }
public IQ createErrorUnknownSession(Jingle request) { StanzaError.Builder error = StanzaError.getBuilder(); error.setCondition(StanzaError.Condition.item_not_found) .addExtension(JingleError.UNKNOWN_SESSION); return IQ.createErrorResponse(request, error); }
/** * 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 * @throws InterruptedException */ protected void replyRejectPacket(IQ packet) throws NotConnectedException, InterruptedException { StanzaError.Builder xmppError = StanzaError.getBuilder(StanzaError.Condition.not_acceptable); IQ errorIQ = IQ.createErrorResponse(packet, xmppError); connection().sendStanza(errorIQ); }
/** * Reject an incoming file transfer. * <p> * Specified in XEP-95 4.2 and 3.2 Example 8 * </p> * @param request * @throws NotConnectedException * @throws InterruptedException */ 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)); connection().sendStanza(rejection); } }
/** * 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()); }
@Override public IQ handleIoTIqRequest(IQ iqRequest) { // TODO Lookup thing and provide data. IoTSetRequest iotSetRequest = (IoTSetRequest) iqRequest; // TODO Add support for multiple things(/NodeInfos). final Thing thing = things.get(NodeInfo.EMPTY); if (thing == null) { // TODO return error if not at least one thing registered. return null; } ThingControlRequest controlRequest = thing.getControlRequestHandler(); if (controlRequest == null) { // TODO return error if no request handler for things. return null; } try { controlRequest.processRequest(iotSetRequest.getFrom(), iotSetRequest.getSetData()); } catch (XMPPErrorException e) { return IQ.createErrorResponse(iotSetRequest, e.getStanzaError()); } return new IoTSetResponse(iotSetRequest); } });
@Override public IQ handleIQRequest(IQ iqRequest) { if (!enabled) return IQ.createErrorResponse(iqRequest, Condition.not_acceptable); LastActivity message = new LastActivity(); message.setType(IQ.Type.result); message.setTo(iqRequest.getFrom()); message.setFrom(iqRequest.getTo()); message.setStanzaId(iqRequest.getStanzaId()); message.setLastActivity(getIdleTime()); return message; } });
/** * According to <a href="http://xmpp.org/rfcs/rfc3920.html#stanzas-semantics-iq" * >RFC3920: IQ Semantics</a> we shouldn't respond to an IQ of type error. * @throws XmppStringprepException */ @Test public void testGeneratingErrorBasedOnError() throws XmppStringprepException { final StanzaError.Builder error = StanzaError.getBuilder(StanzaError.Condition.bad_request); final IQ request = new TestIQ(ELEMENT, NAMESPACE); request.setType(IQ.Type.error); request.setFrom(JidCreate.from("sender@test/Smack")); request.setTo(JidCreate.from("receiver@test/Smack")); request.setError(error); try { IQ.createErrorResponse(request, error); } catch (IllegalArgumentException e) { return; } fail("It shouldn't be possible to generate a response for a error IQ!"); } }
/** * 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()); }