You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@myfaces.apache.org by vo...@apache.org on 2023/05/18 14:32:29 UTC
[myfaces] branch 3.0.x updated: Apply MYFACES-4469 to 3.0.x
This is an automated email from the ASF dual-hosted git repository.
volosied pushed a commit to branch 3.0.x
in repository https://gitbox.apache.org/repos/asf/myfaces.git
The following commit(s) were added to refs/heads/3.0.x by this push:
new 9ccc1a48b Apply MYFACES-4469 to 3.0.x
new 86adb6bad Merge pull request #573 from volosied/myfaces4469-3.0
9ccc1a48b is described below
commit 9ccc1a48bf7a0ba9c46725a1b1708e2992f72957
Author: Thomas Andraschko <ta...@apache.org>
AuthorDate: Tue Mar 28 14:56:49 2023 +0200
Apply MYFACES-4469 to 3.0.x
---
.../application/ApplicationFactoryImpl.java | 6 +-
.../apache/myfaces/config/FacesConfigurator.java | 104 ++++++---------------
.../org/apache/myfaces/config/RuntimeConfig.java | 4 +-
.../context/servlet/FacesContextImplBase.java | 13 ++-
.../myfaces/lifecycle/LifecycleFactoryImpl.java | 6 +-
.../myfaces/renderkit/RenderKitFactoryImpl.java | 6 +-
.../java/org/apache/myfaces/util/Purgeable.java | 24 +++++
7 files changed, 73 insertions(+), 90 deletions(-)
diff --git a/impl/src/main/java/org/apache/myfaces/application/ApplicationFactoryImpl.java b/impl/src/main/java/org/apache/myfaces/application/ApplicationFactoryImpl.java
index c910dce87..1ceea19be 100755
--- a/impl/src/main/java/org/apache/myfaces/application/ApplicationFactoryImpl.java
+++ b/impl/src/main/java/org/apache/myfaces/application/ApplicationFactoryImpl.java
@@ -25,13 +25,14 @@ import jakarta.faces.application.Application;
import jakarta.faces.application.ApplicationFactory;
import jakarta.faces.context.ExternalContext;
import jakarta.faces.context.FacesContext;
+import org.apache.myfaces.util.Purgeable;
/**
* @author Manfred Geiler (latest modification by $Author$)
* @author Thomas Spiegl
* @version $Revision$ $Date$
*/
-public class ApplicationFactoryImpl extends ApplicationFactory
+public class ApplicationFactoryImpl extends ApplicationFactory implements Purgeable
{
private static final Logger log = Logger.getLogger(ApplicationFactoryImpl.class.getName());
@@ -59,7 +60,8 @@ public class ApplicationFactoryImpl extends ApplicationFactory
}
}
- public void purgeApplication()
+ @Override
+ public void purge()
{
createAndLogNewApplication();
}
diff --git a/impl/src/main/java/org/apache/myfaces/config/FacesConfigurator.java b/impl/src/main/java/org/apache/myfaces/config/FacesConfigurator.java
index 8df04dd82..dfd78cd95 100755
--- a/impl/src/main/java/org/apache/myfaces/config/FacesConfigurator.java
+++ b/impl/src/main/java/org/apache/myfaces/config/FacesConfigurator.java
@@ -20,8 +20,6 @@ package org.apache.myfaces.config;
import java.io.IOException;
import java.lang.reflect.Constructor;
-import java.lang.reflect.InvocationTargetException;
-import java.lang.reflect.Method;
import java.net.JarURLConnection;
import java.net.URL;
import java.net.URLConnection;
@@ -153,6 +151,7 @@ import org.apache.myfaces.spi.ResourceLibraryContractsProviderFactory;
import org.apache.myfaces.util.ContainerUtils;
import org.apache.myfaces.util.ExternalSpecifications;
import org.apache.myfaces.util.NavigationUtils;
+import org.apache.myfaces.util.Purgeable;
import org.apache.myfaces.view.ViewDeclarationLanguageFactoryImpl;
import org.apache.myfaces.view.facelets.el.ELText;
import org.apache.myfaces.view.facelets.impl.FaceletCacheFactoryImpl;
@@ -467,34 +466,12 @@ public class FacesConfigurator
long ttl = lastUpdate + refreshPeriod;
if ((System.currentTimeMillis() > ttl) && (getLastModifiedTime() > ttl))
{
- boolean purged = false;
try
{
- purged = purgeConfiguration();
- }
- catch (NoSuchMethodException e)
- {
- log.severe("Configuration objects do not support clean-up. Update aborted");
-
- // We still want to update the timestamp to avoid running purge on every subsequent
- // request after this one.
- //
- lastUpdate = System.currentTimeMillis();
-
- return;
- }
- catch (IllegalAccessException e)
- {
- log.severe("Error during configuration clean-up" + e.getMessage());
- }
- catch (InvocationTargetException e)
- {
- log.severe("Error during configuration clean-up" + e.getMessage());
- }
- if (purged)
- {
+ purgeConfiguration();
+
configure();
-
+
// JSF 2.0 Publish PostConstructApplicationEvent after all configuration resources
// has been parsed and processed
FacesContext facesContext = getFacesContext();
@@ -503,82 +480,57 @@ public class FacesConfigurator
application.publishEvent(facesContext, PostConstructApplicationEvent.class,
Application.class, application);
}
+ catch (Exception e)
+ {
+ log.severe("Error during configuration clean-up" + e.getMessage());
+
+ // We still want to update the timestamp to avoid running purge on every subsequent
+ // request after this one.
+ //
+ lastUpdate = System.currentTimeMillis();
+ }
}
}
}
- private boolean purgeConfiguration() throws NoSuchMethodException, IllegalAccessException, InvocationTargetException
+ private void purgeConfiguration()
{
-
- Method appFactoryPurgeMethod;
- Method renderKitPurgeMethod;
- Method lifecyclePurgeMethod;
- Method facesContextPurgeMethod;
-
// Check that we have access to all of the necessary purge methods before purging anything
- //
+
ApplicationFactory applicationFactory
= (ApplicationFactory) FactoryFinder.getFactory(FactoryFinder.APPLICATION_FACTORY);
- //appFactoryPurgeMethod = applicationFactory.getClass().getMethod("purgeApplication", NO_PARAMETER_TYPES);
- appFactoryPurgeMethod = getPurgeMethod(applicationFactory, "purgeApplication", NO_PARAMETER_TYPES);
+ purge(applicationFactory);
RenderKitFactory renderKitFactory
= (RenderKitFactory) FactoryFinder.getFactory(FactoryFinder.RENDER_KIT_FACTORY);
- //renderKitPurgeMethod = renderKitFactory.getClass().getMethod("purgeRenderKit", NO_PARAMETER_TYPES);
- renderKitPurgeMethod = getPurgeMethod(renderKitFactory, "purgeRenderKit", NO_PARAMETER_TYPES);
+ purge(renderKitFactory);
+
+ RuntimeConfig.getCurrentInstance(_externalContext).purge();
LifecycleFactory lifecycleFactory
= (LifecycleFactory) FactoryFinder.getFactory(FactoryFinder.LIFECYCLE_FACTORY);
- //lifecyclePurgeMethod = lifecycleFactory.getClass().getMethod("purgeLifecycle", NO_PARAMETER_TYPES);
- lifecyclePurgeMethod = getPurgeMethod(lifecycleFactory, "purgeLifecycle", NO_PARAMETER_TYPES);
+ purge(lifecycleFactory);
FacesContext facesContext = getFacesContext();
- facesContextPurgeMethod = getPurgeMethod(facesContext, "purgeFacesContext", NO_PARAMETER_TYPES);
-
- // If there was no exception so far, now we can purge
- //
- if (appFactoryPurgeMethod != null && renderKitPurgeMethod != null && lifecyclePurgeMethod != null &&
- facesContextPurgeMethod != null)
- {
- appFactoryPurgeMethod.invoke(applicationFactory, NO_PARAMETERS);
- renderKitPurgeMethod.invoke(renderKitFactory, NO_PARAMETERS);
- RuntimeConfig.getCurrentInstance(_externalContext).purge();
- lifecyclePurgeMethod.invoke(lifecycleFactory, NO_PARAMETERS);
- facesContextPurgeMethod.invoke(facesContext, NO_PARAMETERS);
-
- // factories and serial factory need not be purged...
+ purge(facesContext);
- // Remove first request processed so we can initialize it again
- _externalContext.getApplicationMap().remove(LifecycleImpl.FIRST_REQUEST_PROCESSED_PARAM);
- return true;
- }
- return false;
+ _externalContext.getApplicationMap().remove(LifecycleImpl.FIRST_REQUEST_PROCESSED_PARAM);
}
- private Method getPurgeMethod(Object instance, String methodName, Class<?>[] parameters)
- {
+ <T> void purge(T instance)
+ {
while (instance != null)
{
- Method purgeMethod = null;
- try
+ if (instance instanceof Purgeable)
{
- purgeMethod = instance.getClass().getMethod(methodName, parameters);
- }
- catch (NoSuchMethodException e)
- {
- // No op, it is expected to found this case, so in that case
- // look for the parent to do the purge
- }
- if (purgeMethod != null)
- {
- return purgeMethod;
+ ((Purgeable) instance).purge();
}
+
if (instance instanceof FacesWrapper)
{
- instance = ((FacesWrapper)instance).getWrapped();
+ instance = ((FacesWrapper<T>) instance).getWrapped();
}
}
- return null;
}
public void configure() throws FacesException
diff --git a/impl/src/main/java/org/apache/myfaces/config/RuntimeConfig.java b/impl/src/main/java/org/apache/myfaces/config/RuntimeConfig.java
index 0ca0096c8..3c5770113 100755
--- a/impl/src/main/java/org/apache/myfaces/config/RuntimeConfig.java
+++ b/impl/src/main/java/org/apache/myfaces/config/RuntimeConfig.java
@@ -47,6 +47,7 @@ import org.apache.myfaces.config.element.NavigationRule;
import org.apache.myfaces.config.element.ResourceBundle;
import org.apache.myfaces.config.element.ViewPoolMapping;
import org.apache.myfaces.config.element.facelets.FaceletTagLibrary;
+import org.apache.myfaces.util.Purgeable;
/**
* Holds all configuration information (from the faces-config xml files) that is needed later during runtime. The config
@@ -57,7 +58,7 @@ import org.apache.myfaces.config.element.facelets.FaceletTagLibrary;
* @version $Revision$ $Date$
*/
@SuppressWarnings("deprecation")
-public class RuntimeConfig
+public class RuntimeConfig implements Purgeable
{
private static final Logger log = Logger.getLogger(RuntimeConfig.class.getName());
@@ -141,6 +142,7 @@ public class RuntimeConfig
return runtimeConfig;
}
+ @Override
public void purge()
{
_navigationRules.clear();
diff --git a/impl/src/main/java/org/apache/myfaces/context/servlet/FacesContextImplBase.java b/impl/src/main/java/org/apache/myfaces/context/servlet/FacesContextImplBase.java
index 3720509b5..8c5518b93 100644
--- a/impl/src/main/java/org/apache/myfaces/context/servlet/FacesContextImplBase.java
+++ b/impl/src/main/java/org/apache/myfaces/context/servlet/FacesContextImplBase.java
@@ -40,6 +40,7 @@ import jakarta.faces.render.RenderKitFactory;
import org.apache.myfaces.context.ReleaseableExternalContext;
import org.apache.myfaces.el.unified.FacesELContext;
+import org.apache.myfaces.util.Purgeable;
import org.apache.myfaces.view.facelets.FaceletViewDeclarationLanguage;
/**
@@ -49,7 +50,7 @@ import org.apache.myfaces.view.facelets.FaceletViewDeclarationLanguage;
* @author Jakob Korherr (latest modification by $Author$)
* @version $Revision$ $Date$
*/
-public abstract class FacesContextImplBase extends FacesContext
+public abstract class FacesContextImplBase extends FacesContext implements Purgeable
{
private Application _application;
private ExternalContext _externalContext;
@@ -173,18 +174,16 @@ public abstract class FacesContextImplBase extends FacesContext
return _application;
}
-
- /**
- *
- */
- public void purgeFacesContext()
+
+ @Override
+ public void purge()
{
_application = null;
_renderKitFactory = null;
_cachedRenderKit = null;
_cachedRenderKitId = null;
}
-
+
@Override
public final ExceptionHandler getExceptionHandler()
{
diff --git a/impl/src/main/java/org/apache/myfaces/lifecycle/LifecycleFactoryImpl.java b/impl/src/main/java/org/apache/myfaces/lifecycle/LifecycleFactoryImpl.java
index 2e5920b35..3d39ed3e0 100755
--- a/impl/src/main/java/org/apache/myfaces/lifecycle/LifecycleFactoryImpl.java
+++ b/impl/src/main/java/org/apache/myfaces/lifecycle/LifecycleFactoryImpl.java
@@ -25,13 +25,14 @@ import java.util.concurrent.ConcurrentHashMap;
import jakarta.faces.FacesException;
import jakarta.faces.lifecycle.Lifecycle;
import jakarta.faces.lifecycle.LifecycleFactory;
+import org.apache.myfaces.util.Purgeable;
/**
* @author Manfred Geiler (latest modification by $Author$)
* @author Anton Koinov
* @version $Revision$ $Date$
*/
-public class LifecycleFactoryImpl extends LifecycleFactory
+public class LifecycleFactoryImpl extends LifecycleFactory implements Purgeable
{
/**
* At start we used synchronized blocks for addLifecycle and getLifecycle. But thinking about it,
@@ -46,7 +47,8 @@ public class LifecycleFactoryImpl extends LifecycleFactory
addLifecycle(LifecycleFactory.DEFAULT_LIFECYCLE, new LifecycleImpl());
}
- public void purgeLifecycle()
+ @Override
+ public void purge()
{
// Note this is not safe, because if by some coincidence one thread call getLifecycle between
// the two lines below it will throw IllegalArgumentException, but this method is not supposed
diff --git a/impl/src/main/java/org/apache/myfaces/renderkit/RenderKitFactoryImpl.java b/impl/src/main/java/org/apache/myfaces/renderkit/RenderKitFactoryImpl.java
index 66c8a9407..14ed92af0 100755
--- a/impl/src/main/java/org/apache/myfaces/renderkit/RenderKitFactoryImpl.java
+++ b/impl/src/main/java/org/apache/myfaces/renderkit/RenderKitFactoryImpl.java
@@ -28,6 +28,7 @@ import jakarta.faces.FacesException;
import jakarta.faces.context.FacesContext;
import jakarta.faces.render.RenderKit;
import jakarta.faces.render.RenderKitFactory;
+import org.apache.myfaces.util.Purgeable;
/**
* RenderKitFactory implementation as defined in Spec. JSF.7.3
@@ -35,7 +36,7 @@ import jakarta.faces.render.RenderKitFactory;
* @author Manfred Geiler (latest modification by $Author$)
* @version $Revision$ $Date$
*/
-public class RenderKitFactoryImpl extends RenderKitFactory
+public class RenderKitFactoryImpl extends RenderKitFactory implements Purgeable
{
private static final Logger log = Logger.getLogger(RenderKitFactoryImpl.class.getName());
@@ -45,7 +46,8 @@ public class RenderKitFactoryImpl extends RenderKitFactory
{
}
- public void purgeRenderKit()
+ @Override
+ public void purge()
{
_renderkits.clear();
}
diff --git a/impl/src/main/java/org/apache/myfaces/util/Purgeable.java b/impl/src/main/java/org/apache/myfaces/util/Purgeable.java
new file mode 100644
index 000000000..a7fbb7553
--- /dev/null
+++ b/impl/src/main/java/org/apache/myfaces/util/Purgeable.java
@@ -0,0 +1,24 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.myfaces.util;
+
+public interface Purgeable
+{
+ void purge();
+}