Google Analytics

Thursday, September 25, 2014

JAVA String Splitting for given length

Observed the code from:
http://stackoverflow.com/questions/12295711/split-a-string-at-every-nth-position

public String[] splitStringEvery(String s, int interval) {
    int arrayLength = (int) Math.ceil(((s.length() / (double)interval)));
    String[] result = new String[arrayLength];

    int j = 0;
    int lastIndex = result.length - 1;
    for (int i = 0; i < lastIndex; i++) {
        result[i] = s.substring(j, j + interval);
        j += interval;
    } //Add the last bit
    result[lastIndex] = s.substring(j);

    return result;
}

Tuesday, September 16, 2014

Send Long SMS using SMPP


smsMessageText: Dear MISS DE MMMAA SSS, your mobile or xxxxx number 111111111 has been selected for festival offer.smsMessageText: Dear MISS DE MMMAA SSS, your mobile or xxxxx number 111111111 has been selected for festival offer. avail 50% discounton 11-SEP-12 @AAApurchase of 1000Rs.testtesttesttesttesttesttestesttesttesttesttesttesttesttesttesttesttesttesttesttesttesttesttesttesttesttesttesttesttesttesttesttesttesttesttesttesttes

connectionReferenceNumber: 111111

org.jsmpp.PDUStringException: Octet String value 'Dear MISS DE MMMAA SSS, your mobile or xxxxx number 111111111 has been selected for festival offer. avail 50% discounton 11-SEP-12 @KFC purchase of 1000Rs.testtesttesttesttesttesttestesttesttesttesttesttesttesttesttesttesttesttesttesttesttesttesttesttesttesttesttesttesttesttesttesttesttesttesttesttesttes' cannot more than 254. Actual length of string is 320

at org.jsmpp.util.StringValidator.validateString(StringValidator.java:73)
at org.jsmpp.util.DefaultComposer.submitSm(DefaultComposer.java:215)
at org.jsmpp.DefaultPDUSender.sendSubmitSm(DefaultPDUSender.java:196)
at org.jsmpp.SynchronizedPDUSender.sendSubmitSm(SynchronizedPDUSender.java:192)
at org.jsmpp.session.SubmitSmCommandTask.executeTask(SubmitSmCommandTask.java:86)
at org.jsmpp.session.AbstractSession.executeSendCommand(AbstractSession.java:248)
at org.jsmpp.session.SMPPSession.submitShortMessage(SMPPSession.java:321)
at abc.ddd.util.sms.SMSClient.submitMessage(SMSClient.java:130)
at abc.ddd.util.sms.AsyncSubmitter.run(AsyncSubmitter.java:21)
at java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:441)
at java.util.concurrent.FutureTask$Sync.innerRun(FutureTask.java:303)
at java.util.concurrent.FutureTask.run(FutureTask.java:138)
at java.util.concurrent.ThreadPoolExecutor$Worker.runTask(ThreadPoolExecutor.java:886)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:908)
at java.lang.Thread.run(Thread.java:619)
testtesttesttestesttesttesttesttesttesttesttesttesttesttesttesttesttesttesttesttesttesttesttesttesttesttesttesttesttesttesttesttesttesttes
connectionReferenceNumber: 111111

org.jsmpp.PDUStringException: Octet String value 'Dear MISS DE MMMAA SSS, your mobile or xxxxx number 111111111 has been selected for festival offer. avail 50% discounton 11-SEP-12 @KFC purchase of 1000Rs.testtesttesttesttesttesttestesttesttesttesttesttesttesttesttesttesttesttesttesttesttesttesttesttesttesttesttesttesttesttesttesttesttesttesttesttesttes' cannot more than 254. Actual length of string is 320


Error codes:
http://www.activexperts.com/xmstoolkit/sms/smpperrorcodes/

SMSRequestConsumerJob [INFO] Status updated successfully for pendingNo: 34239593
org.jsmpp.extra.NegativeResponseException: Negative response 00000001 found
    at org.jsmpp.session.AbstractSession.validateResponse(AbstractSession.java:215)
    at org.jsmpp.session.AbstractSession.executeSendCommand(AbstractSession.java:271)
    at org.jsmpp.session.SMPPSession.submitShortMessage(SMPPSession.java:321)

-------------------------------------------------------------------------------------------------------------
Follow below links:



