Commit a89b3bd1c5fc63d0d43c2719074dafc2fdb1f807
1 parent
231d335a
Exists in
master
Modificação do prefixo das configurações de ExceptionHandler do JSF.
Ainda deve ser mantida a compatibilidade com o prefixo anterior por algum tempo.
Showing
5 changed files
with
156 additions
and
15 deletions
Show diff stats
documentation/reference/pt-BR/properties.xml
@@ -129,7 +129,7 @@ | @@ -129,7 +129,7 @@ | ||
129 | <entry>true</entry> | 129 | <entry>true</entry> |
130 | </row> | 130 | </row> |
131 | <row valign="top"> | 131 | <row valign="top"> |
132 | - <entry>frameworkdemoiselle.​handle.​application.​exception</entry> | 132 | + <entry>frameworkdemoiselle.​exception.​application.​handle</entry> |
133 | <entry> | 133 | <entry> |
134 | <para> | 134 | <para> |
135 | Habilita o tratamento automático das exceções da aplicação anotadas com @ApplicationException. | 135 | Habilita o tratamento automático das exceções da aplicação anotadas com @ApplicationException. |
@@ -138,7 +138,7 @@ | @@ -138,7 +138,7 @@ | ||
138 | <entry>true</entry> | 138 | <entry>true</entry> |
139 | </row> | 139 | </row> |
140 | <row valign="top"> | 140 | <row valign="top"> |
141 | - <entry>frameworkdemoiselle.​handle.​application.​exception.​page</entry> | 141 | + <entry>frameworkdemoiselle.​exception.​default.​redirect.​page</entry> |
142 | <entry> | 142 | <entry> |
143 | <para> | 143 | <para> |
144 | Define o redirecionamento das exceções da aplicação anotadas com @ApplicationException ocorridas | 144 | Define o redirecionamento das exceções da aplicação anotadas com @ApplicationException ocorridas |
impl/extension/jsf/pom.xml
@@ -81,6 +81,12 @@ | @@ -81,6 +81,12 @@ | ||
81 | <scope>test</scope> | 81 | <scope>test</scope> |
82 | </dependency> | 82 | </dependency> |
83 | <dependency> | 83 | <dependency> |
84 | + <groupId>commons-httpclient</groupId> | ||
85 | + <artifactId>commons-httpclient</artifactId> | ||
86 | + <version>3.1</version> | ||
87 | + <scope>test</scope> | ||
88 | + </dependency> | ||
89 | + <dependency> | ||
84 | <groupId>org.glassfish.web</groupId> | 90 | <groupId>org.glassfish.web</groupId> |
85 | <artifactId>el-impl</artifactId> | 91 | <artifactId>el-impl</artifactId> |
86 | <scope>provided</scope> | 92 | <scope>provided</scope> |
impl/extension/jsf/src/main/java/br/gov/frameworkdemoiselle/internal/configuration/ExceptionHandlerConfig.java
@@ -41,22 +41,22 @@ import java.io.Serializable; | @@ -41,22 +41,22 @@ import java.io.Serializable; | ||
41 | import br.gov.frameworkdemoiselle.annotation.Name; | 41 | import br.gov.frameworkdemoiselle.annotation.Name; |
42 | import br.gov.frameworkdemoiselle.configuration.Configuration; | 42 | import br.gov.frameworkdemoiselle.configuration.Configuration; |
43 | 43 | ||
44 | -@Configuration(prefix = "frameworkdemoiselle.handle.") | 44 | +@Configuration(prefix = "frameworkdemoiselle.exception") |
45 | public class ExceptionHandlerConfig implements Serializable { | 45 | public class ExceptionHandlerConfig implements Serializable { |
46 | 46 | ||
47 | private static final long serialVersionUID = 1L; | 47 | private static final long serialVersionUID = 1L; |
48 | 48 | ||
49 | - @Name("application.exception") | ||
50 | - private boolean handleApplicationException = true; | 49 | + @Name("application.handle") |
50 | + private boolean applicationExceptionHandle = true; | ||
51 | 51 | ||
52 | - @Name("application.exception.page") | ||
53 | - private String exceptionPage = "/application_error"; | 52 | + @Name("default.redirect.page") |
53 | + private String defaultRedirectExceptionPage = "/application_error"; | ||
54 | 54 | ||
55 | - public String getExceptionPage() { | ||
56 | - return exceptionPage; | 55 | + public boolean isApplicationExceptionHandle() { |
56 | + return applicationExceptionHandle; | ||
57 | } | 57 | } |
58 | - | ||
59 | - public boolean isHandleApplicationException() { | ||
60 | - return handleApplicationException; | 58 | + |
59 | + public String getDefaultRedirectExceptionPage() { | ||
60 | + return defaultRedirectExceptionPage; | ||
61 | } | 61 | } |
62 | } | 62 | } |
impl/extension/jsf/src/main/java/br/gov/frameworkdemoiselle/internal/configuration/ExceptionHandlerConfigCompatible.java
0 → 100644
@@ -0,0 +1,82 @@ | @@ -0,0 +1,82 @@ | ||
1 | +/* | ||
2 | + * Demoiselle Framework | ||
3 | + * Copyright (C) 2010 SERPRO | ||
4 | + * ---------------------------------------------------------------------------- | ||
5 | + * This file is part of Demoiselle Framework. | ||
6 | + * | ||
7 | + * Demoiselle Framework is free software; you can redistribute it and/or | ||
8 | + * modify it under the terms of the GNU Lesser General Public License version 3 | ||
9 | + * as published by the Free Software Foundation. | ||
10 | + * | ||
11 | + * This program is distributed in the hope that it will be useful, | ||
12 | + * but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
13 | + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
14 | + * GNU General Public License for more details. | ||
15 | + * | ||
16 | + * You should have received a copy of the GNU Lesser General Public License version 3 | ||
17 | + * along with this program; if not, see <http://www.gnu.org/licenses/> | ||
18 | + * or write to the Free Software Foundation, Inc., 51 Franklin Street, | ||
19 | + * Fifth Floor, Boston, MA 02110-1301, USA. | ||
20 | + * ---------------------------------------------------------------------------- | ||
21 | + * Este arquivo é parte do Framework Demoiselle. | ||
22 | + * | ||
23 | + * O Framework Demoiselle é um software livre; você pode redistribuí-lo e/ou | ||
24 | + * modificá-lo dentro dos termos da GNU LGPL versão 3 como publicada pela Fundação | ||
25 | + * do Software Livre (FSF). | ||
26 | + * | ||
27 | + * Este programa é distribuído na esperança que possa ser útil, mas SEM NENHUMA | ||
28 | + * GARANTIA; sem uma garantia implícita de ADEQUAÇÃO a qualquer MERCADO ou | ||
29 | + * APLICAÇÃO EM PARTICULAR. Veja a Licença Pública Geral GNU/LGPL em português | ||
30 | + * para maiores detalhes. | ||
31 | + * | ||
32 | + * Você deve ter recebido uma cópia da GNU LGPL versão 3, sob o título | ||
33 | + * "LICENCA.txt", junto com esse programa. Se não, acesse <http://www.gnu.org/licenses/> | ||
34 | + * ou escreva para a Fundação do Software Livre (FSF) Inc., | ||
35 | + * 51 Franklin St, Fifth Floor, Boston, MA 02111-1301, USA. | ||
36 | + */ | ||
37 | +package br.gov.frameworkdemoiselle.internal.configuration; | ||
38 | + | ||
39 | +import java.io.Serializable; | ||
40 | + | ||
41 | +import org.slf4j.Logger; | ||
42 | + | ||
43 | +import br.gov.frameworkdemoiselle.annotation.Name; | ||
44 | +import br.gov.frameworkdemoiselle.configuration.Configuration; | ||
45 | +import br.gov.frameworkdemoiselle.util.Beans; | ||
46 | + | ||
47 | +@Deprecated | ||
48 | +@Configuration(prefix = "frameworkdemoiselle.handle") | ||
49 | +public class ExceptionHandlerConfigCompatible implements Serializable { | ||
50 | + | ||
51 | + private static final long serialVersionUID = 1L; | ||
52 | + | ||
53 | + @Deprecated | ||
54 | + @Name("application.exception") | ||
55 | + private boolean handleApplicationException = true; | ||
56 | + | ||
57 | + @Deprecated | ||
58 | + @Name("application.exception.page") | ||
59 | + private String exceptionPage = "/application_error"; | ||
60 | + | ||
61 | + @Deprecated | ||
62 | + public boolean isHandleApplicationException() { | ||
63 | + Logger logger = Beans.getReference(Logger.class); | ||
64 | + logger.warn("A propriedade frameworkdemoiselle.handle.application.exception=" | ||
65 | + + handleApplicationException | ||
66 | + + " não será suportada nas próximas versões do framework. Para evitar futuros problemas atualize a propriedade para frameworkdemoiselle.exception.application.handle=" | ||
67 | + + handleApplicationException); | ||
68 | + | ||
69 | + return handleApplicationException; | ||
70 | + } | ||
71 | + | ||
72 | + @Deprecated | ||
73 | + public String getExceptionPage() { | ||
74 | + Logger logger = Beans.getReference(Logger.class); | ||
75 | + logger.warn("A propriedade frameworkdemoiselle.handle.application.exception.page=" | ||
76 | + + exceptionPage | ||
77 | + + " não será suportada nas próximas versões do framework. Para evitar futuros problemas atualize a propriedade para frameworkdemoiselle.exception.default.redirect.page=" | ||
78 | + + exceptionPage); | ||
79 | + | ||
80 | + return exceptionPage; | ||
81 | + } | ||
82 | +} |
impl/extension/jsf/src/main/java/br/gov/frameworkdemoiselle/internal/implementation/ApplicationExceptionHandler.java
@@ -43,7 +43,10 @@ import javax.faces.context.ExceptionHandler; | @@ -43,7 +43,10 @@ import javax.faces.context.ExceptionHandler; | ||
43 | import javax.faces.context.FacesContext; | 43 | import javax.faces.context.FacesContext; |
44 | import javax.faces.event.PhaseId; | 44 | import javax.faces.event.PhaseId; |
45 | 45 | ||
46 | +import org.slf4j.Logger; | ||
47 | + | ||
46 | import br.gov.frameworkdemoiselle.DemoiselleException; | 48 | import br.gov.frameworkdemoiselle.DemoiselleException; |
49 | +import br.gov.frameworkdemoiselle.internal.configuration.ExceptionHandlerConfigCompatible; | ||
47 | import br.gov.frameworkdemoiselle.internal.configuration.ExceptionHandlerConfig; | 50 | import br.gov.frameworkdemoiselle.internal.configuration.ExceptionHandlerConfig; |
48 | import br.gov.frameworkdemoiselle.util.Beans; | 51 | import br.gov.frameworkdemoiselle.util.Beans; |
49 | import br.gov.frameworkdemoiselle.util.Exceptions; | 52 | import br.gov.frameworkdemoiselle.util.Exceptions; |
@@ -58,19 +61,69 @@ public class ApplicationExceptionHandler extends AbstractExceptionHandler { | @@ -58,19 +61,69 @@ public class ApplicationExceptionHandler extends AbstractExceptionHandler { | ||
58 | } | 61 | } |
59 | 62 | ||
60 | protected boolean handleException(final Throwable cause, FacesContext facesContext) { | 63 | protected boolean handleException(final Throwable cause, FacesContext facesContext) { |
64 | + // Apenas para manter compatibilidade entre 2.3.x e 2.4.0-RCx | ||
65 | + ExceptionHandlerConfigCompatible compatibleConfig = Beans.getReference(ExceptionHandlerConfigCompatible.class); | ||
66 | + // Usuário está utilizando pelo menos uma das propriedades com a forma depreciada de forma explícita | ||
67 | + if (!(compatibleConfig.getExceptionPage().equals("/application_error") && compatibleConfig.isHandleApplicationException())) { | ||
68 | + Logger logger = Beans.getReference(Logger.class); | ||
69 | + logger.warn("As propriedades frameworkdemoiselle.handle.application.exception e" | ||
70 | + + " frameworkdemoiselle.handle.application.exception.page" | ||
71 | + + " não serão suportadas nas próximas versões do framework." | ||
72 | + + " Para evitar futuros problemas atualize as propriedades para" | ||
73 | + + " frameworkdemoiselle.exception.application.handle e" | ||
74 | + + " frameworkdemoiselle.exception.default.redirect.page, respectivamente."); | ||
75 | + return handleExceptionCompatibleConfiguration(compatibleConfig, cause, facesContext); | ||
76 | + } | ||
77 | + | ||
78 | + boolean handled = false; | ||
61 | ExceptionHandlerConfig config = Beans.getReference(ExceptionHandlerConfig.class); | 79 | ExceptionHandlerConfig config = Beans.getReference(ExceptionHandlerConfig.class); |
80 | + | ||
81 | + if (config.isApplicationExceptionHandle() && Exceptions.isApplicationException(cause)) { | ||
82 | + | ||
83 | + if (isRendering(facesContext)) { | ||
84 | + handled = handlingDuringRenderResponse(cause, config); | ||
85 | + } else { | ||
86 | + Faces.addMessage(cause); | ||
87 | + handled = true; | ||
88 | + } | ||
89 | + } | ||
90 | + | ||
91 | + return handled; | ||
92 | + } | ||
93 | + | ||
94 | + @Deprecated | ||
95 | + private boolean handleExceptionCompatibleConfiguration(ExceptionHandlerConfigCompatible config, final Throwable cause, | ||
96 | + FacesContext facesContext) { | ||
62 | boolean handled = false; | 97 | boolean handled = false; |
63 | 98 | ||
64 | if (config.isHandleApplicationException() && Exceptions.isApplicationException(cause)) { | 99 | if (config.isHandleApplicationException() && Exceptions.isApplicationException(cause)) { |
65 | 100 | ||
66 | if (isRendering(facesContext)) { | 101 | if (isRendering(facesContext)) { |
67 | - handled = handlingDuringRenderResponse(cause, config); | 102 | + handled = handlingDuringRenderResponseCompatible(cause, config); |
68 | } else { | 103 | } else { |
69 | Faces.addMessage(cause); | 104 | Faces.addMessage(cause); |
70 | handled = true; | 105 | handled = true; |
71 | } | 106 | } |
72 | } | 107 | } |
108 | + return handled; | ||
109 | + } | ||
73 | 110 | ||
111 | + @Deprecated | ||
112 | + private boolean handlingDuringRenderResponseCompatible(final Throwable cause, final ExceptionHandlerConfigCompatible config) { | ||
113 | + boolean handled = false; | ||
114 | + try { | ||
115 | + Map<String, Object> map = new HashMap<String, Object>(); | ||
116 | + map.put("exception", cause.getMessage()); | ||
117 | + Redirector.redirect(config.getExceptionPage(), map); | ||
118 | + handled = true; | ||
119 | + } catch (PageNotFoundException ex) { | ||
120 | + // TODO Colocar a mensagem no bundle | ||
121 | + throw new DemoiselleException( | ||
122 | + "A tela de exibição de erros: \"" | ||
123 | + + ex.getViewId() | ||
124 | + + "\" não foi encontrada. Caso o seu projeto possua outra, defina no arquivo de configuração a chave \"" | ||
125 | + + "frameworkdemoiselle.handle.application.exception.page" + "\"", ex); | ||
126 | + } | ||
74 | return handled; | 127 | return handled; |
75 | } | 128 | } |
76 | 129 | ||
@@ -82,7 +135,7 @@ public class ApplicationExceptionHandler extends AbstractExceptionHandler { | @@ -82,7 +135,7 @@ public class ApplicationExceptionHandler extends AbstractExceptionHandler { | ||
82 | * In render response phase an exception interrupt the renderization. So this method will redirect the renderingo to | 135 | * In render response phase an exception interrupt the renderization. So this method will redirect the renderingo to |
83 | * an page configured in demoiselle.properties | 136 | * an page configured in demoiselle.properties |
84 | * | 137 | * |
85 | - * @see ExceptionHandlerConfig | 138 | + * @see ExceptionHandlerConfigCompatible |
86 | * @param cause | 139 | * @param cause |
87 | * @param config | 140 | * @param config |
88 | * @return | 141 | * @return |
@@ -92,7 +145,7 @@ public class ApplicationExceptionHandler extends AbstractExceptionHandler { | @@ -92,7 +145,7 @@ public class ApplicationExceptionHandler extends AbstractExceptionHandler { | ||
92 | try { | 145 | try { |
93 | Map<String, Object> map = new HashMap<String, Object>(); | 146 | Map<String, Object> map = new HashMap<String, Object>(); |
94 | map.put("exception", cause.getMessage()); | 147 | map.put("exception", cause.getMessage()); |
95 | - Redirector.redirect(config.getExceptionPage(), map); | 148 | + Redirector.redirect(config.getDefaultRedirectExceptionPage(), map); |
96 | handled = true; | 149 | handled = true; |
97 | } catch (PageNotFoundException ex) { | 150 | } catch (PageNotFoundException ex) { |
98 | // TODO Colocar a mensagem no bundle | 151 | // TODO Colocar a mensagem no bundle |