Beispiel #1
0
 /**
  * @param recipient
  * @param msg
  * @return
  * @throws Exception
  */
 public String sendMessage(String recipient, String msg) throws Exception {
   OutboundMessage outboundMessage = new OutboundMessage(recipient, msg);
   if (isServiceRunning()) {
     String longNumber = getProperties().getProperty("provider.longnumber").trim();
     if (longNumber != null && !longNumber.isEmpty()) {
       outboundMessage.setFrom(longNumber);
     }
     Service.getInstance().sendMessage(outboundMessage);
     return "MESSAGE SENT SUCCESSFULLY TO: " + recipient;
   } else {
     return "SERVICE IS NOT RUNNING";
   }
 }
Beispiel #2
0
 /**
  * Reads a given node and tries to parse it
  *
  * @param n The node to parse
  * @return An outboundmessage if the node was parsable or null
  */
 private OutboundMessage readNode(Node n) {
   if ("message".equals(n.getNodeName())) {
     String recipient = null;
     String text = null;
     String originator = null;
     Element e = (Element) n;
     NodeList cnl = n.getChildNodes();
     /* Read required fields */
     for (int i = 0; i < cnl.getLength(); i++) {
       Node en = cnl.item(i);
       if ("recipient".equals(cnl.item(i).getNodeName())) {
         recipient = en.getTextContent();
       } else if ("text".equals(cnl.item(i).getNodeName())) {
         text = en.getTextContent();
       } else if ("originator".equals(cnl.item(i).getNodeName())) {
         originator = en.getTextContent();
       }
     }
     /* Create outbound message */
     OutboundMessage outMsg = new OutboundMessage(recipient, text);
     /* Set required fields */
     outMsg.setFrom(originator);
     if (!"".equals(e.getAttribute("create_date"))) {
       outMsg.setDate(getISO8601AsDate(e.getAttribute("create_date")));
     }
     if (!"".equals(e.getAttribute("gateway_id"))) {
       outMsg.setGatewayId(e.getAttribute("gateway_id"));
     }
     /* Read optional fields - priority */
     String priority = e.getAttribute("priority");
     if ("L".equalsIgnoreCase(priority)) {
       outMsg.setPriority(-1);
     } else if ("N".equalsIgnoreCase(priority)) {
       outMsg.setPriority(0);
     } else if ("H".equalsIgnoreCase(priority)) {
       outMsg.setPriority(+1);
     }
     /* Read optional fields - encoding */
     String encoding = e.getAttribute("encoding");
     if ("7".equals(encoding)) {
       outMsg.setEncoding(MessageEncodings.ENC7BIT);
     } else if ("8".equals(encoding)) {
       outMsg.setEncoding(MessageEncodings.ENC8BIT);
     } else {
       outMsg.setEncoding(MessageEncodings.ENCUCS2);
     }
     /* Read optinal fields - status_report */
     if ("1".equals(e.getAttribute("status_report"))) {
       outMsg.setStatusReport(true);
     }
     /* Read optinal fields - flash_sms */
     if ("1".equals(e.getAttribute("flash_sms"))) {
       outMsg.setFlashSms(true);
     }
     /* Read optinal fields - src_port */
     if (!"".equals(e.getAttribute("src_port"))) {
       outMsg.setSrcPort(Integer.parseInt(e.getAttribute("src_port")));
     }
     /* Read optinal fields - dst_port */
     if (!"".equals(e.getAttribute("dst_port"))) {
       outMsg.setDstPort(Integer.parseInt(e.getAttribute("dst_port")));
     }
     return outMsg;
   }
   return null;
 }