Java 类org.jivesoftware.smack.PacketCollector 实例源码

项目:Smack    文件:AgentSession.java   
/**
 * Sets the agent's current status with the workgroup. The presence mode affects how offers
 * are routed to the agent. The possible presence modes with their meanings are as follows:<ul>
 * <p/>
 * <li>Presence.Mode.AVAILABLE -- (Default) the agent is available for more chats
 * (equivalent to Presence.Mode.CHAT).
 * <li>Presence.Mode.DO_NOT_DISTURB -- the agent is busy and should not be disturbed.
 * However, special case, or extreme urgency chats may still be offered to the agent.
 * <li>Presence.Mode.AWAY -- the agent is not available and should not
 * have a chat routed to them (equivalent to Presence.Mode.EXTENDED_AWAY).</ul>
 *
 * @param presenceMode the presence mode of the agent.
 * @param status       sets the status message of the presence update.
 * @throws XMPPErrorException 
 * @throws NoResponseException 
 * @throws NotConnectedException 
 * @throws IllegalStateException if the agent is not online with the workgroup.
 */
public void setStatus(Presence.Mode presenceMode, String status) throws NoResponseException, XMPPErrorException, NotConnectedException {
    if (!online) {
        throw new IllegalStateException("Cannot set status when the agent is not online.");
    }

    if (presenceMode == null) {
        presenceMode = Presence.Mode.available;
    }
    this.presenceMode = presenceMode;

    Presence presence = new Presence(Presence.Type.available);
    presence.setMode(presenceMode);
    presence.setTo(this.getWorkgroupJID());

    if (status != null) {
        presence.setStatus(status);
    }
    presence.addExtension(new MetaData(this.metaData));

    PacketCollector collector = this.connection.createPacketCollectorAndSend(new AndFilter(new StanzaTypeFilter(Presence.class),
            FromMatchesFilter.create(workgroupJID)), presence);

    collector.nextResultOrThrow();
}
项目:Smack    文件:MultiUserChat.java   
/**
 * Changes the subject within the room. As a default, only users with a role of "moderator"
 * are allowed to change the subject in a room. Although some rooms may be configured to
 * allow a mere participant or even a visitor to change the subject.
 *
 * @param subject the new room's subject to set.
 * @throws XMPPErrorException if someone without appropriate privileges attempts to change the
 *          room subject will throw an error with code 403 (i.e. Forbidden)
 * @throws NoResponseException if there was no response from the server.
 * @throws NotConnectedException 
 */
public void changeSubject(final String subject) throws NoResponseException, XMPPErrorException, NotConnectedException {
    Message message = createMessage();
    message.setSubject(subject);
    // Wait for an error or confirmation message back from the server.
    StanzaFilter responseFilter = new AndFilter(fromRoomGroupchatFilter, new StanzaFilter() {
        @Override
        public boolean accept(Stanza packet) {
            Message msg = (Message) packet;
            return subject.equals(msg.getSubject());
        }
    });
    PacketCollector response = connection.createPacketCollectorAndSend(responseFilter, message);
    // Wait up to a certain number of seconds for a reply.
    response.nextResultOrThrow();
}
项目:Smack    文件:InBandBytestreamTest.java   
/**
 * Target should respond with not-acceptable error if no listeners for incoming In-Band
 * Bytestream requests are registered.
 * 
 * @throws XMPPException should not happen
 */
public void testRespondWithErrorOnInBandBytestreamRequest() throws XMPPException {
    XMPPConnection targetConnection = getConnection(0);

    XMPPConnection initiatorConnection = getConnection(1);

    Open open = new Open("sessionID", 1024);
    open.setFrom(initiatorConnection.getUser());
    open.setTo(targetConnection.getUser());

    PacketCollector collector = initiatorConnection.createPacketCollector(new PacketIDFilter(
                    open.getStanzaId()));
    initiatorConnection.sendStanza(open);
    Packet result = collector.nextResult();

    assertNotNull(result.getError());
    assertEquals(XMPPError.Condition.no_acceptable.toString(), result.getError().getCondition());

}
项目:Smack    文件:Socks5ByteStreamTest.java   
/**
 * Target should respond with not-acceptable error if no listeners for incoming Socks5
 * bytestream requests are registered.
 * 
 * @throws XMPPException should not happen
 */
public void testRespondWithErrorOnSocks5BytestreamRequest() throws XMPPException {
    XMPPConnection targetConnection = getConnection(0);

    XMPPConnection initiatorConnection = getConnection(1);

    Bytestream bytestreamInitiation = Socks5PacketUtils.createBytestreamInitiation(
                    initiatorConnection.getUser(), targetConnection.getUser(), "session_id");
    bytestreamInitiation.addStreamHost("proxy.localhost", "127.0.0.1", 7777);

    PacketCollector collector = initiatorConnection.createPacketCollector(new PacketIDFilter(
                    bytestreamInitiation.getStanzaId()));
    initiatorConnection.sendStanza(bytestreamInitiation);
    Packet result = collector.nextResult();

    assertNotNull(result.getError());
    assertEquals(XMPPError.Condition.no_acceptable.toString(), result.getError().getCondition());

}
项目:Smack    文件:VersionTest.java   
/**
 * Get the version of the server and make sure that all the required data is present
 *
 * Note: This test expects the server to answer an iq:version packet.
 */
