← Back to team overview

dhis2-devs team mailing list archive

[Branch ~dhis2-devs-core/dhis2/trunk] Rev 10055: Proper URL encoding of message when using Simplistic HTTP Gateway (take 3 :P)

 

------------------------------------------------------------
revno: 10055
committer: Magnus Korvald <korvald@xxxxxxxxxxx>
branch nick: trunk
timestamp: Thu 2013-03-07 19:26:42 +0100
message:
  Proper URL encoding of message when using Simplistic HTTP Gateway (take 3 :P)
modified:
  dhis-2/dhis-services/dhis-service-sms/src/main/java/org/hisp/dhis/sms/smslib/SimplisticHttpGetGateWay.java


--
lp:dhis2
https://code.launchpad.net/~dhis2-devs-core/dhis2/trunk

Your team DHIS 2 developers is subscribed to branch lp:dhis2.
To unsubscribe from this branch go to https://code.launchpad.net/~dhis2-devs-core/dhis2/trunk/+edit-subscription
=== modified file 'dhis-2/dhis-services/dhis-service-sms/src/main/java/org/hisp/dhis/sms/smslib/SimplisticHttpGetGateWay.java'
--- dhis-2/dhis-services/dhis-service-sms/src/main/java/org/hisp/dhis/sms/smslib/SimplisticHttpGetGateWay.java	2013-03-07 12:53:46 +0000
+++ dhis-2/dhis-services/dhis-service-sms/src/main/java/org/hisp/dhis/sms/smslib/SimplisticHttpGetGateWay.java	2013-03-07 18:26:42 +0000
@@ -32,6 +32,7 @@
 import java.util.HashMap;
 import java.util.Map;
 
+import org.apache.commons.lang.StringUtils;
 import org.smslib.AGateway;
 import org.smslib.GatewayException;
 import org.smslib.OutboundMessage;
@@ -118,8 +119,8 @@
 
         Map<String, String> requestParameters = new HashMap<String, String>( parameters );
 
-        requestParameters.put( MESSAGE, msg.getText() );
         requestParameters.put( RECIPIENT, msg.getRecipient() );
+
         String sender = msg.getFrom();
         if ( sender != null )
         {
@@ -128,13 +129,16 @@
         }
         try
         {
-            ResponseEntity<String> response = restTemplate.getForEntity( urlTemplate, String.class, requestParameters, "UTF-8" );
-            if ( response.getStatusCode().series() != HttpStatus.Series.SUCCESSFUL )    
+            String requestURL = urlTemplate;
+            String urlEncodedMessage = URLEncoder.encode( msg.getText(), "UTF-8" );
+            requestURL = StringUtils.replace( requestURL, "{" + MESSAGE + "}", urlEncodedMessage );
+
+            ResponseEntity<String> response = restTemplate.getForEntity( requestURL, String.class, requestParameters );
+            if ( response.getStatusCode().series() != HttpStatus.Series.SUCCESSFUL )
             {
                 Logger.getInstance().logWarn( "Couldn't send message, got response " + response, null, getGatewayId() );
                 return false;
             }
-
         }
         catch ( RestClientException e )
         {