Package com.comcast.cqs.model

Examples of com.comcast.cqs.model.CQSMessage


         
          String body = XmlUtil.getCurrentLevelTextValue(messageElement, "Body");
          String id = XmlUtil.getCurrentLevelTextValue(messageElement, "MessageId").trim();
          String handle = XmlUtil.getCurrentLevelTextValue(messageElement, "ReceiptHandle").trim();
         
          CQSMessage msg = new CQSMessage(id, body);
          msg.setReceiptHandle(handle);
         
          List<Element> attributeElements = XmlUtil.getCurrentLevelChildNodes(messageElement, "Attribute");
          Map<String, String> attributes = new HashMap<String, String>();
         
         
          for (Element attribute : attributeElements) {
           
            String name = XmlUtil.getCurrentLevelTextValue(attribute, "Name");
            String value = XmlUtil.getCurrentLevelTextValue(attribute, "Value");
           
            if (name != null && value != null) {
              attributes.put(name, value);
            }
          }
         
          msg.setAttributes(attributes);
         
          availableMessages.add(msg);
        }
       
        //retrieve first messageId from queue. this is for pagination
        String peekRequestFirstMessageUrl = cqsServiceBaseUrl + user.getUserId() + "/" + queueName + "?Action=PeekMessage&AWSAccessKeyId=" + user.getAccessKey() + "&MaxNumberOfMessages=1&Shard=" + shard;
        String peekFirstMessageXml = httpPOST(cqsServiceBaseUrl, peekRequestFirstMessageUrl,awsCredentials);
        Element rootFirstMessage = XmlUtil.buildDoc(peekFirstMessageXml);
       
        List<Element> messageElementsForFirstMessage = XmlUtil.getCurrentLevelChildNodes(XmlUtil.getCurrentLevelChildNodes(rootFirstMessage, "ReceiveMessageResult").get(0), "Message");
        if (messageElementsForFirstMessage.size() == 1){
          queueFirstMessageHandle = XmlUtil.getCurrentLevelTextValue(messageElementsForFirstMessage.get(0), "ReceiptHandle").trim();
        }
      }
   
    } catch (Exception ex) {
      logger.error("event=peek_message queue_url=" + queueUrl, ex);
      throw new ServletException(ex);
    }

    String previousHandle = null;
    nextHandle = null;
   
    out.println("<p><hr width='100%' align='left' /><p>");
    out.println("<h3>Available Messages</h3>");

    if ((availableMessages==null) || (availableMessages.size()==0)) {
      out.println("<p><i>no messages</i></p>");
    }

    for (int i = 0; availableMessages != null && i < availableMessages.size(); i++) {
       
      CQSMessage message = availableMessages.get(i);
         
      Map<String, String> attributes = message.getAttributes();
         
          String timeSent = "";
         
          if (attributes.get("SentTimestamp") != null) {
            try { timeSent = new Date(Long.parseLong(attributes.get("SentTimestamp"))).toString(); } catch (Exception ex) {}
          }
         
          String timeReceived = "";
         
          if (attributes.get("ApproximateFirstReceiveTimestamp") != null) {
            try { timeReceived = new Date(Long.parseLong(attributes.get("ApproximateFirstReceiveTimestamp"))).toString(); } catch (Exception ex) {}
          }
         
          if (i == 0) {
            out.println("<table class = 'alternatecolortable'>");
            out.println("<tr><th></th><th>Receipt Handle</th><th>MD5</th><th>Body</th><th>Time Sent</th><th>Time First Received (Appr.)</th><th>Receive Count (Appr.)</th><th>Sender</th><th>&nbsp;</th></tr>");
            previousHandle = message.getReceiptHandle();
          }
         
          out.println("<tr>");
          out.println("<td>" + i + "</td>");
          out.println("<td>" + message.getReceiptHandle() + "</td>");
          out.println("<td>" + message.getMD5OfBody() + "</td>");
          String messageBody=message.getBody();
          String messageBodyPart1=null;
          String messageBodyPart2=null;
          if((messageBody!=null)&&(messageBody.length()>300)){
            messageBodyPart1=messageBody.substring(0, 299);
            messageBodyPart2=messageBody.substring(299);

            out.println("<td>");
            out.println(messageBodyPart1);
            out.println("<div id='detail"+i+"' style=\"display: none;\">"+messageBodyPart2+"</div>");
            out.println("<input type=button name=type id='bt"+i+"' value='More' onclick=\"setVisibility('detail"+ i+"', 'bt"+i+"');\";> ");
            out.println("</td>");
          } else {
            out.println("<td>"+ message.getBody() + "</td>");
          }
          out.println("<td>"+ timeSent + "</td>");
          out.println("<td>"+ timeReceived + "</td>");
          out.println("<td>"+ attributes.get("ApproximateReceiveCount") + "</td>");
          out.println("<td>"+ attributes.get("SenderId") + "</td>");
        out.println("<td></td></tr>");
       
        if (i == availableMessages.size() - 1) {
          nextHandle = message.getReceiptHandle();
        }
        }
   
        out.println("</table>");
       
View Full Code Here


        attributes.put(CQSConstants.SENDER_ID, userId);
        attributes.put(CQSConstants.SENT_TIMESTAMP, "" + System.currentTimeMillis());
        attributes.put(CQSConstants.APPROXIMATE_RECEIVE_COUNT, "0");
        attributes.put(CQSConstants.APPROXIMATE_FIRST_RECEIVE_TIMESTAMP, "");
       
        CQSMessage message = new CQSMessage(messageBody, attributes);
       
    int shard = rand.nextInt(queue.getNumberOfShards());

        String receiptHandle = PersistenceFactory.getCQSMessagePersistence().sendMessage(queue, shard, message);
View Full Code Here

                attributes.put(CQSConstants.SENDER_ID, user.getUserId());
                attributes.put(CQSConstants.SENT_TIMESTAMP, "" + Calendar.getInstance().getTimeInMillis());
                attributes.put(CQSConstants.APPROXIMATE_RECEIVE_COUNT, "0");
                attributes.put(CQSConstants.APPROXIMATE_FIRST_RECEIVE_TIMESTAMP, "");
               
                CQSMessage msg = new CQSMessage(messageBody, attributes);
               
                msg.setSuppliedMessageId(suppliedId);
                msgList.add(msg);
            }
           
            if (msgList.size() > CMBProperties.getInstance().getCQSMaxMessageCountBatch()) {
                throw new CMBException(CQSErrorCodes.TooManyEntriesInBatchRequest, "Maximum number of entries per request are " + CMBProperties.getInstance().getCQSMaxMessageCountBatch() + ". You have sent " + msgList.size() + ".");
View Full Code Here

TOP

Related Classes of com.comcast.cqs.model.CQSMessage

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.