public void testGetServerVersion() {
    Version version = new Version();
    version.setType(IQ.Type.get);
    version.setTo(getServiceName());

    // Create a packet collector to listen for a response.
    PacketCollector collector = getConnection(0).createPacketCollector(new PacketIDFilter(version.getStanzaId()));

    getConnection(0).sendStanza(version);

    // Wait up to 5 seconds for a result.
    IQ result = (IQ)collector.nextResult(5000);
    // Close the collector
    collector.cancel();

    assertNotNull("No result from the server", result);

    assertEquals("Incorrect result type", IQ.Type.result, result.getType());
    assertNotNull("No name specified in the result", ((Version)result).getName());
    assertNotNull("No version specified in the result", ((Version)result).getVersion());
}
项目:Intercloud    文件:XmppService.java   
@Override
public ResourceDocument sendRestDocument(XmppURI uri, ResourceDocument document) throws XMPPException, IOException, SmackException {
    AbstractXMPPConnection connection = this.connectionManager.getConnection();

    // create an set IQ stanza to uri
    RestIQ setIQ = new RestIQ(uri, document);
    // send stanza
    connection.sendStanza(setIQ);
    // wait for response
    StanzaFilter filter = new AndFilter(new IQReplyFilter(setIQ, connection));
    PacketCollector collector = connection.createPacketCollector(filter);
    IQ resultIQ = collector.nextResultOrThrow();
    if(resultIQ instanceof RestIQ) {
        // create rest doc
        return ((RestIQ) resultIQ).getResourceDocument();
    } else {
        throw new SmackException("Wrong RestIQ has been passed");
    }
}
项目:Intercloud    文件:XmppService.java   
@Override
public ResourceTypeDocument getXwadlDocument(XmppURI uri) throws XMPPException, IOException, SmackException {
    AbstractXMPPConnection connection = this.connectionManager.getConnection();
    // create an get IQ stanza to uri
    IQ getIQ = new GetXwadlIQ(uri);

    // send stanza
    connection.sendStanza(getIQ);
    // wait for response
    StanzaFilter filter = new AndFilter(new IQReplyFilter(getIQ, connection));
    PacketCollector collector = connection.createPacketCollector(filter);
    IQ resultIQ = collector.nextResultOrThrow();
    if (resultIQ instanceof XwadlIQ) {
        // create xwadl
        return ((XwadlIQ) resultIQ).getXwadl();
    } else {
        throw new SmackException("Wrong IQ has been passed");
    }
}
项目:EIM    文件:MultiUserChat.java   
/**
 * Returns the room's configuration form that the room's owner can use or <tt>null</tt> if
 * no configuration is possible. The configuration form allows to set the room's language,
 * enable logging, specify room's type, etc..
 *
 * @return the Form that contains the fields to complete together with the instrucions or
 * <tt>null</tt> if no configuration is possible.
 * @throws XMPPException if an error occurs asking the configuration form for the room.
 */
public Form getConfigurationForm() throws XMPPException {
    MUCOwner iq = new MUCOwner();
    iq.setTo(room);
    iq.setType(IQ.Type.GET);

    // Filter packets looking for an answer from the server.
    PacketFilter responseFilter = new PacketIDFilter(iq.getPacketID());
    PacketCollector response = connection.createPacketCollector(responseFilter);
    // Request the configuration form to the server.
    connection.sendPacket(iq);
    // Wait up to a certain number of seconds for a reply.
    IQ answer = (IQ) response.nextResult(SmackConfiguration.getPacketReplyTimeout());
    // Stop queuing results
    response.cancel();

    if (answer == null) {
        throw new XMPPException("No response from server.");
    }
    else if (answer.getError() != null) {
        throw new XMPPException(answer.getError());
    }
    return Form.getFormFrom(answer);
}
项目:EIM    文件:MultiUserChat.java   
/**
 * Sends the completed configuration form to the server. The room will be configured
 * with the new settings defined in the form. If the form is empty then the server
 * will create an instant room (will use default configuration).
 *
 * @param form the form with the new settings.
 * @throws XMPPException if an error occurs setting the new rooms' configuration.
 */
public void sendConfigurationForm(Form form) throws XMPPException {
    MUCOwner iq = new MUCOwner();
    iq.setTo(room);
    iq.setType(IQ.Type.SET);
    iq.addExtension(form.getDataFormToSend());

    // Filter packets looking for an answer from the server.
    PacketFilter responseFilter = new PacketIDFilter(iq.getPacketID());
    PacketCollector response = connection.createPacketCollector(responseFilter);
    // Send the completed configuration form to the server.
    connection.sendPacket(iq);
    // Wait up to a certain number of seconds for a reply.
    IQ answer = (IQ) response.nextResult(SmackConfiguration.getPacketReplyTimeout());
    // Stop queuing results
    response.cancel();

    if (answer == null) {
        throw new XMPPException("No response from server.");
    }
    else if (answer.getError() != null) {
        throw new XMPPException(answer.getError());
    }
}
项目:EIM    文件:MultiUserChat.java   
/**
 * Returns the room's registration form that an unaffiliated user, can use to become a member
 * of the room or <tt>null</tt> if no registration is possible. Some rooms may restrict the
 * privilege to register members and allow only room admins to add new members.<p>
 *
 * If the user requesting registration requirements is not allowed to register with the room
 * (e.g. because that privilege has been restricted), the room will return a "Not Allowed"
 * error to the user (error code 405).
 *
 * @return the registration Form that contains the fields to complete together with the
 * instrucions or <tt>null</tt> if no registration is possible.
 * @throws XMPPException if an error occurs asking the registration form for the room or a
 * 405 error if the user is not allowed to register with the room.
 */
