예제 #1
0
  public void sendSmppMessageToRestcomm(
      String smppMessage, String smppTo, String smppFrom, Charset charset)
      throws IOException, SmppInvalidArgumentException {
    // http://stackoverflow.com/a/25885741
    try {
      byte[] textBytes;
      if (CharsetUtil.CHARSET_UCS_2 == charset) {
        textBytes = smppMessage.getBytes();
      } else {
        textBytes = CharsetUtil.encode(smppMessage, charset);
      }

      DeliverSm deliver = new DeliverSm();

      deliver.setSourceAddress(new Address((byte) 0x03, (byte) 0x00, smppFrom));
      deliver.setDestAddress(new Address((byte) 0x01, (byte) 0x01, smppTo));
      deliver.setShortMessage(textBytes);
      if (CharsetUtil.CHARSET_UCS_2 == charset) {
        deliver.setDataCoding(DataCoding.DATA_CODING_UCS2);
      } else {
        deliver.setDataCoding(DataCoding.DATA_CODING_GSM7);
      }
      logger.info("deliver.getDataCoding: " + deliver.getDataCoding());

      WindowFuture<Integer, PduRequest, PduResponse> future =
          smppServerSession.sendRequestPdu(deliver, 10000, false);
      if (!future.await()) {
        logger.error("Failed to receive deliver_sm_resp within specified time");
      } else if (future.isSuccess()) {
        DeliverSmResp deliverSmResp = (DeliverSmResp) future.getResponse();
        messageSent = true;
        logger.info(
            "deliver_sm_resp: commandStatus ["
                + deliverSmResp.getCommandStatus()
                + "="
                + deliverSmResp.getResultMessage()
                + "]");
      } else {
        logger.error("Failed to properly receive deliver_sm_resp: " + future.getCause());
      }
    } catch (Exception e) {
      logger.fatal("Exception during sending SMPP message to Restcomm: " + e);
    }
  }
    @Override
    public PduResponse firePduRequestReceived(PduRequest pduRequest) {
      SmppSession session = sessionRef.get();

      SubmitSm req = (SubmitSm) pduRequest;

      String str = CharsetUtil.decode(req.getShortMessage(), CharsetUtil.CHARSET_MODIFIED_UTF8);

      // SmsDTO smsDTO = new SmsDTO();
      smsDTO.setBody(str);
      smsDTO.setSender(req.getSourceAddress().getAddress());
      smsDTO.setDeliveryDate(new Date());
      smsDTO.setSendDate(new Date());

      // SmsDAOImpl smsDAO = new SmsDAOImpl();
      smsDAO.save(smsDTO);

      return pduRequest.createResponse();
    }