Commit aae675b6be703da26ef4e1640737bdfe465b22e5
Exists in
master
Merge branch '2.4.0' of git@github.com:demoiselle/framework.git into 2.4.0
Showing
5 changed files
with
116 additions
and
21 deletions
Show diff stats
impl/core/src/main/java/br/gov/frameworkdemoiselle/internal/management/Management.java
| @@ -46,15 +46,14 @@ import java.util.Set; | @@ -46,15 +46,14 @@ import java.util.Set; | ||
| 46 | import javax.enterprise.context.ApplicationScoped; | 46 | import javax.enterprise.context.ApplicationScoped; |
| 47 | import javax.enterprise.context.RequestScoped; | 47 | import javax.enterprise.context.RequestScoped; |
| 48 | import javax.inject.Inject; | 48 | import javax.inject.Inject; |
| 49 | -import javax.management.ReflectionException; | ||
| 50 | import javax.validation.ConstraintViolation; | 49 | import javax.validation.ConstraintViolation; |
| 50 | +import javax.validation.ConstraintViolationException; | ||
| 51 | import javax.validation.Validation; | 51 | import javax.validation.Validation; |
| 52 | import javax.validation.ValidationException; | 52 | import javax.validation.ValidationException; |
| 53 | import javax.validation.Validator; | 53 | import javax.validation.Validator; |
| 54 | 54 | ||
| 55 | import org.slf4j.Logger; | 55 | import org.slf4j.Logger; |
| 56 | 56 | ||
| 57 | -import br.gov.frameworkdemoiselle.DemoiselleException; | ||
| 58 | import br.gov.frameworkdemoiselle.annotation.ManagedProperty; | 57 | import br.gov.frameworkdemoiselle.annotation.ManagedProperty; |
| 59 | import br.gov.frameworkdemoiselle.annotation.Name; | 58 | import br.gov.frameworkdemoiselle.annotation.Name; |
| 60 | import br.gov.frameworkdemoiselle.internal.context.ContextManager; | 59 | import br.gov.frameworkdemoiselle.internal.context.ContextManager; |
| @@ -62,6 +61,8 @@ import br.gov.frameworkdemoiselle.internal.context.ManagedContext; | @@ -62,6 +61,8 @@ import br.gov.frameworkdemoiselle.internal.context.ManagedContext; | ||
| 62 | import br.gov.frameworkdemoiselle.internal.management.ManagedType.MethodDetail; | 61 | import br.gov.frameworkdemoiselle.internal.management.ManagedType.MethodDetail; |
| 63 | import br.gov.frameworkdemoiselle.lifecycle.ManagementExtension; | 62 | import br.gov.frameworkdemoiselle.lifecycle.ManagementExtension; |
| 64 | import br.gov.frameworkdemoiselle.management.AttributeChangeNotification; | 63 | import br.gov.frameworkdemoiselle.management.AttributeChangeNotification; |
| 64 | +import br.gov.frameworkdemoiselle.management.ManagedAttributeNotFoundException; | ||
| 65 | +import br.gov.frameworkdemoiselle.management.ManagedInvokationException; | ||
| 65 | import br.gov.frameworkdemoiselle.management.NotificationManager; | 66 | import br.gov.frameworkdemoiselle.management.NotificationManager; |
| 66 | import br.gov.frameworkdemoiselle.stereotype.ManagementController; | 67 | import br.gov.frameworkdemoiselle.stereotype.ManagementController; |
| 67 | import br.gov.frameworkdemoiselle.util.Beans; | 68 | import br.gov.frameworkdemoiselle.util.Beans; |
| @@ -124,7 +125,7 @@ public class Management implements Serializable { | @@ -124,7 +125,7 @@ public class Management implements Serializable { | ||
| 124 | * parameters. | 125 | * parameters. |
| 125 | * @return The return value of the original invoked operation. Methods of return type <code>void</code> will return | 126 | * @return The return value of the original invoked operation. Methods of return type <code>void</code> will return |
| 126 | * the {@link Void} type. | 127 | * the {@link Void} type. |
| 127 | - * @throws ReflectionException | 128 | + * @throws ManagedInvokationException |
| 128 | * In case the operation doesn't exist or have a different signature | 129 | * In case the operation doesn't exist or have a different signature |
| 129 | */ | 130 | */ |
| 130 | public Object invoke(ManagedType managedType, String actionName, Object[] params) { | 131 | public Object invoke(ManagedType managedType, String actionName, Object[] params) { |
| @@ -141,16 +142,16 @@ public class Management implements Serializable { | @@ -141,16 +142,16 @@ public class Management implements Serializable { | ||
| 141 | .getType().getCanonicalName())); | 142 | .getType().getCanonicalName())); |
| 142 | return method.getMethod().invoke(delegate, params); | 143 | return method.getMethod().invoke(delegate, params); |
| 143 | } catch (Exception e) { | 144 | } catch (Exception e) { |
| 144 | - throw new DemoiselleException(bundle.getString("management-invoke-error", actionName), e); | 145 | + throw new ManagedInvokationException(bundle.getString("management-invoke-error", actionName), e); |
| 145 | } | 146 | } |
| 146 | } else { | 147 | } else { |
| 147 | - throw new DemoiselleException(bundle.getString("management-invoke-error", actionName)); | 148 | + throw new ManagedInvokationException(bundle.getString("management-invoke-error", actionName)); |
| 148 | } | 149 | } |
| 149 | } finally { | 150 | } finally { |
| 150 | deactivateContexts(managedType.getType()); | 151 | deactivateContexts(managedType.getType()); |
| 151 | } | 152 | } |
| 152 | } else { | 153 | } else { |
| 153 | - throw new DemoiselleException(bundle.getString("management-type-not-found")); | 154 | + throw new ManagedInvokationException(bundle.getString("management-type-not-found")); |
| 154 | } | 155 | } |
| 155 | } | 156 | } |
| 156 | 157 | ||
| @@ -169,6 +170,8 @@ public class Management implements Serializable { | @@ -169,6 +170,8 @@ public class Management implements Serializable { | ||
| 169 | * @param propertyName | 170 | * @param propertyName |
| 170 | * The name of the property | 171 | * The name of the property |
| 171 | * @return The current value of the property | 172 | * @return The current value of the property |
| 173 | + * @throws ManagedAttributeNotFoundException If the given property doesn't exist or there was a problem trying to read the property value. | ||
| 174 | + * @throws ManagedInvokationException If there was an error trying to invoke the getter method to read the propery value. | ||
| 172 | */ | 175 | */ |
| 173 | public Object getProperty(ManagedType managedType, String propertyName) { | 176 | public Object getProperty(ManagedType managedType, String propertyName) { |
| 174 | 177 | ||
| @@ -186,16 +189,16 @@ public class Management implements Serializable { | @@ -186,16 +189,16 @@ public class Management implements Serializable { | ||
| 186 | 189 | ||
| 187 | return getterMethod.invoke(delegate, (Object[]) null); | 190 | return getterMethod.invoke(delegate, (Object[]) null); |
| 188 | } catch (Exception e) { | 191 | } catch (Exception e) { |
| 189 | - throw new DemoiselleException(bundle.getString("management-invoke-error", getterMethod.getName()), | 192 | + throw new ManagedInvokationException(bundle.getString("management-invoke-error", getterMethod.getName()), |
| 190 | e); | 193 | e); |
| 191 | } finally { | 194 | } finally { |
| 192 | deactivateContexts(managedType.getType()); | 195 | deactivateContexts(managedType.getType()); |
| 193 | } | 196 | } |
| 194 | } else { | 197 | } else { |
| 195 | - throw new DemoiselleException(bundle.getString("management-read-value-error", propertyName)); | 198 | + throw new ManagedAttributeNotFoundException(bundle.getString("management-read-value-error", propertyName)); |
| 196 | } | 199 | } |
| 197 | } else { | 200 | } else { |
| 198 | - throw new DemoiselleException(bundle.getString("management-type-not-found")); | 201 | + throw new ManagedInvokationException(bundle.getString("management-type-not-found")); |
| 199 | } | 202 | } |
| 200 | } | 203 | } |
| 201 | 204 | ||
| @@ -215,7 +218,11 @@ public class Management implements Serializable { | @@ -215,7 +218,11 @@ public class Management implements Serializable { | ||
| 215 | * The name of the property | 218 | * The name of the property |
| 216 | * @param newValue | 219 | * @param newValue |
| 217 | * The new value of the property | 220 | * The new value of the property |
| 221 | + * @throws ManagedInvokationException If there was an error trying to call the setter method for this property. | ||
| 222 | + * @throws ManagedAttributeNotFoundException If the giver property doesn't exist or could'n be written to. | ||
| 223 | + * @throws ConstraintViolationException If the property defined one or more validation constraints and setting this value violates some of those constraints. | ||
| 218 | */ | 224 | */ |
| 225 | + @SuppressWarnings("unchecked") | ||
| 219 | public void setProperty(ManagedType managedType, String propertyName, Object newValue) { | 226 | public void setProperty(ManagedType managedType, String propertyName, Object newValue) { |
| 220 | 227 | ||
| 221 | if (managedTypes.contains(managedType)) { | 228 | if (managedTypes.contains(managedType)) { |
| @@ -249,9 +256,9 @@ public class Management implements Serializable { | @@ -249,9 +256,9 @@ public class Management implements Serializable { | ||
| 249 | errorBuffer.insert(errorBuffer.length(), "\r\n"); | 256 | errorBuffer.insert(errorBuffer.length(), "\r\n"); |
| 250 | } | 257 | } |
| 251 | 258 | ||
| 252 | - throw new DemoiselleException(bundle.getString( | ||
| 253 | - "management-validation-constraint-violation", managedType.getType() | ||
| 254 | - .getCanonicalName(), propertyName, errorBuffer.toString())); | 259 | + throw new ConstraintViolationException(bundle.getString("management-validation-constraint-violation" |
| 260 | + , managedType.getType().getCanonicalName(), propertyName, errorBuffer.toString()) | ||
| 261 | + , (Set<ConstraintViolation<?>>) violations); | ||
| 255 | } | 262 | } |
| 256 | } else { | 263 | } else { |
| 257 | logger.warn(bundle.getString("management-validation-validator-not-found")); | 264 | logger.warn(bundle.getString("management-validation-validator-not-found")); |
| @@ -276,19 +283,19 @@ public class Management implements Serializable { | @@ -276,19 +283,19 @@ public class Management implements Serializable { | ||
| 276 | .getCanonicalName()), propertyName, attributeType, oldValue, newValue); | 283 | .getCanonicalName()), propertyName, attributeType, oldValue, newValue); |
| 277 | notificationManager.sendNotification(notification); | 284 | notificationManager.sendNotification(notification); |
| 278 | 285 | ||
| 279 | - } catch (DemoiselleException de) { | ||
| 280 | - throw de; | 286 | + } catch (ConstraintViolationException ce) { |
| 287 | + throw ce; | ||
| 281 | } catch (Exception e) { | 288 | } catch (Exception e) { |
| 282 | - throw new DemoiselleException(bundle.getString("management-invoke-error", method.getName()), e); | 289 | + throw new ManagedInvokationException(bundle.getString("management-invoke-error", method.getName()), e); |
| 283 | } finally { | 290 | } finally { |
| 284 | deactivateContexts(managedType.getType()); | 291 | deactivateContexts(managedType.getType()); |
| 285 | } | 292 | } |
| 286 | 293 | ||
| 287 | } else { | 294 | } else { |
| 288 | - throw new DemoiselleException(bundle.getString("management-write-value-error", propertyName)); | 295 | + throw new ManagedAttributeNotFoundException(bundle.getString("management-write-value-error", propertyName)); |
| 289 | } | 296 | } |
| 290 | } else { | 297 | } else { |
| 291 | - throw new DemoiselleException(bundle.getString("management-type-not-found")); | 298 | + throw new ManagedInvokationException(bundle.getString("management-type-not-found")); |
| 292 | } | 299 | } |
| 293 | 300 | ||
| 294 | } | 301 | } |
impl/core/src/main/java/br/gov/frameworkdemoiselle/management/ManagedAttributeNotFoundException.java
0 → 100644
| @@ -0,0 +1,29 @@ | @@ -0,0 +1,29 @@ | ||
| 1 | +package br.gov.frameworkdemoiselle.management; | ||
| 2 | + | ||
| 3 | +import br.gov.frameworkdemoiselle.DemoiselleException; | ||
| 4 | + | ||
| 5 | +/** | ||
| 6 | + * | ||
| 7 | + * Thrown when a management client tries to read or write a property, but the | ||
| 8 | + * management engine has no knowledge of an attribute with the given name. | ||
| 9 | + * | ||
| 10 | + * @author serpro | ||
| 11 | + * | ||
| 12 | + */ | ||
| 13 | +public class ManagedAttributeNotFoundException extends DemoiselleException { | ||
| 14 | + | ||
| 15 | + private static final long serialVersionUID = 2554101387574235418L; | ||
| 16 | + | ||
| 17 | + public ManagedAttributeNotFoundException(String message, Throwable cause) { | ||
| 18 | + super(message, cause); | ||
| 19 | + } | ||
| 20 | + | ||
| 21 | + public ManagedAttributeNotFoundException(String message) { | ||
| 22 | + super(message); | ||
| 23 | + } | ||
| 24 | + | ||
| 25 | + public ManagedAttributeNotFoundException(Throwable cause) { | ||
| 26 | + super(cause); | ||
| 27 | + } | ||
| 28 | + | ||
| 29 | +} |
impl/core/src/main/java/br/gov/frameworkdemoiselle/management/ManagedInvokationException.java
0 → 100644
| @@ -0,0 +1,23 @@ | @@ -0,0 +1,23 @@ | ||
| 1 | +package br.gov.frameworkdemoiselle.management; | ||
| 2 | + | ||
| 3 | +import br.gov.frameworkdemoiselle.DemoiselleException; | ||
| 4 | + | ||
| 5 | + | ||
| 6 | +public class ManagedInvokationException extends DemoiselleException { | ||
| 7 | + | ||
| 8 | + private static final long serialVersionUID = -1542365184737242152L; | ||
| 9 | + | ||
| 10 | + public ManagedInvokationException(String message, Throwable cause) { | ||
| 11 | + super(message, cause); | ||
| 12 | + } | ||
| 13 | + | ||
| 14 | + public ManagedInvokationException(String message) { | ||
| 15 | + super(message); | ||
| 16 | + } | ||
| 17 | + | ||
| 18 | + public ManagedInvokationException(Throwable cause) { | ||
| 19 | + super(cause); | ||
| 20 | + } | ||
| 21 | + | ||
| 22 | + | ||
| 23 | +} |
impl/extension/jmx/src/main/java/br/gov/frameworkdemoiselle/internal/DynamicMBeanProxy.java
| @@ -58,6 +58,8 @@ import br.gov.frameworkdemoiselle.internal.management.ManagedType.FieldDetail; | @@ -58,6 +58,8 @@ import br.gov.frameworkdemoiselle.internal.management.ManagedType.FieldDetail; | ||
| 58 | import br.gov.frameworkdemoiselle.internal.management.ManagedType.MethodDetail; | 58 | import br.gov.frameworkdemoiselle.internal.management.ManagedType.MethodDetail; |
| 59 | import br.gov.frameworkdemoiselle.internal.management.ManagedType.ParameterDetail; | 59 | import br.gov.frameworkdemoiselle.internal.management.ManagedType.ParameterDetail; |
| 60 | import br.gov.frameworkdemoiselle.internal.management.Management; | 60 | import br.gov.frameworkdemoiselle.internal.management.Management; |
| 61 | +import br.gov.frameworkdemoiselle.management.ManagedAttributeNotFoundException; | ||
| 62 | +import br.gov.frameworkdemoiselle.management.ManagedInvokationException; | ||
| 61 | import br.gov.frameworkdemoiselle.stereotype.ManagementController; | 63 | import br.gov.frameworkdemoiselle.stereotype.ManagementController; |
| 62 | import br.gov.frameworkdemoiselle.util.Beans; | 64 | import br.gov.frameworkdemoiselle.util.Beans; |
| 63 | import br.gov.frameworkdemoiselle.util.ResourceBundle; | 65 | import br.gov.frameworkdemoiselle.util.ResourceBundle; |
| @@ -95,7 +97,21 @@ public class DynamicMBeanProxy implements DynamicMBean { | @@ -95,7 +97,21 @@ public class DynamicMBeanProxy implements DynamicMBean { | ||
| 95 | } | 97 | } |
| 96 | 98 | ||
| 97 | Management manager = Beans.getReference(Management.class); | 99 | Management manager = Beans.getReference(Management.class); |
| 98 | - return manager.getProperty(managedType, attribute); | 100 | + |
| 101 | + try{ | ||
| 102 | + return manager.getProperty(managedType, attribute); | ||
| 103 | + } | ||
| 104 | + catch(DemoiselleException de){ | ||
| 105 | + if (ManagedAttributeNotFoundException.class.isInstance(de)){ | ||
| 106 | + throw new AttributeNotFoundException(de.getMessage()); | ||
| 107 | + } | ||
| 108 | + else if (ManagedInvokationException.class.isInstance(de)){ | ||
| 109 | + throw new MBeanException(new Exception(de.getMessage())); | ||
| 110 | + } | ||
| 111 | + else{ | ||
| 112 | + throw de; | ||
| 113 | + } | ||
| 114 | + } | ||
| 99 | } | 115 | } |
| 100 | 116 | ||
| 101 | @Override | 117 | @Override |
| @@ -108,7 +124,21 @@ public class DynamicMBeanProxy implements DynamicMBean { | @@ -108,7 +124,21 @@ public class DynamicMBeanProxy implements DynamicMBean { | ||
| 108 | } | 124 | } |
| 109 | 125 | ||
| 110 | Management manager = Beans.getReference(Management.class); | 126 | Management manager = Beans.getReference(Management.class); |
| 111 | - manager.setProperty(managedType, attribute.getName(), attribute.getValue()); | 127 | + |
| 128 | + try{ | ||
| 129 | + manager.setProperty(managedType, attribute.getName(), attribute.getValue()); | ||
| 130 | + } | ||
| 131 | + catch(DemoiselleException de){ | ||
| 132 | + if (ManagedAttributeNotFoundException.class.isInstance(de)){ | ||
| 133 | + throw new AttributeNotFoundException(de.getMessage()); | ||
| 134 | + } | ||
| 135 | + else if (ManagedInvokationException.class.isInstance(de)){ | ||
| 136 | + throw new MBeanException(new Exception(de.getMessage())); | ||
| 137 | + } | ||
| 138 | + else{ | ||
| 139 | + throw de; | ||
| 140 | + } | ||
| 141 | + } | ||
| 112 | } | 142 | } |
| 113 | 143 | ||
| 114 | @Override | 144 | @Override |
| @@ -161,7 +191,13 @@ public class DynamicMBeanProxy implements DynamicMBean { | @@ -161,7 +191,13 @@ public class DynamicMBeanProxy implements DynamicMBean { | ||
| 161 | } | 191 | } |
| 162 | 192 | ||
| 163 | Management manager = Beans.getReference(Management.class); | 193 | Management manager = Beans.getReference(Management.class); |
| 164 | - return manager.invoke(managedType, actionName, params); | 194 | + |
| 195 | + try{ | ||
| 196 | + return manager.invoke(managedType, actionName, params); | ||
| 197 | + } | ||
| 198 | + catch(DemoiselleException de){ | ||
| 199 | + throw new MBeanException(new Exception(de.getMessage())); | ||
| 200 | + } | ||
| 165 | } | 201 | } |
| 166 | 202 | ||
| 167 | /** | 203 | /** |
parent/bom/pom.xml
| @@ -107,7 +107,7 @@ | @@ -107,7 +107,7 @@ | ||
| 107 | <dependency> | 107 | <dependency> |
| 108 | <groupId>br.gov.frameworkdemoiselle</groupId> | 108 | <groupId>br.gov.frameworkdemoiselle</groupId> |
| 109 | <artifactId>demoiselle-jmx</artifactId> | 109 | <artifactId>demoiselle-jmx</artifactId> |
| 110 | - <version>2.4.0-BETA2-SNAPSHOT</version> | 110 | + <version>2.4.0-BETA4-SNAPSHOT</version> |
| 111 | </dependency> | 111 | </dependency> |
| 112 | <!-- | 112 | <!-- |
| 113 | <dependency> | 113 | <dependency> |