Package org.saf.pdu

Source Code of org.saf.pdu.BasePDUHelper

package org.saf.pdu;

import org.apache.log4j.Logger;
import org.saf.common.Utilities;
import org.saf.settings.SMPPSettings;
import org.saf.smppagent.VendorCommandStatus;
import com.logica.smpp.Data;
import com.logica.smpp.pdu.DeliverSM;
import com.logica.smpp.pdu.DeliverSMResp;
import com.logica.smpp.pdu.Request;
import com.logica.smpp.pdu.SubmitSM;
import com.logica.smpp.util.ByteBuffer;

public class BasePDUHelper {
  protected static final Logger logger = Logger.getLogger(BasePDUHelper.class)
 
  protected static byte ESM_CLASS_DELIVERY_REPORT = 0x4;
  protected static byte DR_SME_ORIGINATED = 0x4;
 
  protected SMPPSettings settings = null;
 
  public BasePDUHelper(SMPPSettings settings) {
    this.settings = settings;
  }
 
  public static boolean isDeliveryReceipt(DeliverSM deliverSM) {
    boolean ret = false;

    if(deliverSM != null) {
      if(deliverSM.getEsmClass() == ESM_CLASS_DELIVERY_REPORT) {
        ret = true;
      }     
    } else {
      logger.error("null deliverSM");
    }
   
    return ret;
  }
 
  public DeliverSMResp createROKResponse(DeliverSM deliverSM) {
    DeliverSMResp response = createDeliverSMResp(deliverSM);
    response.setCommandStatus(Data.ESME_ROK);
    return response;
  }
 
  public DeliverSMResp createInternalErrorResponse(DeliverSM deliverSM) {
    DeliverSMResp response = createDeliverSMResp(deliverSM);
    response.setCommandStatus(VendorCommandStatus.ESME_INTERNAL_ERR);
    return response;
  }
 
  public DeliverSMResp createGenericErrorResponse(DeliverSM deliverSM) {
    DeliverSMResp response = createDeliverSMResp(deliverSM);
    response.setCommandStatus(VendorCommandStatus.ESME_GENERIC_ERR);
    return response;
 
   
  private DeliverSMResp createDeliverSMResp(DeliverSM deliverSM) {
    DeliverSMResp response = new DeliverSMResp();
    response.setOriginalRequest(deliverSM);
    response.setSequenceNumber(deliverSM.getSequenceNumber());
    return response;
 
   
  public static Request getPDUFromHexDump(String hexDump) {
    Request request = null;
   
    try {
      ByteBuffer bb = new ByteBuffer();
      int count = hexDump.length() / 2;
      boolean isSubmit = false;
      for (int i = 0; i < count; i++) {
        String digit = hexDump.substring(i*2, (i*2)+2).trim();
        byte b = Utilities.strToHex(digit);
        if(i == 7) {
          if(b == 0x5) {
            isSubmit = false;
          } else {
            isSubmit = true;
          }
        }
        bb.appendByte(b);
      }
     
      if(isSubmit == true) {
        request = new SubmitSM();
        request.setData(bb);
      } else {
        request = new DeliverSM();
        request.setData(bb);
      }
    } catch (Exception e) {
      logger.error("getPDUFromHexDump unexpected exception " +
          e.getMessage());
      request = null;
   
   
    return request;
  }
}
TOP

Related Classes of org.saf.pdu.BasePDUHelper

TOP
Copyright © 2018 www.massapi.com. 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.