You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@myfaces.apache.org by lo...@apache.org on 2021/04/08 12:58:19 UTC
[myfaces-tobago] 02/03: feat: TobagoExceptionHandler swtich off
This is an automated email from the ASF dual-hosted git repository.
lofwyr pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/myfaces-tobago.git
commit 77ce02f7f055d6c7eca4da100b00ca5e1b603114
Author: Udo Schnurpfeil <ud...@irian.eu>
AuthorDate: Thu Apr 8 13:55:59 2021 +0200
feat: TobagoExceptionHandler swtich off
The exception handler now can be deactivated, by configuration.
issue: TOBAGO-1946
---
.../apache/myfaces/tobago/config/TobagoConfig.java | 13 +++++++++++
.../context/TobagoExceptionHandlerFactory.java | 25 +++++++++++++---------
.../internal/config/TobagoConfigFragment.java | 9 ++++++++
.../tobago/internal/config/TobagoConfigMerger.java | 4 ++++
.../tobago/internal/config/TobagoConfigParser.java | 5 +++++
.../myfaces/tobago/config/tobago-config-5.0.xsd | 8 +++++++
.../src/main/webapp/WEB-INF/tobago-config.xml | 3 +++
7 files changed, 57 insertions(+), 10 deletions(-)
diff --git a/tobago-core/src/main/java/org/apache/myfaces/tobago/config/TobagoConfig.java b/tobago-core/src/main/java/org/apache/myfaces/tobago/config/TobagoConfig.java
index 17bb190..0e48a95 100644
--- a/tobago-core/src/main/java/org/apache/myfaces/tobago/config/TobagoConfig.java
+++ b/tobago-core/src/main/java/org/apache/myfaces/tobago/config/TobagoConfig.java
@@ -65,6 +65,7 @@ public class TobagoConfig {
private Sanitizer sanitizer;
private boolean decodeLineFeed;
private Map<String, String> mimeTypes;
+ private boolean enableTobagoExceptionHandler;
private boolean locked = false;
@@ -111,6 +112,7 @@ public class TobagoConfig {
decodeLineFeed = true;
contentSecurityPolicy = new ContentSecurityPolicy(ContentSecurityPolicy.Mode.OFF.getValue());
mimeTypes = new HashMap<>();
+ enableTobagoExceptionHandler = true;
// internal
final List<TobagoConfigFragment> fragments = new ArrayList<>();
@@ -290,6 +292,15 @@ public class TobagoConfig {
this.decodeLineFeed = decodeLineFeed;
}
+ public boolean isEnableTobagoExceptionHandler() {
+ return enableTobagoExceptionHandler;
+ }
+
+ public void setEnableTobagoExceptionHandler(boolean enableTobagoExceptionHandler) {
+ checkUnlocked();
+ this.enableTobagoExceptionHandler = enableTobagoExceptionHandler;
+ }
+
public Map<String, String> getMimeTypes() {
return mimeTypes;
}
@@ -352,6 +363,8 @@ public class TobagoConfig {
builder.append(all);
builder.append(", \nmimeTypes=");
builder.append(mimeTypes);
+ builder.append(", \nenableTobagoExceptionHandler=");
+ builder.append(enableTobagoExceptionHandler);
builder.append('}');
return builder.toString();
}
diff --git a/tobago-core/src/main/java/org/apache/myfaces/tobago/context/TobagoExceptionHandlerFactory.java b/tobago-core/src/main/java/org/apache/myfaces/tobago/context/TobagoExceptionHandlerFactory.java
index 3ee56a0..d387be4 100644
--- a/tobago-core/src/main/java/org/apache/myfaces/tobago/context/TobagoExceptionHandlerFactory.java
+++ b/tobago-core/src/main/java/org/apache/myfaces/tobago/context/TobagoExceptionHandlerFactory.java
@@ -19,28 +19,33 @@
package org.apache.myfaces.tobago.context;
+import org.apache.myfaces.tobago.config.TobagoConfig;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
import javax.faces.context.ExceptionHandler;
import javax.faces.context.ExceptionHandlerFactory;
+import javax.faces.context.FacesContext;
/**
- * To enable the TobagoExceptionHandler insert this class in the faces-config.xml like:
- * <pre>
- * <factory>
- * <exception-handler-factory>
- * org.apache.myfaces.tobago.example.demo.TobagoExceptionHandlerFactory
- * </exception-handler-factory>
- * </factory>
- * </pre>
- *
+ * The TobagoExceptionHandler is activated by default via the basic faces-config.xml of tobago-core.
+ * To disable, set the enableTobagoExceptionHandler to false in the tobago-config.xml of the application.
*/
public class TobagoExceptionHandlerFactory extends ExceptionHandlerFactory {
+ private static final Logger LOG = LoggerFactory.getLogger(TobagoExceptionHandlerFactory.class);
+
public TobagoExceptionHandlerFactory(final ExceptionHandlerFactory parent) {
super(parent);
}
@Override
public ExceptionHandler getExceptionHandler() {
- return new TobagoExceptionHandler(getWrapped().getExceptionHandler());
+ LOG.error("xxxxxxxxx enableTobagoExceptionHandler={}", TobagoConfig.getInstance(FacesContext.getCurrentInstance()).isEnableTobagoExceptionHandler());
+ if (TobagoConfig.getInstance(FacesContext.getCurrentInstance()).isEnableTobagoExceptionHandler()) {
+ return new TobagoExceptionHandler(getWrapped().getExceptionHandler());
+ } else {
+ return getWrapped().getExceptionHandler();
+ }
}
}
diff --git a/tobago-core/src/main/java/org/apache/myfaces/tobago/internal/config/TobagoConfigFragment.java b/tobago-core/src/main/java/org/apache/myfaces/tobago/internal/config/TobagoConfigFragment.java
index 064bb4c..8bb0b30 100644
--- a/tobago-core/src/main/java/org/apache/myfaces/tobago/internal/config/TobagoConfigFragment.java
+++ b/tobago-core/src/main/java/org/apache/myfaces/tobago/internal/config/TobagoConfigFragment.java
@@ -48,6 +48,7 @@ public class TobagoConfigFragment {
private Boolean decodeLineFeed;
private Properties sanitizerProperties;
private Map<String, String> mimeTypes;
+ private Boolean enableTobagoExceptionHandler;
public TobagoConfigFragment() {
before = new ArrayList<>();
@@ -193,6 +194,14 @@ public class TobagoConfigFragment {
return mimeTypes;
}
+ public Boolean getEnableTobagoExceptionHandler() {
+ return enableTobagoExceptionHandler;
+ }
+
+ public void setEnableTobagoExceptionHandler(Boolean enableTobagoExceptionHandler) {
+ this.enableTobagoExceptionHandler = enableTobagoExceptionHandler;
+ }
+
@Override
public String toString() {
return name != null ? name : "(id=" + System.identityHashCode(this) + ")";
diff --git a/tobago-core/src/main/java/org/apache/myfaces/tobago/internal/config/TobagoConfigMerger.java b/tobago-core/src/main/java/org/apache/myfaces/tobago/internal/config/TobagoConfigMerger.java
index 9182f40..79e54a2 100644
--- a/tobago-core/src/main/java/org/apache/myfaces/tobago/internal/config/TobagoConfigMerger.java
+++ b/tobago-core/src/main/java/org/apache/myfaces/tobago/internal/config/TobagoConfigMerger.java
@@ -105,6 +105,10 @@ public class TobagoConfigMerger {
tobagoConfig.setDecodeLineFeed(fragment.getDecodeLineFeed());
}
+ if (fragment.getEnableTobagoExceptionHandler() != null) {
+ tobagoConfig.setEnableTobagoExceptionHandler(fragment.getEnableTobagoExceptionHandler());
+ }
+
// theme definition
for (final ThemeImpl theme : fragment.getThemeDefinitions()) {
tobagoConfig.addAvailableTheme(theme);
diff --git a/tobago-core/src/main/java/org/apache/myfaces/tobago/internal/config/TobagoConfigParser.java b/tobago-core/src/main/java/org/apache/myfaces/tobago/internal/config/TobagoConfigParser.java
index 3ace262..baf57e0 100644
--- a/tobago-core/src/main/java/org/apache/myfaces/tobago/internal/config/TobagoConfigParser.java
+++ b/tobago-core/src/main/java/org/apache/myfaces/tobago/internal/config/TobagoConfigParser.java
@@ -101,6 +101,7 @@ public class TobagoConfigParser extends TobagoConfigEntityResolver {
private static final int SANITIZER = 1807639849;
private static final int SANITIZER_CLASS = -974266412;
private static final int DECODE_LINE_FEED = -1764519240;
+ private static final int ENABLE_TOBAGO_EXCEPTION_HANDLER = 1967055403;
private static final int SCRIPT = -907685685;
private static final int STYLE = 109780401;
private static final int PROPERTIES = -926053069;
@@ -425,6 +426,10 @@ public class TobagoConfigParser extends TobagoConfigEntityResolver {
tobagoConfig.setDecodeLineFeed(Boolean.parseBoolean(text));
break;
+ case ENABLE_TOBAGO_EXCEPTION_HANDLER:
+ tobagoConfig.setEnableTobagoExceptionHandler(Boolean.parseBoolean(text));
+ break;
+
case ENTRY:
properties.setProperty(entryKey, text);
entryKey = null;
diff --git a/tobago-core/src/main/resources/org/apache/myfaces/tobago/config/tobago-config-5.0.xsd b/tobago-core/src/main/resources/org/apache/myfaces/tobago/config/tobago-config-5.0.xsd
index 4858b04..3f53d49 100644
--- a/tobago-core/src/main/resources/org/apache/myfaces/tobago/config/tobago-config-5.0.xsd
+++ b/tobago-core/src/main/resources/org/apache/myfaces/tobago/config/tobago-config-5.0.xsd
@@ -135,6 +135,14 @@
</xs:documentation>
</xs:annotation>
</xs:element>
+ <xs:element name="enable-tobago-exception-handler" type="xs:boolean" minOccurs="0" default="true">
+ <xs:annotation>
+ <xs:documentation>
+ Use an instance of org.apache.myfaces.tobago.context.TobagoExceptionHandler as
+ exception handler. Set to false to deactivate.
+ </xs:documentation>
+ </xs:annotation>
+ </xs:element>
<xs:element name="decode-line-feed" type="xs:boolean" minOccurs="0" default="true">
<xs:annotation>
<xs:documentation>
diff --git a/tobago-example/tobago-example-demo/src/main/webapp/WEB-INF/tobago-config.xml b/tobago-example/tobago-example-demo/src/main/webapp/WEB-INF/tobago-config.xml
index 5208695..9c63486 100644
--- a/tobago-example/tobago-example-demo/src/main/webapp/WEB-INF/tobago-config.xml
+++ b/tobago-example/tobago-example-demo/src/main/webapp/WEB-INF/tobago-config.xml
@@ -86,6 +86,9 @@
</sanitizer>
-->
+ <!-- "false" disables the TobagoExceptionHandler -->
+ <!--<enable-tobago-exception-handler>false</enable-tobago-exception-handler>-->
+
<!-- true is the default -->
<!--<decode-line-feed>false</decode-line-feed>-->