Package org.jivesoftware.smack.packet

Examples of org.jivesoftware.smack.packet.Message


        }
    }

    public void process(Exchange exchange) {
        // TODO it would be nice if we could reuse the message from the exchange
        Message message = chat.createMessage();
        message.setTo(participant);
        message.setFrom(endpoint.getUser());
        message.setThread(exchange.getExchangeId());
        message.setType(Message.Type.NORMAL);

        endpoint.getBinding().populateXmppMessage(message, exchange);
        if (LOG.isDebugEnabled()) {
            LOG.debug(">>>> message: " + message.getBody());
        }
        try {
            chat.sendMessage(message);
        } catch (XMPPException e) {
            throw new RuntimeXmppException(e);
View Full Code Here


        }
    }

    public void process(Exchange exchange) {
        // TODO it would be nice if we could reuse the message from the exchange
        Message message = chat.createMessage();
        message.setTo(room);
        message.setFrom(endpoint.getUser());

        endpoint.getBinding().populateXmppMessage(message, exchange);
        if (LOG.isDebugEnabled()) {
            LOG.debug(">>>> message: " + message.getBody());
        }
        try {
            chat.sendMessage(message);
        } catch (XMPPException e) {
            throw new RuntimeXmppException(e);
View Full Code Here

    /**
     * Capturing the packets coming from the user and setting the responseReceived flag.
     * @param packet
     */
    public void processPacket(Packet packet) {
        Message message = (Message) packet;
        if(message.getBody() == null){
            return;
        }
        response = message.getBody();
        this.responseReceived = true;
    }
View Full Code Here

        loggedIn = true;
    }

    public void sendMessage(String to, String message) throws IMException {
        if (loginProcessed && loggedIn) {
            Message chatMessage = new Message();
            chatMessage.setTo(to);
            chatMessage.setBody(message);
            chatMessage.setType(Message.Type.normal);
            connection.sendPacket(chatMessage);
        } else {
            log.error("Got to Log in before a message can be sent.");
            throw new IMException("Got to Log in before a message can be sent.");
        }
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
        .getAxisConfiguration().getTransportOut("xmpp");
    if ((transportIn != null) && (transportOut != null)) {
      msgContext = configurationContext.createMessageContext();
      msgContext.setTransportIn(transportIn);
      msgContext.setTransportOut(transportOut);
      if (isServerSide != null) {
        msgContext.setServerSide(isServerSide.booleanValue());
      }
      msgContext.setProperty(
          CONTENT_TYPE,
          "text/xml");
      msgContext.setProperty(
          Constants.Configuration.CHARACTER_SET_ENCODING, "UTF-8");
      msgContext.setIncomingTransportName("xmpp");

      Map services = configurationContext.getAxisConfiguration()
          .getServices();

      AxisService axisService = (AxisService) services.get(serviceName);
      msgContext.setAxisService(axisService);
      msgContext.setSoapAction(action);

      // pass the configurationFactory to transport sender
      msgContext.setProperty("XMPPConfigurationFactory",
          this.xmppConnectionFactory);

      if (packet.getFrom() != null) {
        msgContext.setFrom(new EndpointReference(packet.getFrom()));
      }
      if (packet.getTo() != null) {
        msgContext.setTo(new EndpointReference(packet.getTo()));
      }

      XMPPOutTransportInfo xmppOutTransportInfo = new XMPPOutTransportInfo();
      xmppOutTransportInfo
          .setConnectionFactory(this.xmppConnectionFactory);

      String packetFrom = packet.getFrom();
      if (packetFrom != null) {
        EndpointReference fromEPR = new EndpointReference(packetFrom);
        xmppOutTransportInfo.setFrom(fromEPR);
        xmppOutTransportInfo.setDestinationAccount(packetFrom);
      }

      // Save Message-Id to set as In-Reply-To on reply
      String xmppMessageId = packet.getPacketID();
      if (xmppMessageId != null) {
        xmppOutTransportInfo.setInReplyTo(xmppMessageId);
      }
      xmppOutTransportInfo.setSequenceID((String)message.getProperty(XMPPConstants.SEQUENCE_ID));
      msgContext.setProperty(
          org.apache.axis2.Constants.OUT_TRANSPORT_INFO,
          xmppOutTransportInfo);
      buildSOAPEnvelope(packet, msgContext);
    } else {
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.debug("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()){
        String contentType = (String)message.getProperty(XMPPConstants.CONTENT_TYPE);
        if(contentType == null){
          throw new AxisFault("Can not Find Content type Property in the XMPP Message");
        }
        envelope = TransportUtils.createSOAPMessage(msgContext, inputStream, contentType);
        msgContext.setProperty(XMPPConstants.CONTAINS_SOAP_ENVELOPE, new Boolean(true));
View Full Code Here

                connectionFactory.connect(serverCredentials);  
                xmppConnection = connectionFactory.getXmppConnection();
            }
        }
   
    Message message = new Message();
    Options options = msgCtx.getOptions();     
      String serviceName = XMPPUtils.getServiceName(targetAddress);   
     
      SOAPVersion version = msgCtx.getEnvelope().getVersion();
      if(version instanceof SOAP12Version){
        message.setProperty(XMPPConstants.CONTENT_TYPE, HTTPConstants.MEDIA_TYPE_APPLICATION_SOAP_XML+ "; action="+ msgCtx.getSoapAction());
      }else{
        message.setProperty(XMPPConstants.CONTENT_TYPE, HTTPConstants.MEDIA_TYPE_TEXT_XML);
      }
     
     
    if (targetAddress != null) {
      xmppOutTransportInfo = new XMPPOutTransportInfo(targetAddress);
      xmppOutTransportInfo.setConnectionFactory(defaultConnectionFactory);
    } else if (msgCtx.getTo() != null &&
        !msgCtx.getTo().hasAnonymousAddress()) {
      //TODO
    } else if (msgCtx.isServerSide()) {
      xmppOutTransportInfo = (XMPPOutTransportInfo)
      msgCtx.getProperty(Constants.OUT_TRANSPORT_INFO);
    }
    try{
    if(msgCtx.isServerSide()){
      message.setProperty(XMPPConstants.IS_SERVER_SIDE, new Boolean(false));
      message.setProperty(XMPPConstants.IN_REPLY_TO, xmppOutTransportInfo.getInReplyTo());
      message.setProperty(XMPPConstants.SEQUENCE_ID, xmppOutTransportInfo.getSequenceID());
    }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);
   
      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()){
          xmppClientSidePacketListener.waitFor(key);
        //xmppConnection.disconnect();
          log.debug("Received response sucessfully");
      }
     

    } catch (XMPPException e) {
      log.error("Error occurred while sending the message : "+message.toXML(),e);
      handleException("Error occurred while sending the message : "+message.toXML(),e);
    } catch (InterruptedException e) {
        log.error("Error occurred while sending the message : "+message.toXML(),e);
            handleException("Error occurred while sending the message : "+message.toXML(),e);
        }finally{
//      if(xmppConnection != null && !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.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

            && lastMessageEventRequest != null
            && lastMessageEventRequest.isComposing()) {
          if (chatInput.getText().equals("")) {
            if (sentComposing) {
              sentComposing = false;
              Message reply = new Message(lastReceivedMessage
                  .getFrom());
              MessageEvent replyEvent = new MessageEvent();
              replyEvent.setPacketID(lastReceivedMessage
                  .getPacketID());
              replyEvent.setComposing(false);
              reply.addExtension(replyEvent);
              account.xmpp.getConnection().sendPacket(reply);
            }
          } else {
            if (!sentComposing) {
              sentComposing = true;
              Message reply = new Message(lastReceivedMessage
                  .getFrom());
              MessageEvent replyEvent = new MessageEvent();
              replyEvent.setPacketID(lastReceivedMessage
                  .getPacketID());
              replyEvent.setComposing(true);
              reply.addExtension(replyEvent);
              account.xmpp.getConnection().sendPacket(reply);
            }
          }
        } else if ((e.stateMask & SWT.CONTROL) != 0 && e.keyCode == 'b') {
          makeInputSelectionBold();
View Full Code Here

  /**
   *
   *
   */
  protected void sendUserInput() {
    Message msg = createMessage();
    if (msg != null) {
      String input = chatInput.getText();
      // System.out.println("Styles: " + chatInput.getStyleRanges());
      if (input.equals("")) {
        chatInput.setText("");
        return;
      }
      StringBuffer xhtmlText = null;
      StyleRange[] ranges = chatInput.getStyleRanges();
      if (ranges != null && ranges.length > 0) {
        int lastposition = 0;
        xhtmlText = new StringBuffer();
        // boolean hasOpenSpanTag = false;
        for (StyleRange range : ranges) {
          if (range.start > lastposition) {
            appendToXHTMLText(xhtmlText,input.substring(lastposition,
                range.start));
//            xhtmlText.append(input.substring(lastposition,
//                range.start).replace(GOIMPlugin.LINESEPARATOR,"<br />"));
            lastposition = range.start;
          }
          // if(hasOpenSpanTag) xhtmlText.appendCloseSpanTag();
          StringBuffer style = new StringBuffer();
          if ((range.fontStyle & SWT.BOLD) != 0)
            style.append("font-weight:bold;");
          if ((range.fontStyle & SWT.ITALIC) != 0)
            style.append("font-style:italic;");
          if (range.underline)
            style.append("text-decoration:underline;");
          if (range.strikeout)
            style.append("text-decoration:line-through;");
          xhtmlText.append("<span style=\"").append(style).append("\">");
//          xhtmlText.appendOpenSpanTag(style.toString());
          // hasOpenSpanTag = true;
          appendToXHTMLText(xhtmlText,input.substring(range.start, range.start
              + range.length));
//          xhtmlText.append(input.substring(range.start, range.start
//              + range.length));
          xhtmlText.append("</span>");
//          xhtmlText.appendCloseSpanTag();
          lastposition = range.start + range.length;
        }
        // if(hasOpenSpanTag) xhtmlText.appendCloseSpanTag();
        if (input.length() > lastposition) {
          appendToXHTMLText(xhtmlText,input.substring(lastposition));
//          xhtmlText.append(input.substring(lastposition).replace(GOIMPlugin.LINESEPARATOR,"<br />"));
        }
      }
      MessageEventManager.addNotificationsRequests(msg, false, false,
          true, true);
      String text = input;
      msg.setBody(text);
      if (xhtmlText != null)
        XHTMLManager.addBody(msg, xhtmlText.toString());
      try {
        sendMessage(msg);
      } catch (XMPPException e) {
View Full Code Here

TOP

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

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.