FELIX-1211 Lazily look up the getResource method otherwise the methods
for wrapped plugins will never be found because the instance initializer
is called *before* the WebConsolePluginAdapter sets the field to be
returned in the getResourceProvider call.
git-svn-id: https://svn.apache.org/repos/asf/felix/trunk@789288 13f79535-47bb-0310-9956-ffa450edef68
diff --git a/webconsole/src/main/java/org/apache/felix/webconsole/AbstractWebConsolePlugin.java b/webconsole/src/main/java/org/apache/felix/webconsole/AbstractWebConsolePlugin.java
index c4f3187..0117909 100644
--- a/webconsole/src/main/java/org/apache/felix/webconsole/AbstractWebConsolePlugin.java
+++ b/webconsole/src/main/java/org/apache/felix/webconsole/AbstractWebConsolePlugin.java
@@ -93,7 +93,22 @@
public static final String GET_RESOURCE_METHOD_NAME = "getResource";
- private final Method getResourceMethod;
+ /**
+ * The reference to the getResource method provided by the
+ * {@link #getResourceProvider()}. This is <code>null</code> if there is
+ * none or before the first check if there is one.
+ *
+ * @see #getGetResourceMethod()
+ */
+ private Method getResourceMethod;
+
+ /**
+ * flag indicating whether the getResource method has already been looked
+ * up or not. This prevens the {@link #getGetResourceMethod()} method from
+ * repeatedly looking up the resource method on plugins which do not have
+ * one.
+ */
+ private boolean getResourceMethodChecked;
private BundleContext bundleContext;
@@ -102,10 +117,6 @@
private String productWeb;
private String vendorName;
- {
- getResourceMethod = getGetResourceMethod();
- }
-
//---------- HttpServlet Overwrites ----------------------------------------
@@ -220,8 +231,12 @@
*/
private Method getGetResourceMethod()
{
- Method tmpGetResourceMethod = null;
+ // return what we know of the getResourceMethod, if we already checked
+ if (getResourceMethodChecked) {
+ return getResourceMethod;
+ }
+ Method tmpGetResourceMethod = null;
Object resourceProvider = getResourceProvider();
if ( resourceProvider != null )
{
@@ -258,7 +273,12 @@
}
}
- return tmpGetResourceMethod;
+ // set what we have found and prevent future lookups
+ getResourceMethod = tmpGetResourceMethod;
+ getResourceMethodChecked = true;
+
+ // now also return the method
+ return getResourceMethod;
}
@@ -283,6 +303,7 @@
private boolean spoolResource( HttpServletRequest request, HttpServletResponse response ) throws IOException
{
// no resource if no resource accessor
+ Method getResourceMethod = getGetResourceMethod();
if ( getResourceMethod == null )
{
return false;