Thursday, June 19, 2008

Designing OptionalParameter API

I will share about how the OptionalParameter API is designed.

OptionalParameter API initially contributed by mikko.koponen. The main problem is come when I try to create jsmpp examples for sending segmented/concatenated message using optional parameter (TLV or Tag Length Value).

short refNum = ....
OptionalParameter sarMsgRefNum = new OptionalParameter.Short(Tag.SAR_MSG_REF_NUM, refNum);
OptionalParameter sarSegmentSeqNum = new OptionalParameter.Byte(Tag.SAR_SEGMENT_SEQNUM, (byte)1);
OptionalParameter sarTotalSegments = new OptionalParameter.Byte(Tag.SAR_TOTAL_SEGMENTS, (byte)3);


Wow, it was to verbose. You will find out how tired writing code like that even if you use IDE that handle code completion.
Now lets see the simple version crossing my mind.

short refNum = ....
OptionalParameter sarMsgRefNum = OptionalParamertes.newSarMsgRefNum(refNum);
OptionalParameter sarSegmentSeqNum = OptionalParameters.newSarSegmentSeqNum(1);
OptionalParameter sarTotalSegments = OptionalParameters.newSarTotalSegments(3);


Does it more friendly?
I didn't throw the old API, I just add new utility functions to OptionalParameters as static method.

Good design might to complex and to hard to use by developer. It's just like test first development. So I try to construct the use case and then implement the code to meet the need of the use case.

9 comments:

Anonymous said...

I am trying to send Ringtone through jsmpp.
I am not sure abut the optional parameters required for the same.
Can u please give any sample code to send ringtone using jsmpp.

Thanks,
Raghu Kiran

Arindam said...

When I am sending LongSMS I am getting the following error. Please can you help me?

TOTAL_SEGMENTS=3Tag of sarMsgRefNum:524, sarTotalSegments:526, sarSegmentSeqnum:527
Receive negative response
org.jsmpp.extra.NegativeResponseException: Negative response 000000c4 found
at org.jsmpp.session.AbstractSession.validateResponse(AbstractSession.ja
va:215)
at org.jsmpp.session.AbstractSession.executeSendCommand(AbstractSession.
java:271)
at org.jsmpp.session.SMPPSession.submitShortMessage(SMPPSession.java:320
)
at org.jsmpp.examples.SendLongTextMessage.submitMessage(SendLongTextMess
age.java:148)
at org.jsmpp.examples.SendLongTextMessage.main(SendLongTextMessage.java:
116)
Message submitted, message_id is null




Advance Thanks,
Arindam

Anonymous said...

I guess there is some issue with the optional parameters used by you.
Normally negative response occurs due to the bad requests submited to the server.
can please post the code.

som said...

I need to set custom optional parameters to submit_sm and extract them from deliver_sm. How this can be done. Example optional parameters like my_tariff,my_sessionId etc.

my first blog said...

I need to use the optional parameter to connect to the SMSGateway which is behind a firewall and need to connect via a proxy server

SpaceHippy Matt said...

@som, I as well am attempting to set custom optional parameters to submit_sm and extract them from deliver_sm. I've reading the optionalParameters from the DeliverSM and finding it regularly null even after they've been sent via simulator.

Unknown said...

Hello ....

I need one help in jSMPP protocol.
I have a requirement with my ServiceProvider they are accepting some optional parameters, with that they are sharing the Amount details. How can i will know (send or receive) amount details for a particular premium message. Please help me in this. Thanks in Advance.

imran raza khan said...

How we can get value of optional parameter in JSMPP?

Onpeaks said...

In order to use an SMPP Server Provider, users need to create a username and a password manually. This is generally done by the service provider. Here, it is also important to note that there are many server providers that offer special wholesale process for their partners who are into sending high volumes of SMSs across the world.