コード例 #1
0
 private void saveToFile(String pduFile, PDU pdu) {
   Logger.info(" Saving PDU into file " + pduFile);
   try {
     byte[] b = pdu.getData().getBuffer();
     java.io.FileOutputStream fout = new java.io.FileOutputStream(pduFile);
     fout.write(b);
     fout.flush();
     fout.close();
   } catch (Exception ex) {
     Logger.error("saveToFile:" + ex.getMessage());
   }
 }
コード例 #2
0
  public void run() {
    // ///////////////////////////
    Gateway.addLiveThread(this);
    // ///////////////////////////
    while (Gateway.running) {
      try {
        pdud = (PDUData) fromSMSC.dequeue(); // blocks until having
        // an item
        // pdu = (PDU) fromSMSC.dequeue(); //blocks until having an item
        pdu = (PDU) pdud.getPDU();
        if (pdu.isRequest()) {
          this.RequestID = pdud.getRequestID();
          processRequest(pdu);
        }
      } catch (DBException ex) { // when lost connection to db
        Logger.error(this.getClass().getName(), "DBException: " + ex.getMessage());
        DBTools.ALERT(
            "RequestProcessor",
            "RequestProcessor",
            Constants.ALERT_WARN,
            Preference.Channel + "DBException: " + ex.getMessage(),
            Preference.ALERT_CONTACT);
        Logger.error(this.getClass().getName(), "Alert2YM DBException: " + ex.getMessage());
      } catch (Exception e) {
        Logger.error(this.getClass().getName(), "Exception: " + e.getMessage());

        DBTools.ALERT(
            "RequestProcessor",
            "RequestProcessor",
            Constants.ALERT_WARN,
            Preference.Channel + "Exception: " + e.getMessage(),
            Preference.ALERT_CONTACT);
      }

      try {
        Thread.sleep(50);
      } catch (InterruptedException e) {
        e.printStackTrace();
      }
    }
    // /////////////////////////////
    Logger.info(this.getClass().getName(), "{" + this.getClass().getName() + " stopped}");
    this.destroy();
    // /////////////////////////////
  }
コード例 #3
0
  // ===================================================================
  private void processRequest(PDU pdu) {
    try {
      switch (pdu.getCommandId()) {
        case Data.DELIVER_SM:
          dsm = (DeliverSM) pdu;
          if (dsm.getEsmClass() == 0x04) {
            // this.deliveryQueue.enqueue(pdu);
            Logger.info(this.getClass().getName(), "dsm.getEsmClass() == 0x04");
          } else {
            DateFormat dateFormat = new SimpleDateFormat("yyMMddHHmmssSSS");
            java.util.Date date = new java.util.Date();
            String datetime = dateFormat.format(date);

            PDUData pd = new PDUData();
            pd.setPDU(pdu);
            pd.setRequestID(Preference.prefix_requestid + datetime);

            this.requestQueue.enqueue(pd);
            // dsm.setSourceAddr(new Address("095"));
            String userid = dsm.getSourceAddr().getAddress();

            dsm.setSourceAddr(
                Preference.formatUserIdMO(userid, Constants.USERID_FORMAT_INTERNATIONAL));

            String dsmLog =
                "{MO-comes}{Request_ID="
                    + Preference.prefix_requestid
                    + datetime
                    + "}{UserID="
                    + dsm.getSourceAddr().getAddress()
                    + "}{ServiceID="
                    + dsm.getDestAddr().getAddress()
                    + "}{Info="
                    + dsm.getShortMessage()
                    + "}";
            Logger.info(this.getClass().getName(), dsmLog);
          }
          break;
        case Data.DATA_SM:
          // System.out.println(" Data_SM --> Not processed.");
          Logger.error(this.getClass().getName(), "  Data_SM --> Not processed.");
          break;
        case Data.UNBIND:
          Logger.info(this.getClass().getName(), "  Data.UNBIND --> Not processed.");
          this.requestQueue.enqueue(pdu);
          break;
        default:
          Logger.error("processRequest: Unspecified SM " + pdu.debugString());
      }
    } catch (Exception e) {

      Logger.error(this.getClass().getName(), "Exception " + e.toString());

      DBTools.ALERT(
          "PDUEventListener",
          "processRequest",
          Constants.ALERT_WARN,
          Preference.Channel + "@processRequest:" + e.toString(),
          Preference.ALERT_CONTACT);
      Logger.printStackTrace(e);
    }
  }