SMS sending through Clickatell I have to implement a method in which i'm passing two arguments as Mobile number and second one is Message to be sent.

I'm using clickatell for the first time and its successfully sending the messages but is it the right approach of coding for it.

Its the test code what i have posted can i implement this in my production code.

I have cleared the Key out and replaced with stars.

As its a paid service should i go for clickatell or is there any others options to send sms i can try out.

Please review the code.

public class Sms {


    public final String APIKEY = "*************************";
    //private String mobile;


    public void sms_generation(String mobile, String Message) {

        System.out.println("\n\nSTARTING WITH TESTING REST:");

        // Create New object (Assign auth straight away.):
        ClickatellRest click = new ClickatellRest(APIKEY);

        // We cannot test for auth, so lets start with balance:
        System.out.println("TESTING GET BALANCE");
        try {
            double response = click.getBalance();
            System.out.println(response);
        } catch (UnknownHostException e) {
            System.out.println("Host could not be found");
        } catch (Exception e) {
            System.out.println(e.getMessage());
        }

        // Assuming the auth was successful, lets send one message, to one
        // recipient:
        System.out.println("\nTESTING SEND SINGLE MESSAGE");
        try {
            ClickatellRest.Message response = click.sendMessage(mobile, Message);
            System.out.println(response);
            if (response.error != null) {
                System.out.println(response.error);
            } else {

                ClickatellRest.Message msg = click
                        .getMessageStatus(response.message_id);
                System.out.println("ID:" + msg.message_id);
                System.out.println("Status:" + msg.status);
                System.out.println("Status Description:" + msg.statusString);
                System.out.println("Charge:" + msg.charge);
                System.out.println("\nTESTING STOP MESSAGE");
                ClickatellRest.Message msgStatus = click
                        .stopMessage(response.message_id);
                System.out.println("ID:" + msgStatus.message_id);
                System.out.println("Status:" + msgStatus.status);
                System.out.println("Status Description:"
                        + msgStatus.statusString);
            }
        } catch (UnknownHostException e) {
            System.out.println("Host could not be found");
        } catch (Exception e) {
            System.out.println(e.getMessage());
        }


    }

}
1 Use Logger, do not print all your app info, in production it will mess up server logs. You can use different log level (debug, info). For example use info level in prod, and debug level in dev environment. 

2  Do no catch all exceptions in service layers, you can throw them up to controller (if you use spring mvc) and catch all that there.

https://spring.io/blog/2013/11/01/exception-handling-in-spring-mvc

3 Try keep your code clean to read and unsderstand.

public void sendMessage(String mobile, String Message) {
        ClickatellRest click = new ClickatellRest(APIKEY);
        ClickatellRest.Message response = click.sendMessage(mobile, Message);
        log.debug(response);
        if (response.error == null) {
            ClickatellRest.Message msg = click.getMessageStatus(response.message_id);
            log.debug(msg);
            ClickatellRest.Message msgStatus = click.stopMessage(response.message_id);
            log.debug(msgStatus);
        } else {
            log.error(response.err);
        }
    }


4 If you can, override toString() method in ClickatellRest.Message class if you often log this object.