public Form getRegistrationForm() throws XMPPException {
    Registration reg = new Registration();
    reg.setType(IQ.Type.GET);
    reg.setTo(room);

    PacketFilter filter =
        new AndFilter(new PacketIDFilter(reg.getPacketID()), new PacketTypeFilter(IQ.class));
    PacketCollector collector = connection.createPacketCollector(filter);
    connection.sendPacket(reg);
    IQ result = (IQ) collector.nextResult(SmackConfiguration.getPacketReplyTimeout());
    collector.cancel();
    if (result == null) {
        throw new XMPPException("No response from server.");
    }
    else if (result.getType() == IQ.Type.ERROR) {
        throw new XMPPException(result.getError());
    }
    return Form.getFormFrom(result);
}
项目:EIM    文件:MultiUserChat.java   
/**
 * Sends the completed registration form to the server. After the user successfully submits
 * the form, the room may queue the request for review by the room admins or may immediately
 * add the user to the member list by changing the user's affiliation from "none" to "member.<p>
 *
 * If the desired room nickname is already reserved for that room, the room will return a
 * "Conflict" error to the user (error code 409). If the room does not support registration,
 * it will return a "Service Unavailable" error to the user (error code 503).
 *
 * @param form the completed registration form.
 * @throws XMPPException if an error occurs submitting the registration form. In particular, a
 *      409 error can occur if the desired room nickname is already reserved for that room;
 *      or a 503 error can occur if the room does not support registration.
 */
public void sendRegistrationForm(Form form) throws XMPPException {
    Registration reg = new Registration();
    reg.setType(IQ.Type.SET);
    reg.setTo(room);
    reg.addExtension(form.getDataFormToSend());

    PacketFilter filter =
        new AndFilter(new PacketIDFilter(reg.getPacketID()), new PacketTypeFilter(IQ.class));
    PacketCollector collector = connection.createPacketCollector(filter);
    connection.sendPacket(reg);
    IQ result = (IQ) collector.nextResult(SmackConfiguration.getPacketReplyTimeout());
    collector.cancel();
    if (result == null) {
        throw new XMPPException("No response from server.");
    }
    else if (result.getType() == IQ.Type.ERROR) {
        throw new XMPPException(result.getError());
    }
}
项目:EIM    文件:MultiUserChat.java   
private void changeAffiliationByOwner(String jid, String affiliation) throws XMPPException {
    MUCOwner iq = new MUCOwner();
    iq.setTo(room);
    iq.setType(IQ.Type.SET);
    // Set the new affiliation.
    MUCOwner.Item item = new MUCOwner.Item(affiliation);
    item.setJid(jid);
    iq.addItem(item);

    // Wait for a response packet back from the server.
    PacketFilter responseFilter = new PacketIDFilter(iq.getPacketID());
    PacketCollector response = connection.createPacketCollector(responseFilter);
    // Send the change request to the server.
    connection.sendPacket(iq);
    // Wait up to a certain number of seconds for a reply.
    IQ answer = (IQ) response.nextResult(SmackConfiguration.getPacketReplyTimeout());
    // Stop queuing results
    response.cancel();

    if (answer == null) {
        throw new XMPPException("No response from server.");
    }
    else if (answer.getError() != null) {
        throw new XMPPException(answer.getError());
    }
}
项目:EIM    文件:SharedGroupManager.java   
/**
 * Returns the collection that will contain the name of the shared groups where the user
 * logged in with the specified session belongs.
 *
 * @param connection connection to use to get the user's shared groups.
 * @return collection with the shared groups' name of the logged user.
 */
public static List getSharedGroups(Connection connection) throws XMPPException {
    // Discover the shared groups of the logged user
    SharedGroupsInfo info = new SharedGroupsInfo();
    info.setType(IQ.Type.GET);

    // Create a packet collector to listen for a response.
    PacketCollector collector =
        connection.createPacketCollector(new PacketIDFilter(info.getPacketID()));

    connection.sendPacket(info);

    // Wait up to 5 seconds for a result.
    IQ result = (IQ) collector.nextResult(SmackConfiguration.getPacketReplyTimeout());
    // Stop queuing results
    collector.cancel();
    if (result == null) {
        throw new XMPPException("No response from the server.");
    }
    if (result.getType() == IQ.Type.ERROR) {
        throw new XMPPException(result.getError());
    }
    return ((SharedGroupsInfo) result).getGroups();
}
项目:EIM    文件:SyncPacketSend.java   
static public Packet getReply(Connection connection, Packet packet, long timeout)
    throws XMPPException
{
       PacketFilter responseFilter = new PacketIDFilter(packet.getPacketID());
       PacketCollector response = connection.createPacketCollector(responseFilter);

       connection.sendPacket(packet);

       // Wait up to a certain number of seconds for a reply.
       Packet result = response.nextResult(timeout);

       // Stop queuing results
       response.cancel();

       if (result == null) {
           throw new XMPPException("No response from server.");
       }
       else if (result.getError() != null) {
           throw new XMPPException(result.getError());
       }
       return result;
}
项目:EIM    文件:Agent.java   
public static Collection<String> getWorkgroups(String serviceJID, String agentJID, Connection connection) throws XMPPException {
    AgentWorkgroups request = new AgentWorkgroups(agentJID);
    request.setTo(serviceJID);
    PacketCollector collector = connection.createPacketCollector(new PacketIDFilter(request.getPacketID()));
    // Send the request
    connection.sendPacket(request);

    AgentWorkgroups response = (AgentWorkgroups)collector.nextResult(SmackConfiguration.getPacketReplyTimeout());

    // Cancel the collector.
    collector.cancel();
    if (response == null) {
        throw new XMPPException("No response from server on status set.");
    }
    if (response.getError() != null) {
        throw new XMPPException(response.getError());
    }
    return response.getWorkgroups();
}
项目:EIM    文件:Agent.java   
/**
 * Return the agents name.
 *
 * @return - the agents name.
 */
