Java: fix for trailing slash problem and encoded url

proposed fix for trailing slash problem that retains check to avoid
baddomain attacks (ie: server.com.baddomain.com)