opentelecoms-org / jsmpp

SMPP implemented in Java
Apache License 2.0
233 stars 163 forks source link

Handle user defined DeliveryReceiptState #71

Open shubhanshushukla opened 7 years ago

shubhanshushukla commented 7 years ago

Currently we have following DeliveryReceiptState

    ENROUTE(0),
    DELIVRD(1),
    EXPIRED(2),
    DELETED(3),
    UNDELIV(4),
    ACCEPTD(5),
    UNKNOWN(6),
    REJECTD(7); 

In India we get many other code apart from standard code mentioned above.
Like code 9 means user found in Do Not Disturb Database. Like code 11 means user found in Corporate Database.

But when we get these code from SMSC, we get exception.

  public static DeliveryReceiptState valueOf(int value)
            throws IllegalArgumentException {
        for (DeliveryReceiptState item : values()) {
            if (item.value() == value) {
                return item;
            }
        }
        throw new IllegalArgumentException(
                "No enum const DeliveryReceiptState with value " + value);
    }

So suggesting below changes


 public enum DeliveryReceiptState {
    /**
     * ENROUTE
     */
    ENROUTE(0),
    /**
     * DELIVERED
     */
    DELIVRD(1),
    /**
     * EXPIRED
     */
    EXPIRED(2),
    /**
     * DELETED
     */
    DELETED(3),
    /**
     * UNDELIVERABLE
     */
    UNDELIV(4),
    /**
     * ACCEPTED
     */
    ACCEPTD(5),
    /**
     * UNKNOWN
     */
    UNKNOWN(6),
    /**
     * REJECTED
     */
    REJECTD(7);

    private int value;

    DeliveryReceiptState(int value) {
        this.value = value;
    }

    public static DeliveryReceiptState getByName(String name) {
        return valueOf(DeliveryReceiptState.class, name);
    }

    public static DeliveryReceiptState valueOf(int value)
            throws IllegalArgumentException {
        for (DeliveryReceiptState item : values()) {
            if (item.value() == value) {
                return item;
            }
        }
        return UNKNOWN;
    }

    public int value() {
        return value;
    }
}
pmoerenhout commented 7 years ago

I rather would implement a custom delivery receipt in your program to handle the extra values. Create a custom enum like CustomDeliveryReceiptState with the state the SMSC supports, add a class CustomDeliveryReceipt extends DeliveryReceipt, implement a class CustomDeliveryReceiptStripper implements DeliveryReceiptStrip, then in the onAcceptDeliverSm do a CustomDeliveryReceipt delReceipt = deliverSm.getDeliveryReceipt(DELIVERY_RECEIPT_STRIPPER), where DELIVERY_RECEIPT_STRIPPER is an instance of CustomDeliveryReceiptStripper. The only thing is that getFinalStatus expects always the original Enum. So your should implement a extra getter/setter for the CustomDeliveryReceiptState in the CustomDeliveryReceipt. I could provide some sample code, if this is unclear.

shubhanshushukla commented 7 years ago

Hi Please provide the sample code, it seems very complex. I will help to create/add documentation for this in GIT WIKI Let say I have created enum called DND_REJECTED `public enum CustomDeliveryReceiptState { DND_REJECTED(9);

private int value; DeliveryReceiptState(int value) { this.value = value; } public int value() { return value; } } ` Please paste the sample for way forward. Many thanks in advance.

pmoerenhout commented 7 years ago

I updated the DeliveryReceipt and put the example into the receipts example directory. Can you see if you get it working for you? If you have the complete list of states, I can put in the example.

shubhanshushukla commented 6 years ago

Please suggest, from where I can call use these classes

  1. CustomDeliveryReceipt.java
  2. CustomDeliveryReceiptState.java
  3. CustomDeliveryReceiptStripper.java

I am using camel-smpp for receiving delivery receipt. camel-smpp using jsmpp internally. If change in camel smpp required I can do it.

pmoerenhout commented 6 years ago

For plain jSMPP, an example is there, in the class CustomSimpleSubmitSimpleReceiveExample. The Camel framework also have to be changed to use this new feature. I will try to find some time to make an working example in Camel.

shubhanshushukla commented 5 years ago

Hi @pmoerenhout could you please share changes required in camel-smpp