本文整理匯總了Java中org.jivesoftware.smack.packet.IQ.setTo方法的典型用法代碼示例。如果您正苦於以下問題:Java IQ.setTo方法的具體用法?Java IQ.setTo怎麽用?Java IQ.setTo使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類org.jivesoftware.smack.packet.IQ
的用法示例。
在下文中一共展示了IQ.setTo方法的9個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。
示例1: sendStanza
import org.jivesoftware.smack.packet.IQ; //導入方法依賴的package包/類
@Override
public void sendStanza(Stanza packet) throws NotConnectedException {
super.sendStanza(packet);
if (packet instanceof IQ && !timeout) {
timeout = false;
// Set reply packet to match one being sent. We haven't started the
// other thread yet so this is still safe.
IQ replyPacket = replyQ.peek();
// If no reply has been set via addIQReply, then we create a simple reply
if (replyPacket == null) {
replyPacket = IQ.createResultIQ((IQ) packet);
replyQ.add(replyPacket);
}
replyPacket.setStanzaId(packet.getStanzaId());
replyPacket.setFrom(packet.getTo());
replyPacket.setTo(packet.getFrom());
replyPacket.setType(Type.result);
new ProcessQueue(replyQ).start();
}
}
示例2: 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;
}
}
}
示例3: createResultIQ
import org.jivesoftware.smack.packet.IQ; //導入方法依賴的package包/類
/**
* Returns a result IQ.
*
* @param from the senders JID
* @param to the recipients JID
* @return a result IQ
*/
public static IQ createResultIQ(String from, String to) {
IQ result = new EmptyResultIQ();
result.setType(IQ.Type.result);
result.setFrom(from);
result.setTo(to);
return result;
}
示例4: shouldFailIfActivateSocks5ProxyFails
import org.jivesoftware.smack.packet.IQ; //導入方法依賴的package包/類
/**
* If the initiator can connect to a SOCKS5 proxy but activating the stream fails an exception
* should be thrown.
*
* @throws Exception should not happen
*/
@Test
public void shouldFailIfActivateSocks5ProxyFails() throws Exception {
// build error response as reply to the stream activation
XMPPError xmppError = new XMPPError(XMPPError.Condition.internal_server_error);
IQ error = new ErrorIQ(xmppError);
error.setFrom(proxyJID);
error.setTo(initiatorJID);
protocol.addResponse(error, Verification.correspondingSenderReceiver,
Verification.requestTypeSET);
// start a local SOCKS5 proxy
Socks5TestProxy socks5Proxy = Socks5TestProxy.getProxy(proxyPort);
socks5Proxy.start();
StreamHost streamHost = new StreamHost(proxyJID,
socks5Proxy.getAddress(), socks5Proxy.getPort());
// create digest to get the socket opened by target
String digest = Socks5Utils.createDigest(sessionID, initiatorJID, targetJID);
Socks5ClientForInitiator socks5Client = new Socks5ClientForInitiator(streamHost, digest,
connection, sessionID, targetJID);
try {
socks5Client.getSocket(10000);
fail("exception should be thrown");
}
catch (XMPPErrorException e) {
assertTrue(XMPPError.Condition.internal_server_error.equals(e.getXMPPError().getCondition()));
protocol.verifyAll();
}
socks5Proxy.stop();
}
示例5: shouldSuccessfullyEstablishConnectionAndActivateSocks5Proxy
import org.jivesoftware.smack.packet.IQ; //導入方法依賴的package包/類
/**
* Target and initiator should successfully connect to a "remote" SOCKS5 proxy and the initiator
* activates the bytestream.
*
* @throws Exception should not happen
*/
@Test
public void shouldSuccessfullyEstablishConnectionAndActivateSocks5Proxy() throws Exception {
// build activation confirmation response
IQ activationResponse = new EmptyResultIQ();
activationResponse.setFrom(proxyJID);
activationResponse.setTo(initiatorJID);
protocol.addResponse(activationResponse, Verification.correspondingSenderReceiver,
Verification.requestTypeSET, new Verification<Bytestream, IQ>() {
public void verify(Bytestream request, IQ response) {
// verify that the correct stream should be activated
assertNotNull(request.getToActivate());
assertEquals(targetJID, request.getToActivate().getTarget());
}
});
// start a local SOCKS5 proxy
Socks5TestProxy socks5Proxy = Socks5TestProxy.getProxy(proxyPort);
socks5Proxy.start();
StreamHost streamHost = new StreamHost(proxyJID,
socks5Proxy.getAddress(), socks5Proxy.getPort());
// create digest to get the socket opened by target
String digest = Socks5Utils.createDigest(sessionID, initiatorJID, targetJID);
Socks5ClientForInitiator socks5Client = new Socks5ClientForInitiator(streamHost, digest,
connection, sessionID, targetJID);
Socket initiatorSocket = socks5Client.getSocket(10000);
InputStream in = initiatorSocket.getInputStream();
Socket targetSocket = socks5Proxy.getSocket(digest);
OutputStream out = targetSocket.getOutputStream();
// verify test data
for (int i = 0; i < 10; i++) {
out.write(i);
assertEquals(i, in.read());
}
protocol.verifyAll();
initiatorSocket.close();
targetSocket.close();
socks5Proxy.stop();
}
示例6: sendRoomInvitation
import org.jivesoftware.smack.packet.IQ; //導入方法依賴的package包/類
/**
* Invites a user or agent to an existing session support. The provided invitee's JID can be of
* a user, an agent, a queue or a workgroup. In the case of a queue or a workgroup the workgroup service
* will decide the best agent to receive the invitation.<p>
*
* This method will return either when the service returned an ACK of the request or if an error occured
* while requesting the invitation. After sending the ACK the service will send the invitation to the target
* entity. When dealing with agents the common sequence of offer-response will be followed. However, when
* sending an invitation to a user a standard MUC invitation will be sent.<p>
*
* The agent or user that accepted the offer <b>MUST</b> join the room. Failing to do so will make
* the invitation to fail. The inviter will eventually receive a message error indicating that the invitee
* accepted the offer but failed to join the room.
*
* Different situations may lead to a failed invitation. Possible cases are: 1) all agents rejected the
* offer and ther are no agents available, 2) the agent that accepted the offer failed to join the room or
* 2) the user that received the MUC invitation never replied or joined the room. In any of these cases
* (or other failing cases) the inviter will get an error message with the failed notification.
*
* @param type type of entity that will get the invitation.
* @param invitee JID of entity that will get the invitation.
* @param sessionID ID of the support session that the invitee is being invited.
* @param reason the reason of the invitation.
* @throws XMPPErrorException if the sender of the invitation is not an agent or the service failed to process
* the request.
* @throws NoResponseException
* @throws NotConnectedException
*/
public void sendRoomInvitation(RoomInvitation.Type type, String invitee, String sessionID, String reason) throws NoResponseException, XMPPErrorException, NotConnectedException
{
final RoomInvitation invitation = new RoomInvitation(type, invitee, sessionID, reason);
IQ iq = new RoomInvitation.RoomInvitationIQ(invitation);
iq.setType(IQ.Type.set);
iq.setTo(workgroupJID);
iq.setFrom(connection.getUser());
connection.createPacketCollectorAndSend(iq).nextResultOrThrow();
}
示例7: sendRoomTransfer
import org.jivesoftware.smack.packet.IQ; //導入方法依賴的package包/類
/**
* Transfer an existing session support to another user or agent. The provided invitee's JID can be of
* a user, an agent, a queue or a workgroup. In the case of a queue or a workgroup the workgroup service
* will decide the best agent to receive the invitation.<p>
*
* This method will return either when the service returned an ACK of the request or if an error occured
* while requesting the transfer. After sending the ACK the service will send the invitation to the target
* entity. When dealing with agents the common sequence of offer-response will be followed. However, when
* sending an invitation to a user a standard MUC invitation will be sent.<p>
*
* Once the invitee joins the support room the workgroup service will kick the inviter from the room.<p>
*
* Different situations may lead to a failed transfers. Possible cases are: 1) all agents rejected the
* offer and there are no agents available, 2) the agent that accepted the offer failed to join the room
* or 2) the user that received the MUC invitation never replied or joined the room. In any of these cases
* (or other failing cases) the inviter will get an error message with the failed notification.
*
* @param type type of entity that will get the invitation.
* @param invitee JID of entity that will get the invitation.
* @param sessionID ID of the support session that the invitee is being invited.
* @param reason the reason of the invitation.
* @throws XMPPErrorException if the sender of the invitation is not an agent or the service failed to process
* the request.
* @throws NoResponseException
* @throws NotConnectedException
*/
public void sendRoomTransfer(RoomTransfer.Type type, String invitee, String sessionID, String reason) throws NoResponseException, XMPPErrorException, NotConnectedException
{
final RoomTransfer transfer = new RoomTransfer(type, invitee, sessionID, reason);
IQ iq = new RoomTransfer.RoomTransferIQ(transfer);
iq.setType(IQ.Type.set);
iq.setTo(workgroupJID);
iq.setFrom(connection.getUser());
connection.createPacketCollectorAndSend(iq).nextResultOrThrow();
}
示例8: createErrorIQ
import org.jivesoftware.smack.packet.IQ; //導入方法依賴的package包/類
/**
* Returns an error IQ.
*
* @param from the senders JID
* @param to the recipients JID
* @param xmppError the XMPP error
* @return an error IQ
*/
public static IQ createErrorIQ(String from, String to, XMPPError xmppError) {
IQ errorIQ = new ErrorIQ(xmppError);
errorIQ.setType(IQ.Type.error);
errorIQ.setFrom(from);
errorIQ.setTo(to);
return errorIQ;
}
示例9: createActivationConfirmation
import org.jivesoftware.smack.packet.IQ; //導入方法依賴的package包/類
/**
* Returns a response IQ for a activation request to the proxy.
*
* @param from JID of the proxy
* @param to JID of the client who wants to activate the SOCKS5 Bytestream
* @return response IQ for a activation request to the proxy
*/
public static IQ createActivationConfirmation(String from, String to) {
IQ response = new EmptyResultIQ();
response.setFrom(from);
response.setTo(to);
return response;
}