CLOUDSTACK-6793: Fixed an invalid Domain Id Issue

Signed-off-by: sedukull <santhosh.edukulla@gmail.com>
(cherry picked from commit 91d054cb00f6a5818f2be1c7e4d3f44a2c58bfcc)
try-with-resource to prevent resource leaks

(cherry picked from commit 39f775c38126bb25a0418f82196caaba463f8c1c)