Beispiel #1
0
 public void setValue(ByteBuffer p_value) {
   if (p_value != null)
     try {
       value = p_value.removeBuffer(p_value.length());
     } catch (NotEnoughDataInByteBufferException e) {
       throw new Error(
           "Removing buf.length() data from ByteBuffer buf reported too little data in buf, which shouldn't happen.");
     }
   else value = null;
   markValueSet();
 }
Beispiel #2
0
 protected void setValueData(ByteBuffer buffer) throws TLVException {
   checkLength(buffer);
   if (buffer != null)
     try {
       value = buffer.removeBuffer(buffer.length());
     } catch (NotEnoughDataInByteBufferException e) {
       throw new Error(
           "Removing buf.length() data from ByteBuffer buf reported too little data in buf, which shouldn't happen.");
     }
   else value = null;
   markValueSet();
 }
  private void processRequest(PDU pdu) throws DBException, IOException {
    // Process the request and add to SMS_RECEIVE_QUEUE
    if (pdu.getCommandId() == Data.DELIVER_SM) {

      dsm = (DeliverSM) pdu;
      this.userId = dsm.getSourceAddr().getAddress();
      this.serviceId = dsm.getDestAddr().getAddress();
      this.info = dsm.getShortMessage();

      ByteBuffer da = null;

      try {
        da = dsm.getDestSubaddress();

        String te = Convert.hexToString(da.getHexDump().substring(2));

        //				this.RequestID = te;
        Gateway.util.log(this.getClass().getName(), "getDestSubaddress:" + te);
      } catch (ValueNotSetException ex) {

      }
      short destport = 0;
      try {
        destport = dsm.getDestinationPort();

        Gateway.util.log(this.getClass().getName(), "getDestinationPort:" + destport);
      } catch (ValueNotSetException e) {
        // TODO Auto-generated catch block
        // Tim Dport o day
        // ByteBuffer otaData =new
        // ByteBuffer(info.getBytes(Data.ENC_ISO8859_1));
        ByteBuffer otaData = new ByteBuffer();
        otaData = dsm.getShortMessagebuff();
        try {

          byte udhlength = otaData.removeByte();
          byte udhele1 = otaData.removeByte();
          byte udhele2 = otaData.removeByte();

          short sdport = otaData.removeShort();

          short ssport = otaData.removeShort();

          String newmsg = otaData.removeString(otaData.length(), Data.ENC_ISO8859_1);

          if (udhlength == 6 && udhele1 == 5) {
            destport = sdport;
            this.info = newmsg;
            Gateway.util.log(
                this.getClass().getName(), "getDestinationPort:" + destport + "@info=" + newmsg);
          }

        } catch (NotEnoughDataInByteBufferException e1) {
          // TODO Auto-generated catch block

        }
      }

      this.Dport = Short.toString(destport);

      if (this.info == null) {
        this.info = "null";
      }
      this.userId = removePlusSign(this.userId);
      this.serviceId = rebuildServiceId(this.serviceId);
      this.operator = Preference.mobileOperator;
      // Added on 22//2003 : VinaPhone gui ban tin DeliverReport voi
      // truong esm_class != 0x4. ==> He thong xem nhu ban tin thuong
      // sai format va gui thong bao -- report -- thong bao --> LOOP./
      // To pass over this, set:

      if (dsm.getEsmClass() == 0x4 || info.startsWith("id:")) { // DeliverReport
        // (not
        // processed)!
        Gateway.util.log(this.getClass().getName(), "It can be DeliverReport (not processed)!");
        return; // not processed
      }

      // Normal message (request):
      // Neu mobile o che do tieng viet
      // --> Loai bo space (ky tu 00) giua cac ky tu
      this.info = StringTool.removeChar(this.info, '\00');

      String newserviceid = this.serviceId;

      newserviceid = newserviceid.substring(newserviceid.length() - 4);

      // DANND add
      DateFormat dateFormat = new SimpleDateFormat("MMddHHmmssSSS");
      java.util.Date date = new java.util.Date();
      String datetime = dateFormat.format(date);
      this.RequestID = Preference.prefix_requestid + datetime + threadId;

      dbTools.add2SMSReceiveQueueR(
          this.userId,
          this.serviceId,
          this.operator,
          this.commandCode,
          this.info,
          this.RequestID,
          this.Dport);
    }
  }
