Commit 232cd2286025f47bc9c000d374af31cae7cd9b7f

Authored by Cleverson Sacramento
1 parent aae2ffe2
Exists in master

FWK-202: Injeção de java.util.logging.Logger

Task-Url: https://demoiselle.atlassian.net/browse/FWK-202
impl/extension/jsf/src/main/java/br/gov/frameworkdemoiselle/internal/implementation/ApplicationExceptionHandler.java
... ... @@ -43,10 +43,7 @@ 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   -
48 46 import br.gov.frameworkdemoiselle.DemoiselleException;
49   -import br.gov.frameworkdemoiselle.internal.configuration.ExceptionHandlerConfigCompatible;
50 47 import br.gov.frameworkdemoiselle.internal.configuration.ExceptionHandlerConfig;
51 48 import br.gov.frameworkdemoiselle.util.Beans;
52 49 import br.gov.frameworkdemoiselle.util.Exceptions;
... ... @@ -54,7 +51,6 @@ import br.gov.frameworkdemoiselle.util.Faces;
54 51 import br.gov.frameworkdemoiselle.util.PageNotFoundException;
55 52 import br.gov.frameworkdemoiselle.util.Redirector;
56 53  
57   -@SuppressWarnings("deprecation")
58 54 public class ApplicationExceptionHandler extends AbstractExceptionHandler {
59 55  
60 56 public ApplicationExceptionHandler(final ExceptionHandler wrapped) {
... ... @@ -62,20 +58,6 @@ public class ApplicationExceptionHandler extends AbstractExceptionHandler {
62 58 }
63 59  
64 60 protected boolean handleException(final Throwable cause, FacesContext facesContext) {
65   - // Apenas para manter compatibilidade entre 2.3.x e 2.4.0-RCx
66   - ExceptionHandlerConfigCompatible compatibleConfig = Beans.getReference(ExceptionHandlerConfigCompatible.class);
67   - // Usuário está utilizando pelo menos uma das propriedades com a forma depreciada de forma explícita
68   - if (!(compatibleConfig.getExceptionPage().equals("/application_error") && compatibleConfig.isHandleApplicationException())) {
69   - Logger logger = Beans.getReference(Logger.class);
70   - logger.warn("As propriedades frameworkdemoiselle.handle.application.exception e"
71   - + " frameworkdemoiselle.handle.application.exception.page"
72   - + " não serão suportadas nas próximas versões do framework."
73   - + " Para evitar futuros problemas atualize as propriedades para"
74   - + " frameworkdemoiselle.exception.application.handle e"
75   - + " frameworkdemoiselle.exception.default.redirect.page, respectivamente.");
76   - return handleExceptionCompatibleConfiguration(compatibleConfig, cause, facesContext);
77   - }
78   -
79 61 boolean handled = false;
80 62 ExceptionHandlerConfig config = Beans.getReference(ExceptionHandlerConfig.class);
81 63  
... ... @@ -92,42 +74,6 @@ public class ApplicationExceptionHandler extends AbstractExceptionHandler {
92 74 return handled;
93 75 }
94 76  
95   - @Deprecated
96   - private boolean handleExceptionCompatibleConfiguration(ExceptionHandlerConfigCompatible config, final Throwable cause,
97   - FacesContext facesContext) {
98   - boolean handled = false;
99   -
100   - if (config.isHandleApplicationException() && Exceptions.isApplicationException(cause)) {
101   -
102   - if (isRendering(facesContext)) {
103   - handled = handlingDuringRenderResponseCompatible(cause, config);
104   - } else {
105   - Faces.addMessage(cause);
106   - handled = true;
107   - }
108   - }
109   - return handled;
110   - }
111   -
112   - @Deprecated
113   - private boolean handlingDuringRenderResponseCompatible(final Throwable cause, final ExceptionHandlerConfigCompatible config) {
114   - boolean handled = false;
115   - try {
116   - Map<String, Object> map = new HashMap<String, Object>();
117   - map.put("exception", cause.getMessage());
118   - Redirector.redirect(config.getExceptionPage(), map);
119   - handled = true;
120   - } catch (PageNotFoundException ex) {
121   - // TODO Colocar a mensagem no bundle
122   - throw new DemoiselleException(
123   - "A tela de exibição de erros: \""
124   - + ex.getViewId()
125   - + "\" não foi encontrada. Caso o seu projeto possua outra, defina no arquivo de configuração a chave \""
126   - + "frameworkdemoiselle.handle.application.exception.page" + "\"", ex);
127   - }
128   - return handled;
129   - }
130   -
131 77 private boolean isRendering(FacesContext context) {
132 78 return PhaseId.RENDER_RESPONSE.equals(context.getCurrentPhaseId());
133 79 }
... ...
impl/extension/jsf/src/main/java/br/gov/frameworkdemoiselle/internal/implementation/FileRendererImpl.java
... ... @@ -36,19 +36,20 @@
36 36 */
37 37 package br.gov.frameworkdemoiselle.internal.implementation;
38 38  
  39 +import static java.util.logging.Level.WARNING;
  40 +
39 41 import java.io.ByteArrayOutputStream;
40 42 import java.io.File;
41 43 import java.io.FileInputStream;
42 44 import java.io.FileNotFoundException;
43 45 import java.io.IOException;
44 46 import java.io.InputStream;
  47 +import java.util.logging.Logger;
45 48  
46 49 import javax.faces.context.FacesContext;
47 50 import javax.inject.Inject;
48 51 import javax.servlet.http.HttpServletResponse;
49 52  
50   -import org.slf4j.Logger;
51   -
52 53 import br.gov.frameworkdemoiselle.util.Faces;
53 54 import br.gov.frameworkdemoiselle.util.FileRenderer;
54 55  
... ... @@ -69,38 +70,40 @@ public class FileRendererImpl implements FileRenderer {
69 70 private FacesContext context;
70 71  
71 72 @Override
72   - public void render(final byte[] byteArray, final ContentType contentType, final String fileName, boolean forceDownload) {
73   - logger.debug("Renderizando para o arquivo " + fileName + ".");
  73 + public void render(final byte[] byteArray, final ContentType contentType, final String fileName,
  74 + boolean forceDownload) {
  75 + logger.fine("Renderizando para o arquivo " + fileName + ".");
74 76  
75 77 try {
76 78 response.setContentType(contentType.getContentType());
77 79 response.setContentLength(byteArray.length);
78   -
  80 +
79 81 String forceDownloadCommand = forceDownload ? "attachment; " : "";
80 82 response.setHeader("Content-Disposition", forceDownloadCommand + "filename=\"" + fileName + "\"");
81 83  
82   - logger.debug("Escrevendo o arquivo " + fileName + " no response.");
  84 + logger.fine("Escrevendo o arquivo " + fileName + " no response.");
83 85 response.getOutputStream().write(byteArray, 0, byteArray.length);
84 86 response.getOutputStream().flush();
85 87 response.getOutputStream().close();
86 88 } catch (IOException e) {
87   - logger.info("Erro na geração do relatório. Incluíndo a exceção de erro em um FacesMessage", e);
  89 + logger.log(WARNING, "Erro na geração do relatório. Incluíndo a exceção de erro em um FacesMessage", e);
88 90 Faces.addMessage(e);
89 91 }
90 92 context.responseComplete();
91 93 }
92   -
  94 +
93 95 @Override
94 96 public void render(final byte[] byteArray, final ContentType contentType, final String fileName) {
95 97 render(byteArray, contentType, fileName, false);
96 98 }
97 99  
98 100 @Override
99   - public void render(final InputStream stream, final ContentType contentType, final String fileName, boolean forceDownload) {
100   - logger.debug("Renderizando o arquivo " + fileName + ".");
  101 + public void render(final InputStream stream, final ContentType contentType, final String fileName,
  102 + boolean forceDownload) {
  103 + logger.fine("Renderizando o arquivo " + fileName + ".");
101 104 render(getBytes(stream), contentType, fileName, forceDownload);
102 105 }
103   -
  106 +
104 107 @Override
105 108 public void render(final InputStream stream, final ContentType contentType, final String fileName) {
106 109 render(stream, contentType, fileName, false);
... ... @@ -108,15 +111,15 @@ public class FileRendererImpl implements FileRenderer {
108 111  
109 112 @Override
110 113 public void render(File file, ContentType contentType, String fileName, boolean forceDownload) {
111   - logger.debug("Renderizando para o arquivo " + fileName + ".");
  114 + logger.fine("Renderizando para o arquivo " + fileName + ".");
112 115 try {
113 116 render(new FileInputStream(file), contentType, fileName, forceDownload);
114 117 } catch (FileNotFoundException e) {
115   - logger.info("Erro na geração do relatório. Incluíndo a exceção de erro em um FacesMessage", e);
  118 + logger.log(WARNING, "Erro na geração do relatório. Incluíndo a exceção de erro em um FacesMessage", e);
116 119 Faces.addMessage(e);
117 120 }
118 121 }
119   -
  122 +
120 123 @Override
121 124 public void render(File file, ContentType contentType, String fileName) {
122 125 render(file, contentType, fileName, false);
... ...
impl/extension/jsf/src/main/java/br/gov/frameworkdemoiselle/internal/implementation/SecurityObserver.java
... ... @@ -39,6 +39,7 @@ package br.gov.frameworkdemoiselle.internal.implementation;
39 39 import java.io.Serializable;
40 40 import java.util.HashMap;
41 41 import java.util.Map;
  42 +import java.util.logging.Logger;
42 43  
43 44 import javax.enterprise.context.SessionScoped;
44 45 import javax.enterprise.event.Observes;
... ... @@ -46,8 +47,6 @@ import javax.faces.context.FacesContext;
46 47 import javax.inject.Inject;
47 48 import javax.servlet.http.HttpSession;
48 49  
49   -import org.slf4j.Logger;
50   -
51 50 import br.gov.frameworkdemoiselle.annotation.Name;
52 51 import br.gov.frameworkdemoiselle.configuration.ConfigurationException;
53 52 import br.gov.frameworkdemoiselle.internal.configuration.JsfSecurityConfig;
... ... @@ -71,7 +70,7 @@ public class SecurityObserver implements Serializable {
71 70  
72 71 @Inject
73 72 private Logger logger;
74   -
  73 +
75 74 @Inject
76 75 @Name("demoiselle-jsf-bundle")
77 76 private ResourceBundle bundle;
... ... @@ -113,7 +112,7 @@ public class SecurityObserver implements Serializable {
113 112 Redirector.redirect(getConfig().getLoginPage());
114 113  
115 114 } catch (PageNotFoundException cause) {
116   - throw new ConfigurationException( bundle.getString("login-page-not-found",cause.getViewId()) , cause);
  115 + throw new ConfigurationException(bundle.getString("login-page-not-found", cause.getViewId()), cause);
117 116 }
118 117 }
119 118  
... ... @@ -131,7 +130,8 @@ public class SecurityObserver implements Serializable {
131 130  
132 131 } catch (PageNotFoundException cause) {
133 132 if (redirectedFromConfig) {
134   - throw new ConfigurationException( bundle.getString("after-login-page-not-found",cause.getViewId()) , cause);
  133 + throw new ConfigurationException(bundle.getString("after-login-page-not-found", cause.getViewId()),
  134 + cause);
135 135 } else {
136 136 throw cause;
137 137 }
... ... @@ -148,14 +148,15 @@ public class SecurityObserver implements Serializable {
148 148 }
149 149  
150 150 } catch (PageNotFoundException cause) {
151   - throw new ConfigurationException( bundle.getString("after-logout-page-not-found",cause.getViewId()) , cause);
  151 + throw new ConfigurationException(bundle.getString("after-logout-page-not-found", cause.getViewId()), cause);
152 152  
153 153 } finally {
154 154 try {
155   - HttpSession session = (HttpSession)FacesContext.getCurrentInstance().getExternalContext().getSession(false);
  155 + HttpSession session = (HttpSession) FacesContext.getCurrentInstance().getExternalContext()
  156 + .getSession(false);
156 157 session.invalidate();
157 158 } catch (IllegalStateException e) {
158   - logger.debug("Esta sessão já foi invalidada.");
  159 + logger.fine("Esta sessão já foi invalidada.");
159 160 }
160 161 }
161 162 }
... ...