if (contextRoot != null) {
try {
return new URL(contextRoot, location).toExternalForm();
} catch (MalformedURLException ex) {
throw new LocationException("URL to construct is malformed.", ex.getCause());
}
}
throw new LocationException(String.format(
"The location %s is not valid URI and no contextRoot was discovered to treat it as relative URL",
location));
}