Java 类org.jivesoftware.smack.filter.PacketIDFilter 实例源码

项目:Smack    文件:IQTest.java   
/**
 * Check that sending an IQ to a full JID that is offline returns an IQ ERROR instead
 * of being route to some other resource of the same user. 
 */
public void testFullJIDToOfflineUser() {
    // Request the version from the server.
    Version versionRequest = new Version();
    versionRequest.setType(IQ.Type.get);
    versionRequest.setFrom(getFullJID(0));
    versionRequest.setTo(getBareJID(0) + "/Something");

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

    getConnection(0).sendStanza(versionRequest);

    // Wait up to 5 seconds for a result.
    IQ result = (IQ)collector.nextResult(SmackConfiguration.getPacketReplyTimeout());
    // Stop queuing results
    collector.cancel();
    assertNotNull("No response from server", result);
    assertEquals("The server didn't reply with an error packet", IQ.Type.error, result.getType());
    assertEquals("Server answered an incorrect error code", 503, result.getError().getCode());
}
项目:Smack    文件:PacketReaderTest.java   
/**
 * Verify that when Smack receives a "not implemented IQ" answers with an IQ packet
 * with error code 501.
 */
public void testIQNotImplemented() {

    // Create a new type of IQ to send. The new IQ will include a
    // non-existant namespace to cause the "feature-not-implemented" answer
    IQ iqPacket = new IQ() {
        public String getChildElementXML() {
            return "<query xmlns=\"my:ns:test\"/>";
        }
    };
    iqPacket.setTo(getFullJID(1));
    iqPacket.setType(IQ.Type.get);

    // Send the IQ and wait for the answer
    PacketCollector collector = getConnection(0).createPacketCollector(
            new PacketIDFilter(iqPacket.getStanzaId()));
    getConnection(0).sendStanza(iqPacket);
    IQ response = (IQ) collector.nextResult(SmackConfiguration.getPacketReplyTimeout());
    if (response == null) {
        fail("No response from the other user.");
    }
    assertEquals("The received IQ is not of type ERROR", IQ.Type.error, response.getType());
    assertEquals("The error code is not 501", 501, response.getError().getCode());
    collector.cancel();
}
项目: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());
}
项目:androidPN-client.    文件: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;
}
项目:EIM    文件:NonSASLAuthentication.java   
public String authenticateAnonymously() throws XMPPException {
    // Create the authentication packet we'll send to the server.
    Authentication auth = new Authentication();

    PacketCollector collector =
        connection.createPacketCollector(new PacketIDFilter(auth.getPacketID()));
    // Send the packet.
    connection.sendPacket(auth);
    // Wait up to a certain number of seconds for a response from the server.
    IQ response = (IQ) collector.nextResult(SmackConfiguration.getPacketReplyTimeout());
    if (response == null) {
        throw new XMPPException("Anonymous login failed.");
    }
    else if (response.getType() == IQ.Type.ERROR) {
        throw new XMPPException(response.getError());
    }
    // We're done with the collector, so explicitly cancel it.
    collector.cancel();

    if (response.getTo() != null) {
        return response.getTo();
    }
    else {
        return connection.getServiceName() + "/" + ((Authentication) response).getResource();
    }
}
项目:EIM    文件:AccountManager.java   
/**
 * Changes the password of the currently logged-in account. This operation can only
 * be performed after a successful login operation has been completed. Not all servers
 * support changing passwords; an XMPPException will be thrown when that is the case.
 *
 * @throws IllegalStateException if not currently logged-in to the server.
 * @throws XMPPException if an error occurs when changing the password.
 */
public void changePassword(String newPassword) throws XMPPException {
    Registration reg = new Registration();
    reg.setType(IQ.Type.SET);
    reg.setTo(connection.getServiceName());
    Map<String, String> map = new HashMap<String, String>();
    map.put("username",StringUtils.parseName(connection.getUser()));
    map.put("password",newPassword);
    reg.setAttributes(map);
    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());
    // Stop queuing results
    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    文件:AccountManager.java   
/**
 * Deletes the currently logged-in account from the server. This operation can only
 * be performed after a successful login operation has been completed. Not all servers
 * support deleting accounts; an XMPPException will be thrown when that is the case.
 *
 * @throws IllegalStateException if not currently logged-in to the server.
 * @throws XMPPException if an error occurs when deleting the account.
 */
public void deleteAccount() throws XMPPException {
    if (!connection.isAuthenticated()) {
        throw new IllegalStateException("Must be logged in to delete a account.");
    }
    Registration reg = new Registration();
    reg.setType(IQ.Type.SET);
    reg.setTo(connection.getServiceName());
    Map<String, String> attributes = new HashMap<String, String>();
    // To delete an account, we add a single attribute, "remove", that is blank.
    attributes.put("remove", "");
    reg.setAttributes(attributes);
    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());
    // Stop queuing results
    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   
/**
 * 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);
}
项目:androidPN-client.    文件: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    文件: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();
}
项目:androidPN-client.    文件: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    文件: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    文件: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;
}
项目:androidPN-client.    文件: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    文件: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    文件:ServiceDiscoveryManager.java   
/**
 * Returns the discovered information of a given XMPP entity addressed by its JID and
 * note attribute. Use this message only when trying to query information which is not 
 * directly addressable.
 * 
 * @param entityID the address of the XMPP entity.
 * @param node the attribute that supplements the 'jid' attribute.
 * @return the discovered information.
 * @throws XMPPException if the operation failed for some reason.
 */
