You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@camel.apache.org by cartoondog <ca...@hotmail.com> on 2013/08/14 22:35:13 UTC

How to add Vendor Specific Optional Parameter in CamelSmppOptionalParameters

I am new to Apache Camel and trying to use its SMPP component to send sms to
SMSC.  However, the smsc vendor needs me to specify the operator id (i.e.
mobile phone carrier id) in the smpp optional parameters header with a tag
identifier 0x2150 which falls inside the range of SMSC Vendor specific
optional parameters as per SMPP 3.4 specification.  I am almost done in
building the system except this very last part.  Hope someone can show me
the way to complete the task.  Thank you very much in advance 



--
View this message in context: http://camel.465427.n5.nabble.com/How-to-add-Vendor-Specific-Optional-Parameter-in-CamelSmppOptionalParameters-tp5737268.html
Sent from the Camel - Users mailing list archive at Nabble.com.

Re: How to add Vendor Specific Optional Parameter in CamelSmppOptionalParameters

Posted by cartoondog <ca...@hotmail.com>.
Hi Christ,

Jira created.  #CAMEL-6655.


I think I have messed up the code in my last post and revised the method as
below.  Kindly check and advise if this can work.

/*
    <p>Since it is vendor specified, so users must have the code and type,
         therefore users should concatenate these information as a string
         using a separator(":") and pass this in as the Entry's value
    </p>
    <p>Usage: Entry<String, String>
                   String key must equal
 "VENDOR_SPECIFIC_OPTIONAL_PARAMETER"
                   String value should be "code:type:param_value"
*/
   protected OptionalParameter generateVendorSpecificOptParam(Entry<String,
String> entry)
           throws SecurityException, IllegalArgumentException,
IllegalAccessException{

           OptionalParameter optParam = null ;

       String valueStr = (String)entry.getValue() ;
       String[] inputStr = valueStr.split(":", 3) ;     
       short code = Short.parseShort(inputStr[0]) ;
  //code must fall inside the ranges specified in SMPP 3.4 specification
  //0x1400 - 0x3FFF
             if ( !(code >= 0x1400 or code <= 0x3FFF)
                  throw new IllegalArgumentException() ;

  //type must be one of the defined Class and must be in uppercase

        String type = inputStr[1] ;
        if ( type.equals("OCTETSTRING") ){
                 optParam = new OptionalParameter.OctetString(code,
inputStr[2]) ;           
        }else if (type.equals("COCTETSTRING") ) {
                 optParam = new OptionalParameter.COctetString(code,
inputStr[2]) ; 
        }else if(type.equals("BYTE") ){
                 optParam = new OptionalParameter.Byte(code,
Byte.valueOf(inputStr[2])) ; 
        }else if (type.equals("INT") ){
                optParam = new OptionalParameter.Int(code,
Integer.valueOf(inputStr[2]));
        }else if (type.equals("SHORT") ) {
                optParam = new OptionalParameter.Short(code,
Short.valueOf(inputStr[2]));
        }else if (type.equals("NULL") )
                optParam = new OptionalParameter.Null(code);
        }else
                throw new IllegualArgumentException() ;
        }
             return optParam ;
   } 





--
View this message in context: http://camel.465427.n5.nabble.com/How-to-add-Vendor-Specific-Optional-Parameter-in-CamelSmppOptionalParameters-tp5737268p5737639.html
Sent from the Camel - Users mailing list archive at Nabble.com.

Re: How to add Vendor Specific Optional Parameter in CamelSmppOptionalParameters

Posted by Christian Müller <ch...@gmail.com>.
Yes, you have to create a different account [1].
Afterwards you can create an enhancement request at [2].
And as you may know, we love contributions [3]. Feel free to attach your
proposed solution which should include unit tests.
And helping out with the documentation is also welcome [4].

[1] https://issues.apache.org/jira/secure/Dashboard.jspa
[2] https://issues.apache.org/jira/browse/CAMEL
[3] http://camel.apache.org/contributing.html
[4] http://camel.apache.org/how-do-i-edit-the-website.html

Best,
Christian
-----------------

Software Integration Specialist

Apache Camel committer: https://camel.apache.org/team
V.P. Apache Camel: https://www.apache.org/foundation/
Apache Member: https://www.apache.org/foundation/members.html

https://www.linkedin.com/pub/christian-mueller/11/551/642


On Fri, Aug 16, 2013 at 6:59 PM, cartoondog <ca...@hotmail.com> wrote:

