Package org.jivesoftware.smack

Examples of org.jivesoftware.smack.Chat


        chat.sendMessage(message);
    }
   
    private Chat chatWith(String recipient)
    {
        Chat chat = chats.get(recipient);
        if (chat == null)
        {
            chat = connection.getChatManager().createChat(recipient, this);
            chats.put(recipient, chat);
        }
View Full Code Here


        handleException("Connection to XMPP Server is not established.");       
      }
   
    //initialize the chat manager using connection
    ChatManager chatManager = xmppConnection.getChatManager();
    Chat chat = chatManager.createChat(xmppOutTransportInfo.getDestinationAccount(), null);   
   
    try
    {
      OMElement msgElement = msgCtx.getEnvelope();
      if (msgCtx.isDoingREST()) {
        msgElement = msgCtx.getEnvelope().getBody().getFirstElement();
      }
      boolean waitForResponse =
        msgCtx.getOperationContext() != null &&
        WSDL2Constants.MEP_URI_OUT_IN.equals(
            msgCtx.getOperationContext().getAxisOperation().getMessageExchangePattern());
     
     
      String soapMessage = msgElement.toString();
      //int endOfXMLDeclaration = soapMessage.indexOf("?>");
      //String modifiedSOAPMessage = soapMessage.substring(endOfXMLDeclaration+2);
      message.setBody(soapMessage)
     
      XMPPClientSidePacketListener xmppClientSidePacketListener = null;
      if(waitForResponse && !msgCtx.isServerSide()){
        PacketFilter filter = new PacketTypeFilter(message.getClass());       
        xmppClientSidePacketListener = new XMPPClientSidePacketListener(msgCtx);
        xmppConnection.addPacketListener(xmppClientSidePacketListener,filter);
      }     

      chat.sendMessage(message);
      log.debug("Sent message :"+message.toXML());

      //If this is on client side, wait for the response from server.
      //Is this the best way to do this?
      if(waitForResponse && !msgCtx.isServerSide()){
View Full Code Here

        try {
            Thread.sleep(500);

            // User1 sends some messages to User2 which is not available at the moment
            Chat chat = getConnection(0).getChatManager().createChat(getBareJID(1), null);
            chat.sendMessage("Test 1");
            chat.sendMessage("Test 2");

            Thread.sleep(500);

            // User2 checks the number of offline messages
            OfflineMessageManager offlineManager = new OfflineMessageManager(getConnection(1));
View Full Code Here

        try {
            Thread.sleep(500);

            // User1 sends some messages to User2 which is not available at the moment
            Chat chat = getConnection(0).getChatManager().createChat(getBareJID(1), null);
            chat.sendMessage("Test 1");
            chat.sendMessage("Test 2");

            Thread.sleep(500);

            // User2 checks the number of offline messages
            OfflineMessageManager offlineManager = new OfflineMessageManager(getConnection(1));
View Full Code Here

     * This is a simple test to use with a 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");
  }
View Full Code Here

     * 3. User_1 will wait several seconds for an ACK from user_2, if none is received then
     * something is wrong
     */
    public void testSendSimpleXHTMLMessageAndDisplayReceivedXHTMLMessage() {
  // Create a chat for each connection
  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);
View Full Code Here

     * 3. User_1 will wait several seconds for an ACK from user_2, if none is received then
     * something is wrong
     */
    public void testSendComplexXHTMLMessageAndDisplayReceivedXHTMLMessage() {
  // Create a chat for each connection
  Chat chat1 = getConnection(0).getChatManager().createChat(getBareJID(1), null);
  final PacketCollector chat2 = getConnection(1).createPacketCollector(
    new ThreadFilter(chat1.getThreadID()));

  // Create a Listener that listens for Messages with the extension
  //"http://jabber.org/protocol/xhtml-im"
  // This listener will listen on the conn2 and answer an ACK if everything is ok
  PacketFilter packetFilter =
      new PacketExtensionFilter("html", "http://jabber.org/protocol/xhtml-im");
  PacketListener packetListener = new PacketListener() {
      @Override
      public void processPacket(Packet packet) {

      }
  };
  getConnection(1).addPacketListener(packetListener, packetFilter);

        // User1 creates a message to send to user2
        Message msg = new Message();
        msg.setSubject("Any subject you want");
        msg.setBody(
                "awesome! As Emerson once said: A foolish consistency is the hobgoblin of little minds.");
        // Create an XHTMLExtension and add it to the message
        XHTMLExtension xhtmlExtension = new XHTMLExtension();
        xhtmlExtension.addBody(
                "<body xml:lang=\"es-ES\"><h1>impresionante!</h1><p>Como Emerson dijo una vez:</p><blockquote><p>Una consistencia ridicula es el espantajo de mentes pequenas.</p></blockquote></body>");
        xhtmlExtension.addBody(
                "<body xml:lang=\"en-US\"><h1>awesome!</h1><p>As Emerson once said:</p><blockquote><p>A foolish consistency is the hobgoblin of little minds.</p></blockquote></body>");
        msg.addExtension(xhtmlExtension);

  // User1 sends the message that contains the XHTML to user2
  try {
      bodiesSent = xhtmlExtension.getBodiesCount();
      bodiesReceived = 0;
      chat1.sendMessage(msg);
  }
  catch (Exception e) {
      fail("An error occured sending the message with XHTML");
  }
  Packet packet = chat2.nextResult(2000);
View Full Code Here

        field.setLabel("How old are you?");
        field.setType(FormField.TYPE_TEXT_SINGLE);
        formToSend.addField(field);

        // Create the chats between the two participants
        Chat chat = getConnection(0).getChatManager().createChat(getBareJID(1), null);
        PacketCollector collector = getConnection(0).createPacketCollector(
                new ThreadFilter(chat.getThreadID()));
        PacketCollector collector2 = getConnection(1).createPacketCollector(
                new ThreadFilter(chat.getThreadID()));

        Message msg = new Message();
        msg.setBody("To enter a case please fill out this form and send it back to me");
        msg.addExtension(formToSend.getDataFormToSend());

        try {
            // Send the message with the form to fill out
            chat.sendMessage(msg);

            // Get the message with the form to fill out
            Message msg2 = (Message)collector2.nextResult(2000);
            assertNotNull("Messge not found", msg2);
            // Retrieve the form to fill out
View Full Code Here

        if (isConnectionInvalid()) {
            throw new IOException("Connection is not open");
        }

        try {
            Chat chat = getChat(jid);
            chat.sendMessage(message);
        } catch (XMPPException e) {
            throw new CausedIOException("Failed to send message", e);
        }
    }
View Full Code Here

    private void putIncomingChat(JID jid, String thread) {

        synchronized (this.chats) {
            if (!this.chats.containsKey(jid)) {
                Chat chat = this.chatmanager.getThreadChat(thread);
                this.chats.put(jid, chat);
            }
        }
    }
View Full Code Here

TOP

Related Classes of org.jivesoftware.smack.Chat

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.