Changeset 621


Ignore:
Timestamp:
Jun 25, 2010, 2:03:22 PM (7 years ago)
Author:
jahn
Message:

Added java.net.URLEncoder.encode() to protect URL parameters.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/groovy/dbnp/rest/CommunicationManager.groovy

    r615 r621  
    44import java.util.List
    55import java.util.HashMap
     6import java.net.URLEncoder
    67import grails.converters.JSON
    78import org.codehaus.groovy.grails.web.json.*
     
    3738    def static ServerURL = "http://nbx5.nugo.org/sam"
    3839    def static RestServerURL = ServerURL + "/rest"
     40    def static Encoding = "UTF-8"
    3941
    4042
    4143    /* Methods implemented for CleanDataLayer */
    42 
    4344
    4445
     
    7374     */
    7475    public Object getFeatures() {
    75     //    return  request( "features" )
     76        //    return  request( "features" )
    7677        return  getStudiesForKeyword("ldl")
    7778    }
     
    150151
    151152    /**
    152      * Convenience method for constructing URLs for SAM that need parameters
     153     * Convenience method for constructing URLs for SAM that need parameters.
     154     * Note that parameters are first convereted to strings by calling their toString() method
     155     * and then Encoded to protect special characters.
    153156     *
    154157     * @params String resource The name of the resource, e.g. importer/pages
     
    161164                params.each { name, value ->
    162165                        if(first) {
    163                                 first = false                                     // this needs to be protected, otherwise might break url
    164                                 url += '/nil?' + name + "='" + value.toString() + "'"   
     166                                first = false
     167                                url += '/nil?' + name + "=" + URLEncoder.encode( value.toString(), Encoding )
    165168                        }
    166169                        else {
    167                                 url += '&' + name + "='" + value.toString() + "'"   
     170                                url += '&' + name + "=" + URLEncoder.encode( value.toString(), Encoding  )
    168171                        }
    169172                }
     
    224227    }
    225228
    226 
    227229}
Note: See TracChangeset for help on using the changeset viewer.