Skip to content

Commit

Permalink
URL decoding when parsing query parameters
Browse files Browse the repository at this point in the history
A URL decoding operation shall be considered when parsing query parameters from a CamelHttpQuery header.
  • Loading branch information
vadimklimov authored May 5, 2023
1 parent 4495f1d commit 5a0c440
Showing 1 changed file with 12 additions and 18 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -18,27 +18,21 @@ The integration flow *Scripting – Read Url Get Parameters* reads the individua
> ### Sample Code:
> ```
> import com.sap.gateway.ip.core.customdev.util.Message;
> import java.util.HashMap;
> import com.sap.gateway.ip.core.customdev.util.Message
> import java.nio.charset.Charset
>
> def Message extractUrlGetParameters(Message message) {
> Message extractUrlGetParameters(Message message) {
> String httpQuery = message.getHeader('CamelHttpQuery', String)
>
> //get url
> def map = message.getHeaders();
> def queryString = map.get("CamelHttpQuery");
> if (httpQuery) {
> Map<String, String> queryParameters = URLDecoder.decode(httpQuery, Charset.defaultCharset().name())
> .tokenize('&')
> .collectEntries { it.tokenize('=') }
> message.setProperties(queryParameters)
> }
>
> //split url
> String[] vQuery;
> vQuery = queryString.split('&');
>
> //set properties
> for( String pair : vQuery ) {
> String[] vPairs = pair.split('=')
> message.setProperty(vPairs[0].replace("\$",""), vPairs[1]);
> }
>
> return message;
> }
> return message
> }
> ```
As a next step, the WebShop example application \([https://help.sap.com/viewer/DRAFT/368c481cd6954bdfa5d0435479fd4eaf/DEV/en-US/767d8ef11b0f4e04819f9fe03d76c4a2.html](https://help.sap.com/viewer/DRAFT/368c481cd6954bdfa5d0435479fd4eaf/DEV/en-US/767d8ef11b0f4e04819f9fe03d76c4a2.html)\) is called and given the corresponding properties to build the right query options.
Expand Down

0 comments on commit 5a0c440

Please sign in to comment.