Fix a reported issue when running under a security manager.
Refactor to enable some basic unit testing to hopefully avoid some of these issues in future.

git-svn-id: https://svn.apache.org/repos/asf/tomcat/trunk@1551652 13f79535-47bb-0310-9956-ffa450edef68
Add a basic unit test

git-svn-id: https://svn.apache.org/repos/asf/tomcat/trunk@1551653 13f79535-47bb-0310-9956-ffa450edef68