Skip to content

Commit f8238f5

Browse files
committed
Servlet/PortletContextResource's "isReadable()" implementation returns false for directories (SPR-9067)
1 parent 7a170e8 commit f8238f5

File tree

2 files changed

+46
-2
lines changed

2 files changed

+46
-2
lines changed

org.springframework.web.portlet/src/main/java/org/springframework/web/portlet/context/PortletContextResource.java

Lines changed: 23 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2002-2011 the original author or authors.
2+
* Copyright 2002-2012 the original author or authors.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -107,6 +107,28 @@ public boolean exists() {
107107
}
108108
}
109109

110+
/**
111+
* This implementation delegates to <code>PortletContext.getResourceAsStream</code>,
112+
* which returns <code>null</code> in case of a non-readable resource (e.g. a directory).
113+
* @see javax.portlet.PortletContext#getResourceAsStream(String)
114+
*/
115+
@Override
116+
public boolean isReadable() {
117+
InputStream is = this.portletContext.getResourceAsStream(this.path);
118+
if (is != null) {
119+
try {
120+
is.close();
121+
}
122+
catch (IOException ex) {
123+
// ignore
124+
}
125+
return true;
126+
}
127+
else {
128+
return false;
129+
}
130+
}
131+
110132
/**
111133
* This implementation delegates to <code>PortletContext.getResourceAsStream</code>,
112134
* but throws a FileNotFoundException if not found.

org.springframework.web/src/main/java/org/springframework/web/context/support/ServletContextResource.java

Lines changed: 23 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2002-2011 the original author or authors.
2+
* Copyright 2002-2012 the original author or authors.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -107,6 +107,28 @@ public boolean exists() {
107107
}
108108
}
109109

110+
/**
111+
* This implementation delegates to <code>ServletContext.getResourceAsStream</code>,
112+
* which returns <code>null</code> in case of a non-readable resource (e.g. a directory).
113+
* @see javax.servlet.ServletContext#getResourceAsStream(String)
114+
*/
115+
@Override
116+
public boolean isReadable() {
117+
InputStream is = this.servletContext.getResourceAsStream(this.path);
118+
if (is != null) {
119+
try {
120+
is.close();
121+
}
122+
catch (IOException ex) {
123+
// ignore
124+
}
125+
return true;
126+
}
127+
else {
128+
return false;
129+
}
130+
}
131+
110132
/**
111133
* This implementation delegates to <code>ServletContext.getResourceAsStream</code>,
112134
* but throws a FileNotFoundException if no resource found.

0 commit comments

Comments
 (0)