Beispiel #4
0
    public static Collection buildSubmitEMS(String filename, String srcAddress, String destAddress, int contentType, int MsgType, String sCommand_code, int TotalSegments)
        throws EMSException
    {
        Vector vRequests;
        SubmitSM request = null;
        vRequests = new Vector();
        ByteBuffer otaData = null;
        short port = 0;
        switch(contentType)
        {
        case 3: // '\003'
            port = 5507;
            Cli cli = new Cli(filename);
            cli.encode();
            otaData = cli.getEncoded();
            break;

        case 2: // '\002'
            port = 5506;
            OperatorLogo logo = new OperatorLogo(filename);
            logo.setMobileOperator(Preference.mobileOperator);
            logo.encode();
            otaData = logo.getEncoded();
            break;

        case 4: // '\004'
            port = 5514;
            PictureMessage pic = new PictureMessage(filename);
            pic.encode();
            otaData = pic.getEncoded();
            break;

        case 1: // '\001'
            port = 5505;
            otaData = loadByteBuffer(filename);
            break;

        default:
            throw new EMSException("Invalid content type " + contentType + ")");
        }
        if(otaData.length() <= 133)
        {
            MAX_LENGTH = 133;
            isFragmented = false;
            totalSegments = 1;
        } else
        {
            MAX_LENGTH = 128;
            isFragmented = true;
            totalSegments = (byte)(otaData.length() / MAX_LENGTH + 1);
        }
        ByteBuffer message = null;
        for(byte i = 1; i <= totalSegments; i++)
        {
            SubmitSM request = new SubmitSM();
            request.setSourceAddr((byte)0, (byte)0, srcAddress);
            request.setDestAddr((byte)1, (byte)1, destAddress);
            message = new ByteBuffer();
            if(isFragmented)
                message.appendByte((byte)11);
            else
                message.appendByte((byte)6);
            message.appendByte((byte)5);
            message.appendByte((byte)4);
            message.appendShort(port);
            message.appendShort((short)0);
            if(isFragmented)
            {
                message.appendByte((byte)0);
                message.appendByte((byte)3);
                message.appendByte((byte)0);
                message.appendByte(totalSegments);
                message.appendByte(i);
            }
            if(otaData.length() <= MAX_LENGTH)
                message.appendBuffer(otaData);
            else
                message.appendBuffer(otaData.removeBuffer(MAX_LENGTH));
            request.setShortMessageData(message);
            request.setEsmClass((byte)64);
            request.setDataCoding((byte)-11);
            request.setSequenceNumber(i + 1);
            if(MsgType == 2 || MsgType > 19 && MsgType < 30)
                MsgType = 0;
            else
            if((MsgType == 1 || MsgType == 3) && i == 1)
                MsgType = 1;
            else
                MsgType = 4;
            if(srcAddress.equals("996") && MsgType == 0 && (sCommand_code.equals("XSMN") || sCommand_code.equals("XSMT") || sCommand_code.equals("XSMN") || sCommand_code.equals("XSTD")))
                MsgType = 4;
            if(TotalSegments == 0)
                TotalSegments = 1;
            ByteBuffer Charge = new ByteBuffer();
            Charge.appendByte((byte)-96);
            Charge.appendString(sCommand_code + "," + MsgType + "," + TotalSegments);
            request.setSourceSubaddress(Charge);
            vRequests.addElement(request);
        }

        return vRequests;
        Exception e;
        e;
        throw new EMSException(e.getMessage());
    }
Beispiel #5
0
    public static Collection buildSubmitEMS(ByteBuffer otaData, String srcAddr, String destAddr, int contentType, BigDecimal emsId, byte registeredDelivery, int MsgType, String sCommand_code, 
            int TotalSegments)
        throws EMSException
    {
        Vector vRequests;
        SubmitSM request = null;
        vRequests = new Vector();
        String mobileOperator = Preference.mobileOperator;
        otaData = addHeaders2OTAData(otaData, mobileOperator, contentType);
        if(otaData.length() <= 133)
        {
            MAX_LENGTH = 133;
            isFragmented = false;
            totalSegments = 1;
        } else
        {
            MAX_LENGTH = 128;
            isFragmented = true;
            totalSegments = (byte)(otaData.length() / MAX_LENGTH + 1);
        }
        ByteBuffer message = null;
        for(byte i = 1; i <= totalSegments; i++)
        {
            SubmitSM request = new SubmitSM();
            request.setSourceAddr((byte)0, (byte)1, srcAddr);
            request.setDestAddr((byte)1, (byte)1, destAddr);
            message = new ByteBuffer();
            if(isFragmented)
                message.appendByte((byte)11);
            else
                message.appendByte((byte)6);
            message.appendByte((byte)5);
            message.appendByte((byte)4);
            switch(contentType)
            {
            case 3: // '\003'
                message.appendShort((short)5507);
                break;

            case 2: // '\002'
                message.appendShort((short)5506);
                break;

            case 4: // '\004'
                message.appendShort((short)5514);
                break;

            case 1: // '\001'
                message.appendShort((short)5505);
                break;

            case 6: // '\006'
            case 8: // '\b'
                message.appendShort((short)2948);
                break;

            case 7: // '\007'
                message.appendShort((short)-15537);
                break;

            case 10: // '\n'
                message.appendShort((short)9204);
                break;

            case 11: // '\013'
                message.appendShort((short)9205);
                break;

            case 5: // '\005'
            case 9: // '\t'
            default:
                throw new EMSException("Invalid content type " + contentType + ")");
            }
            if(contentType == 8 || contentType == 6)
                message.appendShort((short)9200);
            else
            if(contentType == 7)
                message.appendShort((short)-16382);
            else
                message.appendShort((short)0);
            if(isFragmented)
            {
                message.appendByte((byte)0);
                message.appendByte((byte)3);
                message.appendByte((byte)0);
                message.appendByte(totalSegments);
                message.appendByte(i);
            }
            if(otaData.length() <= MAX_LENGTH)
                message.appendBuffer(otaData);
            else
                message.appendBuffer(otaData.removeBuffer(MAX_LENGTH));
            request.setShortMessageData(message);
            request.setEsmClass((byte)64);
            request.setDataCoding((byte)-11);
            String s_emsId = emsId.toString();
            request.setSequenceNumber(Integer.parseInt(s_emsId + i));
            if(TotalSegments == 0)
                TotalSegments = 1;
            ByteBuffer Charge = new ByteBuffer();
            Charge.appendByte((byte)-96);
            Charge.appendString(sCommand_code + "," + MsgType + "," + TotalSegments);
            request.setSourceSubaddress(Charge);
            if(i == totalSegments)
                request.setRegisteredDelivery(registeredDelivery);
            vRequests.addElement(request);
        }

        return vRequests;
        Exception e;
        e;
        throw new EMSException(e.getMessage());
    }
