Special characters not returned correctly in Fusion Cloud services, that is the statement/question I recently got from a Cloud HCM customer. As you can see in de screenshots above, my last name contains a special character that get's returned incorrectly from Cloud HCM Rest Api.
But why does this happen, it is stored and displayed correctly in Cloud HCM?
Actually it is not Cloud HCM Rest Api that returns the incorrect character, it is the client encoding that interprets the response incorrectly. Cloud HCM responses are in UTF-8 encoding. To property interpret the response you need to either set your client encoding to UTF-8 or convert the response to UTF-8.
With SoapUI you can easily set the encoding to UTF-8 through the request properties, like in below screenshot.
Now let's try calling the Rest Api from a database.
set define off
declare
l_param_list varchar2(512);
l_http_request utl_http.req;
l_http_response utl_http.resp;
l_response_text varchar2(4000);
begin
utl_http.set_wallet([your_wallet_location],[wallet_pswd]);
-- preparing Request...
l_http_request := utl_http.begin_request ('https://[your_instance].oraclecloud.com/hcmCoreApi/resources/11.1.10/emps/?onlyData=true&q=FirstName=Hakan&fields=FirstName,LastName'
,'GET'
,'HTTP/1.1'
);
-- set headers attributes
utl_http.set_header (l_http_request
,'Authorization'
,'Basic ZGlkeW91cmVhbGx5dHJ5dG9kZWNvZGV0aGlzPw=='
);
utl_http.set_header (l_http_request
,'Content-Type'
,'application/json; charset=UTF-8'
);
utl_http.set_header (l_http_request
,'Accept'
,'application/json'
);
-- set input parameters
utl_http.write_text (l_http_request,l_param_list);
-- get Response and obtain received value
l_http_response := utl_http.get_response (l_http_request);
loop
utl_http.read_text(l_http_response, l_response_text);
dbms_output.put_line(l_response_text);
end loop;
utl_http.end_response(l_http_response);
exception
when utl_http.end_of_body
then
utl_http.end_response (l_http_response);
when others
then
utl_http.end_response (l_http_response);
end ;
As you can see the special character in the response is not correctly interpreted.
By converting the response to UTF-8 from a character set that supports this character, will do the job.
No comments:
Post a Comment