back port KARAF-1738 KARAF-1752


https://issues.apache.org/jira/browse/KARAF-1738

https://issues.apache.org/jira/browse/KARAF-1752