Fixing APIMANAGER-2004 and applying patch provided by Malintha

Fixing APIMANAGER-2004 and applying patch provided by Malintha