T ispn 2865 m

https://issues.jboss.org/browse/ISPN-2888
https://issues.jboss.org/browse/ISPN-2865
Please backport to 5.2.x as well.