public String getName() throws XMPPException {
    AgentInfo agentInfo = new AgentInfo();
    agentInfo.setType(IQ.Type.GET);
    agentInfo.setTo(workgroupJID);
    agentInfo.setFrom(getUser());
    PacketCollector collector = connection.createPacketCollector(new PacketIDFilter(agentInfo.getPacketID()));
    // Send the request
    connection.sendPacket(agentInfo);

    AgentInfo response = (AgentInfo)collector.nextResult(SmackConfiguration.getPacketReplyTimeout());

    // Cancel the collector.
    collector.cancel();
    if (response == null) {
        throw new XMPPException("No response from server on status set.");
    }
    if (response.getError() != null) {
        throw new XMPPException(response.getError());
    }
    return response.getName();
}
项目:EIM    文件:Agent.java   
/**
 * Changes the name of the agent in the server. The server may have this functionality
 * disabled for all the agents or for this agent in particular. If the agent is not
 * allowed to change his name then an exception will be thrown with a service_unavailable
 * error code.
 *
 * @param newName the new name of the agent.
 * @throws XMPPException if the agent is not allowed to change his name or no response was
 *                       obtained from the server.
 */
public void setName(String newName) throws XMPPException {
    AgentInfo agentInfo = new AgentInfo();
    agentInfo.setType(IQ.Type.SET);
    agentInfo.setTo(workgroupJID);
    agentInfo.setFrom(getUser());
    agentInfo.setName(newName);
    PacketCollector collector = connection.createPacketCollector(new PacketIDFilter(agentInfo.getPacketID()));
    // Send the request
    connection.sendPacket(agentInfo);

    IQ response = (IQ)collector.nextResult(SmackConfiguration.getPacketReplyTimeout());

    // Cancel the collector.
    collector.cancel();
    if (response == null) {
        throw new XMPPException("No response from server on status set.");
    }
    if (response.getError() != null) {
        throw new XMPPException(response.getError());
    }
    return;
}
项目:EIM    文件:TranscriptSearchManager.java   
/**
 * Returns the Form to use for searching transcripts. It is unlikely that the server
 * will change the form (without a restart) so it is safe to keep the returned form
 * for future submissions.
 *
 * @param serviceJID the address of the workgroup service.
 * @return the Form to use for searching transcripts.
 * @throws XMPPException if an error occurs while sending the request to the server.
 */
public Form getSearchForm(String serviceJID) throws XMPPException {
    TranscriptSearch search = new TranscriptSearch();
    search.setType(IQ.Type.GET);
    search.setTo(serviceJID);

    PacketCollector collector = connection.createPacketCollector(
            new PacketIDFilter(search.getPacketID()));
    connection.sendPacket(search);

    TranscriptSearch response = (TranscriptSearch) collector.nextResult(
            SmackConfiguration.getPacketReplyTimeout());

    // Cancel the collector.
    collector.cancel();
    if (response == null) {
        throw new XMPPException("No response from server on status set.");
    }
    if (response.getError() != null) {
        throw new XMPPException(response.getError());
    }
    return Form.getFormFrom(response);
}
项目:EIM    文件:TranscriptSearchManager.java   
/**
 * Submits the completed form and returns the result of the transcript search. The result
 * will include all the data returned from the server so be careful with the amount of
 * data that the search may return.
 *
 * @param serviceJID    the address of the workgroup service.
 * @param completedForm the filled out search form.
 * @return the result of the transcript search.
 * @throws XMPPException if an error occurs while submiting the search to the server.
 */
public ReportedData submitSearch(String serviceJID, Form completedForm) throws XMPPException {
    TranscriptSearch search = new TranscriptSearch();
    search.setType(IQ.Type.GET);
    search.setTo(serviceJID);
    search.addExtension(completedForm.getDataFormToSend());

    PacketCollector collector = connection.createPacketCollector(new PacketIDFilter(search.getPacketID()));
    connection.sendPacket(search);

    TranscriptSearch response = (TranscriptSearch) collector.nextResult(SmackConfiguration.getPacketReplyTimeout());

    // Cancel the collector.
    collector.cancel();
    if (response == null) {
        throw new XMPPException("No response from server on status set.");
    }
    if (response.getError() != null) {
        throw new XMPPException(response.getError());
    }
    return ReportedData.getReportedDataFrom(response);
}
项目:EIM    文件:TranscriptManager.java   
/**
 * Returns the full conversation transcript of a given session.
 *
 * @param sessionID the id of the session to get the full transcript.
 * @param workgroupJID the JID of the workgroup that will process the request.
 * @return the full conversation transcript of a given session.
 * @throws XMPPException if an error occurs while getting the information.
 */
