in core/src/main/java/org/apache/cxf/resource/URIResolver.java [135:251]
private void tryFileSystem(String baseUriStr, String uriStr) throws IOException, MalformedURLException {
// It is possible that spaces have been encoded. We should decode them first.
String fileStr = uriStr.replace("%20", " ");
try {
final File uriFileTemp = new File(fileStr);
File uriFile = new File(AccessController.doPrivileged(new PrivilegedAction<String>() {
@Override
public String run() {
return uriFileTemp.getAbsolutePath();
}
}));
if (!SecurityActions.fileExists(uriFile, CXFPermissions.RESOLVE_URI)) {
try {
URI urif = new URI(URLDecoder.decode(uriStr, "ASCII"));
if ("file".equals(urif.getScheme()) && urif.isAbsolute()) {
File f2 = new File(urif);
if (f2.exists()) {
uriFile = f2;
}
}
} catch (URISyntaxException ex) {
//ignore
}
}
final URI relative;
if (!SecurityActions.fileExists(uriFile, CXFPermissions.RESOLVE_URI)) {
relative = new URI(uriStr.replace(" ", "%20"));
} else {
relative = uriFile.getAbsoluteFile().toURI();
}
if (relative.isAbsolute()) {
uri = relative;
url = relative.toURL();
try {
HttpURLConnection huc = createInputStream();
int status = huc.getResponseCode();
if (status != HttpURLConnection.HTTP_OK && followRedirect(status)) {
// only redirect once.
uri = new URI(huc.getHeaderField("Location"));
url = uri.toURL();
createInputStream();
}
} catch (ClassCastException ex) {
is = url.openStream();
}
} else if (!StringUtils.isEmpty(baseUriStr)) {
URI base;
File baseFile = new File(baseUriStr);
if (!baseFile.exists() && baseUriStr.startsWith("file:")) {
baseFile = new File(getFilePathFromUri(baseUriStr));
}
if (baseFile.exists()) {
base = baseFile.toURI();
} else {
base = new URI(baseUriStr);
}
base = base.resolve(relative);
if (base.isAbsolute() && "file".equalsIgnoreCase(base.getScheme())) {
try {
// decode space before create a file
baseFile = new File(base.getPath().replace("%20", " "));
if (baseFile.exists()) {
is = base.toURL().openStream();
uri = base;
} else {
tryClasspath(base.toString().startsWith("file:")
? base.toString().substring(5) : base.toString());
}
} catch (Throwable th) {
tryClasspath(base.toString().startsWith("file:")
? base.toString().substring(5) : base.toString());
}
} else {
tryClasspath(base.toString().startsWith("file:")
? base.toString().substring(5) : base.toString());
}
} else {
tryClasspath(fileStr.startsWith("file:")
? fileStr.substring(5) : fileStr);
}
} catch (URISyntaxException e) {
// do nothing
}
if (is == null && baseUriStr != null && baseUriStr.startsWith("classpath:")) {
tryClasspath(baseUriStr + fileStr);
}
if (is == null && uri != null && "file".equals(uri.getScheme())) {
try {
file = new File(uri);
} catch (IllegalArgumentException iae) {
file = new File(uri.toURL().getPath());
if (!file.exists()) {
file = null;
}
}
}
if (is == null && file != null && file.exists()) {
uri = file.toURI();
try {
is = Files.newInputStream(file.toPath());
} catch (FileNotFoundException e) {
throw new RuntimeException("File was deleted! " + fileStr, e);
}
url = file.toURI().toURL();
} else if (is == null) {
tryClasspath(fileStr);
}
}