Package org.jivesoftware.smack

Examples of org.jivesoftware.smack.Chat


            try {
                if (target instanceof GroupChatIMMessageTarget) {
                  getOrCreateGroupChat((GroupChatIMMessageTarget) target).sendMessage(
                      text);
                } else {
                  final Chat chat = getOrCreatePrivateChat(target.toString(), null);
                  chat.sendMessage(text);
                }
            } catch (final XMPPException e) {
              // server unavailable ? Target-host unknown ? Well. Just skip this
              // one.
                LOGGER.warning(ExceptionHelper.dump(e));
View Full Code Here


        if (logger.isDebugEnabled())
        {
            logger.debug("Will send chat message to \"" + recipient + "\" with payload \"" + payload + "\"");
        }

        Chat chat = chatWith(recipient);
        Message message = buildMessage(Message.Type.chat, recipient, payload);
        chat.sendMessage(message);
    }
View Full Code Here

        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

public class JabberTransportTest extends TestCase {
    private XMPPConnection xmppConnection;
    private BrokerContainer brokerContainer;

    public void testSendJabberQueueMessage() throws Exception {
        Chat chat = xmppConnection.createChat("jdoe@jabber.org");
        chat.sendMessage("Hey, how's it going?");
    }
View Full Code Here

    }
   
    XMPPConnection connection = new XMPPConnection(p.fJabberServer);
    connection.connect();
    connection.login(p.fJabberLogin, p.fJabberPassword);
    final Chat chat = connection.getChatManager().createChat(p.fJabberAdmin, new MessageListener() {

        public void processMessage(Chat chat, Message message) {
            System.out.println("Received message: " + message.getThread() + " " + message.getBody());
        }
    });

    MibewConnection conn = new MibewConnection("http://localhost:8080/webim/", "admin", "1");
    if(!conn.connect()) {
      System.err.println("Wrong server, login or password.");
      return;
    }
    MibewTracker mt = new MibewTracker(conn, new MibewTrackerListener(){
     
      @Override
      public void threadCreated(MibewThread thread) {
        try {
          chat.sendMessage(thread.getId() + ": " + thread.getAddress() + " " + thread.getClientName());
        } catch (XMPPException e) {
          e.printStackTrace();
        }
      }
     
View Full Code Here

        }

        for(String toUser : toUsers){

            ChatManager chatmanager = connection.getChatManager();
            Chat chat = chatmanager.createChat(toUser, null);

            try {
                // google bounces back the default message types, you must use chat
                Message msg = new Message(toUser, Message.Type.chat);
                msg.setBody(text);
                chat.sendMessage(msg);
                System.out.println("Message Sended");
            } catch (XMPPException e) {
                System.out.println("Failed to send message");
                // handle this how?
            }
View Full Code Here

   
     
     
    //initialize the chat manager using connection
    ChatManager chatManager = xmppConnection.getChatManager();
    Chat chat = chatManager.createChat(xmppOutTransportInfo.getDestinationAccount(), null);
   
      boolean waitForResponse =
        msgCtx.getOperationContext() != null &&
        WSDL2Constants.MEP_URI_OUT_IN.equals(
            msgCtx.getOperationContext().getAxisOperation().getMessageExchangePattern());
     
      OMElement msgElement;     
      String messageToBeSent = "";
     
      if(XMPPConstants.XMPP_CONTENT_TYPE_STRING.equals(xmppOutTransportInfo.getContentType())){
        //if request is received from a chat client, whole soap envelope
        //should not be sent.
        OMElement soapBodyEle = msgCtx.getEnvelope().getBody();
        OMElement responseEle = soapBodyEle.getFirstElement();
        if(responseEle != null){
          msgElement = responseEle.getFirstElement();         
        }else{
          msgElement = responseEle;
        }
      }else{
        //if request received from a ws client whole soap envelope
        //must be sent.
        msgElement = msgCtx.getEnvelope();
     
      messageToBeSent = msgElement.toString();
      message.setBody(messageToBeSent);
     
      String key = null;
      if(waitForResponse && !msgCtx.isServerSide()){
        PacketFilter filter = new PacketTypeFilter(message.getClass());       
        xmppConnection.addPacketListener(xmppClientSidePacketListener,filter);
        key = UUID.randomUUID().toString();
        xmppClientSidePacketListener.listenForResponse(key, msgCtx);
        message.setProperty(XMPPConstants.SEQUENCE_ID, key);
      }     

      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

           handleException("Could not find message sender details.");
         }        
       
        //initialize the chat manager using connection
        ChatManager chatManager = xmppConnection.getChatManager();
        Chat chat = chatManager.createChat(xmppOutTransportInfo.getDestinationAccount(), null);       
        try{        
            message.setProperty(XMPPConstants.SEQUENCE_ID,
                    xmppOutTransportInfo.getSequenceID());
           message.setBody(responseMsg);   
          chat.sendMessage(message);
          log.debug("Sent message :"+message.toXML());
        } catch (XMPPException e) {
          XMPPSender.handleException("Error occurred while sending the message : "+message.toXML(),e);
        }
        } 
View Full Code Here

        } catch (XMPPException e) {
            throw new RuntimeException("Could not connect to XMPP server.", e);
        }

        ChatManager chatManager = connection.getChatManager();
        Chat chat = getOrCreateChat(chatManager);
        Message message = null;
        try {
            message = new Message();
            message.setTo(getParticipant());
            message.setThread(endpoint.getChatId());
            message.setType(Message.Type.normal);

            endpoint.getBinding().populateXmppMessage(message, exchange);

            if (LOG.isDebugEnabled()) {
                LOG.debug("Sending XMPP message to {} from {} : {}", new Object[]{endpoint.getParticipant(), endpoint.getUser(), message.getBody()});
            }
            chat.sendMessage(message);
        } catch (XMPPException xmppe) {
            throw new RuntimeExchangeException("Could not send XMPP message: to " + endpoint.getParticipant() + " from " + endpoint.getUser() + " : " + message
                    + " to: " + XmppEndpoint.getConnectionMessage(connection), exchange, xmppe);
        } catch (Exception e) {
            throw new RuntimeExchangeException("Could not send XMPP message to " + endpoint.getParticipant() + " from " + endpoint.getUser() + " : " + message
View Full Code Here

    private synchronized Chat getOrCreateChat(ChatManager chatManager) {
        if (LOG.isTraceEnabled()) {
            LOG.trace("Looking for existing chat instance with thread ID {}", endpoint.getChatId());
        }
        Chat chat = chatManager.getThreadChat(endpoint.getChatId());
        if (chat == null) {
            if (LOG.isTraceEnabled()) {
                LOG.trace("Creating new chat instance with thread ID {}", endpoint.getChatId());
            }
            chat = chatManager.createChat(getParticipant(), endpoint.getChatId(), new MessageListener() {
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.