public Transcript getTranscript(String workgroupJID, String sessionID) throws XMPPException {
    Transcript request = new Transcript(sessionID);
    request.setTo(workgroupJID);
    PacketCollector collector = connection.createPacketCollector(new PacketIDFilter(request.getPacketID()));
    // Send the request
    connection.sendPacket(request);

    Transcript response = (Transcript) collector.nextResult(SmackConfiguration.getPacketReplyTimeout());

    // Cancel the collector.
    collector.cancel();
    if (response == null) {
        throw new XMPPException("No response from server on status set.");
    }
    if (response.getError() != null) {
        throw new XMPPException(response.getError());
    }
    return response;
}
项目:EIM    文件:TranscriptManager.java   
/**
 * Returns the transcripts of a given user. The answer will contain the complete history of
 * conversations that a user had.
 *
 * @param userID the id of the user to get his conversations.
 * @param workgroupJID the JID of the workgroup that will process the request.
 * @return the transcripts of a given user.
 * @throws XMPPException if an error occurs while getting the information.
 */
public Transcripts getTranscripts(String workgroupJID, String userID) throws XMPPException {
    Transcripts request = new Transcripts(userID);
    request.setTo(workgroupJID);
    PacketCollector collector = connection.createPacketCollector(new PacketIDFilter(request.getPacketID()));
    // Send the request
    connection.sendPacket(request);

    Transcripts response = (Transcripts) collector.nextResult(SmackConfiguration.getPacketReplyTimeout());

    // Cancel the collector.
    collector.cancel();
    if (response == null) {
        throw new XMPPException("No response from server on status set.");
    }
    if (response.getError() != null) {
        throw new XMPPException(response.getError());
    }
    return response;
}
项目:EIM    文件:UserSearch.java   
/**
 * Returns the form for all search fields supported by the search service.
 *
 * @param con           the current Connection.
 * @param searchService the search service to use. (ex. search.jivesoftware.com)
 * @return the search form received by the server.
 * @throws org.jivesoftware.smack.XMPPException
 *          thrown if a server error has occurred.
 */
public Form getSearchForm(Connection con, String searchService) throws XMPPException {
    UserSearch search = new UserSearch();
    search.setType(IQ.Type.GET);
    search.setTo(searchService);

    PacketCollector collector = con.createPacketCollector(new PacketIDFilter(search.getPacketID()));
    con.sendPacket(search);

    IQ response = (IQ) collector.nextResult(SmackConfiguration.getPacketReplyTimeout());

    // Cancel the collector.
    collector.cancel();
    if (response == null) {
        throw new XMPPException("No response from server on status set.");
    }
    if (response.getError() != null) {
        throw new XMPPException(response.getError());
    }
    return Form.getFormFrom(response);
}
项目:EIM    文件:UserSearch.java   
/**
 * Sends the filled out answer form to be sent and queried by the search service.
 *
 * @param con           the current Connection.
 * @param searchForm    the <code>Form</code> to send for querying.
 * @param searchService the search service to use. (ex. search.jivesoftware.com)
 * @return ReportedData the data found from the query.
 * @throws org.jivesoftware.smack.XMPPException
 *          thrown if a server error has occurred.
 */
public ReportedData sendSearchForm(Connection con, Form searchForm, String searchService) throws XMPPException {
    UserSearch search = new UserSearch();
    search.setType(IQ.Type.SET);
    search.setTo(searchService);
    search.addExtension(searchForm.getDataFormToSend());

    PacketCollector collector = con.createPacketCollector(new PacketIDFilter(search.getPacketID()));

    con.sendPacket(search);

    IQ response = (IQ) collector.nextResult(SmackConfiguration.getPacketReplyTimeout());

    // Cancel the collector.
    collector.cancel();
    if (response == null) {
        throw new XMPPException("No response from server on status set.");
    }
    if (response.getError() != null) {
        return sendSimpleSearchForm(con, searchForm, searchService);
    }


    return ReportedData.getReportedDataFrom(response);
}
项目:EIM    文件:StreamNegotiator.java   
Packet initiateIncomingStream(Connection connection, StreamInitiation initiation) throws XMPPException {
    StreamInitiation response = createInitiationAccept(initiation,
            getNamespaces());

    // establish collector to await response
    PacketCollector collector = connection
            .createPacketCollector(getInitiationPacketFilter(initiation.getFrom(), initiation.getSessionID()));
    connection.sendPacket(response);

    Packet streamMethodInitiation = collector
            .nextResult(SmackConfiguration.getPacketReplyTimeout());
    collector.cancel();
    if (streamMethodInitiation == null) {
        throw new XMPPException("No response from file transfer initiator");
    }

    return streamMethodInitiation;
}
项目:EIM    文件:OfflineMessageManager.java   
/**
 * Deletes the specified list of offline messages. The request will include the list of
 * stamps that uniquely identifies the offline messages to delete.
 *
 * @param nodes the list of stamps that uniquely identifies offline message.
 * @throws XMPPException If the user is not allowed to make this request or the server does
 *                       not support offline message retrieval.
 */
