Java Code Examples for org.jivesoftware.smack.packet.Message#setType()

The following examples show how to use org.jivesoftware.smack.packet.Message#setType() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: SendMessage.java    From jmeter-bzm-plugins with Apache License 2.0 6 votes vote down vote up
@Override
public SampleResult perform(JMeterXMPPSampler sampler, SampleResult res) throws Exception {
    // sending message
    String recipient = sampler.getPropertyAsString(RECIPIENT);
    String body = sampler.getPropertyAsString(BODY);
    boolean wait_response = sampler.getPropertyAsBoolean(WAIT_RESPONSE);
    if (wait_response) {
        body += "\r\n" + System.currentTimeMillis() + "@" + NEED_RESPONSE_MARKER;
    }

    Message msg = new Message(recipient);
    msg.setType(Message.Type.fromString(sampler.getPropertyAsString(TYPE, Message.Type.normal.toString())));
    msg.addBody("", body);
    res.setSamplerData(msg.toXML().toString());
    sampler.getXMPPConnection().sendPacket(msg);
    res.setSamplerData(msg.toXML().toString()); // second time to reflect the changes made to packet by conn

    if (wait_response) {
        return waitResponse(res, recipient);
    }
    return res;
}
 
Example 2
Source File: OperationSetTypingNotificationsJabberImpl.java    From jitsi with Apache License 2.0 6 votes vote down vote up
/**
 * Creates and sends a packet for the new chat state.
 * @param chatState the new chat state.
 * @param jid the JID of the receiver.
 */
private void setCurrentState(ChatState chatState, Jid jid)
    throws NotConnectedException, InterruptedException
{
    String threadID = opSetBasicIM.getThreadIDForAddress(jid.asBareJid());
    if(threadID == null)
        return;

    Message message = new Message();
    ChatStateExtension extension = new ChatStateExtension(chatState);
    message.addExtension(extension);

    message.setTo(jid);
    message.setType(Message.Type.chat);
    message.setThread(threadID);
    message.setFrom(parentProvider.getConnection().getUser());
    parentProvider.getConnection().sendStanza(message);
}
 
Example 3
Source File: OTREngineHost.java    From Spark with Apache License 2.0 6 votes vote down vote up
@Override
public void injectMessage(SessionID arg0, String arg1) {
    Message injection = new Message();
    injection.setType(Message.Type.chat);
    injection.setTo(_chatRoom.getParticipantJID());
    injection.setFrom(SparkManager.getSessionManager().getJID());
    String threadID = StringUtils.randomString(6);
    injection.setThread(threadID);
    injection.setBody(arg1);
    try
    {
        SparkManager.getConnection().sendStanza(injection);
    }
    catch ( SmackException.NotConnectedException e )
    {
        Log.warning( "Unable to send injection to " + injection.getTo(), e );
    }
}
 
Example 4
Source File: SendMessage.java    From jmeter-bzm-plugins with Apache License 2.0 5 votes vote down vote up
private void sendResponseMessage(Message inMsg) {
    Message outMsg = new Message(inMsg.getFrom());
    outMsg.setType(inMsg.getType());
    outMsg.addBody("", inMsg.getBody() + "\r\n" + System.currentTimeMillis() + "@" + RESPONSE_MARKER);
    log.debug("Responding to message: " + outMsg.toXML());
    try {
        conn.sendPacket(outMsg);
    } catch (SmackException e) {
        log.error("Failed to send response", e);
    }
}
 
Example 5
Source File: XmppClient.java    From riotapi with Apache License 2.0 5 votes vote down vote up
public void sendToUser(String to, String message) throws Exception {
	Message packet = new Message(to);
	packet.setBody(message);
	packet.setType(Message.Type.chat);
	packet.setFrom(getUser().split("/")[0]);
	sendPacket(packet);
}
 
Example 6
Source File: Chat.java    From Smack with Apache License 2.0 5 votes vote down vote up
/**
 * Sends a message to the other chat participant. The thread ID, recipient,
 * and message type of the message will automatically set to those of this chat.
 *
 * @param message the message to send.
 * @throws NotConnectedException if the XMPP connection is not connected.
 * @throws InterruptedException if the calling thread was interrupted.
 */
public void sendMessage(Message message) throws NotConnectedException, InterruptedException {
    // Force the recipient, message type, and thread ID since the user elected
    // to send the message through this chat object.
    message.setTo(participant);
    message.setType(Message.Type.chat);
    message.setThread(threadID);
    chatManager.sendMessage(this, message);
}
 
Example 7
Source File: GroupChatRoom.java    From Spark with Apache License 2.0 5 votes vote down vote up
/**
 * Sends a message.
 *
 * @param message - the message to send.
 */
@Override
public void sendMessage( Message message )
{
    try
    {
        message.setTo( chat.getRoom() );
        message.setType( Message.Type.groupchat );
        MessageEventManager.addNotificationsRequests( message, true, true, true, true );
        addPacketID( message.getStanzaId() );

        SparkManager.getChatManager().filterOutgoingMessage( this, message );
        SparkManager.getChatManager().fireGlobalMessageSentListeners( this, message );

        chat.sendMessage( message );
    }
    catch ( SmackException | InterruptedException ex )
    {
        Log.error( "Unable to send message in conference chat.", ex );
    }

    // Notify users that message has been sent.
    fireMessageSent( message );

    addToTranscript( message, false );

    getChatInputEditor().clear();
    getTranscriptWindow().validate();
    getTranscriptWindow().repaint();

    getChatInputEditor().setCaretPosition( 0 );
    getChatInputEditor().requestFocusInWindow();
    scrollToBottom();

    lastActivity = System.currentTimeMillis();
}
 
Example 8
Source File: CoBrowser.java    From Spark with Apache License 2.0 5 votes vote down vote up
private void send(Message message) {
    GroupChatRoom groupChatRoom = (GroupChatRoom)chatRoom;
    try {
        message.setTo(groupChatRoom.getRoomname());
        message.setType(Message.Type.groupchat);
        MessageEventManager.addNotificationsRequests(message, true, true, true, true);


        groupChatRoom.getMultiUserChat().sendMessage(message);
    }
    catch (SmackException | InterruptedException ex) {
        Log.error("Unable to send message in conference chat.", ex);
    }

}