You don't have a closing </gateway> tag in that example. Not sure if
that is your actual issue though.

Umm, well that might be missing there, its not causing the problem. I've tried several approaches before posting. The only left is to debug. Like printing that "profile.username" string and if its really null or where did it get lost etc.

Have you reloaded the configuration/rescaned the sofia gateways since
changing the file? Could you give us an example of the console log
showing the fault, please?

Yeah did that. This is the exact copy-paste of the relevant output:

2012-08-03 01:02:19.768103 [NOTICE] sofia.c:2168 Waiting for worker thread
2012-08-03 01:02:19.768103 [NOTICE] sofia_glue.c:5574 deleted gateway example.com from profile external
2012-08-03 01:02:19.768103 [NOTICE] sofia.c:4782 Started Profile external [sofia_reg_external]
2012-08-03 01:02:19.788155 [ERR] sofia.c:2606 ERROR: username param is REQUIRED!
2012-08-03 01:02:19.788155 [NOTICE] sofia_reg.c:2904 Added gateway 'example.com' to profile 'external'

--
Sincerely,
Sazzad Bin Kamal