public void deleteMessages(List<String> nodes) throws XMPPException {
    OfflineMessageRequest request = new OfflineMessageRequest();
    for (String node : nodes) {
        OfflineMessageRequest.Item item = new OfflineMessageRequest.Item(node);
        item.setAction("remove");
        request.addItem(item);
    }
    // Filter packets looking for an answer from the server.
    PacketFilter responseFilter = new PacketIDFilter(request.getPacketID());
    PacketCollector response = connection.createPacketCollector(responseFilter);
    // Send the deletion request to the server.
    connection.sendPacket(request);
    // Wait up to a certain number of seconds for a reply.
    IQ answer = (IQ) response.nextResult(SmackConfiguration.getPacketReplyTimeout());
    // Stop queuing results
    response.cancel();

    if (answer == null) {
        throw new XMPPException("No response from server.");
    } else if (answer.getError() != null) {
        throw new XMPPException(answer.getError());
    }
}
项目:EIM    文件:OfflineMessageManager.java   
/**
 * Deletes all offline messages of the user.
 *
 * @throws XMPPException If the user is not allowed to make this request or the server does
 *                       not support offline message retrieval.
 */
public void deleteMessages() throws XMPPException {
    OfflineMessageRequest request = new OfflineMessageRequest();
    request.setPurge(true);
    // Filter packets looking for an answer from the server.
    PacketFilter responseFilter = new PacketIDFilter(request.getPacketID());
    PacketCollector response = connection.createPacketCollector(responseFilter);
    // Send the deletion request to the server.
    connection.sendPacket(request);
    // Wait up to a certain number of seconds for a reply.
    IQ answer = (IQ) response.nextResult(SmackConfiguration.getPacketReplyTimeout());
    // Stop queuing results
    response.cancel();

    if (answer == null) {
        throw new XMPPException("No response from server.");
    } else if (answer.getError() != null) {
        throw new XMPPException(answer.getError());
    }
}
项目:EIM    文件:VCard.java   
/**
 * Save this vCard for the user connected by 'connection'. Connection should be authenticated
 * and not anonymous.<p>
 * <p/>
 * NOTE: the method is asynchronous and does not wait for the returned value.
 *
 * @param connection the Connection to use.
 * @throws XMPPException thrown if there was an issue setting the VCard in the server.
 */
public void save(Connection connection) throws XMPPException {
    checkAuthenticated(connection, true);

    setType(IQ.Type.SET);
    setFrom(connection.getUser());
    PacketCollector collector = connection.createPacketCollector(new PacketIDFilter(getPacketID()));
    connection.sendPacket(this);

    Packet response = collector.nextResult(SmackConfiguration.getPacketReplyTimeout());

    // Cancel the collector.
    collector.cancel();
    if (response == null) {
        throw new XMPPException("No response from server on status set.");
    }
    if (response.getError() != null) {
        throw new XMPPException(response.getError());
    }
}
项目:EIM    文件:VCard.java   
private void doLoad(Connection connection, String user) throws XMPPException {
    setType(Type.GET);
    PacketCollector collector = connection.createPacketCollector(
            new PacketIDFilter(getPacketID()));
    connection.sendPacket(this);

    VCard result = null;
    try {
        result = (VCard) collector.nextResult(SmackConfiguration.getPacketReplyTimeout());

        if (result == null) {
            String errorMessage = "Timeout getting VCard information";
            throw new XMPPException(errorMessage, new XMPPError(
                    XMPPError.Condition.request_timeout, errorMessage));
        }
        if (result.getError() != null) {
            throw new XMPPException(result.getError());
        }
    }
    catch (ClassCastException e) {
        System.out.println("No VCard for " + user);
    }

    copyFieldsFrom(result);
}
项目:EIM    文件:SyncPacketSend.java   
static public Packet getReply(Connection connection, Packet packet, long timeout)
    throws XMPPException
{
       PacketFilter responseFilter = new PacketIDFilter(packet.getPacketID());
       PacketCollector response = connection.createPacketCollector(responseFilter);

       connection.sendPacket(packet);

       // Wait up to a certain number of seconds for a reply.
       Packet result = response.nextResult(timeout);

       // Stop queuing results
       response.cancel();

       if (result == null) {
           throw new XMPPException("No response from server.");
       }
       else if (result.getError() != null) {
           throw new XMPPException(result.getError());
       }
       return result;
}
项目:EIM    文件:LastActivity.java   
/**
 * Retrieve the last activity of a particular jid.
 * @param con the current Connection.
 * @param jid the JID of the user.
 * @return the LastActivity packet of the jid.
 * @throws XMPPException thrown if a server error has occured.
 * @deprecated This method only retreives the lapsed time since the last logout of a particular jid. 
 * Replaced by {@link  org.jivesoftware.smackx.LastActivityManager#getLastActivity(Connection, String)  getLastActivity}
 */
