CA API Gateway - Problem with javascript assertion replaces Special Characters (umlaut) with '?' symbol in api gateway 9.4
search cancel

CA API Gateway - Problem with javascript assertion replaces Special Characters (umlaut) with '?' symbol in api gateway 9.4

book

Article ID: 199558

calendar_today

Updated On: 09-21-2020

Products

CA API Gateway API SECURITY CA API Gateway Precision API Monitoring Module for API Gateway (Layer 7) CA API Gateway Enterprise Service Manager (Layer 7) STARTER PACK-7 CA Microgateway

Issue/Introduction

We are facing problems when using the following function inside the "Execute Javascript assertion":
  resp1 = context.getOrCreateMessageVariable ('request');
  requestBody = resp1.getContent();

When there are special characters in the payload like accents or 'ñ'; it automatically replaces them with the '?' symbol. 
We need to make transformation with the different payloads allowing special characters and not replacing it with '?' characters. Can you help us?

You can try with this payload:

{
"Uuid""xxxxxxx",
"Description""Updated Description.",
"Name""Updated Organización Test",
"Status""ENABLED",
"AccountPlanUuid""xxxxxx"
}

And you will get the following result:
{
"Uuid""{{GENERATED_GUID}}",
"Description""Updated Description.",
"Name""Updated Organizaci?n Test",
"Status""ENABLED",
"AccountPlanUuid""xxxxxx"
}

Environment

Release : 9.4

Component : API GATEWAY

Resolution

The solution is to add Content-Type header with value "application/json" when sending the request.

When the Content-Type header is application/json, I can see the special characters correctly. I tried with the payload in the description and the longer payload in one of the comments

If you send something like Content-Type: text/plain, you will see the question marks

Above solution didn't seem to work in this use case scenario; however, add Content-Type header with value "application/javascript" and it worked!

Furthermore,

1. Add LANG environment variable when starting the container gateway: LANG=en_US.UTF-8 (docker-compose for example has a way to define environment variables in docker-compose file)

  - This should start the container gateway with the en_US.UTF-8 locale instead of POSIX

2. Use Content-Type application/json