http://www.ashishpaliwal.com/blog/2009/01/smpp-sending-long-sms-through-smpp/

SMPP 3.4 spec --> optional parameters for concatenation
http://sourceforge.net/p/smppapi/discussion/84650/thread/73ceac01/
http://www.activexperts.com/sms-component/smpp-specifications/smpp-parameter-definition/

Lib method definitions:
https://github.com/uudashr/jsmpp/blob/master/jsmpp/src/main/java/org/jsmpp/bean/OptionalParameter.java

------------------------------------------------------------------------------------------------------------
http://jsmpp.googlecode.com/svn-history/r163/trunk/src/java/examples/org/jsmpp/examples/SubmitLongMessageExample.java

Sample:
public void run() {
        //super.run();
        messageId = SMSClient.getInstance().submitMessage(source, "94" + destination, message);
        handleDeliveryId(messageId);
    }

public String submitMessage(String source, String destination, String message){
        String messageId = null;
        log.info("Inside submitMessage");
        int msgTotalSegCount = splitStringSMS(message,157).length;
        int msgSeqNo = 1;
        int msgSegRefNo = 0;
        for (String msg: splitStringSMS(message,157))
        {
          System.out.println(msg);
          System.out.println("----------------------");
        
          try {
              
                /*messageId = session.submitShortMessage("",
                        TypeOfNumber.valueOf(props.getProperty(SOURCE_TON)), NumberingPlanIndicator.valueOf(props.getProperty(SOURCE_NPI)),
                        source, TypeOfNumber.valueOf(props.getProperty(DESTINATION_TON)),
                        NumberingPlanIndicator.valueOf(props.getProperty(DESTINATION_NPI)), destination, new ESMClass(),
                        (byte) 0, (byte) 1, timeFormatter.format(new Date()), null,
                        registeredDelivery, (byte) 0, new GeneralDataCoding(false,
                                true, MessageClass.CLASS1, Alphabet.ALPHA_DEFAULT),
                        (byte) 0, message.getBytes());*/
              
                OptionalParameter sarMsgRefNumParameter = new OptionalParameter.Int(Tag.SAR_MSG_REF_NUM, msgSegRefNo);
                OptionalParameter sarTotalSegmentsParameter = new OptionalParameter.Int(Tag.SAR_TOTAL_SEGMENTS, msgTotalSegCount);
                OptionalParameter sarSegmentSeqnumParameter = new OptionalParameter.Int(Tag.SAR_SEGMENT_SEQNUM, msgSeqNo);
              
                //Optional parameters added
                messageId = session.submitShortMessage("",
                        TypeOfNumber.valueOf(props.getProperty(SOURCE_TON)), NumberingPlanIndicator.valueOf(props.getProperty(SOURCE_NPI)),
                        source, TypeOfNumber.valueOf(props.getProperty(DESTINATION_TON)),
                        NumberingPlanIndicator.valueOf(props.getProperty(DESTINATION_NPI)), destination, new ESMClass(),
                        (byte) 0, (byte) 1, timeFormatter.format(new Date()), null,
                        registeredDelivery, (byte) 0, new GeneralDataCoding(Alphabet.ALPHA_DEFAULT, MessageClass.CLASS1, false),
                        (byte) 0, msg.getBytes(),sarMsgRefNumParameter,sarTotalSegmentsParameter,sarSegmentSeqnumParameter);  
                msgSeqNo++;
              
            } catch (Exception e) {
                e.printStackTrace();
                throw new RuntimeException("Submission failure .....",e);
            }
        }
      
        long id = Long.parseLong(messageId) & 0xffffffff;
        messageId = Long.toString(id,16).toUpperCase();
        System.out.println("Message seq>> " + msgSeqNo);
        System.out.println("Message total segment count>> " + msgTotalSegCount);
        System.out.println("Message referanceNo>> " + msgSegRefNo);
      
        log.info("Message submitted, source:" + source + " ,destination:" + destination + " ,messageId:" + messageId);
      
        return messageId;
    }



Tuesday, September 9, 2014

Check PL/SQL http request working.

Check PL/SQL http request working.

SELECT UTL_HTTP.REQUEST('http://www.abc.com') FROM DUAL;

More Info:
http://docs.oracle.com/cd/B19306_01/appdev.102/b14258/u_http.htm
http://www.dba-oracle.com/t_advanced_utl_http_package.htm

Thursday, September 4, 2014