public static LastActivity getLastActivity(Connection con, String jid) throws XMPPException {
    LastActivity activity = new LastActivity();
    jid = StringUtils.parseBareAddress(jid);
    activity.setTo(jid);

    PacketCollector collector = con.createPacketCollector(new PacketIDFilter(activity.getPacketID()));
    con.sendPacket(activity);

    LastActivity response = (LastActivity) collector.nextResult(SmackConfiguration.getPacketReplyTimeout());

    // Cancel the collector.
    collector.cancel();
    if (response == null) {
        throw new XMPPException("No response from server on status set.");
    }
    if (response.getError() != null) {
        throw new XMPPException(response.getError());
    }
    return response;
}
项目:androidPN-client.    文件:SyncPacketSend.java   
static public Packet getReply(Connection connection, Packet packet, long timeout)
    throws XMPPException
{
       PacketFilter responseFilter = new PacketIDFilter(packet.getPacketID());
       PacketCollector response = connection.createPacketCollector(responseFilter);

       connection.sendPacket(packet);

       // Wait up to a certain number of seconds for a reply.
       Packet result = response.nextResult(timeout);

       // Stop queuing results
       response.cancel();

       if (result == null) {
           throw new XMPPException("No response from server.");
       }
       else if (result.getError() != null) {
           throw new XMPPException(result.getError());
       }
       return result;
}
项目:androidPN-client.    文件:MultiUserChat.java   
/**
 * Returns the room's configuration form that the room's owner can use or <tt>null</tt> if
 * no configuration is possible. The configuration form allows to set the room's language,
 * enable logging, specify room's type, etc..
 *
 * @return the Form that contains the fields to complete together with the instrucions or
 * <tt>null</tt> if no configuration is possible.
 * @throws XMPPException if an error occurs asking the configuration form for the room.
 */
public Form getConfigurationForm() throws XMPPException {
    MUCOwner iq = new MUCOwner();
    iq.setTo(room);
    iq.setType(IQ.Type.GET);

    // Filter packets looking for an answer from the server.
    PacketFilter responseFilter = new PacketIDFilter(iq.getPacketID());
    PacketCollector response = connection.createPacketCollector(responseFilter);
    // Request the configuration form to the server.
    connection.sendPacket(iq);
    // Wait up to a certain number of seconds for a reply.
    IQ answer = (IQ) response.nextResult(SmackConfiguration.getPacketReplyTimeout());
    // Stop queuing results
    response.cancel();

    if (answer == null) {
        throw new XMPPException("No response from server.");
    }
    else if (answer.getError() != null) {
        throw new XMPPException(answer.getError());
    }
    return Form.getFormFrom(answer);
}
项目:androidPN-client.    文件:MultiUserChat.java   
/**
 * Sends the completed configuration form to the server. The room will be configured
 * with the new settings defined in the form. If the form is empty then the server
 * will create an instant room (will use default configuration).
 *
 * @param form the form with the new settings.
 * @throws XMPPException if an error occurs setting the new rooms' configuration.
 */
public void sendConfigurationForm(Form form) throws XMPPException {
    MUCOwner iq = new MUCOwner();
    iq.setTo(room);
    iq.setType(IQ.Type.SET);
    iq.addExtension(form.getDataFormToSend());

    // Filter packets looking for an answer from the server.
    PacketFilter responseFilter = new PacketIDFilter(iq.getPacketID());
    PacketCollector response = connection.createPacketCollector(responseFilter);
    // Send the completed configuration form to the server.
    connection.sendPacket(iq);
    // Wait up to a certain number of seconds for a reply.
    IQ answer = (IQ) response.nextResult(SmackConfiguration.getPacketReplyTimeout());
    // Stop queuing results
    response.cancel();

    if (answer == null) {
        throw new XMPPException("No response from server.");
    }
    else if (answer.getError() != null) {
        throw new XMPPException(answer.getError());
    }
}
项目:androidPN-client.    文件:MultiUserChat.java   
/**
 * Returns the room's registration form that an unaffiliated user, can use to become a member
 * of the room or <tt>null</tt> if no registration is possible. Some rooms may restrict the
 * privilege to register members and allow only room admins to add new members.<p>
 *
 * If the user requesting registration requirements is not allowed to register with the room
 * (e.g. because that privilege has been restricted), the room will return a "Not Allowed"
 * error to the user (error code 405).
 *
 * @return the registration Form that contains the fields to complete together with the
 * instrucions or <tt>null</tt> if no registration is possible.
 * @throws XMPPException if an error occurs asking the registration form for the room or a
 * 405 error if the user is not allowed to register with the room.
 */
public Form getRegistrationForm() throws XMPPException {
    Registration reg = new Registration();
    reg.setType(IQ.Type.GET);
    reg.setTo(room);

    PacketFilter filter =
        new AndFilter(new PacketIDFilter(reg.getPacketID()), new PacketTypeFilter(IQ.class));
    PacketCollector collector = connection.createPacketCollector(filter);
    connection.sendPacket(reg);
    IQ result = (IQ) collector.nextResult(SmackConfiguration.getPacketReplyTimeout());
    collector.cancel();
    if (result == null) {
        throw new XMPPException("No response from server.");
    }
    else if (result.getType() == IQ.Type.ERROR) {
        throw new XMPPException(result.getError());
    }
    return Form.getFormFrom(result);
}
项目:androidPN-client.    文件:MultiUserChat.java   
/**
 * Sends the completed registration form to the server. After the user successfully submits
 * the form, the room may queue the request for review by the room admins or may immediately
 * add the user to the member list by changing the user's affiliation from "none" to "member.<p>
 *
 * If the desired room nickname is already reserved for that room, the room will return a
 * "Conflict" error to the user (error code 409). If the room does not support registration,
 * it will return a "Service Unavailable" error to the user (error code 503).
 *
 * @param form the completed registration form.
 * @throws XMPPException if an error occurs submitting the registration form. In particular, a
 *      409 error can occur if the desired room nickname is already reserved for that room;
 *      or a 503 error can occur if the room does not support registration.
 */
