Achieving encoding for URL with spaces in 'Invoke REST API' palette of REST and JSON plug-in.
book
Article ID: KB0082785
calendar_today
Updated On:
Products
Versions
TIBCO ActiveMatrix BusinessWorks Plug-in for REST and JSON
2.0.0, 2.0.1, 2.0.1, 2.1.0
Description
At this moment we don't have option to encode the url in invoke rest api activity of REST and JSON plug-in. So when REST service created using 'REST Dispatch and Reply' palette of REST and JSON plug-in or any third party REST Service having service url with spaces in it and if invoke rest api palette is getting url with spaces then we get following type of error:
********** Error happened when invoking REST server, [ Illegal character in path at index <number>: <URL containing space> ]
ex.- Error happened when invoking REST server, [ Illegal character in path at index 25: http://localhost:6666/get name ] **********
Because we have following type of url:
ex. 1) http://localhost:6666/get name ex. 2) http://localhost:12000/consultation_document_test-war/rest/deltad/DAU_D1000 004/DAU_D1000 004.xml
and REST service is expecting following type of url:
Please note that every Web page on the Internet has a uniform resource locator, or URL, such as “http://www.example.com/products.html“. A URL cannot contain a space, which presents a problem if an HTML file is named “products and services.html.” Spaces and other characters that aren’t allowed in a URL must be encoded using a percent sign and the hexadecimal value assigned to the character in the ISO-Latin character set. A space is assigned number 32, which is 20 in hexadecimal. When you see “%20,” it represents a space in an encoded URL, for example, http://www.example.com/products%20and%20services.html
We can add encoding for URL using following two approaches of BusinessWorks:
* Approach 1
We need to use "Java Code" activity of BusineesWorks. We can select this activity from: add resources >> Java >> Java code . While using java code activity write java code which will check for spaces in input url string and will replace it with '%20'. For reference you can go through the project attached herewith which contains java code activity under process name "Invoking_Service_Java_Code".
* Approach 2
We need to use concat and tokenize string functions from 'XPath Formula Builder'. Tokenize string function will tokenize the input string url using space as delimiter, then we can add '%20' between tokenized urls using concat string function of 'XPath Formula Builder'. For reference you can go through the project attached herewith which contains invoke rest api activity under process name "Invoking_Service_Tokenizer".
Note: Approach 2 may have limitation of having only single space in URL, but for single and multiple spaces URL we can always use approach 1.
Issue/Introduction
Achieving encoding for URL with spaces in 'Invoke REST API' palette of REST and JSON plug-in.