當前位置: 首頁>>代碼示例>>Java>>正文


Java Message.setBody方法代碼示例

本文整理匯總了Java中org.jivesoftware.smack.packet.Message.setBody方法的典型用法代碼示例。如果您正苦於以下問題:Java Message.setBody方法的具體用法?Java Message.setBody怎麽用?Java Message.setBody使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在org.jivesoftware.smack.packet.Message的用法示例。


在下文中一共展示了Message.setBody方法的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。

示例1: perform

import org.jivesoftware.smack.packet.Message; //導入方法依賴的package包/類
@Test
public void perform() throws Exception {
    SendMessage action = new SendMessage();
    XMPPConnectionMock connection = new XMPPConnectionMock();
    action.connected(connection);
    Message resp = new Message();
    resp.setFrom("[email protected]");
    resp.setBody(SendMessage.RESPONSE_MARKER);
    action.processPacket(resp);
    JMeterXMPPSampler sampler = new JMeterXMPPSamplerMock();
    sampler.getXMPPConnection().setFromMode(XMPPConnection.FromMode.USER);
    sampler.setProperty(SendMessage.RECIPIENT, "[email protected]");
    sampler.setProperty(SendMessage.WAIT_RESPONSE, true);
    SampleResult res = new SampleResult();
    action.perform(sampler, res);
    Assert.assertTrue(res.getResponseDataAsString().contains(SendMessage.RESPONSE_MARKER));
    Assert.assertTrue(res.getSamplerData().contains("from"));
}
 
開發者ID:Blazemeter,項目名稱:jmeter-bzm-plugins,代碼行數:19,代碼來源:SendMessageTest.java

示例2: sendMessage

import org.jivesoftware.smack.packet.Message; //導入方法依賴的package包/類
public void sendMessage(String body, String chatJid, long timestamp) throws SmackException {
    Random random = new Random(timestamp + body.length() + chatJid.length());
    Log.d(TAG, "Sending message to : " + chatJid);
    MultiUserChat chat = MultiUserChatManager.getInstanceFor(groupChatConnection)
            .getMultiUserChat(chatJid);
    chat.addMessageListener(this);

    Message message = new Message();
    QuickbloxChatExtension extension = new QuickbloxChatExtension();
    extension.setProperty("date_sent", timestamp + "");
    message.setStanzaId(StanzaIdUtil.newStanzaId());
    message.setBody(body);
    message.addExtension(extension);
    message.setType(Message.Type.chat);

    chat.sendMessage(message);
}
 
開發者ID:ukevgen,項目名稱:BizareChat,代碼行數:18,代碼來源:QuickbloxGroupXmppConnection.java

示例3: sendPrivateMessage

import org.jivesoftware.smack.packet.Message; //導入方法依賴的package包/類
public void sendPrivateMessage(String body, String receiverJid, long timestamp, String stanzaId) {
    Log.d(TAG, "Sending message to : " + receiverJid);

    Chat chat;
    if ((chat = privateChats.get(receiverJid)) == null) {
        chat = ChatManager.getInstanceFor(privateChatConnection).createChat(receiverJid, this);
        privateChats.put(receiverJid, chat);
    }

    QuickbloxChatExtension extension = new QuickbloxChatExtension();
    extension.setProperty("date_sent", timestamp + "");
    extension.setProperty("save_to_history", "1");

    Message message = new Message(receiverJid);
    message.setStanzaId(stanzaId);
    message.setBody(body);
    message.setType(Message.Type.chat);
    message.addExtension(new Markable());
    message.addExtension(extension);

    try {
        chat.sendMessage(message);
    } catch (SmackException.NotConnectedException ex) {
        offlineMessages.add(message);
    }
}
 
開發者ID:ukevgen,項目名稱:BizareChat,代碼行數:27,代碼來源:QuickbloxPrivateXmppConnection.java

示例4: sendPublicMessage