public void sendRegistrationForm(Form form) throws XMPPException {
    Registration reg = new Registration();
    reg.setType(IQ.Type.SET);
    reg.setTo(room);
    reg.addExtension(form.getDataFormToSend());

    PacketFilter filter =
        new AndFilter(new PacketIDFilter(reg.getPacketID()), new PacketTypeFilter(IQ.class));
    PacketCollector collector = connection.createPacketCollector(filter);
    connection.sendPacket(reg);
    IQ result = (IQ) collector.nextResult(SmackConfiguration.getPacketReplyTimeout());
    collector.cancel();
    if (result == null) {
        throw new XMPPException("No response from server.");
    }
    else if (result.getType() == IQ.Type.ERROR) {
        throw new XMPPException(result.getError());
    }
}
项目:androidPN-client.    文件:MultiUserChat.java   
private void changeAffiliationByOwner(String jid, String affiliation) throws XMPPException {
    MUCOwner iq = new MUCOwner();
    iq.setTo(room);
    iq.setType(IQ.Type.SET);
    // Set the new affiliation.
    MUCOwner.Item item = new MUCOwner.Item(affiliation);
    item.setJid(jid);
    iq.addItem(item);

    // Wait for a response packet back from the server.
    PacketFilter responseFilter = new PacketIDFilter(iq.getPacketID());
    PacketCollector response = connection.createPacketCollector(responseFilter);
    // Send the change request to the server.
    connection.sendPacket(iq);
    // Wait up to a certain number of seconds for a reply.
    IQ answer = (IQ) response.nextResult(SmackConfiguration.getPacketReplyTimeout());
    // Stop queuing results
    response.cancel();

    if (answer == null) {
        throw new XMPPException("No response from server.");
    }
    else if (answer.getError() != null) {
        throw new XMPPException(answer.getError());
    }
}
项目:androidPN-client.    文件:SharedGroupManager.java   
/**
 * Returns the collection that will contain the name of the shared groups where the user
 * logged in with the specified session belongs.
 *
 * @param connection connection to use to get the user's shared groups.
 * @return collection with the shared groups' name of the logged user.
 */
public static List<String> getSharedGroups(Connection connection) throws XMPPException {
    // Discover the shared groups of the logged user
    SharedGroupsInfo info = new SharedGroupsInfo();
    info.setType(IQ.Type.GET);

    // Create a packet collector to listen for a response.
    PacketCollector collector =
        connection.createPacketCollector(new PacketIDFilter(info.getPacketID()));

    connection.sendPacket(info);

    // Wait up to 5 seconds for a result.
    IQ result = (IQ) collector.nextResult(SmackConfiguration.getPacketReplyTimeout());
    // Stop queuing results
    collector.cancel();
    if (result == null) {
        throw new XMPPException("No response from the server.");
    }
    if (result.getType() == IQ.Type.ERROR) {
        throw new XMPPException(result.getError());
    }
    return ((SharedGroupsInfo) result).getGroups();
}
项目:androidPN-client.    文件:SyncPacketSend.java   
static public Packet getReply(Connection connection, Packet packet, long timeout)
    throws XMPPException
{
       PacketFilter responseFilter = new PacketIDFilter(packet.getPacketID());
       PacketCollector response = connection.createPacketCollector(responseFilter);

       connection.sendPacket(packet);

       // Wait up to a certain number of seconds for a reply.
       Packet result = response.nextResult(timeout);

       // Stop queuing results
       response.cancel();

       if (result == null) {
           throw new XMPPException("No response from server.");
       }
       else if (result.getError() != null) {
           throw new XMPPException(result.getError());
       }
       return result;
}
项目:androidPN-client.    文件:CarbonManager.java   
/**
 * Notify server to change the carbons state. This method blocks
 * some time until the server replies to the IQ and returns true on
 * success.
 *
 * You should first check for support using isSupportedByServer().
 *
 * @param new_state whether carbons should be enabled or disabled
 *
 * @return true if the operation was successful
 */
public boolean setCarbonsEnabled(final boolean new_state) {
    if (enabled_state == new_state)
        return true;

    IQ setIQ = carbonsEnabledIQ(new_state);

    PacketCollector collector =
            connection.createPacketCollector(new PacketIDFilter(setIQ.getPacketID()));
    connection.sendPacket(setIQ);
    IQ result = (IQ) collector.nextResult(SmackConfiguration.getPacketReplyTimeout());
    collector.cancel();

    if (result != null && result.getType() == IQ.Type.RESULT) {
        enabled_state = new_state;
        return true;
    }
    return false;
}