case SmsConstants.ALPHABET_GSM: String msg = SmsPduUtil.readSeptets(thePdu.getUserData(), thePdu.getUserDataLength()); msg = URLEncoder.encode(msg); udh = SmsPduUtil.bytesToHexString(thePdu.getUserDataHeaders()); requestString = MessageFormat.format( "http: new Object[] { mySessionId, theDestination.getAddress(), theSender.getAddress(), udh, msg }); break;
case SmsConstants.DCS_DEFAULT_7BIT: throw new SmsException("Clickatell API cannot send 7 bit encoded messages with UDH");
    public void send(SmsPdu thePdu, SmsAddress theDestination, SmsAddress theSender) throws SmsException    {        String response = null;        MessageFormat responseFormat = new MessageFormat("{0}: {1}");        String requestString;        String ud;        String udh;        if (theDestination.getTypeOfNumber() == SmsConstants.TON_ALPHANUMERIC)        {            throw new SmsException("Cannot sent SMS to an ALPHANUMERIC address");        }        if (mySessionId == null)        {            throw new SmsException("Must connect before sending");        }        //        // Generate request URL        //        if (thePdu.getUserDataHeaders() == null)        {            //            // Message without UDH            //            switch (SmsDcsUtil.getAlphabet(thePdu.getDataCodingScheme()))            {            case SmsConstants.ALPHABET_8BIT:                throw new SmsException("Clickatell API cannot send 8 bit encoded messages without UDH");            case SmsConstants.ALPHABET_UCS2:                ud = SmsPduUtil.bytesToHexString(thePdu.getUserData());                requestString = MessageFormat.format(                    "http://api.clickatell.com/http/sendmsg?session_id={0}&to={1}&from={2}&text={3}&unicode=1",                    new Object[] { mySessionId, theDestination.getAddress(), theSender.getAddress(), ud });                break;            case SmsConstants.ALPHABET_GSM:                String msg = SmsPduUtil.readSeptets(thePdu.getUserData(), thePdu.getUserDataLength());                msg = URLEncoder.encode(msg);                requestString = MessageFormat.format(                    "http://api.clickatell.com/http/sendmsg?session_id={0}&to={1}&from={2}&text={3}",                    new Object[] { mySessionId, theDestination.getAddress(), theSender.getAddress(), msg });                break;            default:                throw new SmsException("Unsupported data coding scheme");            }        }        else        {            //            // Message Contains UDH            //            switch (thePdu.getDataCodingScheme())            {            case SmsConstants.ALPHABET_8BIT:                ud = SmsPduUtil.bytesToHexString(thePdu.getUserData());                udh = SmsPduUtil.bytesToHexString(thePdu.getUserDataHeaders());                requestString = MessageFormat.format(                    "http://api.clickatell.com/http/sendmsg?session_id={0}&to={1}&from={2}&udh={3}&text={4}",                    new Object[] { mySessionId, theDestination.getAddress(), theSender.getAddress(), udh, ud });                break;            case SmsConstants.ALPHABET_UCS2:                ud = SmsPduUtil.bytesToHexString(thePdu.getUserData());                udh = SmsPduUtil.bytesToHexString(thePdu.getUserDataHeaders());                requestString = MessageFormat.format(                    "http://api.clickatell.com/http/sendmsg?session_id={0}&to={1}&from={2}&udh={3}&text={4}&unicode=1",                    new Object[] { mySessionId, theDestination.getAddress(), theSender.getAddress(), udh, ud });                break;            case SmsConstants.ALPHABET_GSM:                String msg = SmsPduUtil.readSeptets(thePdu.getUserData(), thePdu.getUserDataLength());                msg = URLEncoder.encode(msg);                udh = SmsPduUtil.bytesToHexString(thePdu.getUserDataHeaders());                requestString = MessageFormat.format(                    "http://api.clickatell.com/http/sendmsg?session_id={0}&to={1}&from={2}&udh={3}&text={4}&msg_type=SMS_TEXT",                    new Object[] { mySessionId, theDestination.getAddress(), theSender.getAddress(), udh, msg });                break;            default:                throw new SmsException("Unsupported data coding scheme");            }        }        //        // Send request to clickatell        //        try        {            URL requestURL = new URL(requestString);            // Connect            BufferedReader responseReader =                new BufferedReader(new InputStreamReader(requestURL.openStream()));            // Read response            response = responseReader.readLine();            responseReader.close();            // Parse response            Object[] objs = responseFormat.parse(response);            if ( "ID".equalsIgnoreCase((String)objs[0]) )            {                // Could do something with this, we just ignore it.                String msgId = (String)objs[1];            }            else            {                // ERR                String errorMsg = (String) objs[1];                throw new SmsException("Clickatell error. Error " + errorMsg);            }        }        catch (ParseException ex)        {            throw new SmsException("Unexpected response from Clickatell. : " + response);        }        catch (MalformedURLException ex)        {            throw new SmsException(ex.getMessage());        }        catch (IOException ex)        {            throw new SmsException(ex.getMessage());        }    }