> Hi Chris,
>
> Do I have to create another account to log in ASF JIRA?  My user id here
> cannot log in ASF JIRA.
>
> After looking into the source code, I found that we can add support to
> Vendor Specific Optional Parameter
> by adding some codes in the AbstractSmppCommand class like below.  Please
> correct me if I am wrong.
>
>    @SuppressWarnings("rawtypes")
>     protected List<OptionalParameter> createOptionalParameters(Map<String,
> String> optinalParamaters) {
>         List<OptionalParameter> optParams = new
> ArrayList<OptionalParameter>();
>
>         for (Entry<String, String> entry : optinalParamaters.entrySet()) {
>             OptionalParameter optParam = null;
>
>             try {
>
> //add a checking to distinguish Vendor Specfic Optional Parameter
> //from other static defined optional parameters
>
>                 if
> (((String)entry.getKey()).equals.("VENDOR_SPECFIC_OPTIONAL_PARAMETER"){
>                      optParam = generateVenderSpecificOptParam(entry) ;
>                 } else {
>                     Tag tag = Tag.valueOf(entry.getKey());
>                     Class type = determineTypeClass(tag);
>
>                     if (OctetString.class.equals(type)) {
>                       optParam = new
> OptionalParameter.OctetString(tag.code(), entry.getValue());
>                     } else if (COctetString.class.equals(type)) {
>                        optParam = new
> OptionalParameter.COctetString(tag.code(), entry.getValue());
>                     } else if
> (org.jsmpp.bean.OptionalParameter.Byte.class.equals(type)) {
>                        optParam = new OptionalParameter.Byte(tag.code(),
> Byte.valueOf(entry.getValue()));
>                     } else if
> (org.jsmpp.bean.OptionalParameter.Int.class.equals(type)) {
>                        optParam = new OptionalParameter.Int(tag.code(),
> Integer.valueOf(entry.getValue()));
>                     } else if
> (org.jsmpp.bean.OptionalParameter.Short.class.equals(type)) {
>                        optParam = new OptionalParameter.Short(tag.code(),
> Short.valueOf(entry.getValue()));
>                     } else if
> (org.jsmpp.bean.OptionalParameter.Null.class.equals(type)) {
>                       optParam = new OptionalParameter.Null(tag);
>                     }
>                 }
>                 optParams.add(optParam);
>             } catch (Exception e) {
>                 log.info("Couldn't determine optional parameter for key {}
> and value {}. Skip this one.", entry.getKey(), entry.getValue());
>             }
>         }
>
>         return optParams;
>     }
>
> /*
>    <p>Since it is vendor specified, so users must have the code and type,
>         therefore users should concatenate these information as a string
>         using a separator(":") and pass this in as the Entry's value
>    </p>
>    <p>Usage: Entry<String, String>
>                   String key must equal
> "VENDOR_SPECIFIC_OPTIONAL_PARAMETER"
>                   String value should be "code:type:param_value"
> */
>     protected OptionalParameter
> generateVendorSpecificOptParam(Entry<String,
> String> entry)
>           throws SecurityException, IllegalArgumentException,
> IllegalAccessException{
>
>           OptionalParameter optParam = null ;
>
>    //code must be in 4 character and can be parsed into a hex
>             String code = entry.getValue().substring(0,4) ;
>    //code must fall inside the ranges specified in SMPP 3.4 specification
>    //0x1400 - 0x3FFF
>             if ( !(code >= 0x1400 or code <= 0x3FFF)
>                  throw new IllegalArgumentException() ;
>
>   //type must be one of the defined Class and must be in uppercase
>
>             int pos2 = entry.getValue().indexOf(':', 5) ;
>             String type = entry.getValue().substring(5,pos2-1) ;
>             if ( type.equals("OCTETSTRING") ){
>                optParam = new OptionalParameter.OctetString(hexcode,
> entry.getValue().substring(pos2+1) ;
>             }else if (type.equals("COCTETSTRING") ) {
>                optParam = new OptionalParameter.COctetString(hexcode,
> entry.getValue().substring(pos2+1 );
>             }else if(type.equals("BYTE") ){
>                optParam = new OptionalParameter.Byte(hexcode,
> Byte.valueOf(entry.getValue().substring(pos2+1)));
>             }else if (type.equals("INT") ){
>                optParam = new OptionalParameter.Int(hexcode,
> Integer.valueOf(entry.getValue().substring(pos2+1)));
>             }else if (type.equals("SHORT") ) {
>                optParam = new OptionalParameter.Short(hexcode,
> Short.valueOf(entry.getValue().substring(pos2+1)));
>             }else if (type.equals("NULL") )
>                 optParam = new OptionalParameter.Null(tag);
>             }else
>                  throw new IllegualArgumentException() ;
>             }
>
>             return optParam ;
>       }
>
>
>
> --
> View this message in context:
> http://camel.465427.n5.nabble.com/How-to-add-Vendor-Specific-Optional-Parameter-in-CamelSmppOptionalParameters-tp5737268p5737427.html
> Sent from the Camel - Users mailing list archive at Nabble.com.
>

Re: How to add Vendor Specific Optional Parameter in CamelSmppOptionalParameters

Posted by cartoondog <ca...@hotmail.com>.
Hi Chris,

Do I have to create another account to log in ASF JIRA?  My user id here
cannot log in ASF JIRA.

After looking into the source code, I found that we can add support to
Vendor Specific Optional Parameter
by adding some codes in the AbstractSmppCommand class like below.  Please
correct me if I am wrong.

   @SuppressWarnings("rawtypes")
    protected List<OptionalParameter> createOptionalParameters(Map<String,
String> optinalParamaters) {
        List<OptionalParameter> optParams = new
ArrayList<OptionalParameter>();

        for (Entry<String, String> entry : optinalParamaters.entrySet()) {
            OptionalParameter optParam = null;

            try {

//add a checking to distinguish Vendor Specfic Optional Parameter 
//from other static defined optional parameters

                if
(((String)entry.getKey()).equals.("VENDOR_SPECFIC_OPTIONAL_PARAMETER"){
                     optParam = generateVenderSpecificOptParam(entry) ;
                } else {
                    Tag tag = Tag.valueOf(entry.getKey());
                    Class type = determineTypeClass(tag);

                    if (OctetString.class.equals(type)) {
                      optParam = new
OptionalParameter.OctetString(tag.code(), entry.getValue());
                    } else if (COctetString.class.equals(type)) {
                       optParam = new
OptionalParameter.COctetString(tag.code(), entry.getValue());
                    } else if
(org.jsmpp.bean.OptionalParameter.Byte.class.equals(type)) {
                       optParam = new OptionalParameter.Byte(tag.code(),
Byte.valueOf(entry.getValue()));
                    } else if
(org.jsmpp.bean.OptionalParameter.Int.class.equals(type)) {
                       optParam = new OptionalParameter.Int(tag.code(),
Integer.valueOf(entry.getValue()));
                    } else if
(org.jsmpp.bean.OptionalParameter.Short.class.equals(type)) {
                       optParam = new OptionalParameter.Short(tag.code(),
Short.valueOf(entry.getValue()));
                    } else if
(org.jsmpp.bean.OptionalParameter.Null.class.equals(type)) {
                      optParam = new OptionalParameter.Null(tag);
                    }
                }
                optParams.add(optParam);
            } catch (Exception e) {
                log.info("Couldn't determine optional parameter for key {}
and value {}. Skip this one.", entry.getKey(), entry.getValue());
            }
        }

        return optParams;
    }

/* 
   <p>Since it is vendor specified, so users must have the code and type,
        therefore users should concatenate these information as a string 
        using a separator(":") and pass this in as the Entry's value 
   </p>
   <p>Usage: Entry<String, String>
                  String key must equal "VENDOR_SPECIFIC_OPTIONAL_PARAMETER"
                  String value should be "code:type:param_value"  
*/
    protected OptionalParameter generateVendorSpecificOptParam(Entry<String,
String> entry) 
          throws SecurityException, IllegalArgumentException,
IllegalAccessException{
           
          OptionalParameter optParam = null ;

   //code must be in 4 character and can be parsed into a hex
            String code = entry.getValue().substring(0,4) ;
   //code must fall inside the ranges specified in SMPP 3.4 specification
   //0x1400 - 0x3FFF
            if ( !(code >= 0x1400 or code <= 0x3FFF) 
                 throw new IllegalArgumentException() ; 

  //type must be one of the defined Class and must be in uppercase
 
            int pos2 = entry.getValue().indexOf(':', 5) ;
            String type = entry.getValue().substring(5,pos2-1) ;
            if ( type.equals("OCTETSTRING") ){
               optParam = new OptionalParameter.OctetString(hexcode,
entry.getValue().substring(pos2+1) ;
            }else if (type.equals("COCTETSTRING") ) {
               optParam = new OptionalParameter.COctetString(hexcode,
entry.getValue().substring(pos2+1 );
            }else if(type.equals("BYTE") ){
               optParam = new OptionalParameter.Byte(hexcode,                                                                                                 
Byte.valueOf(entry.getValue().substring(pos2+1)));
            }else if (type.equals("INT") ){
               optParam = new OptionalParameter.Int(hexcode,
Integer.valueOf(entry.getValue().substring(pos2+1)));
            }else if (type.equals("SHORT") ) {
               optParam = new OptionalParameter.Short(hexcode,
Short.valueOf(entry.getValue().substring(pos2+1)));
            }else if (type.equals("NULL") )
                optParam = new OptionalParameter.Null(tag);
            }else 
                 throw new IllegualArgumentException() ; 
            }

            return optParam ;
      }



--
View this message in context: http://camel.465427.n5.nabble.com/How-to-add-Vendor-Specific-Optional-Parameter-in-CamelSmppOptionalParameters-tp5737268p5737427.html
Sent from the Camel - Users mailing list archive at Nabble.com.

Re: How to add Vendor Specific Optional Parameter in CamelSmppOptionalParameters

Posted by Christian Müller <ch...@gmail.com>.
I'm afraid this is not possible right now, but it could be added. Feel free
to log a JIRA and I will work on a patch.

Best,
Christian
-----------------

Software Integration Specialist

Apache Camel committer: https://camel.apache.org/team
V.P. Apache Camel: https://www.apache.org/foundation/
Apache Member: https://www.apache.org/foundation/members.html

https://www.linkedin.com/pub/christian-mueller/11/551/642


On Wed, Aug 14, 2013 at 10:35 PM, cartoondog <ca...@hotmail.com> wrote:

> I am new to Apache Camel and trying to use its SMPP component to send sms
> to
> SMSC.  However, the smsc vendor needs me to specify the operator id (i.e.
> mobile phone carrier id) in the smpp optional parameters header with a tag
> identifier 0x2150 which falls inside the range of SMSC Vendor specific
> optional parameters as per SMPP 3.4 specification.  I am almost done in
> building the system except this very last part.  Hope someone can show me
> the way to complete the task.  Thank you very much in advance
>
>
>
> --
> View this message in context:
> http://camel.465427.n5.nabble.com/How-to-add-Vendor-Specific-Optional-Parameter-in-CamelSmppOptionalParameters-tp5737268.html
> Sent from the Camel - Users mailing list archive at Nabble.com.
>

Re: How to add Vendor Specific Optional Parameter in CamelSmppOptionalParameters

Posted by cartoondog <ca...@hotmail.com>.
Hi Christian,

I tested the new function with version 2.12.0, it works well when sending
out sms messages, but exception is thrown by SmppConsumer.  I used selenium
smppsim and put the option to append optional parameter in the config file
as follows:
DELIVERY_RECEIPT_TLV=2150/02/0076

So when smppsim startup, it will show this info
2013.09.25 14:33:36 843 INFO    1 = Delivery receipts will always have
optional parameter with TLV=8528/2/0076


and when Camel smpp endpoint receives delivery receipt from smppsim,
SmppConsumer will throw IllegalArgumentException as below:

[pool-2-thread-3] SmppConsumer                   WARN  Cannot create
exchange. This exception will be ignored.. Caused by:
[java.lang.IllegalArgumentException - No tag for: 8528]
java.lang.IllegalArgumentException: No tag for: 8528
        at
org.jsmpp.bean.OptionalParameter$Tag.valueOf(OptionalParameter.java:308)
        at
org.apache.camel.component.smpp.SmppBinding.createOptionalParameterByName(SmppBinding.java:161)
        at
org.apache.camel.component.smpp.SmppBinding.createSmppMessage(SmppBinding.java:112)
        at
org.apache.camel.component.smpp.SmppEndpoint.createOnAcceptDeliverSmExchange(SmppEndpoint.java:119)
        at
org.apache.camel.component.smpp.SmppEndpoint.createOnAcceptDeliverSmExchange(SmppEndpoint.java:103)
        at
org.apache.camel.component.smpp.MessageReceiverListenerImpl.onAcceptDeliverSm(MessageReceiverListenerImpl.java:70)
        at
org.jsmpp.session.SMPPSession.fireAcceptDeliverSm(SMPPSession.java:44
5)
        at org.jsmpp.session.SMPPSession.access$0(SMPPSession.java:443)
        at
org.jsmpp.session.SMPPSession$ResponseHandlerImpl.processDeliverSm(SMPPSession.java:462)
        at
org.jsmpp.session.state.SMPPSessionBoundRX.processDeliverSm0(SMPPSessionBoundRX.java:109)
        at
org.jsmpp.session.state.SMPPSessionBoundRX.processDeliverSm(SMPPSessionBoundRX.java:51)
        at org.jsmpp.session.PDUProcessTask.run(PDUProcessTask.java:81)
        at
java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1145)
        at
java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:615)
        at java.lang.Thread.run(Thread.java:724)

Did I setup wrong or it is still an issue? 

Thanks, 
Peter



--
View this message in context: http://camel.465427.n5.nabble.com/How-to-add-Vendor-Specific-Optional-Parameter-in-CamelSmppOptionalParameters-tp5737268p5740212.html
Sent from the Camel - Users mailing list archive at Nabble.com.