当前位置: 首页>>代码示例>>Java>>正文


Java IQ类代码示例

本文整理汇总了Java中org.jivesoftware.smack.packet.IQ的典型用法代码示例。如果您正苦于以下问题:Java IQ类的具体用法?Java IQ怎么用?Java IQ使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。


IQ类属于org.jivesoftware.smack.packet包,在下文中一共展示了IQ类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: checkProvider

import org.jivesoftware.smack.packet.IQ; //导入依赖的package包/类
@Test
public void checkProvider() throws Exception {
    XMLBuilder xml = XMLBuilder.create("iq");
    xml.a("from", "[email protected]/orchard")
        .a("id", "last2")
        .a("to", "[email protected]/balcony")
        .a("type", "get")
        .e("query")
            .namespace(LastActivity.NAMESPACE);

    DummyConnection c = new DummyConnection();
    c.connect();
    IQ lastRequest = (IQ) PacketParserUtils.parseStanza(xml.asString());
    assertTrue(lastRequest instanceof LastActivity);

    c.processPacket(lastRequest);
    Stanza reply = c.getSentPacket();
    assertTrue(reply instanceof LastActivity);
    LastActivity l = (LastActivity) reply;
    assertEquals("last2", l.getStanzaId());
    assertEquals(IQ.Type.result, l.getType());
}
 
开发者ID:TTalkIM,项目名称:Smack,代码行数:23,代码来源:LastActivityTest.java

示例2: createAck

import org.jivesoftware.smack.packet.IQ; //导入依赖的package包/类
/**
 * Acknowledge a IQ packet.
 * 
 * @param iq
 *            The IQ to acknowledge
 */
public IQ createAck(IQ iq) {
    IQ result = null;

    if (iq != null) {
        // Don't acknowledge ACKs, errors...
        if (iq.getType().equals(IQ.Type.set)) {
            IQ ack = IQ.createResultIQ(iq);

            // No! Don't send it.  Let it flow to the normal way IQ results get processed and sent.
            // getConnection().sendStanza(ack);
            result = ack;
        }
    }
    return result;
}
 
开发者ID:TTalkIM,项目名称:Smack,代码行数:22,代码来源:JingleSession.java

示例3: receiveSessionInitiateAction

import org.jivesoftware.smack.packet.IQ; //导入依赖的package包/类
/**
 *  Receive a session-initiate packet.
 *  @param jingle
 *  @param description
 *  @return the iq
 */
private IQ receiveSessionInitiateAction(Jingle jingle, JingleDescription description) {
    IQ response = null;

    List<PayloadType> offeredPayloads = new ArrayList<PayloadType>();

    offeredPayloads = description.getAudioPayloadTypesList();
    bestCommonAudioPt = calculateBestCommonAudioPt(offeredPayloads);
    
    synchronized (remoteAudioPts) {
        remoteAudioPts.addAll(offeredPayloads);
    }

    // If there are suitable/matching payload types then accept this content.
    if (bestCommonAudioPt != null) {
        // Let thre transport negotiators sort-out connectivity and content-accept instead.
        //response = createAudioPayloadTypesOffer();
        setNegotiatorState(JingleNegotiatorState.PENDING);
    } else {
        // Don't really know what to send here.  XEP-166 is not clear.
        setNegotiatorState(JingleNegotiatorState.FAILED);
    }

    return response;
}
 
开发者ID:TTalkIM,项目名称:Smack,代码行数:31,代码来源:MediaNegotiator.java

示例4: shouldRejectRequestWithTooBigBlockSize

import org.jivesoftware.smack.packet.IQ; //导入依赖的package包/类
/**
 * Open request with a block size that exceeds the maximum block size should be replied with an
 * resource-constraint error.
 * 
 * @throws Exception should not happen
 */
@Test
public void shouldRejectRequestWithTooBigBlockSize() throws Exception {
    byteStreamManager.setMaximumBlockSize(1024);

    // run the listener with the initiation packet
    initiationListener.handleIQRequest(initBytestream);

    // wait because packet is processed in an extra thread
    Thread.sleep(200);

    // capture reply to the In-Band Bytestream open request
    ArgumentCaptor<IQ> argument = ArgumentCaptor.forClass(IQ.class);
    verify(connection).sendStanza(argument.capture());

    // assert that reply is the correct error packet
    assertEquals(initiatorJID, argument.getValue().getTo());
    assertEquals(IQ.Type.error, argument.getValue().getType());
    assertEquals(XMPPError.Condition.resource_constraint,
                    argument.getValue().getError().getCondition());

}
 
开发者ID:TTalkIM,项目名称:Smack,代码行数:28,代码来源:InitiationListenerTest.java

示例5: shouldReturnSession