Move DATA to history table

Create history table --> CM_OCS_FILE_STAT_H.

Get CM_OCS_FILE_STAT script.

Remove disk space related stuffs and execute.

Move data to history table

Insert into CM_OCS_FILE_STAT select * from CM_OCS_FILE_STAT_H

Drop table data only.
Toad--> Truncate Table

Monday, August 18, 2014

ORA-00907: missing right parenthesis

Wrong Script
create table ddd.xx_aa_bb
(
  a_id   varchar2(10 byte)                not null,
  b_id   varchar2(10 byte)                default 'NULL'                 not null,
  message      varchar2(159 byte)            
  description  varchar2(250 byte)             
)
tablespace data_ts
pctused    0
pctfree    10
initrans   1
maxtrans   255
storage    (
            initial          64k
            next             1m
            minextents       1
            maxextents       unlimited
            pctincrease      0
            buffer_pool      default
           )
logging
nocompress
nocache
noparallel
monitoring;

--------------------------------------------------------------

Correct Script (missing , at the message field)
create table ddd.xx_aa_bb
(
  a_id   varchar2(10 byte)                not null,
  b_id   varchar2(10 byte)                default 'NULL'                 not null,
  message      varchar2(159 byte),            
  description  varchar2(250 byte)             
)
tablespace data_ts
pctused    0
pctfree    10
initrans   1
maxtrans   255
storage    (
            initial          64k
            next             1m
            minextents       1
            maxextents       unlimited
            pctincrease      0
            buffer_pool      default
           )
logging
nocompress
nocache
noparallel
monitoring;

Thursday, July 31, 2014

JAVA Could not find or load main class


 If below type error occur:

Java and cmd "Could not find or load main class"
-bash: ./xxx.sh: /bin/sh^M: bad interpreter: No such file or direct


>>Format the xxx.sh from unix.
>>: set fileformat=unix

More info:
http://lanvu.wordpress.com/2012/01/06/linux-shell-scripting-bad-interpreter-no-such-file-or-directory/

Thursday, July 10, 2014

Correctly close PL/SQL Statements

Close PL/SQL Statements

*Check null before close.
*Close result set first.
*Close Statement second.

https://issues.jboss.org/browse/JBAS-5303


https://community.jboss.org/thread/92980?tstart=0&_sscc=t

java.sql.SQLException: Exhausted ResultSet

public String getCxAANo(String rr, String bb) {
        String returnCode = "";
        ResultSet rst = null;
        Statement stm = null;
        ResultSet rstSimTbl = null;
        PreparedStatement stmSimTbl = null;
        try {
            stm = objDBCon.createStatement();
            rst = stm.executeQuery("select distinct(XXX) from AAA where QQ_NO='" + qqNo+ "'");


            if (rst != null) {
                while (rst.next()) {
                    simVal = rst.getString("XX");
                    count++;
                }
            }
            if (count == 0) {
                returnCode = "NODATA";
            } else if (count == 1) {
                         stmSimTbl = objDBCon.prepareStatement("select count(*) from BBB_CONFIG where XX_NO=? and DD_CODE=?");
                stmSimTbl.setString(1, XXVal);
                stmSimTbl.setString(2,DD_code);
                rstSimTbl = stmSimTbl.executeQuery();

                if (rstSimTbl != null) {
                    while (rstSimTbl.next()) {
                        simCount = rstSimTbl.getInt(1);
                    }
                }

                if (simCount == 1) {
                    returnCode = "ALLOWED";
                } else {
                    returnCode = "RESTRICTED";
                }
            }
        } catch (Exception er) {
            returnCode = "ERROR";
        } finally {
            try {
                if (rstSimTbl != null) {
                    rstSimTbl.close();
                }
            } catch (Exception ex) {
                ex.getMessage();
            }
            try {
                if (stmSimTbl != null) {
                    stmSimTbl.close();
                }
            } catch (Exception ex) {
                ex.getMessage();
            }
            try {
                if (rst != null) {
                    rst.close();
                }
            } catch (Exception ex) {
                ex.getMessage();
            }
            try {
                if (stm != null) {
                    stm.close();
                }
            } catch (Exception ex) {
                ex.getMessage();
            }
        }
        return returnCode;
    }
 


Answer 5:
http://stackoverflow.com/questions/3502005/java-sql-sqlexception-exhausted-resultset