import org.jivesoftware.smack.packet.Message; //導入方法依賴的package包/類
public void sendPublicMessage(String body, String chatJid, long timestamp, String stanzaId) {
    Log.d(TAG, "Sending message to : " + chatJid);

    MultiUserChat mucChat = publicChats.get(chatJid);

    QuickbloxChatExtension extension = new QuickbloxChatExtension();
    extension.setProperty("date_sent", timestamp + "");
    extension.setProperty("save_to_history", "1");

    Message message = new Message(chatJid);
    message.setStanzaId(stanzaId);
    message.setBody(body);
    message.setType(Message.Type.groupchat);
    message.addExtension(extension);

    try {
        if (mucChat != null) {
            mucChat.sendMessage(message);
        }
    } catch (SmackException.NotConnectedException ex) {
        offlineMessages.add(message);
    }
}
 
開發者ID:ukevgen,項目名稱:BizareChat,代碼行數:24,代碼來源:QuickbloxPrivateXmppConnection.java

示例5: sendMessage

import org.jivesoftware.smack.packet.Message; //導入方法依賴的package包/類
/**
 * Send provided message to provided JID. Message type is always NORMAL.
 * 
 * @param message
 * @param jid
 * @throws NotConnectedException
 */
public void sendMessage(String message, String jid) throws NotConnectedException {
	
	try{
	String jidFinal = getFullJid(jid);
	logger.debug("Sending message: {} to user: {}", new Object[] { message, jidFinal });
	Message msg = new Message(jidFinal, Message.Type.normal);
	msg.setBody(message);
	connection.sendStanza(msg);
	logger.debug("Successfully sent message to user: {}", jidFinal);}
	catch(NotConnectedException ex){
		ex.printStackTrace();
		
		try {
			logger.debug("Tring again to connect..");
			init();
		} catch (Exception e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
	}
}
 
開發者ID:Pardus-LiderAhenk,項目名稱:lider,代碼行數:29,代碼來源:XMPPClientImpl.java

示例6: testInvitation

import org.jivesoftware.smack.packet.Message; //導入方法依賴的package包/類
public void testInvitation() {
    try {
        GroupChatInvitation invitation = new GroupChatInvitation("[email protected]" + getChatDomain());
        Message message = new Message(getBareJID(1));
        message.setBody("Group chat invitation!");
        message.addExtension(invitation);
        getConnection(0).sendStanza(message);

        Thread.sleep(250);

        Message result = (Message)collector.pollResult();
        assertNotNull("Message not delivered correctly.", result);

        GroupChatInvitation resultInvite = (GroupChatInvitation)result.getExtension("x",
                "jabber:x:conference");

        assertEquals("Invitation not to correct room", "[email protected]" + getChatDomain(),
                resultInvite.getRoomAddress());
    }
    catch (Exception e) {
        fail(e.getMessage());
    }
}
 
開發者ID:TTalkIM,項目名稱:Smack,代碼行數:24,代碼來源:GroupChatInvitationTest.java

示例7: testSendSimpleXHTMLMessage

import org.jivesoftware.smack.packet.Message; //導入方法依賴的package包/類
/**
    * Low level API test.
    * This is a simple test to use with an XMPP client and check if the client receives the message
    * 1. User_1 will send a message with formatted text (XHTML) to user_2
    */
   public void testSendSimpleXHTMLMessage() {
// User1 creates a chat with user2
Chat chat1 = getConnection(0).getChatManager().createChat(getBareJID(1), null);

// User1 creates a message to send to user2
Message msg = new Message();
msg.setSubject("Any subject you want");
msg.setBody("Hey John, this is my new green!!!!");
// Create a XHTMLExtension Package and add it to the message
XHTMLExtension xhtmlExtension = new XHTMLExtension();
xhtmlExtension.addBody(
"<body><p style='font-size:large'>Hey John, this is my new <span style='color:green'>green</span><em>!!!!</em></p></body>");
msg.addExtension(xhtmlExtension);

// User1 sends the message that contains the XHTML to user2
try {
    chat1.sendMessage(msg);
    Thread.sleep(200);
}
catch (Exception e) {
    fail("An error occured sending the message with XHTML");
}
   }
 
開發者ID:TTalkIM,項目名稱:Smack,代碼行數:29,代碼來源:XHTMLExtensionTest.java

示例8: sendProjChromMsg

import org.jivesoftware.smack.packet.Message; //導入方法依賴的package包/類
/**
 * 發送信息到雲同步室
 *
 * @param room  雲同步室
 * @param msg   將要發送的信息
 */
public void sendProjChromMsg(MultiUserChat room, Object msg) {
    if (!room.isJoined())
        return;
    try {
        Message message = new Message(room.getRoom(), Message.Type.groupchat);
        message.setBody(SysUtil.getInstance().getDateAndTimeFormated());
        message.setProperty(MSGCLOUD, msg);
        room.sendMessage(message);
    } catch (XMPPException e) {
        e.printStackTrace();
    }
}
 
開發者ID:lfkdsk,項目名稱:PracticeCode,代碼行數:19,代碼來源:XSCHelper.java

示例9: processMessageWithoutAlias

import org.jivesoftware.smack.packet.Message; //導入方法依賴的package包/類
/**
 * This method sends a message without an alias, the listener should send an error message back
 * to the sender.
 *
 * @param listener
 *            The listener.
 * @param connection
 *            The connection.
 * @throws NotConnectedException
 */
private void processMessageWithoutAlias(PacketListener listener, XMPPConnection connection)
        throws NotConnectedException {
    Message message = new Message();
    String sender = user.getAlias() + ".global" + USER_SUFFIX;
    message.setFrom(sender);
    message.setThread(blog.getNameIdentifier() + ".global" + BLOG_SUFFIX);
    message.setBody("Empty");
    listener.processPacket(message);
    Packet packet = connection.getLastPacket();
    Assert.assertEquals(packet.getTo(), sender);
    Assert.assertTrue(((Message) packet).getBody().contains("To post to a topic"));
}
 
開發者ID:Communote,項目名稱:communote-server,代碼行數:23,代碼來源:XMPPPacketListenerTest.java

示例10: createChatPacket

import org.jivesoftware.smack.packet.Message; //導入方法依賴的package包/類
private Message createChatPacket(final String threadId, final boolean isFullJid) {
    Message chatMsg = new Message("[email protected]", Message.Type.chat);
    chatMsg.setBody("the body message - " + System.currentTimeMillis());
    chatMsg.setFrom("[email protected]" + (isFullJid ? "/resource" : ""));
    chatMsg.setThread(threadId);
    return chatMsg;
}
 
開發者ID:TTalkIM,項目名稱:Smack,代碼行數:8,代碼來源:ChatConnectionTest.java

示例11: populateXmppMessage

import org.jivesoftware.smack.packet.Message; //導入方法依賴的package包/類
/**
 * Populates the given XMPP message from the inbound exchange
 */
public void populateXmppMessage(Message message, Exchange exchange) {
    message.setBody(exchange.getIn().getBody(String.class));

    Set<Map.Entry<String, Object>> entries = exchange.getIn().getHeaders().entrySet();
    for (Map.Entry<String, Object> entry : entries) {
        String name = entry.getKey();
        Object value = entry.getValue();
        if (!headerFilterStrategy.applyFilterToCamelHeaders(name, value, exchange)) {

            if ("subject".equalsIgnoreCase(name)) {
                // special for subject
                String subject = exchange.getContext().getTypeConverter().convertTo(String.class, value);
                message.setSubject(subject);
            } else if ("language".equalsIgnoreCase(name)) {
                // special for language
                String language = exchange.getContext().getTypeConverter().convertTo(String.class, value);
                message.setLanguage(language);
            } else {
                try {
                    JivePropertiesManager.addProperty(message, name, value);
                    LOG.trace("Added property name: {} value: {}", name, value.toString());
                } catch (IllegalArgumentException iae) {
                    if (LOG.isDebugEnabled()) {
                        LOG.debug("Cannot add property " + name + " to XMPP message due: ", iae);
                    }
                }
            }
        }
    }

    String id = exchange.getExchangeId();
    if (id != null) {
        JivePropertiesManager.addProperty(message, "exchangeId", id);
    }
}
 
開發者ID:HydAu,項目名稱:Camel,代碼行數:39,代碼來源:XmppBinding.java

示例12: sendRoomChanged

import org.jivesoftware.smack.packet.Message; //導入方法依賴的package包/類
public void sendRoomChanged() throws XMPPException {
  Message m = monitorRoom.createMessage();
  m.setBody(ROOM_CHANGE_ACTION);
  monitorRoom.sendMessage(m);
}
 
開發者ID:ajmath,項目名稱:VASSAL-src,代碼行數:6,代碼來源:JabberClient.java

示例13: postDefaultMessage

import org.jivesoftware.smack.packet.Message; //導入方法依賴的package包/類
private void postDefaultMessage(MultiUserChat chat, FirehoseMessage firehoseMessage) {
        Message msg = chat.createMessage();
        msg.setBody(MessageFormat.format("<{0}>: {1}", firehoseMessage.user, firehoseMessage.content));

        XHTMLText xhtml = new XHTMLText(null, null);
        xhtml.appendOpenSpanTag("color: #" + MiscUtils.toRGB(firehoseMessage.user));
        xhtml.append(firehoseMessage.user);
        xhtml.appendCloseSpanTag();
//        xhtml.appendOpenStrongTag();
//        xhtml.append(firehoseMessage.user);
//        xhtml.appendCloseStrongTag();
        xhtml.append(": ");

        XMPPUtils.toXMPPXHTML(firehoseMessage.content, xhtml);

        XHTMLManager.addBody(msg, xhtml.toString());
        try {
            chat.sendMessage(msg);
        } catch (XMPPException e) {
            logger.error(MessageFormat.format("Error publishing XHTML-enabled message to chatroom {0}. Message: {1}. Original message: {2}",
                                              chat.getRoom(),
                                              e.getMessage(),
                                              firehoseMessage.toLogString()
                                             ));
            try {
                logger.info(
                        MessageFormat.format(
                                "Attempting to send plain XMPP message to chatroom {0}: {1}",
                                chat.getRoom(),
                                firehoseMessage.toLogString()
                                            )
                           );
                chat.sendMessage(firehoseMessage.user + ": " + firehoseMessage.content);
            } catch (XMPPException e1) {
                logger.error(
                        MessageFormat.format(
                                "Error publishing plain message to chatroom {0}. Message: {1}. Original message: {2}",
                                chat.getRoom(),
                                e1.getMessage(),
                                firehoseMessage.toLogString()
                                            )
                            );
            }
        }
    }
 
開發者ID:dmitriid,項目名稱:tetrad,代碼行數:46,代碼來源:TetradXMPP.java

示例14: testProperties

import org.jivesoftware.smack.packet.Message; //導入方法依賴的package包/類
public void testProperties() {
    try {
        Chat newChat = getConnection(0).getChatManager().createChat(getFullJID(1), null);
        PacketCollector collector = getConnection(1)
                .createPacketCollector(new ThreadFilter(newChat.getThreadID()));

        Message msg = new Message();

        msg.setSubject("Subject of the chat");
        msg.setBody("Body of the chat");
        msg.setProperty("favoriteColor", "red");
        msg.setProperty("age", 30);
        msg.setProperty("distance", 30f);
        msg.setProperty("weight", 30d);
        msg.setProperty("male", true);
        msg.setProperty("birthdate", new Date());
        newChat.sendMessage(msg);

        Message msg2 = (Message) collector.nextResult(2000);

        assertNotNull("No message was received", msg2);
        assertEquals("Subjects are different", msg.getSubject(), msg2.getSubject());
        assertEquals("Bodies are different", msg.getBody(), msg2.getBody());
        assertEquals(
                "favoriteColors are different",
                msg.getProperty("favoriteColor"),
                msg2.getProperty("favoriteColor"));
        assertEquals(
                "ages are different",
                msg.getProperty("age"),
                msg2.getProperty("age"));
        assertEquals(
                "distances are different",
                msg.getProperty("distance"),
                msg2.getProperty("distance"));
        assertEquals(
                "weights are different",
                msg.getProperty("weight"),
                msg2.getProperty("weight"));
        assertEquals(
                "males are different",
                msg.getProperty("male"),
                msg2.getProperty("male"));
        assertEquals(
                "birthdates are different",
                msg.getProperty("birthdate"),
                msg2.getProperty("birthdate"));
    }
    catch (XMPPException e) {
        e.printStackTrace();
        fail(e.getMessage());
    }
}
 
開發者ID:TTalkIM,項目名稱:Smack,代碼行數:54,代碼來源:ChatTest.java

示例15: testSending

import org.jivesoftware.smack.packet.Message; //導入方法依賴的package包/類
/**
 * Ensures that sending and receiving of packets is ok.
 */
public void testSending() throws XMPPException {

    PacketCollector collector1 =
            getConnection(1).createPacketCollector(new MessageTypeFilter(Message.Type.normal));
    PacketCollector collector2 =
            getConnection(2).createPacketCollector(new MessageTypeFilter(Message.Type.normal));
    PacketCollector collector3 =
            getConnection(3).createPacketCollector(new MessageTypeFilter(Message.Type.normal));

    Message message = new Message();
    message.setBody("Hola");
    List<String> to = Arrays.asList(new String[]{getBareJID(1)});
    List<String> cc = Arrays.asList(new String[]{getBareJID(2)});
    List<String> bcc = Arrays.asList(new String[]{getBareJID(3)});
    MultipleRecipientManager.send(getConnection(0), message, to, cc, bcc);

    Packet message1 = collector1.nextResult(SmackConfiguration.getPacketReplyTimeout());
    assertNotNull("XMPPConnection 1 never received the message", message1);
    MultipleRecipientInfo info1 = MultipleRecipientManager.getMultipleRecipientInfo(message1);
    assertNotNull("Message 1 does not contain MultipleRecipientInfo", info1);
    assertFalse("Message 1 should be 'replyable'", info1.shouldNotReply());
    List<?> addresses1 = info1.getTOAddresses();
    assertEquals("Incorrect number of TO addresses", 1, addresses1.size());
    String address1 = ((MultipleAddresses.Address) addresses1.get(0)).getJid();
    assertEquals("Incorrect TO address", getBareJID(1), address1);
    addresses1 = info1.getCCAddresses();
    assertEquals("Incorrect number of CC addresses", 1, addresses1.size());
    address1 = ((MultipleAddresses.Address) addresses1.get(0)).getJid();
    assertEquals("Incorrect CC address", getBareJID(2), address1);

    Packet message2 = collector2.nextResult(SmackConfiguration.getPacketReplyTimeout());
    assertNotNull("XMPPConnection 2 never received the message", message2);
    MultipleRecipientInfo info2 = MultipleRecipientManager.getMultipleRecipientInfo(message2);
    assertNotNull("Message 2 does not contain MultipleRecipientInfo", info2);
    assertFalse("Message 2 should be 'replyable'", info2.shouldNotReply());
    List<MultipleAddresses.Address> addresses2 = info2.getTOAddresses();
    assertEquals("Incorrect number of TO addresses", 1, addresses2.size());
    String address2 = ((MultipleAddresses.Address) addresses2.get(0)).getJid();
    assertEquals("Incorrect TO address", getBareJID(1), address2);
    addresses2 = info2.getCCAddresses();
    assertEquals("Incorrect number of CC addresses", 1, addresses2.size());
    address2 = ((MultipleAddresses.Address) addresses2.get(0)).getJid();
    assertEquals("Incorrect CC address", getBareJID(2), address2);

    Packet message3 = collector3.nextResult(SmackConfiguration.getPacketReplyTimeout());
    assertNotNull("XMPPConnection 3 never received the message", message3);
    MultipleRecipientInfo info3 = MultipleRecipientManager.getMultipleRecipientInfo(message3);
    assertNotNull("Message 3 does not contain MultipleRecipientInfo", info3);
    assertFalse("Message 3 should be 'replyable'", info3.shouldNotReply());
    List<MultipleAddresses.Address> addresses3 = info3.getTOAddresses();
    assertEquals("Incorrect number of TO addresses", 1, addresses3.size());
    String address3 = ((MultipleAddresses.Address) addresses3.get(0)).getJid();
    assertEquals("Incorrect TO address", getBareJID(1), address3);
    addresses3 = info3.getCCAddresses();
    assertEquals("Incorrect number of CC addresses", 1, addresses3.size());
    address3 = ((MultipleAddresses.Address) addresses3.get(0)).getJid();
    assertEquals("Incorrect CC address", getBareJID(2), address3);

    collector1.cancel();
    collector2.cancel();
    collector3.cancel();
}
 
開發者ID:TTalkIM,項目名稱:Smack,代碼行數:66,代碼來源:MultipleRecipientManagerTest.java


注:本文中的org.jivesoftware.smack.packet.Message.setBody方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。