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,10 +43,7 @@ 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 -  
48 import br.gov.frameworkdemoiselle.DemoiselleException; 46 import br.gov.frameworkdemoiselle.DemoiselleException;
49 -import br.gov.frameworkdemoiselle.internal.configuration.ExceptionHandlerConfigCompatible;  
50 import br.gov.frameworkdemoiselle.internal.configuration.ExceptionHandlerConfig; 47 import br.gov.frameworkdemoiselle.internal.configuration.ExceptionHandlerConfig;
51 import br.gov.frameworkdemoiselle.util.Beans; 48 import br.gov.frameworkdemoiselle.util.Beans;
52 import br.gov.frameworkdemoiselle.util.Exceptions; 49 import br.gov.frameworkdemoiselle.util.Exceptions;
@@ -54,7 +51,6 @@ import br.gov.frameworkdemoiselle.util.Faces; @@ -54,7 +51,6 @@ import br.gov.frameworkdemoiselle.util.Faces;
54 import br.gov.frameworkdemoiselle.util.PageNotFoundException; 51 import br.gov.frameworkdemoiselle.util.PageNotFoundException;
55 import br.gov.frameworkdemoiselle.util.Redirector; 52 import br.gov.frameworkdemoiselle.util.Redirector;
56 53
57 -@SuppressWarnings("deprecation")  
58 public class ApplicationExceptionHandler extends AbstractExceptionHandler { 54 public class ApplicationExceptionHandler extends AbstractExceptionHandler {
59 55
60 public ApplicationExceptionHandler(final ExceptionHandler wrapped) { 56 public ApplicationExceptionHandler(final ExceptionHandler wrapped) {
@@ -62,20 +58,6 @@ public class ApplicationExceptionHandler extends AbstractExceptionHandler { @@ -62,20 +58,6 @@ public class ApplicationExceptionHandler extends AbstractExceptionHandler {
62 } 58 }
63 59
64 protected boolean handleException(final Throwable cause, FacesContext facesContext) { 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 boolean handled = false; 61 boolean handled = false;
80 ExceptionHandlerConfig config = Beans.getReference(ExceptionHandlerConfig.class); 62 ExceptionHandlerConfig config = Beans.getReference(ExceptionHandlerConfig.class);
81 63
@@ -92,42 +74,6 @@ public class ApplicationExceptionHandler extends AbstractExceptionHandler { @@ -92,42 +74,6 @@ public class ApplicationExceptionHandler extends AbstractExceptionHandler {
92 return handled; 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 private boolean isRendering(FacesContext context) { 77 private boolean isRendering(FacesContext context) {
132 return PhaseId.RENDER_RESPONSE.equals(context.getCurrentPhaseId()); 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,19 +36,20 @@
36 */ 36 */
37 package br.gov.frameworkdemoiselle.internal.implementation; 37 package br.gov.frameworkdemoiselle.internal.implementation;
38 38
  39 +import static java.util.logging.Level.WARNING;
  40 +
39 import java.io.ByteArrayOutputStream; 41 import java.io.ByteArrayOutputStream;
40 import java.io.File; 42 import java.io.File;
41 import java.io.FileInputStream; 43 import java.io.FileInputStream;
42 import java.io.FileNotFoundException; 44 import java.io.FileNotFoundException;
43 import java.io.IOException; 45 import java.io.IOException;
44 import java.io.InputStream; 46 import java.io.InputStream;
  47 +import java.util.logging.Logger;
45 48
46 import javax.faces.context.FacesContext; 49 import javax.faces.context.FacesContext;
47 import javax.inject.Inject; 50 import javax.inject.Inject;
48 import javax.servlet.http.HttpServletResponse; 51 import javax.servlet.http.HttpServletResponse;
49 52
50 -import org.slf4j.Logger;  
51 -  
52 import br.gov.frameworkdemoiselle.util.Faces; 53 import br.gov.frameworkdemoiselle.util.Faces;
53 import br.gov.frameworkdemoiselle.util.FileRenderer; 54 import br.gov.frameworkdemoiselle.util.FileRenderer;
54 55
@@ -69,38 +70,40 @@ public class FileRendererImpl implements FileRenderer { @@ -69,38 +70,40 @@ public class FileRendererImpl implements FileRenderer {
69 private FacesContext context; 70 private FacesContext context;
70 71
71 @Override 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 try { 77 try {
76 response.setContentType(contentType.getContentType()); 78 response.setContentType(contentType.getContentType());
77 response.setContentLength(byteArray.length); 79 response.setContentLength(byteArray.length);
78 - 80 +
79 String forceDownloadCommand = forceDownload ? "attachment; " : ""; 81 String forceDownloadCommand = forceDownload ? "attachment; " : "";
80 response.setHeader("Content-Disposition", forceDownloadCommand + "filename=\"" + fileName + "\""); 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 response.getOutputStream().write(byteArray, 0, byteArray.length); 85 response.getOutputStream().write(byteArray, 0, byteArray.length);
84 response.getOutputStream().flush(); 86 response.getOutputStream().flush();
85 response.getOutputStream().close(); 87 response.getOutputStream().close();
86 } catch (IOException e) { 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 Faces.addMessage(e); 90 Faces.addMessage(e);
89 } 91 }
90 context.responseComplete(); 92 context.responseComplete();
91 } 93 }
92 - 94 +
93 @Override 95 @Override
94 public void render(final byte[] byteArray, final ContentType contentType, final String fileName) { 96 public void render(final byte[] byteArray, final ContentType contentType, final String fileName) {
95 render(byteArray, contentType, fileName, false); 97 render(byteArray, contentType, fileName, false);
96 } 98 }
97 99
98 @Override 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 render(getBytes(stream), contentType, fileName, forceDownload); 104 render(getBytes(stream), contentType, fileName, forceDownload);
102 } 105 }
103 - 106 +
104 @Override 107 @Override
105 public void render(final InputStream stream, final ContentType contentType, final String fileName) { 108 public void render(final InputStream stream, final ContentType contentType, final String fileName) {
106 render(stream, contentType, fileName, false); 109 render(stream, contentType, fileName, false);
@@ -108,15 +111,15 @@ public class FileRendererImpl implements FileRenderer { @@ -108,15 +111,15 @@ public class FileRendererImpl implements FileRenderer {
108 111
109 @Override 112 @Override
110 public void render(File file, ContentType contentType, String fileName, boolean forceDownload) { 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 try { 115 try {
113 render(new FileInputStream(file), contentType, fileName, forceDownload); 116 render(new FileInputStream(file), contentType, fileName, forceDownload);
114 } catch (FileNotFoundException e) { 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 Faces.addMessage(e); 119 Faces.addMessage(e);
117 } 120 }
118 } 121 }
119 - 122 +
120 @Override 123 @Override
121 public void render(File file, ContentType contentType, String fileName) { 124 public void render(File file, ContentType contentType, String fileName) {
122 render(file, contentType, fileName, false); 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,6 +39,7 @@ package br.gov.frameworkdemoiselle.internal.implementation;
39 import java.io.Serializable; 39 import java.io.Serializable;
40 import java.util.HashMap; 40 import java.util.HashMap;
41 import java.util.Map; 41 import java.util.Map;
  42 +import java.util.logging.Logger;
42 43
43 import javax.enterprise.context.SessionScoped; 44 import javax.enterprise.context.SessionScoped;
44 import javax.enterprise.event.Observes; 45 import javax.enterprise.event.Observes;
@@ -46,8 +47,6 @@ import javax.faces.context.FacesContext; @@ -46,8 +47,6 @@ import javax.faces.context.FacesContext;
46 import javax.inject.Inject; 47 import javax.inject.Inject;
47 import javax.servlet.http.HttpSession; 48 import javax.servlet.http.HttpSession;
48 49
49 -import org.slf4j.Logger;  
50 -  
51 import br.gov.frameworkdemoiselle.annotation.Name; 50 import br.gov.frameworkdemoiselle.annotation.Name;
52 import br.gov.frameworkdemoiselle.configuration.ConfigurationException; 51 import br.gov.frameworkdemoiselle.configuration.ConfigurationException;
53 import br.gov.frameworkdemoiselle.internal.configuration.JsfSecurityConfig; 52 import br.gov.frameworkdemoiselle.internal.configuration.JsfSecurityConfig;
@@ -71,7 +70,7 @@ public class SecurityObserver implements Serializable { @@ -71,7 +70,7 @@ public class SecurityObserver implements Serializable {
71 70
72 @Inject 71 @Inject
73 private Logger logger; 72 private Logger logger;
74 - 73 +
75 @Inject 74 @Inject
76 @Name("demoiselle-jsf-bundle") 75 @Name("demoiselle-jsf-bundle")
77 private ResourceBundle bundle; 76 private ResourceBundle bundle;
@@ -113,7 +112,7 @@ public class SecurityObserver implements Serializable { @@ -113,7 +112,7 @@ public class SecurityObserver implements Serializable {
113 Redirector.redirect(getConfig().getLoginPage()); 112 Redirector.redirect(getConfig().getLoginPage());
114 113
115 } catch (PageNotFoundException cause) { 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,7 +130,8 @@ public class SecurityObserver implements Serializable {
131 130
132 } catch (PageNotFoundException cause) { 131 } catch (PageNotFoundException cause) {
133 if (redirectedFromConfig) { 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 } else { 135 } else {
136 throw cause; 136 throw cause;
137 } 137 }
@@ -148,14 +148,15 @@ public class SecurityObserver implements Serializable { @@ -148,14 +148,15 @@ public class SecurityObserver implements Serializable {
148 } 148 }
149 149
150 } catch (PageNotFoundException cause) { 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 } finally { 153 } finally {
154 try { 154 try {
155 - HttpSession session = (HttpSession)FacesContext.getCurrentInstance().getExternalContext().getSession(false); 155 + HttpSession session = (HttpSession) FacesContext.getCurrentInstance().getExternalContext()
  156 + .getSession(false);
156 session.invalidate(); 157 session.invalidate();
157 } catch (IllegalStateException e) { 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 }