import org.jivesoftware.smack.packet.IQ; //导入依赖的package包/类
@Test
public void shouldReturnSession() throws Exception {
    InBandBytestreamManager byteStreamManager = InBandBytestreamManager.getByteStreamManager(connection);

    IQ success = IBBPacketUtils.createResultIQ(targetJID, initiatorJID);
    protocol.addResponse(success, Verification.correspondingSenderReceiver,
                    Verification.requestTypeSET);

    // start In-Band Bytestream
    InBandBytestreamSession session = byteStreamManager.establishSession(targetJID);

    assertNotNull(session);
    assertNotNull(session.getInputStream());
    assertNotNull(session.getOutputStream());

    protocol.verifyAll();

}
 
开发者ID:TTalkIM,项目名称:Smack,代码行数:19,代码来源:InBandBytestreamManagerTest.java

示例6: unregisterIQRequestHandler

import org.jivesoftware.smack.packet.IQ; //导入依赖的package包/类
@Override
public IQRequestHandler unregisterIQRequestHandler(String element, String namespace, IQ.Type type) {
    final String key = XmppStringUtils.generateKey(element, namespace);
    switch (type) {
    case set:
        synchronized (setIqRequestHandler) {
            return setIqRequestHandler.remove(key);
        }
    case get:
        synchronized (getIqRequestHandler) {
            return getIqRequestHandler.remove(key);
        }
    default:
        throw new IllegalArgumentException("Only IQ type of 'get' and 'set' allowed");
    }
}
 
开发者ID:TTalkIM,项目名称:Smack,代码行数:17,代码来源:AbstractXMPPConnection.java

示例7: receiveSessionInitiateAction

import org.jivesoftware.smack.packet.IQ; //导入依赖的package包/类
/**
 *  @param jingle
 *  @param jingleTransport
 *  @return the iq
 * @throws SmackException 
 */
private IQ receiveSessionInitiateAction(Jingle jingle) throws XMPPException, SmackException {
    IQ response = null;

    // Parse the Jingle and get any proposed transport candidates
    //addRemoteCandidates(obtainCandidatesList(jin));

    // Start offering candidates
    sendTransportCandidatesOffer();

    // All these candidates will be checked asyncronously. Wait for some
    // time and check if we have a valid candidate to use...
    delayedCheckBestCandidate(session, jingle);

    // Set the next state
    setNegotiatorState(JingleNegotiatorState.PENDING);

    return response;
}
 
开发者ID:TTalkIM,项目名称:Smack,代码行数:25,代码来源:TransportNegotiator.java

示例8: InBandBytestreamSession

import org.jivesoftware.smack.packet.IQ; //导入依赖的package包/类
/**
 * Constructor.
 * 
 * @param connection the XMPP connection
 * @param byteStreamRequest the In-Band Bytestream open request for this session
 * @param remoteJID JID of the remote peer
 */
protected InBandBytestreamSession(XMPPConnection connection, Open byteStreamRequest,
                String remoteJID) {
    this.connection = connection;
    this.byteStreamRequest = byteStreamRequest;
    this.remoteJID = remoteJID;

    // initialize streams dependent to the uses stanza type
    switch (byteStreamRequest.getStanza()) {
    case IQ:
        this.inputStream = new IQIBBInputStream();
        this.outputStream = new IQIBBOutputStream();
        break;
    case MESSAGE:
        this.inputStream = new MessageIBBInputStream();
        this.outputStream = new MessageIBBOutputStream();
        break;
    }

}
 
开发者ID:TTalkIM,项目名称:Smack,代码行数:27,代码来源:InBandBytestreamSession.java

示例9: writeToXML

import org.jivesoftware.smack.packet.IQ; //导入依赖的package包/类
@Override
protected synchronized void writeToXML(DataPacketExtension data) throws IOException {
    // create IQ stanza containing data packet
    IQ iq = new Data(data);
    iq.setTo(remoteJID);

    try {
        connection.createPacketCollectorAndSend(iq).nextResultOrThrow();
    }
    catch (Exception e) {
        // close session unless it is already closed
        if (!this.isClosed) {
            InBandBytestreamSession.this.close();
            // Sadly we are unable to use the IOException(Throwable) constructor because this
            // constructor is only supported from Android API 9 on.
            IOException ioException = new IOException();
            ioException.initCause(e);
            throw ioException;
        }
    }

}
 
开发者ID:TTalkIM,项目名称:Smack,代码行数:23,代码来源:InBandBytestreamSession.java

示例10: shouldRespondWithError

import org.jivesoftware.smack.packet.IQ; //导入依赖的package包/类
/**
 * If no listeners are registered for incoming In-Band Bytestream requests, all request should
 * be rejected with an error.
 * 
 * @throws Exception should not happen
 */
