org.jivesoftware.smack.packet.StanzaError Java Examples
The following examples show how to use
org.jivesoftware.smack.packet.StanzaError.
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: InitiationListenerTest.java From Smack with Apache License 2.0 | 6 votes |
/** * If no listeners are registered for incoming In-Band Bytestream requests, all request should * be rejected with an error. * * @throws Exception should not happen */ @Test public void shouldRespondWithError() throws Exception { // run the listener with the initiation packet initiationListener.handleIQRequest(initBytestream); // wait because packet is processed in an extra thread Thread.sleep(200); // capture reply to the In-Band Bytestream open request ArgumentCaptor<IQ> argument = ArgumentCaptor.forClass(IQ.class); verify(connection).sendStanza(argument.capture()); // assert that reply is the correct error packet assertEquals(initiatorJID, argument.getValue().getTo()); assertEquals(IQ.Type.error, argument.getValue().getType()); assertEquals(StanzaError.Condition.not_acceptable, argument.getValue().getError().getCondition()); }
Example #2
Source File: ParseStreamManagementTest.java From Smack with Apache License 2.0 | 6 votes |
@Test public void testParseFailedWithTExt() throws XmlPullParserException, IOException { // @formatter:off final String failedNonza = "<failed h='20' xmlns='urn:xmpp:sm:3'>" + "<item-not-found xmlns='urn:ietf:params:xml:ns:xmpp-stanzas'/>" + "<text xml:lang='en' xmlns='urn:ietf:params:xml:ns:xmpp-stanzas'>" + "Previous session timed out" + "</text>" + "</failed>"; // @formatter:on XmlPullParser parser = PacketParserUtils.getParserFor(failedNonza); StreamManagement.Failed failed = ParseStreamManagement.failed(parser); assertEquals(StanzaError.Condition.item_not_found, failed.getStanzaErrorCondition()); List<StanzaErrorTextElement> textElements = failed.getTextElements(); assertEquals(1, textElements.size()); StanzaErrorTextElement textElement = textElements.get(0); assertEquals("Previous session timed out", textElement.getText()); assertEquals("en", textElement.getLanguage()); }
Example #3
Source File: StreamManagement.java From Smack with Apache License 2.0 | 6 votes |
@Override public CharSequence toXML(org.jivesoftware.smack.packet.XmlEnvironment enclosingNamespace) { XmlStringBuilder xml = new XmlStringBuilder(this, enclosingNamespace); if (condition == null && textElements.isEmpty()) { xml.closeEmptyElement(); } else { if (condition != null) { xml.rightAngleBracket(); xml.append(condition.toString()); xml.xmlnsAttribute(StanzaError.ERROR_CONDITION_AND_TEXT_NAMESPACE); xml.closeEmptyElement(); } xml.append(textElements); xml.closeElement(ELEMENT); } return xml; }
Example #4
Source File: InitiationListenerTest.java From Smack with Apache License 2.0 | 6 votes |
/** * Open request with a block size that exceeds the maximum block size should be replied with an * resource-constraint error. * * @throws Exception should not happen */ @Test public void shouldRejectRequestWithTooBigBlockSize() throws Exception { byteStreamManager.setMaximumBlockSize(1024); // run the listener with the initiation packet initiationListener.handleIQRequest(initBytestream); // wait because packet is processed in an extra thread Thread.sleep(200); // capture reply to the In-Band Bytestream open request ArgumentCaptor<IQ> argument = ArgumentCaptor.forClass(IQ.class); verify(connection).sendStanza(argument.capture()); // assert that reply is the correct error packet assertEquals(initiatorJID, argument.getValue().getTo()); assertEquals(IQ.Type.error, argument.getValue().getType()); assertEquals(StanzaError.Condition.resource_constraint, argument.getValue().getError().getCondition()); }
Example #5
Source File: VCardManager.java From Spark with Apache License 2.0 | 6 votes |
/** * Loads the vcard for this Spark user * @return this users VCard. */ public void reloadPersonalVCard() { try { personalVCard.load(SparkManager.getConnection()); personalVCardAvatar = personalVCard.getAvatar(); personalVCardHash = null; // reload lazy later, when need // If VCard is loaded, then save the avatar to the personal folder. if (personalVCardAvatar != null && personalVCardAvatar.length > 0) { ImageIcon icon = new ImageIcon(personalVCardAvatar); icon = VCardManager.scale(icon); if (icon.getIconWidth() != -1) { BufferedImage image = GraphicUtils.convert(icon.getImage()); ImageIO.write(image, "PNG", imageFile); } } } catch (Exception e) { StanzaError.Builder errorBuilder = StanzaError.getBuilder(StanzaError.Condition.conflict); personalVCard.setError(errorBuilder); personalVCardAvatar = null; personalVCardHash = null; Log.error(e); } }
Example #6
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 #7
Source File: OpenPgpPubSubUtil.java From Smack with Apache License 2.0 | 6 votes |
/** * Try to get a {@link LeafNode} the traditional way (first query information using disco#info), then query the node. * If that fails, query the node directly. * * @param pm PubSubManager * @param nodeName name of the node * @return node TODO javadoc me please * * @throws XMPPException.XMPPErrorException in case of an XMPP protocol error. * @throws PubSubException.NotALeafNodeException if the queried node is not a {@link LeafNode}. * @throws InterruptedException in case the thread gets interrupted * @throws PubSubException.NotAPubSubNodeException in case the queried entity is not a PubSub node. * @throws SmackException.NotConnectedException in case the connection is not connected. * @throws SmackException.NoResponseException in case the server doesn't respond. */ static LeafNode getLeafNode(PubSubManager pm, String nodeName) throws XMPPException.XMPPErrorException, PubSubException.NotALeafNodeException, InterruptedException, PubSubException.NotAPubSubNodeException, SmackException.NotConnectedException, SmackException.NoResponseException { LeafNode node; try { node = pm.getLeafNode(nodeName); } catch (XMPPException.XMPPErrorException e) { // It might happen, that the server doesn't allow disco#info queries from strangers. // In that case we have to fetch the node directly if (e.getStanzaError().getCondition() == StanzaError.Condition.subscription_required) { node = getOpenLeafNode(pm, nodeName); } else { throw e; } } return node; }
Example #8
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 #9
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 #10
Source File: InBandBytestreamManagerTest.java From Smack with Apache License 2.0 | 6 votes |
/** * Invoking {@link InBandBytestreamManager#establishSession(org.jxmpp.jid.Jid)} should * throw an exception if the given target does not support in-band * bytestream. * @throws SmackException if Smack detected an exceptional situation. * @throws XMPPException if an XMPP protocol error was received. * @throws InterruptedException if the calling thread was interrupted. */ @Test public void shouldFailIfTargetDoesNotSupportIBB() throws SmackException, XMPPException, InterruptedException { InBandBytestreamManager byteStreamManager = InBandBytestreamManager.getByteStreamManager(connection); try { IQ errorIQ = IBBPacketUtils.createErrorIQ(targetJID, initiatorJID, StanzaError.Condition.feature_not_implemented); protocol.addResponse(errorIQ); // start In-Band Bytestream byteStreamManager.establishSession(targetJID); fail("exception should be thrown"); } catch (XMPPErrorException e) { assertEquals(StanzaError.Condition.feature_not_implemented, e.getStanzaError().getCondition()); } }
Example #11
Source File: InBandBytestreamRequestTest.java From Smack with Apache License 2.0 | 6 votes |
/** * Test reject() method. * @throws NotConnectedException if the XMPP connection is not connected. * @throws InterruptedException if the calling thread was interrupted. */ @Test public void shouldReplyWithErrorIfRequestIsRejected() throws NotConnectedException, InterruptedException { InBandBytestreamRequest ibbRequest = new InBandBytestreamRequest( byteStreamManager, initBytestream); // reject request ibbRequest.reject(); // capture reply to the In-Band Bytestream open request ArgumentCaptor<IQ> argument = ArgumentCaptor.forClass(IQ.class); verify(connection).sendStanza(argument.capture()); // assert that reply is the correct error packet assertEquals(initiatorJID, argument.getValue().getTo()); assertEquals(IQ.Type.error, argument.getValue().getType()); assertEquals(StanzaError.Condition.not_acceptable, argument.getValue().getError().getCondition()); }
Example #12
Source File: FailureProviderTest.java From Smack with Apache License 2.0 | 6 votes |
@Test public void withStanzaErrrorFailureTest() throws Exception { final String xml = "<failure xmlns='http://jabber.org/protocol/compress'>" + "<setup-failed/>" + "<error xmlns='jabber:client' type='modify'>" + "<bad-request xmlns='urn:ietf:params:xml:ns:xmpp-stanzas'/>" + "</error>" + "</failure>"; final XmlPullParser parser = PacketParserUtils.getParserFor(xml); final Failure failure = FailureProvider.INSTANCE.parse(parser); assertEquals(Failure.CompressFailureError.setup_failed, failure.getCompressFailureError()); final StanzaError error = failure.getStanzaError(); assertEquals(Condition.bad_request, error.getCondition()); }
Example #13
Source File: FailureTest.java From Smack with Apache License 2.0 | 6 votes |
@Test public void withStanzaErrrorFailureTest() throws SAXException, IOException { StanzaError stanzaError = StanzaError.getBuilder() .setCondition(Condition.bad_request) .build(); Failure failure = new Failure(Failure.CompressFailureError.setup_failed, stanzaError); CharSequence xml = failure.toXML(); final String expectedXml = "<failure xmlns='http://jabber.org/protocol/compress'>" + "<setup-failed/>" + "<error xmlns='jabber:client' type='modify'>" + "<bad-request xmlns='urn:ietf:params:xml:ns:xmpp-stanzas'/>" + "</error>" + "</failure>"; assertXmlSimilar(expectedXml, xml.toString()); }
Example #14
Source File: PacketParserUtilsTest.java From Smack with Apache License 2.0 | 6 votes |
@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(); assertXmlSimilar(errorXml, error.toXML(StreamOpen.CLIENT_NAMESPACE)); }
Example #15
Source File: PubSubManager.java From Smack with Apache License 2.0 | 6 votes |
/** * Check if it is possible to create PubSub nodes on this service. It could be possible that the * PubSub service allows only certain XMPP entities (clients) to create nodes and publish items * to them. * <p> * Note that since XEP-60 does not provide an API to determine if an XMPP entity is allowed to * create nodes, therefore this method creates an instant node calling {@link #createNode()} to * determine if it is possible to create nodes. * </p> * * @return <code>true</code> if it is possible to create nodes, <code>false</code> otherwise. * @throws NoResponseException if there was no response from the remote entity. * @throws NotConnectedException if the XMPP connection is not connected. * @throws InterruptedException if the calling thread was interrupted. * @throws XMPPErrorException if there was an XMPP error returned. */ public boolean canCreateNodesAndPublishItems() throws NoResponseException, NotConnectedException, InterruptedException, XMPPErrorException { LeafNode leafNode = null; try { leafNode = createNode(); } catch (XMPPErrorException e) { if (e.getStanzaError().getCondition() == StanzaError.Condition.forbidden) { return false; } throw e; } finally { if (leafNode != null) { deleteNode(leafNode.getId()); } } return true; }
Example #16
Source File: InitiationListenerTest.java From Smack with Apache License 2.0 | 6 votes |
/** * If listener for a specific user is registered it should not be notified on incoming requests * from other users. * * @throws Exception should not happen */ @Test public void shouldNotInvokeListenerForUser() throws Exception { // add listener for request of user "other_initiator" Socks5BytestreamListener listener = mock(Socks5BytestreamListener.class); byteStreamManager.addIncomingBytestreamListener(listener, JidCreate.from("other_" + initiatorJID)); // run the listener with the initiation packet initiationListener.handleIQRequest(initBytestream); // assert listener is not called ArgumentCaptor<BytestreamRequest> byteStreamRequest = ArgumentCaptor.forClass(BytestreamRequest.class); verify(listener, never()).incomingBytestreamRequest(byteStreamRequest.capture()); // capture reply to the SOCKS5 Bytestream initiation ArgumentCaptor<IQ> argument = ArgumentCaptor.forClass(IQ.class); verify(connection, timeout(TIMEOUT)).sendStanza(argument.capture()); // assert that reply is the correct error packet assertEquals(initiatorJID, argument.getValue().getTo()); assertEquals(IQ.Type.error, argument.getValue().getType()); assertEquals(StanzaError.Condition.not_acceptable, argument.getValue().getError().getCondition()); }
Example #17
Source File: InitiationListenerTest.java From Smack with Apache License 2.0 | 6 votes |
/** * If no listeners are registered for incoming SOCKS5 Bytestream requests, all request should be * rejected with an error. * * @throws Exception should not happen */ @Test public void shouldRespondWithError() throws Exception { // run the listener with the initiation packet initiationListener.handleIQRequest(initBytestream); // capture reply to the SOCKS5 Bytestream initiation ArgumentCaptor<IQ> argument = ArgumentCaptor.forClass(IQ.class); verify(connection, timeout(TIMEOUT)).sendStanza(argument.capture()); // assert that reply is the correct error packet assertEquals(initiatorJID, argument.getValue().getTo()); assertEquals(IQ.Type.error, argument.getValue().getType()); assertEquals(StanzaError.Condition.not_acceptable, argument.getValue().getError().getCondition()); }
Example #18
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 #19
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 #20
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 #21
Source File: InitiationListenerTest.java From Smack with Apache License 2.0 | 5 votes |
/** * If listener for a specific user is registered it should not be notified on incoming requests * from other users. * * @throws Exception should not happen */ @Test public void shouldNotInvokeListenerForUser() throws Exception { // add listener for request of user "other_initiator" InBandBytestreamListener listener = mock(InBandBytestreamListener.class); byteStreamManager.addIncomingBytestreamListener(listener, JidCreate.from("other_" + initiatorJID)); // run the listener with the initiation packet initiationListener.handleIQRequest(initBytestream); // wait because packet is processed in an extra thread Thread.sleep(200); // assert listener is not called ArgumentCaptor<BytestreamRequest> byteStreamRequest = ArgumentCaptor.forClass(BytestreamRequest.class); verify(listener, never()).incomingBytestreamRequest(byteStreamRequest.capture()); // capture reply to the In-Band Bytestream open request ArgumentCaptor<IQ> argument = ArgumentCaptor.forClass(IQ.class); verify(connection).sendStanza(argument.capture()); // assert that reply is the correct error packet assertEquals(initiatorJID, argument.getValue().getTo()); assertEquals(IQ.Type.error, argument.getValue().getType()); assertEquals(StanzaError.Condition.not_acceptable, argument.getValue().getError().getCondition()); }
Example #22
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 #23
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 #24
Source File: InBandBytestreamSessionTest.java From Smack with Apache License 2.0 | 5 votes |
/** * If the data stanza has a sequence that is already used an 'unexpected-request' error should * be returned. See XEP-0047 Section 2.2. * * @throws Exception should not happen */ @Test public void shouldReplyWithErrorIfAlreadyUsedSequenceIsReceived() throws Exception { // verify reply to first valid data packet is of type RESULT protocol.addResponse(null, Verification.requestTypeRESULT); // verify reply to invalid data packet is an error protocol.addResponse(null, Verification.requestTypeERROR, new Verification<IQ, IQ>() { @Override public void verify(IQ request, IQ response) { assertEquals(StanzaError.Condition.unexpected_request, request.getError().getCondition()); } }); // get IBB sessions data packet listener InBandBytestreamSession session = new InBandBytestreamSession(connection, initBytestream, initiatorJID); InputStream inputStream = session.getInputStream(); StanzaListener listener = Whitebox.getInternalState(inputStream, "dataPacketListener", StanzaListener.class); // build data packets String base64Data = Base64.encode("Data"); DataPacketExtension dpe = new DataPacketExtension(sessionID, 0, base64Data); Data data1 = new Data(dpe); Data data2 = new Data(dpe); // notify listener listener.processStanza(data1); listener.processStanza(data2); protocol.verifyAll(); }
Example #25
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 #26
Source File: BlockedErrorExtension.java From Smack with Apache License 2.0 | 5 votes |
public static BlockedErrorExtension from(Message message) { StanzaError error = message.getError(); if (error == null) { return null; } return error.getExtension(ELEMENT, NAMESPACE); }
Example #27
Source File: PubSubManager.java From Smack with Apache License 2.0 | 5 votes |
/** * Delete the specified node. * * @param nodeId TODO javadoc me please * @throws XMPPErrorException if there was an XMPP error returned. * @throws NoResponseException if there was no response from the remote entity. * @throws NotConnectedException if the XMPP connection is not connected. * @throws InterruptedException if the calling thread was interrupted. * @return <code>true</code> if this node existed and was deleted and <code>false</code> if this node did not exist. */ public boolean deleteNode(String nodeId) throws NoResponseException, XMPPErrorException, NotConnectedException, InterruptedException { boolean res = true; try { sendPubsubPacket(Type.set, new NodeExtension(PubSubElementType.DELETE, nodeId), PubSubElementType.DELETE.getNamespace()); } catch (XMPPErrorException e) { if (e.getStanzaError().getCondition() == StanzaError.Condition.item_not_found) { res = false; } else { throw e; } } nodeMap.remove(nodeId); return res; }
Example #28
Source File: CloseListenerTest.java From Smack with Apache License 2.0 | 5 votes |
/** * If a close request to an unknown session is received it should be replied * with an <item-not-found/> error. * * @throws Exception should not happen */ @Test public void shouldReplyErrorIfSessionIsUnknown() throws Exception { // mock connection XMPPConnection connection = mock(XMPPConnection.class); // initialize InBandBytestreamManager to get the CloseListener InBandBytestreamManager byteStreamManager = InBandBytestreamManager.getByteStreamManager(connection); // get the CloseListener from InBandByteStreamManager CloseListener closeListener = Whitebox.getInternalState(byteStreamManager, "closeListener", CloseListener.class); Close close = new Close("unknownSessionId"); close.setFrom(initiatorJID); close.setTo(targetJID); closeListener.handleIQRequest(close); // wait because packet is processed in an extra thread Thread.sleep(200); // capture reply to the In-Band Bytestream close request ArgumentCaptor<IQ> argument = ArgumentCaptor.forClass(IQ.class); verify(connection).sendStanza(argument.capture()); // assert that reply is the correct error packet assertEquals(initiatorJID, argument.getValue().getTo()); assertEquals(IQ.Type.error, argument.getValue().getType()); assertEquals(StanzaError.Condition.item_not_found, argument.getValue().getError().getCondition()); }
Example #29
Source File: PacketParserUtilsTest.java From Smack with Apache License 2.0 | 5 votes |
@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); assertEquals(text, error.getDescriptiveText()); }
Example #30
Source File: InBandBytestreamSessionTest.java From Smack with Apache License 2.0 | 5 votes |
/** * If the data stanza contains invalid Base64 encoding an 'bad-request' error should be * returned. See XEP-0047 Section 2.2. * * @throws Exception should not happen */ @Test public void shouldReplyWithErrorIfDataIsInvalid() throws Exception { // verify reply to invalid data packet is an error protocol.addResponse(null, Verification.requestTypeERROR, new Verification<IQ, IQ>() { @Override public void verify(IQ request, IQ response) { assertEquals(StanzaError.Condition.bad_request, request.getError().getCondition()); } }); // get IBB sessions data packet listener InBandBytestreamSession session = new InBandBytestreamSession(connection, initBytestream, initiatorJID); InputStream inputStream = session.getInputStream(); StanzaListener listener = Whitebox.getInternalState(inputStream, "dataPacketListener", StanzaListener.class); // build data packets DataPacketExtension dpe = new DataPacketExtension(sessionID, 0, "AA=BB"); Data data = new Data(dpe); // notify listener listener.processStanza(data); protocol.verifyAll(); }