Author: sergeyb
Date: Wed Nov  6 12:37:51 2013
New Revision: 1539324

URL: http://svn.apache.org/r1539324
Log:
[CXF-5309] Fixing JAX-RS ExceptionMapper, patch from Andriy Redko applied

Added:
    
cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/validation/ValidationExceptionMapper.java
   (with props)
Removed:
    
cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/validation/ConstraintViolationExceptionMapper.java
Modified:
    
cxf/trunk/systests/jaxrs/src/test/java/org/apache/cxf/systest/jaxrs/validation/JAXRSClientServerValidationTest.java

Added: 
cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/validation/ValidationExceptionMapper.java
URL: 
http://svn.apache.org/viewvc/cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/validation/ValidationExceptionMapper.java?rev=1539324&view=auto
==============================================================================
--- 
cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/validation/ValidationExceptionMapper.java
 (added)
+++ 
cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/validation/ValidationExceptionMapper.java
 Wed Nov  6 12:37:51 2013
@@ -0,0 +1,59 @@
+/**
+ * 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 implements ExceptionMapper< 
ValidationException > {
+    private static final Logger LOG = 
LogUtils.getL7dLogger(ValidationExceptionMapper.class);
+    
+    @Override
+    public Response toResponse(ValidationException exception) {
+        if (exception instanceof ConstraintViolationException) { 
+            final ConstraintViolationException constraint = 
(ConstraintViolationException) exception;
+            
+            for (final ConstraintViolation< ? > violation: 
constraint.getConstraintViolations()) {
+                LOG.log(Level.SEVERE, 
+                    violation.getRootBeanClass().getSimpleName() 
+                    + "." + violation.getPropertyPath() 
+                    + ": " + violation.getMessage());
+            }
+            
+            if (constraint instanceof ResponseConstraintViolationException) {
+                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();
+        }
+    }
+}

Propchange: 
cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/validation/ValidationExceptionMapper.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: 
cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/validation/ValidationExceptionMapper.java
------------------------------------------------------------------------------
    svn:keywords = Rev Date

Modified: 
cxf/trunk/systests/jaxrs/src/test/java/org/apache/cxf/systest/jaxrs/validation/JAXRSClientServerValidationTest.java
URL: 
http://svn.apache.org/viewvc/cxf/trunk/systests/jaxrs/src/test/java/org/apache/cxf/systest/jaxrs/validation/JAXRSClientServerValidationTest.java?rev=1539324&r1=1539323&r2=1539324&view=diff
==============================================================================
--- 
cxf/trunk/systests/jaxrs/src/test/java/org/apache/cxf/systest/jaxrs/validation/JAXRSClientServerValidationTest.java
 (original)
+++ 
cxf/trunk/systests/jaxrs/src/test/java/org/apache/cxf/systest/jaxrs/validation/JAXRSClientServerValidationTest.java
 Wed Nov  6 12:37:51 2013
@@ -31,9 +31,9 @@ import org.apache.cxf.jaxrs.client.WebCl
 import org.apache.cxf.jaxrs.interceptor.JAXRSOutExceptionMapperInterceptor;
 import org.apache.cxf.jaxrs.lifecycle.SingletonResourceProvider;
 import org.apache.cxf.jaxrs.model.AbstractResourceInfo;
-import org.apache.cxf.jaxrs.validation.ConstraintViolationExceptionMapper;
 import org.apache.cxf.jaxrs.validation.JAXRSValidationInInterceptor;
 import org.apache.cxf.jaxrs.validation.JAXRSValidationOutInterceptor;
+import org.apache.cxf.jaxrs.validation.ValidationExceptionMapper;
 import org.apache.cxf.message.Message;
 import org.apache.cxf.testutil.common.AbstractBusClientServerTestBase;
 import org.apache.cxf.testutil.common.AbstractBusTestServerBase;
@@ -55,7 +55,7 @@ public class JAXRSClientServerValidation
             sf.setResourceClasses(BookStoreWithValidation.class);
             sf.setResourceProvider(BookStoreWithValidation.class, 
                 new SingletonResourceProvider(new BookStoreWithValidation()));
-            sf.setProvider(new ConstraintViolationExceptionMapper());
+            sf.setProvider(new ValidationExceptionMapper());
 
             sf.setAddress("http://localhost:"; + PORT + "/");
             sf.setInInterceptors(Arrays.< Interceptor< ? extends Message > 
>asList(


Reply via email to