@@ -42,22 +42,21 @@ public class SendSmsServlet extends HttpServlet {
4242 @ Override
4343 public void service (HttpServletRequest req , HttpServletResponse resp ) throws IOException ,
4444 ServletException {
45- final String TWILIO_ACCOUNT_SID = System .getenv ("TWILIO_ACCOUNT_SID" );
46- final String TWILIO_AUTH_TOKEN = System .getenv ("TWILIO_AUTH_TOKEN" );
47- final String TWILIO_NUMBER = System .getenv ("TWILIO_NUMBER" );
48- final String TO_NUMBER = (String ) req .getParameter ("to" );
49- if (TO_NUMBER == null ) {
50- resp .getWriter (). print ( "Please provide the number to message in the \" to \" query string"
51- + " parameter." );
45+ final String twilioAccountSid = System .getenv ("TWILIO_ACCOUNT_SID" );
46+ final String twilioAuthToken = System .getenv ("TWILIO_AUTH_TOKEN" );
47+ final String twilioNumber = System .getenv ("TWILIO_NUMBER" );
48+ final String toNumber = (String ) req .getParameter ("to" );
49+ if (toNumber == null ) {
50+ resp .getWriter ()
51+ . print ( "Please provide the number to message in the \" to \" query string parameter." );
5252 return ;
5353 }
54- TwilioRestClient client = new TwilioRestClient (TWILIO_ACCOUNT_SID ,
55- TWILIO_AUTH_TOKEN );
54+ TwilioRestClient client = new TwilioRestClient (twilioAccountSid , twilioAuthToken );
5655 Account account = client .getAccount ();
5756 MessageFactory messageFactory = account .getMessageFactory ();
5857 List <NameValuePair > params = new ArrayList <NameValuePair >();
59- params .add (new BasicNameValuePair ("To" , TO_NUMBER ));
60- params .add (new BasicNameValuePair ("From" , TWILIO_NUMBER ));
58+ params .add (new BasicNameValuePair ("To" , toNumber ));
59+ params .add (new BasicNameValuePair ("From" , twilioNumber ));
6160 params .add (new BasicNameValuePair ("Body" , "Hello from Twilio!" ));
6261 try {
6362 Message sms = messageFactory .create (params );
0 commit comments