cxf-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From serg...@apache.org
Subject git commit: [CXF-5966] Fixing NPE
Date Fri, 22 Aug 2014 13:32:57 GMT
Repository: cxf
Updated Branches:
  refs/heads/3.0.x-fixes 0b53d75ce -> 1aac5314c


[CXF-5966] Fixing NPE


Project: http://git-wip-us.apache.org/repos/asf/cxf/repo
Commit: http://git-wip-us.apache.org/repos/asf/cxf/commit/1aac5314
Tree: http://git-wip-us.apache.org/repos/asf/cxf/tree/1aac5314
Diff: http://git-wip-us.apache.org/repos/asf/cxf/diff/1aac5314

Branch: refs/heads/3.0.x-fixes
Commit: 1aac5314c181a025b6d549b644a82082a615a571
Parents: 0b53d75
Author: Sergey Beryozkin <sberyozkin@talend.com>
Authored: Fri Aug 22 14:31:36 2014 +0100
Committer: Sergey Beryozkin <sberyozkin@talend.com>
Committed: Fri Aug 22 14:32:38 2014 +0100

----------------------------------------------------------------------
 .../JAXRSDefaultFaultOutInterceptor.java          |  3 +++
 .../validation/ValidationExceptionMapper.java     | 18 +++++++-----------
 .../JAXRSClientServerValidationTest.java          | 12 +++++++++++-
 3 files changed, 21 insertions(+), 12 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/cxf/blob/1aac5314/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/interceptor/JAXRSDefaultFaultOutInterceptor.java
----------------------------------------------------------------------
diff --git a/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/interceptor/JAXRSDefaultFaultOutInterceptor.java
b/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/interceptor/JAXRSDefaultFaultOutInterceptor.java
index dbb7d86..c2b5309 100644
--- a/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/interceptor/JAXRSDefaultFaultOutInterceptor.java
+++ b/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/interceptor/JAXRSDefaultFaultOutInterceptor.java
@@ -58,6 +58,9 @@ public class JAXRSDefaultFaultOutInterceptor extends AbstractOutDatabindingInter
         if (r != null) {
             JAXRSUtils.setMessageContentType(message, r);
             message.setContent(List.class, new MessageContentsList(r));
+            if (message.getExchange().getOutMessage() == null && message.getExchange().getOutFaultMessage()
!= null) {
+                message.getExchange().setOutMessage(message.getExchange().getOutFaultMessage());
+            }
             new JAXRSOutInterceptor().handleMessage(message);
             return;
         }

http://git-wip-us.apache.org/repos/asf/cxf/blob/1aac5314/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/validation/ValidationExceptionMapper.java
----------------------------------------------------------------------
diff --git a/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/validation/ValidationExceptionMapper.java
b/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/validation/ValidationExceptionMapper.java
index c1cbd32..b15ad0b 100644
--- a/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/validation/ValidationExceptionMapper.java
+++ b/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/validation/ValidationExceptionMapper.java
@@ -29,6 +29,7 @@ import javax.ws.rs.ext.ExceptionMapper;
 import javax.ws.rs.ext.Provider;
 
 import org.apache.cxf.common.logging.LogUtils;
+import org.apache.cxf.jaxrs.utils.JAXRSUtils;
 import org.apache.cxf.validation.ResponseConstraintViolationException;
 
 @Provider
@@ -37,11 +38,11 @@ public class ValidationExceptionMapper implements ExceptionMapper<
ValidationExc
     
     @Override
     public Response toResponse(ValidationException exception) {
+        Response.Status errorStatus = Response.Status.INTERNAL_SERVER_ERROR;
         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() 
@@ -49,15 +50,10 @@ public class ValidationExceptionMapper implements ExceptionMapper<
ValidationExc
                     + ": " + violation.getMessage());
             }
             
-            if (isResponseException) {
-                return Response.status(Response.Status.INTERNAL_SERVER_ERROR).build();
+            if (!(constraint instanceof ResponseConstraintViolationException)) {
+                errorStatus = Response.Status.BAD_REQUEST;
             }
-            
-            return Response.status(Response.Status.BAD_REQUEST).build();
-        } else {
-            return Response.status(Response.Status.INTERNAL_SERVER_ERROR).build();
-        }
-        
-        
+        } 
+        return JAXRSUtils.toResponse(errorStatus);
     }
 }

http://git-wip-us.apache.org/repos/asf/cxf/blob/1aac5314/systests/jaxrs/src/test/java/org/apache/cxf/systest/jaxrs/validation/JAXRSClientServerValidationTest.java
----------------------------------------------------------------------
diff --git a/systests/jaxrs/src/test/java/org/apache/cxf/systest/jaxrs/validation/JAXRSClientServerValidationTest.java
b/systests/jaxrs/src/test/java/org/apache/cxf/systest/jaxrs/validation/JAXRSClientServerValidationTest.java
index 50e0154..104f2f6 100644
--- a/systests/jaxrs/src/test/java/org/apache/cxf/systest/jaxrs/validation/JAXRSClientServerValidationTest.java
+++ b/systests/jaxrs/src/test/java/org/apache/cxf/systest/jaxrs/validation/JAXRSClientServerValidationTest.java
@@ -21,6 +21,7 @@ package org.apache.cxf.systest.jaxrs.validation;
 import java.util.Arrays;
 import java.util.Collections;
 
+import javax.validation.ValidationException;
 import javax.ws.rs.core.Form;
 import javax.ws.rs.core.MediaType;
 import javax.ws.rs.core.Response;
@@ -30,11 +31,13 @@ import org.apache.cxf.interceptor.Interceptor;
 import org.apache.cxf.jaxrs.JAXRSServerFactoryBean;
 import org.apache.cxf.jaxrs.lifecycle.SingletonResourceProvider;
 import org.apache.cxf.jaxrs.model.AbstractResourceInfo;
+import org.apache.cxf.jaxrs.utils.JAXRSUtils;
 import org.apache.cxf.jaxrs.validation.JAXRSBeanValidationInInterceptor;
 import org.apache.cxf.jaxrs.validation.JAXRSBeanValidationOutInterceptor;
 import org.apache.cxf.jaxrs.validation.JAXRSParameterNameProvider;
 import org.apache.cxf.jaxrs.validation.ValidationExceptionMapper;
 import org.apache.cxf.message.Message;
+import org.apache.cxf.systest.jaxrs.Book;
 import org.apache.cxf.testutil.common.AbstractBusTestServerBase;
 import org.apache.cxf.validation.BeanValidationInInterceptor;
 import org.apache.cxf.validation.BeanValidationProvider;
@@ -55,7 +58,14 @@ public class JAXRSClientServerValidationTest extends AbstractJAXRSValidationTest
             sf.setResourceClasses(BookStoreWithValidation.class);
             sf.setResourceProvider(BookStoreWithValidation.class, 
                 new SingletonResourceProvider(new BookStoreWithValidation()));
-            sf.setProvider(new ValidationExceptionMapper());
+            sf.setProvider(new ValidationExceptionMapper() {
+                @Override
+                public Response toResponse(ValidationException exception) {
+                    Response r = super.toResponse(exception);
+                    return JAXRSUtils.toResponseBuilder(
+                        r.getStatus()).type("application/xml").entity(new Book("Validation",
123L)).build();
+                }
+            });
 
             sf.setAddress("http://localhost:" + PORT + "/");
             BeanValidationInInterceptor in = new JAXRSBeanValidationInInterceptor();


Mime
View raw message