public DiscoverInfo discoverInfo(String entityID, String node) throws XMPPException {
    // Discover the entity's info
    DiscoverInfo disco = new DiscoverInfo();
    disco.setType(IQ.Type.GET);
    disco.setTo(entityID);
    disco.setNode(node);

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

    connection.sendPacket(disco);

    // 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 (DiscoverInfo) result;
}
项目:EIM    文件:ServiceDiscoveryManager.java   
/**
 * Returns the discovered items of a given XMPP entity addressed by its JID and
 * note attribute. Use this message only when trying to query information which is not 
 * directly addressable.
 * 
 * @param entityID the address of the XMPP entity.
 * @param node the attribute that supplements the 'jid' attribute.
 * @return the discovered items.
 * @throws XMPPException if the operation failed for some reason.
 */
public DiscoverItems discoverItems(String entityID, String node) throws XMPPException {
    // Discover the entity's items
    DiscoverItems disco = new DiscoverItems();
    disco.setType(IQ.Type.GET);
    disco.setTo(entityID);
    disco.setNode(node);

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

    connection.sendPacket(disco);

    // 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 (DiscoverItems) result;
}
项目:EIM    文件:ServiceDiscoveryManager.java   
/**
 * Publishes new items to a parent entity and node. The item elements to publish MUST have at 
 * least a 'jid' attribute specifying the Entity ID of the item, and an action attribute which 
 * specifies the action being taken for that item. Possible action values are: "update" and 
 * "remove".
 * 
 * @param entityID the address of the XMPP entity.
 * @param node the attribute that supplements the 'jid' attribute.
 * @param discoverItems the DiscoveryItems to publish.
 * @throws XMPPException if the operation failed for some reason.
 */
public void publishItems(String entityID, String node, DiscoverItems discoverItems)
        throws XMPPException {
    discoverItems.setType(IQ.Type.SET);
    discoverItems.setTo(entityID);
    discoverItems.setNode(node);

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

    connection.sendPacket(discoverItems);

    // 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());
    }
}
项目:androidPN-client.    文件: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    文件: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.    文件: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);
}
项目:androidPN-client.    文件: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;
}
项目:androidpn_enhanced_client    文件:Roster.java   
/**
 * Removes a roster entry from the roster. The roster entry will also be removed from the
 * unfiled entries or from any roster group where it could belong and will no longer be part
 * of the roster. Note that this is an asynchronous call -- Smack must wait for the server
 * to send an updated subscription status.
 *
 * @param entry a roster entry.
 * @throws XMPPException if an XMPP error occurs.
 */
public void removeEntry(RosterEntry entry) throws XMPPException {
    // Only remove the entry if it's in the entry list.
    // The actual removal logic takes place in RosterPacketListenerprocess>>Packet(Packet)
    if (!entries.containsKey(entry.getUser())) {
        return;
    }
    RosterPacket packet = new RosterPacket();
    packet.setType(IQ.Type.SET);
    RosterPacket.Item item = RosterEntry.toRosterItem(entry);
    // Set the item type as REMOVE so that the server will delete the entry
    item.setItemType(RosterPacket.ItemType.remove);
    packet.addRosterItem(item);
    PacketCollector collector = connection.createPacketCollector(
            new PacketIDFilter(packet.getPacketID()));
    connection.sendPacket(packet);
    IQ response = (IQ) collector.nextResult(SmackConfiguration.getPacketReplyTimeout());
    collector.cancel();
    if (response == null) {
        throw new XMPPException("No response from the server.");
    }
    // If the server replied with an error, throw an exception.
    else if (response.getType() == IQ.Type.ERROR) {
        throw new XMPPException(response.getError());
    }
}
项目:androidpn_enhanced_client    文件:AccountManager.java   
/**
 * Changes the password of the currently logged-in account. This operation can only
 * be performed after a successful login operation has been completed. Not all servers
 * support changing passwords; an XMPPException will be thrown when that is the case.
 *
 * @throws IllegalStateException if not currently logged-in to the server.
 * @throws XMPPException if an error occurs when changing the password.
 */
public void changePassword(String newPassword) throws XMPPException {
    Registration reg = new Registration();
    reg.setType(IQ.Type.SET);
    reg.setTo(connection.getServiceName());
    reg.setUsername(StringUtils.parseName(connection.getUser()));
    reg.setPassword(newPassword);
    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());
    // Stop queuing results
    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_enhanced_client    文件:AccountManager.java   
/**
 * Deletes the currently logged-in account from the server. This operation can only
 * be performed after a successful login operation has been completed. Not all servers
 * support deleting accounts; an XMPPException will be thrown when that is the case.
 *
 * @throws IllegalStateException if not currently logged-in to the server.
 * @throws XMPPException if an error occurs when deleting the account.
 */
public void deleteAccount() throws XMPPException {
    if (!connection.isAuthenticated()) {
        throw new IllegalStateException("Must be logged in to delete a account.");
    }
    Registration reg = new Registration();
    reg.setType(IQ.Type.SET);
    reg.setTo(connection.getServiceName());
    // To delete an account, we set remove to true
    reg.setRemove(true);
    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());
    // Stop queuing results
    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_enhanced_client    文件:AccountManager.java   
/**
 * Gets the account registration info from the server.
 *
 * @throws XMPPException if an error occurs.
 */
private synchronized void getRegistrationInfo() throws XMPPException {
    Registration reg = new Registration();
    reg.setTo(connection.getServiceName());
    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());
    // Stop queuing results
    collector.cancel();
    if (result == null) {
        throw new XMPPException("No response from server.");
    }
    else if (result.getType() == IQ.Type.ERROR) {
        throw new XMPPException(result.getError());
    }
    else {
        info = (Registration)result;
    }
}