Java 类org.jivesoftware.smackx.packet.Version 实例源码

项目: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    文件: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());
}
项目:java-bells    文件: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.getPacketID()));

    getConnection(0).sendPacket(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());
}
项目:java-bells    文件: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.getPacketID()));

    getConnection(0).sendPacket(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());
}
项目:Smack    文件:CompressionTest.java   
/**
 * Test that stream compression works fine. It is assumed that the server supports and has
 * stream compression enabled.
 */
public void testSuccessCompression() throws XMPPException {

    // Create the configuration for this new connection
    ConnectionConfiguration config = new ConnectionConfiguration(getHost(), getPort());
    config.setCompressionEnabled(true);
    config.setSASLAuthenticationEnabled(true);

    XMPPTCPConnection connection = new XMPPConnection(config);
    connection.connect();

    // Login with the test account
    connection.login("user0", "user0");

    assertTrue("XMPPConnection is not using stream compression", connection.isUsingCompression());

    // Request the version of the server
    Version version = new Version();
    version.setType(IQ.Type.get);
    version.setTo(getServiceName());

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

    connection.sendStanza(version);

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

    assertNotNull("No reply was received from the server", result);
    assertEquals("Incorrect IQ type from server", IQ.Type.result, result.getType());

    // Close connection
    connection.disconnect();
}
项目:java-bells    文件:CompressionTest.java   
/**
 * Test that stream compression works fine. It is assumed that the server supports and has
 * stream compression enabled.
 */
public void testSuccessCompression() throws XMPPException {

    // Create the configuration for this new connection
    ConnectionConfiguration config = new ConnectionConfiguration(getHost(), getPort());
    config.setCompressionEnabled(true);
    config.setSASLAuthenticationEnabled(true);

    XMPPConnection connection = new XMPPConnection(config);
    connection.connect();

    // Login with the test account
    connection.login("user0", "user0");

    assertTrue("Connection is not using stream compression", connection.isUsingCompression());

    // Request the version of the server
    Version version = new Version();
    version.setType(IQ.Type.GET);
    version.setTo(getServiceName());

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

    connection.sendPacket(version);

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

    assertNotNull("No reply was received from the server", result);
    assertEquals("Incorrect IQ type from server", IQ.Type.RESULT, result.getType());

    // Close connection
    connection.disconnect();
}
项目:maven-yaxim    文件:SmackableImp.java   
static void registerSmackProviders() {
    ProviderManager pm = ProviderManager.getInstance();
    // add IQ handling
    pm.addIQProvider("query","http://jabber.org/protocol/disco#info", new DiscoverInfoProvider());
    pm.addIQProvider("query","http://jabber.org/protocol/disco#items", new DiscoverItemsProvider());
    // add delayed delivery notifications
    pm.addExtensionProvider("delay","urn:xmpp:delay", new DelayInfoProvider());
    pm.addExtensionProvider("x","jabber:x:delay", new DelayInfoProvider());
    // add XEP-0092 Software Version
    pm.addIQProvider("query", Version.NAMESPACE, new Version.Provider());

    // add carbons and forwarding
    pm.addExtensionProvider("forwarded", Forwarded.NAMESPACE, new Forwarded.Provider());
    pm.addExtensionProvider("sent", Carbon.NAMESPACE, new Carbon.Provider());
    pm.addExtensionProvider("received", Carbon.NAMESPACE, new Carbon.Provider());
    // add delivery receipts
    pm.addExtensionProvider(DeliveryReceipt.ELEMENT, DeliveryReceipt.NAMESPACE, new DeliveryReceipt.Provider());
    pm.addExtensionProvider(DeliveryReceiptRequest.ELEMENT, DeliveryReceipt.NAMESPACE, new DeliveryReceiptRequest.Provider());
    // add XMPP Ping (XEP-0199)
    pm.addIQProvider("ping","urn:xmpp:ping", new PingProvider());

    ServiceDiscoveryManager.setDefaultIdentity(YAXIM_IDENTITY);

    // XEP-0115 Entity Capabilities
    pm.addExtensionProvider("c", "http://jabber.org/protocol/caps", new CapsExtensionProvider());

    XmppStreamHandler.addExtensionProviders();
}
项目:maven-yaxim    文件:SmackableImp.java   
private void initServiceDiscovery() {
    // register connection features
    ServiceDiscoveryManager sdm = ServiceDiscoveryManager.getInstanceFor(mXMPPConnection);

    // init Entity Caps manager with storage in app's cache dir
    try {
        if (capsCacheDir == null) {
            capsCacheDir = new File(mService.getCacheDir(), "entity-caps-cache");
            capsCacheDir.mkdirs();
            EntityCapsManager.setPersistentCache(new SimpleDirectoryPersistentCache(capsCacheDir));
        }
    } catch (java.io.IOException e) {
        Log.e(TAG, "Could not init Entity Caps cache: " + e.getLocalizedMessage());
    }

    // reference PingManager, set ping flood protection to 10s
    PingManager.getInstanceFor(mXMPPConnection).setPingMinimumInterval(10*1000);

    // set Version for replies
    String app_name = mService.getString(org.yaxim.androidclient.R.string.app_name);
    String build_version[] = mService.getString(org.yaxim.androidclient.R.string.build_version).split(" ");
    Version.Manager.getInstanceFor(mXMPPConnection).setVersion(
            new Version(app_name, build_version[1], "Android"));

    // reference DeliveryReceiptManager, add listener
    DeliveryReceiptManager dm = DeliveryReceiptManager.getInstanceFor(mXMPPConnection);
    dm.enableAutoReceipts();
    dm.addReceiptReceivedListener(new ReceiptReceivedListener() { // DOES NOT WORK IN CARBONS
        public void onReceiptReceived(String fromJid, String toJid, String receiptId) {
            Log.d(TAG, "got delivery receipt for " + receiptId);
            changeMessageDeliveryStatus(receiptId, ChatConstants.DS_ACKED);
        }});
}