@Test
public void shouldRespondWithError() throws Exception {

    // run the listener with the initiation packet
    initiationListener.handleIQRequest(initBytestream);

    // wait because packet is processed in an extra thread
    Thread.sleep(200);

    // capture reply to the In-Band Bytestream open request
    ArgumentCaptor<IQ> argument = ArgumentCaptor.forClass(IQ.class);
    verify(connection).sendStanza(argument.capture());

    // assert that reply is the correct error packet
    assertEquals(initiatorJID, argument.getValue().getTo());
    assertEquals(IQ.Type.error, argument.getValue().getType());
    assertEquals(XMPPError.Condition.not_acceptable,
                    argument.getValue().getError().getCondition());

}
 
开发者ID:TTalkIM,项目名称:Smack,代码行数:27,代码来源:InitiationListenerTest.java

示例11: createAccount

import org.jivesoftware.smack.packet.IQ; //导入依赖的package包/类
/**
 * Creates a new account using the specified username, password and account attributes.
 * The attributes Map must contain only String name/value pairs and must also have values
 * for all required attributes.
 *
 * @param username the username.
 * @param password the password.
 * @param attributes the account attributes.
 * @throws XMPPErrorException if an error occurs creating the account.
 * @throws NoResponseException if there was no response from the server.
 * @throws NotConnectedException 
 * @see #getAccountAttributes()
 */
public void createAccount(String username, String password, Map<String, String> attributes)
                throws NoResponseException, XMPPErrorException, NotConnectedException {
    if (!connection().isSecureConnection() && !allowSensitiveOperationOverInsecureConnection) {
        // TODO throw exception in newer Smack versions
        LOGGER.warning("Creating account over insecure connection. "
                        + "This will throw an exception in future versions of Smack if AccountManager.sensitiveOperationOverInsecureConnection(true) is not set");
    }
    attributes.put("username", username);
    attributes.put("password", password);
    Registration reg = new Registration(attributes);
    reg.setType(IQ.Type.set);
    reg.setTo(connection().getServiceName());
    createPacketCollectorAndSend(reg).nextResultOrThrow();
}
 
开发者ID:TTalkIM,项目名称:Smack,代码行数:28,代码来源:AccountManager.java

示例12: testGetServerVersion

import org.jivesoftware.smack.packet.IQ; //导入依赖的package包/类
/**
 * 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());
}
 
开发者ID:TTalkIM,项目名称:Smack,代码行数:27,代码来源:VersionTest.java

示例13: closeByPeer

import org.jivesoftware.smack.packet.IQ; //导入依赖的package包/类
/**
 * This method is invoked if a request to close the In-Band Bytestream has been received.
 * 
 * @param closeRequest the close request from the remote peer
 * @throws NotConnectedException 
 */
protected void closeByPeer(Close closeRequest) throws NotConnectedException {

    /*
     * close streams without flushing them, because stream is already considered closed on the
     * remote peers side
     */
    this.inputStream.closeInternal();
    this.inputStream.cleanup();
    this.outputStream.closeInternal(false);

    // acknowledge close request
    IQ confirmClose = IQ.createResultIQ(closeRequest);
    this.connection.sendStanza(confirmClose);

}
 
开发者ID:TTalkIM,项目名称:Smack,代码行数:22,代码来源:InBandBytestreamSession.java

示例14: getChatSettings

import org.jivesoftware.smack.packet.IQ; //导入依赖的package包/类
/**
 * Asks the workgroup for it's Chat Settings.
 *
 * @return key specify a key to retrieve only that settings. Otherwise for all settings, key should be null.
 * @throws NoResponseException 
 * @throws XMPPErrorException if an error occurs while getting information from the server.
 * @throws NotConnectedException 
 */
private ChatSettings getChatSettings(String key, int type) throws NoResponseException, XMPPErrorException, NotConnectedException {
    ChatSettings request = new ChatSettings();
    if (key != null) {
        request.setKey(key);
    }
    if (type != -1) {
        request.setType(type);
    }
    request.setType(IQ.Type.get);
    request.setTo(workgroupJID);

    ChatSettings response = (ChatSettings) connection.createPacketCollectorAndSend(request).nextResultOrThrow();

    return response;
}
 
开发者ID:TTalkIM,项目名称:Smack,代码行数:24,代码来源:Workgroup.java

示例15: receiveResult

import org.jivesoftware.smack.packet.IQ; //导入依赖的package包/类
/**
     * Process the ACK of our list of codecs (our offer).
     */
    private Jingle receiveResult(IQ iq) throws XMPPException {
        Jingle response = null;

//        if (!remoteAudioPts.isEmpty()) {
//            // Calculate the best common codec
//            bestCommonAudioPt = calculateBestCommonAudioPt(remoteAudioPts);
//
//            // and send an accept if we havee an agreement...
//            if (bestCommonAudioPt != null) {
//                response = createAcceptMessage();
//            } else {
//                throw new JingleException(JingleError.NO_COMMON_PAYLOAD);
//            }
//        }
        return response;
    }
 
开发者ID:TTalkIM,项目名称:Smack,代码行数:20,代码来源:MediaNegotiator.java


注:本文中的org.jivesoftware.smack.packet.IQ类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。