Package org.xmpp.packet

Examples of org.xmpp.packet.IQ


    public void processPacket(final Packet packet) {
        threadPool.execute(new Runnable() {
            public void run() {
                if (packet instanceof IQ) {
                    IQ iq = (IQ) packet;
                    IQ.Type iqType = iq.getType();
                    if (IQ.Type.result == iqType || IQ.Type.error == iqType) {
                        // The server got an answer to an IQ packet that was sent from the component
                        IQResultListener iqResultListener = resultListeners.remove(iq.getID());
                        resultTimeout.remove(iq.getID());
                        if (iqResultListener != null) {
                            try {
                                iqResultListener.receivedAnswer(iq);
                            }
                            catch (Exception e) {
View Full Code Here


            public void answerTimeout(String packetId) {
                //Do nothing
            }
        }, timeout);
        sendPacket(component, packet);
        IQ reply = null;
        try {
            reply = answer.poll(timeout, TimeUnit.MILLISECONDS);
        } catch (InterruptedException e) {
            // Ignore
        }
View Full Code Here

   * Test that if (e.g.) an IQ is sent, then an IQ must be returned as a
   * response. If a Message is returned instead, this should invoke an error
   * callback.
   */
  public void testDropInvalidResponseType() throws Exception {
    IQ packet = server1.manager.createRequestIQ(server2.jid);

    // Disable routing so we can intercept the packet.
    server1.transport.router = null;
    PacketCallback callback = mock(PacketCallback.class);
    server1.manager.send(packet, callback, PACKET_TIMEOUT);

    // Generate an explicit Message receipt.
    Message response = new Message();
    response.setTo(packet.getFrom());
    response.setID(packet.getID());
    response.setFrom(packet.getTo());
    response.addChildElement("received", XmppNamespace.NAMESPACE_XMPP_RECEIPTS);
    server1.manager.receivePacket(response);

    // Confirm that an error callback is invoked.
    ArgumentCaptor<FederationError> returnedError = ArgumentCaptor.forClass(FederationError.class);
    verify(callback).error(returnedError.capture());
    verify(callback, never()).run(any(Packet.class));
    assertEquals(FederationError.Code.UNDEFINED_CONDITION, returnedError.getValue().getErrorCode());

    // Confirm that sending a correct response now does nothing.
    reset(callback);
    IQ correctResponse = IQ.createResultIQ(packet);
    server1.manager.receivePacket(correctResponse);
    verifyZeroInteractions(callback);
  }
View Full Code Here

  private SuccessFailCallback<String, String> callback;

  protected void setUp() throws Exception {
    super.setUp();
    XmppManager manager = mock(XmppManager.class);
    when(manager.createRequestIQ(eq(REMOTE_DOMAIN))).thenReturn(new IQ());

    DateTimeUtils.setCurrentMillisFixed(0);
    remoteDisco = new RemoteDisco(manager, REMOTE_DOMAIN, FAIL_EXPIRY_SECS,
                                              SUCCESS_EXPIRY_SECS);
    callback = mockDiscoCallback();
View Full Code Here

    remote.submitRequest(REMOTE_WAVELET, DUMMY_SIGNED_DELTA, listener);
    verifyZeroInteractions(listener);
    assertEquals(1, transport.packetsSent);

    // Validate the outgoing request.
    IQ outgoingRequest = (IQ) transport.packets.poll();
    assertEquals(EXPECTED_SUBMIT_REQUEST, outgoingRequest.toString());

    // Send the outgoing request back to the manager, so it hooks up to the
    // Federation Host.
    manager.receivePacket(outgoingRequest);

    // Provide the remote's host with a dummy answer to verified input.
    ArgumentCaptor<SubmitResultListener> remoteListener =
        ArgumentCaptor.forClass(SubmitResultListener.class);
    verify(mockProvider)
        .submitRequest(eq(REMOTE_WAVELET), eq(DUMMY_SIGNED_DELTA), remoteListener.capture());
    remoteListener.getValue().onSuccess(OPS_APPLIED, APPLIED_AT, TIMESTAMP_APPLIED);

    // Confirm that the packet has been sent back out over the transport.
    assertEquals(2, transport.packetsSent);
    IQ historyResponse = (IQ) transport.packets.poll();
    manager.receivePacket(historyResponse);

    // Confirm that the success is finally delivered to the listener.
    verify(listener, never()).onFailure(any(FederationError.class));
    verify(listener)
View Full Code Here

    verifyZeroInteractions(listener);
    assertEquals(1, transport.packetsSent);

    // Validate the outgoing request.
    IQ outgoingRequest = (IQ) transport.packets.poll();
    assertEquals(EXPECTED_SUBMIT_REQUEST, outgoingRequest.toString());

    // Return a confusing error response (<registration-required>).
    IQ errorResponse = IQ.createResultIQ(outgoingRequest);
    errorResponse.setError(PacketError.Condition.registration_required);
    manager.receivePacket(errorResponse);

    // Confirm error is passed through to the callback.
    ArgumentCaptor<FederationError> error = ArgumentCaptor.forClass(FederationError.class);
    verify(listener).onFailure(error.capture());
View Full Code Here

    remote.requestHistory(REMOTE_WAVELET, REMOTE_DOMAIN, START_VERSION, VERSION_ONE, -1, listener);
    verifyZeroInteractions(listener);
    assertEquals(1, transport.packetsSent);

    // Validate the outgoing request.
    IQ outgoingRequest = (IQ) transport.packets.poll();
    assertEquals(EXPECTED_HISTORY_REQUEST, outgoingRequest.toString());

    // Send the outgoing request back to the manager, so it hooks up to the
    // Federation Host.
    manager.receivePacket(outgoingRequest);

    ArgumentCaptor<HistoryResponseListener> remoteListener =
        ArgumentCaptor.forClass(HistoryResponseListener.class);
    // TODO(thorogood): Note that the caller's JID is not the domain we expect
    // here - it is not actually the domain of the requester!
    verify(mockProvider).requestHistory(eq(REMOTE_WAVELET), eq(LOCAL_JID), eq(START_VERSION),
        eq(VERSION_ONE), anyInt(), remoteListener.capture());
    remoteListener.getValue().onSuccess(ImmutableList.of(DELTA_BYTESTRING), VERSION_ONE, 0);

    // Confirm that the packet has been sent back out over the transport.
    assertEquals(2, transport.packetsSent);
    IQ historyResponse = (IQ) transport.packets.poll();
    manager.receivePacket(historyResponse);

    // Confirm that the success is finally delivered to the listener.
    ArgumentCaptor<ProtocolHashedVersion> commitVersion =
      ArgumentCaptor.forClass(ProtocolHashedVersion.class);
View Full Code Here

    remote.getDeltaSignerInfo(FAKE_SIGNER_ID, REMOTE_WAVELET, VERSION_ONE, listener);
    verifyZeroInteractions(listener);
    assertEquals(1, transport.packetsSent);

    // Validate the outgoing request.
    IQ outgoingRequest = (IQ) transport.packets.poll();
    //assertEquals(EXPECTED_HISTORY_REQUEST, outgoingRequest.toString());

    // Send the outgoing request back to the manager, so it hooks up to the
    // Federation Host.
    manager.receivePacket(outgoingRequest);

    ArgumentCaptor<DeltaSignerInfoResponseListener> remoteListener =
        ArgumentCaptor.forClass(DeltaSignerInfoResponseListener.class);
    verify(mockProvider).getDeltaSignerInfo(eq(FAKE_SIGNER_ID), eq(REMOTE_WAVELET), eq(VERSION_ONE),
        remoteListener.capture());
    remoteListener.getValue().onSuccess(FAKE_SIGNER_INFO);

    // Confirm that the packet has been sent back out over the transport.
    assertEquals(2, transport.packetsSent);
    IQ historyResponse = (IQ) transport.packets.poll();
    manager.receivePacket(historyResponse);

    // Confirm that the success is finally delivered to the listener.
    verify(listener, never()).onFailure(any(FederationError.class));
    verify(listener).onSuccess(eq(FAKE_SIGNER_INFO));
View Full Code Here

    remote.postSignerInfo(REMOTE_DOMAIN, FAKE_SIGNER_INFO, listener);
    verifyZeroInteractions(listener);
    assertEquals(1, transport.packetsSent);

    // Validate the outgoing request.
    IQ outgoingRequest = (IQ) transport.packets.poll();
    //assertEquals(EXPECTED_HISTORY_REQUEST, outgoingRequest.toString());

    // Send the outgoing request back to the manager, so it hooks up to the
    // Federation Host.
    manager.receivePacket(outgoingRequest);

    ArgumentCaptor<PostSignerInfoResponseListener> remoteListener =
        ArgumentCaptor.forClass(PostSignerInfoResponseListener.class);
    verify(mockProvider).postSignerInfo(eq(REMOTE_DOMAIN), eq(FAKE_SIGNER_INFO),
        remoteListener.capture());
    remoteListener.getValue().onSuccess();

    // Confirm that the packet has been sent back out over the transport.
    assertEquals(2, transport.packetsSent);
    IQ historyResponse = (IQ) transport.packets.poll();
    manager.receivePacket(historyResponse);

    // Confirm that the success is finally delivered to the listener.
    verify(listener, never()).onFailure(any(FederationError.class));
    verify(listener).onSuccess();
View Full Code Here

  /**
   * Test the simple case of packet send/receive by sending a malformed request.
   */
  public void testPacketSendMalformedFailure() {
    Packet packet = new IQ();
    packet.setFrom(server1.jid);
    packet.setID("irrelevant");
    packet.setTo(server2.jid);

    PacketCallback callback = mock(PacketCallback.class);

    // Send an outgoing packet from server1 -> server2
    server1.manager.send(packet, callback, PACKET_TIMEOUT);
View Full Code Here

TOP

Related Classes of org.xmpp.packet.IQ

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.