Package org.jivesoftware.smack.packet

Examples of org.jivesoftware.smack.packet.Message$Type


        //Listener für eingehende Messages, dass dann ein Fenster geöffnet wird
        final PacketListener pktListener = new PacketListener() {
            public void processPacket(Packet pktPacket) {
                boolean bWindow = false;
                if (pktPacket instanceof Message) {
                    Message msg = (Message) pktPacket;
                    //String strFrom = msg.getFrom().substring(0, msg.getFrom().indexOf("/"));
                    String strFrom = msg.getFrom();
                    //System.out.println("Message: " + msg.getFrom() + " " + msg.getBody());
                    //System.out.println("geoeffnete Fenster:");
                    for(Frame frame : JFrame.getFrames()){
                        //if(frame.isVisible()){
                        //System.out.println(frame.getTitle());
                        //}
                        if (frame.getTitle().equals(strFrom))
                        {
                            //es ist schon ein ChatWindow für diesen Kontakt da
                            //wie sende ich die machricht am geschicktesten da hin???
                            //(ChatWindow) frame.setMessage(msg);
                            bWindow = true;
                            System.out.println("FENSTER offen!");
//                           xmppConnection.getChatManager().getThreadChat(msg.getThread()).
                            break;
                        }
                    }
                    if (bWindow == false)
                    {
                        ChatWindow wndChat1 = new ChatWindow(xmppconnection, msg, contacts.getContact(msg.getFrom(), false));
                        wndChat1.setVisible(true);
                        andFilter.addFilter(new NotFilter(new FromContainsFilter(msg.getFrom())));
                        xmppconnection.addPacketListener(this, andFilter);
                    }
                }
            }
        };
View Full Code Here


            // Get the offline messages
            Iterator messages = offlineManager.getMessages(stamps);
            assertTrue("No message was found", messages.hasNext());
            stamps = new ArrayList<String>();
            while (messages.hasNext()) {
                Message message = (Message) messages.next();
                OfflineMessageInfo info = (OfflineMessageInfo) message.getExtension("offline",
                        "http://jabber.org/protocol/offline");
                assertNotNull("No offline information was included in the offline message", info);
                assertNotNull("No stamp was found in the message header", info.getNode());
                stamps.add(info.getNode());
            }
            assertEquals("Wrong number of messages", 2, stamps.size());
            // Check that the offline messages have not been deleted
            assertEquals("Wrong number of offline messages", 2, offlineManager.getMessageCount());

            // User2 becomes available again
            PacketCollector collector = getConnection(1).createPacketCollector(
                    new MessageTypeFilter(Message.Type.chat));
            getConnection(1).sendPacket(new Presence(Presence.Type.available));

            // Check that no offline messages was sent to the user
            Message message = (Message) collector.nextResult(2500);
            assertNull("An offline message was sent from the server", message);

            // Delete the retrieved offline messages
            offlineManager.deleteMessages(stamps);
            // Check that there are no offline message for this user
View Full Code Here

            // Get all offline messages
            Iterator messages = offlineManager.getMessages();
            assertTrue("No message was found", messages.hasNext());
            List<String> stamps = new ArrayList<String>();
            while (messages.hasNext()) {
                Message message = (Message) messages.next();
                OfflineMessageInfo info = (OfflineMessageInfo) message.getExtension("offline",
                        "http://jabber.org/protocol/offline");
                assertNotNull("No offline information was included in the offline message", info);
                assertNotNull("No stamp was found in the message header", info.getNode());
                stamps.add(info.getNode());
            }
            assertEquals("Wrong number of messages", 2, stamps.size());
            // Check that the offline messages have not been deleted
            assertEquals("Wrong number of offline messages", 2, offlineManager.getMessageCount());

            // User2 becomes available again
            PacketCollector collector = getConnection(1).createPacketCollector(
                    new MessageTypeFilter(Message.Type.chat));
            getConnection(1).sendPacket(new Presence(Presence.Type.available));

            // Check that no offline messages was sent to the user
            Message message = (Message) collector.nextResult(2500);
            assertNull("An offline message was sent from the server", message);

            // Delete all offline messages
            offlineManager.deleteMessages();
            // Check that there are no offline message for this user
View Full Code Here

        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 to = Arrays.asList(new String[]{getBareJID(1)});
        List cc = Arrays.asList(new String[]{getBareJID(2)});
        List bcc = Arrays.asList(new String[]{getBareJID(3)});
        MultipleRecipientManager.send(getConnection(0), message, to, cc, bcc);
