Package org.jivesoftware.smack.packet

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


            }
        });
       
        for (int i = 0; i < 10; i++) {
            System.out.println("Sending message: " + i);
            Message message = new Message("consumer");
            message.setType(Message.Type.chat);
            message.setBody("Hello from producer, message # " + i);
            chat.sendMessage(message);
        }
      
        //make sure the consumer has time to receive all the messages...
        Thread.sleep(sleepTime);

        //create an identical 2nd consumer
        XMPPConnection lastguyCon = new XMPPConnection(config);
        lastguyCon.connect();
        addLoggingListeners("LASTGUY", consumerCon);
        lastguyCon.login("consumer", "consumer");
        final ConsumerMessageListener listener2 = new ConsumerMessageListener();
        lastguyCon.getChatManager().addChatListener(new ChatManagerListener() {
            public void chatCreated(Chat chat, boolean createdLocally) {
                chat.addMessageListener(listener2);
            }
        });

        for (int i = 0; i < 10; i++) {
            System.out.println("Sending message: " + i);
            Message message = new Message("consumer");
            message.setType(Message.Type.chat);
            message.setBody("Hello from producer, message # " + i);
            chat.sendMessage(message);
        }

        System.out.println("Sent all messages!");
        Thread.sleep(sleepTime);
View Full Code Here


                    }
                }
            });
        }

        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 " + endpoint.getParticipant() + " from " + endpoint.getUser() + " : " + message.getBody());
            }
            chat.sendMessage(message);
        } catch (XMPPException xmppe) {
            throw new RuntimeExchangeException("Cannot send XMPP message: to " + endpoint.getParticipant() + " from " + endpoint.getUser() + " : " + message
                    + " to: " + XmppEndpoint.getConnectionMessage(connection), exchange, xmppe);
View Full Code Here

        super(endpoint);
        this.endpoint = endpoint;
    }

    public void process(Exchange exchange) {
        Message message = chat.createMessage();
        message.setTo(room);
        message.setFrom(endpoint.getUser());

        endpoint.getBinding().populateXmppMessage(message, exchange);
        try {
            // make sure we are connected
            if (!connection.isConnected()) {
                if (LOG.isDebugEnabled()) {
                    LOG.debug("Reconnecting to: " + XmppEndpoint.getConnectionMessage(connection));
                }
                connection.connect();
            }

            if (LOG.isDebugEnabled()) {
                LOG.debug("Sending XMPP message: " + message.getBody());
            }
            chat.sendMessage(message);
            // must invoke nextMessage to consume the response from the server
            // otherwise the client local queue will fill up (CAMEL-1467)
            chat.pollMessage();
View Full Code Here

            connection = null;
        }
    }

    public void processPacket(Packet packet) {
        Message message = (Message)packet;

        if (LOG.isDebugEnabled()) {
            LOG.debug("Recieved XMPP message: " + message.getBody());
        }

        XmppExchange exchange = endpoint.createExchange(message);
        try {
            getProcessor().process(exchange);
View Full Code Here

    //if on client side,create connection to xmpp server
    if(!msgCtx.isServerSide()){
      connectUsingClientOptions(msgCtx);
    }
   
    Message message = new Message();
    Options options = msgCtx.getOptions();     
      String serviceName = XMPPUtils.getServiceName(targetAddress);     
     
    if (targetAddress != null) {
      xmppOutTransportInfo = new XMPPOutTransportInfo(targetAddress);
      xmppOutTransportInfo.setConnectionFactory(connectionFactory);
    } else if (msgCtx.getTo() != null &&
        !msgCtx.getTo().hasAnonymousAddress()) {
      //TODO
    } else if (msgCtx.isServerSide()) {
      xmppOutTransportInfo = (XMPPOutTransportInfo)
      msgCtx.getProperty(Constants.OUT_TRANSPORT_INFO);
    }
     
    xmppConnection = xmppOutTransportInfo.getConnectionFactory().getXmppConnection();   
   
    if(msgCtx.isServerSide()){
      message.setProperty(XMPPConstants.IS_SERVER_SIDE, new Boolean(false));
      message.setProperty(XMPPConstants.IN_REPLY_TO, xmppOutTransportInfo.getInReplyTo());
    }else{
      //message is going to be processed on server side
      message.setProperty(XMPPConstants.IS_SERVER_SIDE,new Boolean(true));
      //we are sending a soap envelope as a message
      message.setProperty(XMPPConstants.CONTAINS_SOAP_ENVELOPE, new Boolean(true));
      message.setProperty(XMPPConstants.SERVICE_NAME, serviceName);
      String action = options.getAction();
      if (action == null) {
        AxisOperation axisOperation = msgCtx.getAxisOperation();
        if (axisOperation != null) {
          action = axisOperation.getSoapAction();
        }
      }
      if (action != null) {
        message.setProperty(XMPPConstants.ACTION, action);
      }
    }   
      if(xmppConnection == null){
        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
    {
      boolean waitForResponse =
        msgCtx.getOperationContext() != null &&
        WSDL2Constants.MEP_URI_OUT_IN.equals(
            msgCtx.getOperationContext().getAxisOperation().getMessageExchangePattern());
     
      //int endOfXMLDeclaration = soapMessage.indexOf("?>");
      //String modifiedSOAPMessage = soapMessage.substring(endOfXMLDeclaration+2);

      OMElement msgElement;     
      String messageToBeSent = "";
     
      //TODO : need to read from a constant
      if("xmpp/text".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);
     
     
      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()){
        //TODO : need to add a timeout
        while(! xmppClientSidePacketListener.isResponseReceived()){
          try {
            Thread.sleep(1000);
          } catch (InterruptedException e) {
            log.debug("Sleep interrupted",e);
          }   
        }
        xmppConnection.disconnect();
      }

    } catch (XMPPException e) {
      log.error("Error occurred while sending the message : "+message.toXML(),e);
      handleException("Error occurred while sending the message : "+message.toXML(),e);
    }finally{
      if(!msgCtx.isServerSide()){
        xmppConnection.disconnect();
      }
    }
View Full Code Here

     * @throws AxisFault
     */
    private static void sendChatMessage(MessageContext msgCtx,String responseMsg) throws AxisFault {
        XMPPConnection xmppConnection = null;
        XMPPOutTransportInfo xmppOutTransportInfo = null;       
        Message message = new Message();
         
         xmppOutTransportInfo = (XMPPOutTransportInfo)msgCtx.getProperty(Constants.OUT_TRANSPORT_INFO);
         if(xmppOutTransportInfo != null){
           message.setProperty(XMPPConstants.IN_REPLY_TO, xmppOutTransportInfo.getInReplyTo());
             xmppConnection = xmppOutTransportInfo.getConnectionFactory().getXmppConnection();
               if(xmppConnection == null){
                 handleException("Connection to XMPP Server is not established.");       
               }            
         }else{
           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.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

  /**
   * This method will be triggered, when a message is arrived at client side
   */
  public void processPacket(Packet packet) {   
    Message message = (Message)packet;
    String xml = StringEscapeUtils.unescapeXml(message.getBody());
    log.info("Client received message : "+xml);
    this.responseReceived = true;
    InputStream inputStream = new ByteArrayInputStream(xml.getBytes());
    messageContext.setProperty(MessageContext.TRANSPORT_IN, inputStream);
  }
View Full Code Here

   * @param packet
   * @return MessageContext
   * @throws AxisFault
   */
  private MessageContext createMessageContext(Packet packet) throws AxisFault {
    Message message = (Message) packet;   

    Boolean isServerSide = (Boolean) message
        .getProperty(XMPPConstants.IS_SERVER_SIDE);
    String serviceName = (String) message
        .getProperty(XMPPConstants.SERVICE_NAME);
    String action = (String) message.getProperty(XMPPConstants.ACTION);
    MessageContext msgContext = null;

    TransportInDescription transportIn = configurationContext
        .getAxisConfiguration().getTransportIn("xmpp");
    TransportOutDescription transportOut = configurationContext
View Full Code Here

     * @param packet
     * @param msgContext
     * @throws AxisFault
     */
  private void buildSOAPEnvelope(Packet packet, MessageContext msgContext) throws AxisFault{
    Message message = (Message)packet;   
    String logMsg = "Trying to create " +
    "message content using XMPP message received :"+packet.toXML();
     
    String messageBody = StringEscapeUtils.unescapeXml(message.getBody());
    if(msgContext.isServerSide()){
      log.info("Received Envelope : "+messageBody);
    }
   
    InputStream inputStream = new ByteArrayInputStream(messageBody.getBytes());
    SOAPEnvelope envelope = null;
    try {
      Object obj = message.getProperty(XMPPConstants.CONTAINS_SOAP_ENVELOPE);
      if(obj != null && ((Boolean)obj).booleanValue()){
        envelope = TransportUtils.createSOAPMessage(msgContext, inputStream, "text/xml");
        msgContext.setProperty(XMPPConstants.CONTAINS_SOAP_ENVELOPE, new Boolean(true));
      }else{
        //A text message has been received from a chat client
View Full Code Here

        XmppMessage receivedMessage = receivedExchange.getIn();

        Assert.assertEquals("cheese header", 123, receivedMessage.getHeader("cheese"));
        Object body = receivedMessage.getBody();
        XmppRouteTest.LOG.debug("Received body: " + body);
        Message xmppMessage = receivedMessage.getXmppMessage();
        assertNotNull(xmppMessage);

        XmppRouteTest.LOG.debug("Received XMPP message: " + xmppMessage.getBody());
        return body;
    }
View Full Code Here

TOP

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

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.