backport changes in pull request #1037 to 2.2.eap5 branch for JBPAPP-11049

https://issues.jboss.org/browse/JBPAPP-11049
backport changes in pull request #1037 to 2.2.eap5 branch (only difference is that I did not add the test inside due to some api changes)