Commit a89b3bd1c5fc63d0d43c2719074dafc2fdb1f807

Authored by Emerson Oliveira
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.
documentation/reference/pt-BR/properties.xml
... ... @@ -129,7 +129,7 @@
129 129 <entry>true</entry>
130 130 </row>
131 131 <row valign="top">
132   - <entry>frameworkdemoiselle.&#8203;handle.&#8203;application.&#8203;exception</entry>
  132 + <entry>frameworkdemoiselle.&#8203;exception.&#8203;application.&#8203;handle</entry>
133 133 <entry>
134 134 <para>
135 135 Habilita o tratamento automático das exceções da aplicação anotadas com @ApplicationException.
... ... @@ -138,7 +138,7 @@
138 138 <entry>true</entry>
139 139 </row>
140 140 <row valign="top">
141   - <entry>frameworkdemoiselle.&#8203;handle.&#8203;application.&#8203;exception.&#8203;page</entry>
  141 + <entry>frameworkdemoiselle.&#8203;exception.&#8203;default.&#8203;redirect.&#8203;page</entry>
142 142 <entry>
143 143 <para>
144 144 Define o redirecionamento das exceções da aplicação anotadas com @ApplicationException ocorridas
... ...
impl/extension/jsf/pom.xml
... ... @@ -81,6 +81,12 @@
81 81 <scope>test</scope>
82 82 </dependency>
83 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 90 <groupId>org.glassfish.web</groupId>
85 91 <artifactId>el-impl</artifactId>
86 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 41 import br.gov.frameworkdemoiselle.annotation.Name;
42 42 import br.gov.frameworkdemoiselle.configuration.Configuration;
43 43  
44   -@Configuration(prefix = "frameworkdemoiselle.handle.")
  44 +@Configuration(prefix = "frameworkdemoiselle.exception")
45 45 public class ExceptionHandlerConfig implements Serializable {
46 46  
47 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 @@
  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 43 import javax.faces.context.FacesContext;
44 44 import javax.faces.event.PhaseId;
45 45  
  46 +import org.slf4j.Logger;
  47 +
46 48 import br.gov.frameworkdemoiselle.DemoiselleException;
  49 +import br.gov.frameworkdemoiselle.internal.configuration.ExceptionHandlerConfigCompatible;
47 50 import br.gov.frameworkdemoiselle.internal.configuration.ExceptionHandlerConfig;
48 51 import br.gov.frameworkdemoiselle.util.Beans;
49 52 import br.gov.frameworkdemoiselle.util.Exceptions;
... ... @@ -58,19 +61,69 @@ public class ApplicationExceptionHandler extends AbstractExceptionHandler {
58 61 }
59 62  
60 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 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 97 boolean handled = false;
63 98  
64 99 if (config.isHandleApplicationException() && Exceptions.isApplicationException(cause)) {
65 100  
66 101 if (isRendering(facesContext)) {
67   - handled = handlingDuringRenderResponse(cause, config);
  102 + handled = handlingDuringRenderResponseCompatible(cause, config);
68 103 } else {
69 104 Faces.addMessage(cause);
70 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 127 return handled;
75 128 }
76 129  
... ... @@ -82,7 +135,7 @@ public class ApplicationExceptionHandler extends AbstractExceptionHandler {
82 135 * In render response phase an exception interrupt the renderization. So this method will redirect the renderingo to
83 136 * an page configured in demoiselle.properties
84 137 *
85   - * @see ExceptionHandlerConfig
  138 + * @see ExceptionHandlerConfigCompatible
86 139 * @param cause
87 140 * @param config
88 141 * @return
... ... @@ -92,7 +145,7 @@ public class ApplicationExceptionHandler extends AbstractExceptionHandler {
92 145 try {
93 146 Map<String, Object> map = new HashMap<String, Object>();
94 147 map.put("exception", cause.getMessage());
95   - Redirector.redirect(config.getExceptionPage(), map);
  148 + Redirector.redirect(config.getDefaultRedirectExceptionPage(), map);
96 149 handled = true;
97 150 } catch (PageNotFoundException ex) {
98 151 // TODO Colocar a mensagem no bundle
... ...