Beispiel #6
0
    public static Collection buildSubmitEMS(ByteBuffer otaData, String srcAddr, String destAddr, int contentType, BigDecimal emsId, byte registeredDelivery, int MsgType, BigDecimal RequestID)
        throws EMSException
    {
        Vector vRequests;
        SubmitSM request = null;
        vRequests = new Vector();
        String mobileOperator = "";
        mobileOperator = Preference.mobileOperator;
        otaData = addHeaders2OTAData(otaData, mobileOperator, contentType);
        Logger.info("otadata.length:" + otaData.length());
        if(otaData.length() <= 133)
        {
            MAX_LENGTH = 133;
            isFragmented = false;
            totalSegments = 1;
        } else
        {
            MAX_LENGTH = 128;
            isFragmented = true;
            totalSegments = (byte)(otaData.length() / MAX_LENGTH + 1);
        }
        ByteBuffer message = null;
        for(byte i = 1; i <= totalSegments; i++)
        {
            SubmitSM request = new SubmitSM();
            request.setSourceAddr((byte)0, (byte)1, srcAddr);
            request.setDestAddr((byte)1, (byte)1, destAddr);
            request.setServiceType("WPUSH");
            message = new ByteBuffer();
            if(otaData.length() <= MAX_LENGTH)
                message.appendBuffer(otaData);
            else
                message.appendBuffer(otaData.removeBuffer(MAX_LENGTH));
            request.setShortMessageData(message);
            request.setEsmClass((byte)0);
            request.setProtocolId((byte)0);
            String s_emsId = emsId.toString();
            request.setSequenceNumber(Integer.parseInt(s_emsId + i));
            if(i == totalSegments)
                request.setRegisteredDelivery(registeredDelivery);
            String DestSubAddress = "0xB0";
            if(MsgType != 3)
            {
                ByteBuffer ChargeDest = new ByteBuffer();
                ChargeDest.appendByte((byte)-80);
                ChargeDest.appendString(RequestID);
                DestSubAddress = DestSubAddress + RequestID;
                if("SFONE".equalsIgnoreCase(Preference.mobileOperator))
                    request.setDestSubaddress(ChargeDest);
            }
            String chargeflag = "0x0000";
            if("SFONE".equalsIgnoreCase(Preference.mobileOperator))
                if(MsgType == 1)
                {
                    request.setSfoneChargeFlag((short)256);
                    chargeflag = "0x0100";
                } else
                if((new StringBuffer(String.valueOf(MsgType))).toString().startsWith("21"))
                {
                    request.setSfoneChargeFlag((short)513);
                    chargeflag = "0x0201";
                } else
                if((new StringBuffer(String.valueOf(MsgType))).toString().startsWith("22"))
                {
                    request.setSfoneChargeFlag((short)514);
                    chargeflag = "0x0202";
                } else
                if((new StringBuffer(String.valueOf(MsgType))).toString().equals("2"))
                {
                    request.setSfoneChargeFlag((short)513);
                    chargeflag = "0x0201";
                } else
                {
                    request.setSfoneChargeFlag((short)0);
                }
            Logger.info("SMSCTools.buildSubmitSM", "{RequestID=" + RequestID + "}{srcAddr=" + srcAddr + "}{destAddr=" + destAddr + "}{setDestSubaddress=" + DestSubAddress + "} {chargeflag=" + chargeflag + "} ");
            vRequests.addElement(request);
        }

        return vRequests;
        Exception e;
        e;
        throw new EMSException(e.getMessage());
    }