Friday, December 16, 2016

Special characters not returned correctly in Oracle Cloud services?

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
    l_param_list      varchar2(512);
    l_http_request    utl_http.req;
    l_http_response   utl_http.resp;
    l_response_text   varchar2(4000);
    -- preparing Request...
    l_http_request := utl_http.begin_request ('https://[your_instance],LastName'
    -- set headers attributes
    utl_http.set_header (l_http_request
                        ,'Basic ZGlkeW91cmVhbGx5dHJ5dG9kZWNvZGV0aGlzPw=='

    utl_http.set_header (l_http_request
                        ,'application/json; charset=UTF-8'
    utl_http.set_header (l_http_request

    -- 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);
      utl_http.read_text(l_http_response, l_response_text);
    end loop;

    when utl_http.end_of_body
      utl_http.end_response (l_http_response);
    when others
      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.