View Full Code Here

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

        // Send the intial message with multiple recipients
        Message message = new Message();
        message.setBody("Hola");
        List to = Arrays.asList(new String[]{getBareJID(1)});
        List cc = Arrays.asList(new String[]{getBareJID(2)});
        List bcc = Arrays.asList(new String[]{getBareJID(3)});
        MultipleRecipientManager.send(getConnection(0), message, to, cc, bcc);

        // Get the message and ensure it's ok
        Message message1 =
                (Message) collector1.nextResult(SmackConfiguration.getPacketReplyTimeout());
        assertNotNull("Connection 1 never received the message", message1);
        MultipleRecipientInfo info = MultipleRecipientManager.getMultipleRecipientInfo(message1);
        assertNotNull("Message 1 does not contain MultipleRecipientInfo", info);
        assertFalse("Message 1 should be 'replyable'", info.shouldNotReply());
        assertEquals("Incorrect number of TO addresses", 1, info.getTOAddresses().size());
        assertEquals("Incorrect number of CC addresses", 1, info.getCCAddresses().size());

        // Prepare and send the reply
        Message reply1 = new Message();
        reply1.setBody("This is my reply");
        MultipleRecipientManager.reply(getConnection(1), message1, reply1);

        // Get the reply and ensure it's ok
        reply1 = (Message) collector0.nextResult(SmackConfiguration.getPacketReplyTimeout());
        assertNotNull("Connection 0 never received the reply", reply1);
        info = MultipleRecipientManager.getMultipleRecipientInfo(reply1);
        assertNotNull("Replied message does not contain MultipleRecipientInfo", info);
        assertFalse("Replied message should be 'replyable'", info.shouldNotReply());
        assertEquals("Incorrect number of TO addresses", 1, info.getTOAddresses().size());
        assertEquals("Incorrect number of CC addresses", 1, info.getCCAddresses().size());

        // Send a reply to the reply
        Message reply2 = new Message();
        reply2.setBody("This is my reply to your reply");
        reply2.setFrom(getBareJID(0));
        MultipleRecipientManager.reply(getConnection(0), reply1, reply2);

        // Get the reply and ensure it's ok
        reply2 = (Message) collector1.nextResult(SmackConfiguration.getPacketReplyTimeout());
        assertNotNull("Connection 1 never received the reply", reply2);
View Full Code Here

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

        // Send the intial message with multiple recipients
        Message message = new Message();
        message.setBody("Hola");
        List to = Arrays.asList(new String[]{getBareJID(1)});
        List cc = Arrays.asList(new String[]{getBareJID(2)});
        List bcc = Arrays.asList(new String[]{getBareJID(3)});
        MultipleRecipientManager.send(getConnection(0), message, to, cc, bcc, null, null, true);

        // Get the message and ensure it's ok
        Message message1 =
                (Message) collector1.nextResult(SmackConfiguration.getPacketReplyTimeout());
        assertNotNull("Connection 1 never received the message", message1);
        MultipleRecipientInfo info = MultipleRecipientManager.getMultipleRecipientInfo(message1);
        assertNotNull("Message 1 does not contain MultipleRecipientInfo", info);
        assertTrue("Message 1 should be not 'replyable'", info.shouldNotReply());
        assertEquals("Incorrect number of TO addresses", 1, info.getTOAddresses().size());
        assertEquals("Incorrect number of CC addresses", 1, info.getCCAddresses().size());

        // Prepare and send the reply
        Message reply1 = new Message();
        reply1.setBody("This is my reply");
        try {
            MultipleRecipientManager.reply(getConnection(1), message1, reply1);
            fail("It was possible to send a reply to a not replyable message");
        }
        catch (XMPPException e) {
View Full Code Here

        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());
        }
View Full Code Here

        };
        // Add a listener for all message packets so that we can deliver errant
        // messages to the best Chat instance available.
        connection.addPacketListener(new PacketListener() {
            public void processPacket(Packet packet) {
                Message message = (Message) packet;
                Chat chat;
                if (message.getThread() == null) {
                  chat = getUserChat(message.getFrom());
                }
                else {
                    chat = getThreadChat(message.getThread());
                    if (chat == null) {
                        // Try to locate the chat based on the sender of the message
                      chat = getUserChat(message.getFrom());
                    }
                }

                if(chat == null) {
                    chat = createChat(message);
View Full Code Here

    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);
View Full Code Here

  Chat chat1 = getConnection(0).getChatManager().createChat(getBareJID(1), null);
  final PacketCollector chat2 = getConnection(1).createPacketCollector(
    new ThreadFilter(chat1.getThreadID()));

  // 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);
  }
  catch (Exception e) {
      fail("An error occured sending the message with XHTML");
  }
  Packet packet = chat2.nextResult(2000);
  Message message = (Message) packet;
  assertNotNull("Body is null", message.getBody());
  try {
      xhtmlExtension =
    (XHTMLExtension) message.getExtension(
      "html",
    "http://jabber.org/protocol/xhtml-im");
      assertNotNull(
        "Message without extension \"http://jabber.org/protocol/xhtml-im\"",
        xhtmlExtension);
View Full Code Here

TOP

Related Classes of org.jivesoftware.smack.packet.Message$Type

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.