Author: rmannibucau
Date: Thu Nov 21 17:47:45 2013
New Revision: 1544261
URL: http://svn.apache.org/r1544261
Log:
few cast/hypothesis fixes thanks to cxf
Added:
bval/branches/bval-11/bval-tck11/src/main/java/org/apache/cxf/
bval/branches/bval-11/bval-tck11/src/main/java/org/apache/cxf/jaxrs/
bval/branches/bval-11/bval-tck11/src/main/java/org/apache/cxf/jaxrs/validation/
bval/branches/bval-11/bval-tck11/src/main/java/org/apache/cxf/jaxrs/validation/ValidationExceptionMapper.java
Modified:
bval/branches/bval-11/bval-jsr/src/main/java/org/apache/bval/jsr/BeanDescriptorImpl.java
bval/branches/bval-11/bval-jsr/src/main/java/org/apache/bval/jsr/ClassValidator.java
Modified:
bval/branches/bval-11/bval-jsr/src/main/java/org/apache/bval/jsr/BeanDescriptorImpl.java
URL:
http://svn.apache.org/viewvc/bval/branches/bval-11/bval-jsr/src/main/java/org/apache/bval/jsr/BeanDescriptorImpl.java?rev=1544261&r1=1544260&r2=1544261&view=diff
==============================================================================
---
bval/branches/bval-11/bval-jsr/src/main/java/org/apache/bval/jsr/BeanDescriptorImpl.java
(original)
+++
bval/branches/bval-11/bval-jsr/src/main/java/org/apache/bval/jsr/BeanDescriptorImpl.java
Thu Nov 21 17:47:45 2013
@@ -236,6 +236,13 @@ public class BeanDescriptorImpl extends
return Collections.unmodifiableSet(validatedProperties);
}
+ public MethodDescriptor getInternalConstraintsForMethod(final String
methodName, final Class<?>... parameterTypes) {
+ if (methodName == null) {
+ throw new IllegalArgumentException("Method name can't be null");
+ }
+ return meta.methodConstraints.get(methodName +
Arrays.toString(parameterTypes));
+ }
+
public MethodDescriptor getConstraintsForMethod(final String methodName,
final Class<?>... parameterTypes) {
if (methodName == null) {
throw new IllegalArgumentException("Method name can't be null");
@@ -823,10 +830,13 @@ public class BeanDescriptorImpl extends
*/
final ConstraintAnnotationAttributes.Worker<? extends
Annotation> worker =
ConstraintAnnotationAttributes.VALUE.analyze(annotation.annotationType());
if (worker.isValid()) {
- Annotation[] children =
Annotation[].class.cast(worker.read(annotation));
- if (children != null) {
- for (Annotation child : children) {
- processAnnotation(child, desc, access,
validations); // recursion
+ final Object value = worker.read(annotation);
+ if (Annotation[].class.isInstance(value)) {
+ final Annotation[] children =
Annotation[].class.cast(value);
+ if (children != null) {
+ for (Annotation child : children) {
+ processAnnotation(child, desc, access,
validations); // recursion
+ }
}
}
}
Modified:
bval/branches/bval-11/bval-jsr/src/main/java/org/apache/bval/jsr/ClassValidator.java
URL:
http://svn.apache.org/viewvc/bval/branches/bval-11/bval-jsr/src/main/java/org/apache/bval/jsr/ClassValidator.java?rev=1544261&r1=1544260&r2=1544261&view=diff
==============================================================================
---
bval/branches/bval-11/bval-jsr/src/main/java/org/apache/bval/jsr/ClassValidator.java
(original)
+++
bval/branches/bval-11/bval-jsr/src/main/java/org/apache/bval/jsr/ClassValidator.java
Thu Nov 21 17:47:45 2013
@@ -1064,7 +1064,7 @@ public class ClassValidator implements C
}
final MethodDescriptorImpl methodDescriptor =
findMethodDescriptor(object, method);
- if (methodDescriptor == null) { // no constraint
+ if (methodDescriptor == null ||
!(methodDescriptor.hasConstrainedParameters() ||
methodDescriptor.hasConstrainedReturnValue())) { // no constraint
return Collections.emptySet();
}
@@ -1110,7 +1110,9 @@ public class ClassValidator implements C
private <T> MethodDescriptorImpl findMethodDescriptor(final T object,
final Method method) {
// return
MethodDescriptorImpl.class.cast(getConstraintsForClass(Proxies.classFor(object.getClass())).getConstraintsForMethod(method.getName(),
method.getParameterTypes()));
- return
MethodDescriptorImpl.class.cast(getConstraintsForClass(Proxies.classFor(method.getDeclaringClass())).getConstraintsForMethod(method.getName(),
method.getParameterTypes()));
+ return MethodDescriptorImpl.class.cast(
+
BeanDescriptorImpl.class.cast(getConstraintsForClass(Proxies.classFor(method.getDeclaringClass())))
+ .getInternalConstraintsForMethod(method.getName(),
method.getParameterTypes()));
}
private <T> void initMetaBean(final GroupValidationContext<T> context,
final MetaBeanFinder metaBeanFinder, final Class<?> directValueClass) {
Added:
bval/branches/bval-11/bval-tck11/src/main/java/org/apache/cxf/jaxrs/validation/ValidationExceptionMapper.java
URL:
http://svn.apache.org/viewvc/bval/branches/bval-11/bval-tck11/src/main/java/org/apache/cxf/jaxrs/validation/ValidationExceptionMapper.java?rev=1544261&view=auto
==============================================================================
---
bval/branches/bval-11/bval-tck11/src/main/java/org/apache/cxf/jaxrs/validation/ValidationExceptionMapper.java
(added)
+++
bval/branches/bval-11/bval-tck11/src/main/java/org/apache/cxf/jaxrs/validation/ValidationExceptionMapper.java
Thu Nov 21 17:47:45 2013
@@ -0,0 +1,63 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.cxf.jaxrs.validation;
+
+import java.util.logging.Level;
+import java.util.logging.Logger;
+
+import javax.validation.ConstraintViolation;
+import javax.validation.ConstraintViolationException;
+import javax.validation.ValidationException;
+/*import javax.ws.rs.core.Response;
+import javax.ws.rs.ext.ExceptionMapper;
+import javax.ws.rs.ext.Provider;
+
+import org.apache.cxf.common.logging.LogUtils;
+import org.apache.cxf.validation.ResponseConstraintViolationException;*/
+
+//@Provider
+public class ValidationExceptionMapper {
+
+
+ //@Override
+ public String toResponse(ValidationException exception) {
+ //if (exception instanceof ConstraintViolationException) {
+
+ /*final ConstraintViolationException constraint =
(ConstraintViolationException) exception;
+ final boolean isResponseException = constraint instanceof
ResponseConstraintViolationException;
+
+ for (final ConstraintViolation< ? > violation:
constraint.getConstraintViolations()) {
+ LOG.log(Level.WARNING,
+ violation.getRootBeanClass().getSimpleName()
+ + "." + violation.getPropertyPath()
+ + ": " + violation.getMessage());
+ }
+
+ if (isResponseException) {
+ return
Response.status(Response.Status.INTERNAL_SERVER_ERROR).build();
+ }
+
+ return Response.status(Response.Status.BAD_REQUEST).build();
+ } else {
+ return
Response.status(Response.Status.INTERNAL_SERVER_ERROR).build();
+ }*/return "";
+
+
+ }
+}