Commit 2bbaddb1d28d6bd45d4ce0548d1c252a15f61a94

Authored by Cleverson Sacramento
2 parents d38b5f4c 6e5cb42d
Exists in master

Merge branch 'master' into 2.4.0

impl/core/src/main/java/br/gov/frameworkdemoiselle/configuration/Configuration.java
@@ -61,7 +61,6 @@ import javax.enterprise.util.Nonbinding; @@ -61,7 +61,6 @@ import javax.enterprise.util.Nonbinding;
61 * 61 *
62 * @author SERPRO 62 * @author SERPRO
63 */ 63 */
64 -// @Singleton  
65 @Stereotype 64 @Stereotype
66 @Inherited 65 @Inherited
67 @Target(TYPE) 66 @Target(TYPE)
impl/core/src/main/java/br/gov/frameworkdemoiselle/internal/configuration/ConfigurationLoader.java
@@ -82,9 +82,9 @@ public class ConfigurationLoader implements Serializable { @@ -82,9 +82,9 @@ public class ConfigurationLoader implements Serializable {
82 private ResourceBundle bundle; 82 private ResourceBundle bundle;
83 83
84 private Logger logger; 84 private Logger logger;
85 - 85 +
86 private CoreBootstrap bootstrap; 86 private CoreBootstrap bootstrap;
87 - 87 +
88 /** 88 /**
89 * Loads a config class filling it with the corresponding values. 89 * Loads a config class filling it with the corresponding values.
90 * 90 *
@@ -159,7 +159,17 @@ public class ConfigurationLoader implements Serializable { @@ -159,7 +159,17 @@ public class ConfigurationLoader implements Serializable {
159 159
160 Configuration classAnnotation = type.getAnnotation(Configuration.class); 160 Configuration classAnnotation = type.getAnnotation(Configuration.class);
161 if (!Strings.isEmpty(classAnnotation.prefix())) { 161 if (!Strings.isEmpty(classAnnotation.prefix())) {
162 - prefix = classAnnotation.prefix() + "."; 162 +
  163 + prefix = classAnnotation.prefix();
  164 +
  165 + if (prefix.charAt(prefix.length() - 1) != '.') {
  166 + getLogger().warn(
  167 + "ATENÇÃO!!! Informe o ponto (.) ao final da declaração do atributo prefix = \"" + prefix
  168 + + "\" da anotação @Configuration da classe " + type.getCanonicalName()
  169 + + " para evitar incompatibilidade com as próximas versões do Demoiselle.");
  170 +
  171 + prefix += ".";
  172 + }
163 } 173 }
164 174
165 return prefix; 175 return prefix;
@@ -196,6 +206,13 @@ public class ConfigurationLoader implements Serializable { @@ -196,6 +206,13 @@ public class ConfigurationLoader implements Serializable {
196 } 206 }
197 } 207 }
198 208
  209 + if (!field.getName().equals(key)) {
  210 + getLogger().warn(
  211 + "ATENÇÃO!!! Anote o atributo " + field.getName() + " da classe "
  212 + + field.getDeclaringClass().getCanonicalName() + " com @Name(\"" + key
  213 + + "\") para evitar incompatibilidade com as próximas versões do Demoiselle.");
  214 + }
  215 +
199 if (matches == 0) { 216 if (matches == 0) {
200 getLogger().debug(getBundle().getString("configuration-key-not-found", key, conventions)); 217 getLogger().debug(getBundle().getString("configuration-key-not-found", key, conventions));
201 } else if (matches > 1) { 218 } else if (matches > 1) {
@@ -445,12 +462,12 @@ public class ConfigurationLoader implements Serializable { @@ -445,12 +462,12 @@ public class ConfigurationLoader implements Serializable {
445 462
446 return logger; 463 return logger;
447 } 464 }
448 -  
449 - private CoreBootstrap getBootstrap(){  
450 - if (bootstrap == null){ 465 +
  466 + private CoreBootstrap getBootstrap() {
  467 + if (bootstrap == null) {
451 bootstrap = Beans.getReference(CoreBootstrap.class); 468 bootstrap = Beans.getReference(CoreBootstrap.class);
452 } 469 }
453 - 470 +
454 return bootstrap; 471 return bootstrap;
455 } 472 }
456 } 473 }
impl/core/src/main/java/br/gov/frameworkdemoiselle/internal/configuration/PaginationConfig.java
@@ -47,7 +47,7 @@ import br.gov.frameworkdemoiselle.configuration.Configuration; @@ -47,7 +47,7 @@ import br.gov.frameworkdemoiselle.configuration.Configuration;
47 * 47 *
48 * @author SERPRO 48 * @author SERPRO
49 */ 49 */
50 -@Configuration(prefix = "frameworkdemoiselle.pagination") 50 +@Configuration(prefix = "frameworkdemoiselle.pagination.")
51 public class PaginationConfig implements Serializable { 51 public class PaginationConfig implements Serializable {
52 52
53 private static final long serialVersionUID = 1L; 53 private static final long serialVersionUID = 1L;
impl/core/src/main/java/br/gov/frameworkdemoiselle/internal/configuration/SecurityConfigImpl.java
@@ -38,19 +38,23 @@ package br.gov.frameworkdemoiselle.internal.configuration; @@ -38,19 +38,23 @@ package br.gov.frameworkdemoiselle.internal.configuration;
38 38
39 import java.io.Serializable; 39 import java.io.Serializable;
40 40
  41 +import br.gov.frameworkdemoiselle.annotation.Name;
41 import br.gov.frameworkdemoiselle.configuration.Configuration; 42 import br.gov.frameworkdemoiselle.configuration.Configuration;
42 import br.gov.frameworkdemoiselle.security.Authenticator; 43 import br.gov.frameworkdemoiselle.security.Authenticator;
43 import br.gov.frameworkdemoiselle.security.Authorizer; 44 import br.gov.frameworkdemoiselle.security.Authorizer;
44 45
45 -@Configuration(prefix = "frameworkdemoiselle.security") 46 +@Configuration(prefix = "frameworkdemoiselle.security.")
46 public class SecurityConfigImpl implements Serializable, SecurityConfig { 47 public class SecurityConfigImpl implements Serializable, SecurityConfig {
47 48
48 private static final long serialVersionUID = 1L; 49 private static final long serialVersionUID = 1L;
49 50
  51 + @Name("enabled")
50 private boolean enabled = true; 52 private boolean enabled = true;
51 53
  54 + @Name("authenticator.class")
52 private Class<? extends Authenticator> authenticatorClass; 55 private Class<? extends Authenticator> authenticatorClass;
53 56
  57 + @Name("authorizer.class")
54 private Class<? extends Authorizer> authorizerClass; 58 private Class<? extends Authorizer> authorizerClass;
55 59
56 /* 60 /*
impl/core/src/main/java/br/gov/frameworkdemoiselle/internal/configuration/TransactionConfig.java
@@ -42,7 +42,7 @@ import br.gov.frameworkdemoiselle.annotation.Name; @@ -42,7 +42,7 @@ import br.gov.frameworkdemoiselle.annotation.Name;
42 import br.gov.frameworkdemoiselle.configuration.Configuration; 42 import br.gov.frameworkdemoiselle.configuration.Configuration;
43 import br.gov.frameworkdemoiselle.transaction.Transaction; 43 import br.gov.frameworkdemoiselle.transaction.Transaction;
44 44
45 -@Configuration(prefix = "frameworkdemoiselle.transaction") 45 +@Configuration(prefix = "frameworkdemoiselle.transaction.")
46 public class TransactionConfig implements Serializable { 46 public class TransactionConfig implements Serializable {
47 47
48 private static final long serialVersionUID = 1L; 48 private static final long serialVersionUID = 1L;
impl/core/src/main/java/br/gov/frameworkdemoiselle/internal/interceptor/ExceptionHandlerInterceptor.java
@@ -69,11 +69,11 @@ public class ExceptionHandlerInterceptor implements Serializable { @@ -69,11 +69,11 @@ public class ExceptionHandlerInterceptor implements Serializable {
69 69
70 private final Map<Class<?>, Map<Class<?>, Method>> cache = new HashMap<Class<?>, Map<Class<?>, Method>>(); 70 private final Map<Class<?>, Map<Class<?>, Method>> cache = new HashMap<Class<?>, Map<Class<?>, Method>>();
71 71
72 - private final boolean handleException(final Exception cause, final InvocationContext ic) throws Exception { 72 + private final boolean handleException(final Exception cause, final Object target) throws Exception {
73 getLogger().info(getBundle().getString("handling-exception", cause.getClass().getCanonicalName())); 73 getLogger().info(getBundle().getString("handling-exception", cause.getClass().getCanonicalName()));
74 74
75 boolean handled = false; 75 boolean handled = false;
76 - Class<?> type = getType(ic); 76 + Class<?> type = getType(target);
77 77
78 if (!isLoaded(type)) { 78 if (!isLoaded(type)) {
79 loadHandlers(type); 79 loadHandlers(type);
@@ -81,22 +81,22 @@ public class ExceptionHandlerInterceptor implements Serializable { @@ -81,22 +81,22 @@ public class ExceptionHandlerInterceptor implements Serializable {
81 81
82 Method handler = getMethod(type, cause); 82 Method handler = getMethod(type, cause);
83 if (handler != null) { 83 if (handler != null) {
84 - invoke(handler, ic.getTarget(), cause); 84 + invoke(handler, target, cause);
85 handled = true; 85 handled = true;
86 } 86 }
87 87
88 return handled; 88 return handled;
89 } 89 }
90 90
91 - private final Class<?> getType(final InvocationContext ic) {  
92 - Class<?> type = ic.getTarget().getClass(); 91 + private final Class<?> getType(final Object target) {
  92 + Class<?> type = target.getClass();
93 CoreBootstrap bootstrap = Beans.getReference(CoreBootstrap.class); 93 CoreBootstrap bootstrap = Beans.getReference(CoreBootstrap.class);
94 94
95 if (!bootstrap.isAnnotatedType(type)) { 95 if (!bootstrap.isAnnotatedType(type)) {
96 - type = type.getSuperclass();  
97 getLogger().debug( 96 getLogger().debug(
98 - getBundle().getString("proxy-detected", ic.getTarget().getClass(),  
99 - ic.getTarget().getClass().getSuperclass())); 97 + getBundle().getString("proxy-detected", type,
  98 + type.getSuperclass()));
  99 + type = type.getSuperclass();
100 } 100 }
101 101
102 return type; 102 return type;
@@ -183,13 +183,15 @@ public class ExceptionHandlerInterceptor implements Serializable { @@ -183,13 +183,15 @@ public class ExceptionHandlerInterceptor implements Serializable {
183 183
184 @AroundInvoke 184 @AroundInvoke
185 public Object manage(final InvocationContext ic) throws Exception { 185 public Object manage(final InvocationContext ic) throws Exception {
  186 + Object target = null;
186 Object result = null; 187 Object result = null;
187 188
188 try { 189 try {
  190 + target = ic.getTarget();
189 result = ic.proceed(); 191 result = ic.proceed();
190 192
191 } catch (Exception cause) { 193 } catch (Exception cause) {
192 - if (!handleException(cause, ic)) { 194 + if (!handleException(cause, target)) {
193 throw cause; 195 throw cause;
194 } 196 }
195 } 197 }
impl/core/src/main/java/br/gov/frameworkdemoiselle/util/Exceptions.java
@@ -26,7 +26,7 @@ public final class Exceptions { @@ -26,7 +26,7 @@ public final class Exceptions {
26 } 26 }
27 27
28 public static boolean isApplicationException(final Throwable throwable) { 28 public static boolean isApplicationException(final Throwable throwable) {
29 - return throwable.getClass().isAnnotationPresent(ApplicationException.class); 29 + return throwable != null && throwable.getClass().isAnnotationPresent(ApplicationException.class);
30 } 30 }
31 31
32 public static void handleToRuntimeException(final Throwable throwable) throws RuntimeException { 32 public static void handleToRuntimeException(final Throwable throwable) throws RuntimeException {
impl/core/src/test/java/br/gov/frameworkdemoiselle/internal/configuration/ConfigurationLoaderTest.java
@@ -133,7 +133,7 @@ public class ConfigurationLoaderTest { @@ -133,7 +133,7 @@ public class ConfigurationLoaderTest {
133 133
134 } 134 }
135 135
136 - @Configuration(prefix = "frameworkdemoiselle.configurationtest") 136 + @Configuration(prefix = "frameworkdemoiselle.configurationtest.")
137 public class ConfigurationWithPrefix { 137 public class ConfigurationWithPrefix {
138 138
139 @Name("nameConfiguration") 139 @Name("nameConfiguration")
@@ -282,7 +282,7 @@ public class ConfigurationLoaderTest { @@ -282,7 +282,7 @@ public class ConfigurationLoaderTest {
282 282
283 } 283 }
284 284
285 - @Configuration(prefix = "br.gov.frameworkdemoiselle") 285 + @Configuration(prefix = "br.gov.frameworkdemoiselle.")
286 public class ConfigurationPropertiesSuccessWithPrefixNonAmbiguous { 286 public class ConfigurationPropertiesSuccessWithPrefixNonAmbiguous {
287 287
288 protected String success; 288 protected String success;
impl/core/src/test/java/br/gov/frameworkdemoiselle/internal/interceptor/ExceptionHandlerInterceptorTest.java
@@ -155,6 +155,7 @@ public class ExceptionHandlerInterceptorTest { @@ -155,6 +155,7 @@ public class ExceptionHandlerInterceptorTest {
155 @Test 155 @Test
156 public void manageSuccessfully() throws Throwable { 156 public void manageSuccessfully() throws Throwable {
157 expect(this.context.proceed()).andReturn(null); 157 expect(this.context.proceed()).andReturn(null);
  158 + expect(this.context.getTarget()).andReturn(null);
158 replayAll(); 159 replayAll();
159 assertEquals(null, this.interceptor.manage(this.context)); 160 assertEquals(null, this.interceptor.manage(this.context));
160 verify(); 161 verify();
impl/extension/jpa/src/main/java/br/gov/frameworkdemoiselle/internal/configuration/EntityManagerConfig.java
@@ -44,7 +44,7 @@ import br.gov.frameworkdemoiselle.configuration.Configuration; @@ -44,7 +44,7 @@ import br.gov.frameworkdemoiselle.configuration.Configuration;
44 /** 44 /**
45 * Configuration class responsible for retrieving specific entity manager parameter values from properties file. 45 * Configuration class responsible for retrieving specific entity manager parameter values from properties file.
46 */ 46 */
47 -@Configuration(prefix = "frameworkdemoiselle.persistence") 47 +@Configuration(prefix = "frameworkdemoiselle.persistence.")
48 public class EntityManagerConfig implements Serializable { 48 public class EntityManagerConfig implements Serializable {
49 49
50 private static final long serialVersionUID = 1L; 50 private static final long serialVersionUID = 1L;
impl/extension/jsf/src/main/java/br/gov/frameworkdemoiselle/internal/configuration/ExceptionHandlerConfig.java
@@ -41,7 +41,7 @@ import java.io.Serializable; @@ -41,7 +41,7 @@ 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.handle.")
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;
impl/extension/jsf/src/main/java/br/gov/frameworkdemoiselle/internal/configuration/JsfSecurityConfig.java
@@ -41,7 +41,7 @@ import java.io.Serializable; @@ -41,7 +41,7 @@ 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.security") 44 +@Configuration(prefix = "frameworkdemoiselle.security.")
45 public class JsfSecurityConfig implements Serializable { 45 public class JsfSecurityConfig implements Serializable {
46 46
47 private static final long serialVersionUID = 1L; 47 private static final long serialVersionUID = 1L;
@@ -49,7 +49,6 @@ public class JsfSecurityConfig implements Serializable { @@ -49,7 +49,6 @@ public class JsfSecurityConfig implements Serializable {
49 @Name("login.page") 49 @Name("login.page")
50 private String loginPage = "/login"; 50 private String loginPage = "/login";
51 51
52 - // @Name("welcome.page")  
53 @Name("redirect.after.login") 52 @Name("redirect.after.login")
54 private String redirectAfterLogin = "/index"; 53 private String redirectAfterLogin = "/index";
55 54
impl/extension/jsf/src/main/java/br/gov/frameworkdemoiselle/internal/implementation/ApplicationExceptionHandler.java
@@ -108,7 +108,7 @@ public class ApplicationExceptionHandler extends AbstractExceptionHandler { @@ -108,7 +108,7 @@ public class ApplicationExceptionHandler extends AbstractExceptionHandler {
108 protected Throwable getRoot(final Throwable throwable) { 108 protected Throwable getRoot(final Throwable throwable) {
109 Throwable root = throwable; 109 Throwable root = throwable;
110 110
111 - while (!Exceptions.isApplicationException(root)) { 111 + while (root != null && !Exceptions.isApplicationException(root)) {
112 root = root.getCause(); 112 root = root.getCause();
113 } 113 }
114 114