cxf-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From serg...@apache.org
Subject svn commit: r1333440 - in /cxf/branches/2.3.x-fixes: ./ rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/provider/ rt/frontend/jaxrs/src/test/java/org/apache/cxf/jaxrs/provider/
Date Thu, 03 May 2012 12:55:44 GMT
Author: sergeyb
Date: Thu May  3 12:55:44 2012
New Revision: 1333440

URL: http://svn.apache.org/viewvc?rev=1333440&view=rev
Log:
Merged revisions 1333428 via svnmerge from 
https://svn.apache.org/repos/asf/cxf/branches/2.4.x-fixes

................
  r1333428 | sergeyb | 2012-05-03 13:37:16 +0100 (Thu, 03 May 2012) | 27 lines
  
  Merged revisions 1333414,1333417 via svnmerge from 
  https://svn.apache.org/repos/asf/cxf/branches/2.5.x-fixes
  
  ................
    r1333414 | sergeyb | 2012-05-03 13:01:55 +0100 (Thu, 03 May 2012) | 9 lines
    
    Merged revisions 1333086 via svnmerge from 
    https://svn.apache.org/repos/asf/cxf/trunk
    
    ........
      r1333086 | sergeyb | 2012-05-02 16:54:05 +0100 (Wed, 02 May 2012) | 1 line
      
      [CXF-4284] Updates to JAXB-based providers to get 400 reported in case of various read
errors
    ........
  ................
    r1333417 | sergeyb | 2012-05-03 13:11:49 +0100 (Thu, 03 May 2012) | 9 lines
    
    Merged revisions 1333400 via svnmerge from 
    https://svn.apache.org/repos/asf/cxf/trunk
    
    ........
      r1333400 | sergeyb | 2012-05-03 11:29:10 +0100 (Thu, 03 May 2012) | 1 line
      
      [CXF-4284] Applying few more updates from Govindaram PS
    ........
  ................
................

Modified:
    cxf/branches/2.3.x-fixes/   (props changed)
    cxf/branches/2.3.x-fixes/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/provider/AbstractJAXBProvider.java
    cxf/branches/2.3.x-fixes/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/provider/JAXBElementProvider.java
    cxf/branches/2.3.x-fixes/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/provider/JSONProvider.java
    cxf/branches/2.3.x-fixes/rt/frontend/jaxrs/src/test/java/org/apache/cxf/jaxrs/provider/JSONProviderTest.java

Propchange: cxf/branches/2.3.x-fixes/
------------------------------------------------------------------------------
--- svn:mergeinfo (added)
+++ svn:mergeinfo Thu May  3 12:55:44 2012
@@ -0,0 +1,3 @@
+/cxf/branches/2.4.x-fixes:1333428
+/cxf/branches/2.5.x-fixes:1333414-1333417
+/cxf/trunk:1333086,1333400

Propchange: cxf/branches/2.3.x-fixes/
------------------------------------------------------------------------------
Binary property 'svnmerge-integrated' - no diff available.

Modified: cxf/branches/2.3.x-fixes/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/provider/AbstractJAXBProvider.java
URL: http://svn.apache.org/viewvc/cxf/branches/2.3.x-fixes/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/provider/AbstractJAXBProvider.java?rev=1333440&r1=1333439&r2=1333440&view=diff
==============================================================================
--- cxf/branches/2.3.x-fixes/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/provider/AbstractJAXBProvider.java
(original)
+++ cxf/branches/2.3.x-fixes/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/provider/AbstractJAXBProvider.java
Thu May  3 12:55:44 2012
@@ -536,8 +536,8 @@ public abstract class AbstractJAXBProvid
         ex.printStackTrace(new PrintWriter(sw));
         return sw.toString();
     }
-    
-    protected static void handleJAXBException(JAXBException e, boolean read) {
+    //TODO: move these methods into the dedicated utility class
+    protected static StringBuilder handleExceptionStart(Exception e) {
         LOG.warning(getStackTrace(e));
         StringBuilder sb = new StringBuilder();
         if (e.getMessage() != null) {
@@ -546,6 +546,19 @@ public abstract class AbstractJAXBProvid
         if (e.getCause() != null && e.getCause().getMessage() != null) {
             sb.append(e.getCause().getMessage()).append(". ");
         }
+        return sb;
+    }
+    
+    protected static void handleExceptionEnd(Throwable t, String message, boolean read) {
+        Response.Status status = read 
+            ? Response.Status.BAD_REQUEST : Response.Status.INTERNAL_SERVER_ERROR; 
+        Response r = Response.status(status)
+            .type(MediaType.TEXT_PLAIN).entity(message).build();
+        throw new WebApplicationException(t, r);
+    }
+    
+    protected static void handleJAXBException(JAXBException e, boolean read) {
+        StringBuilder sb = handleExceptionStart(e);
         if (e.getLinkedException() != null && e.getLinkedException().getMessage()
!= null) {
             sb.append(e.getLinkedException().getMessage()).append(". ");
         }
@@ -553,11 +566,12 @@ public abstract class AbstractJAXBProvid
             ? e.getLinkedException() : e.getCause() != null ? e.getCause() : e;
         String message = new org.apache.cxf.common.i18n.Message("JAXB_EXCEPTION", 
                              BUNDLE, sb.toString()).toString();
-        Response.Status status = read 
-            ? Response.Status.BAD_REQUEST : Response.Status.INTERNAL_SERVER_ERROR; 
-        Response r = Response.status(status)
-            .type(MediaType.TEXT_PLAIN).entity(message).build();
-        throw new WebApplicationException(t, r);
+        handleExceptionEnd(t, message, read);
+    }
+    
+    protected static void handleXMLStreamException(XMLStreamException e, boolean read) {
+        StringBuilder sb = handleExceptionStart(e);
+        handleExceptionEnd(e, sb.toString(), read);
     }
     
     public void setOutTransformElements(Map<String, String> outElements) {

Modified: cxf/branches/2.3.x-fixes/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/provider/JAXBElementProvider.java
URL: http://svn.apache.org/viewvc/cxf/branches/2.3.x-fixes/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/provider/JAXBElementProvider.java?rev=1333440&r1=1333439&r2=1333440&view=diff
==============================================================================
--- cxf/branches/2.3.x-fixes/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/provider/JAXBElementProvider.java
(original)
+++ cxf/branches/2.3.x-fixes/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/provider/JAXBElementProvider.java
Thu May  3 12:55:44 2012
@@ -173,7 +173,7 @@ public class JAXBElementProvider extends
             throw e;
         } catch (Exception e) {
             LOG.warning(getStackTrace(e));
-            throw new WebApplicationException(e);        
+            throw new WebApplicationException(e, Response.status(400).build());        
         }
         // unreachable
         return null;

Modified: cxf/branches/2.3.x-fixes/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/provider/JSONProvider.java
URL: http://svn.apache.org/viewvc/cxf/branches/2.3.x-fixes/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/provider/JSONProvider.java?rev=1333440&r1=1333439&r2=1333440&view=diff
==============================================================================
--- cxf/branches/2.3.x-fixes/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/provider/JSONProvider.java
(original)
+++ cxf/branches/2.3.x-fixes/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/provider/JSONProvider.java
Thu May  3 12:55:44 2012
@@ -41,6 +41,7 @@ import javax.ws.rs.WebApplicationExcepti
 import javax.ws.rs.core.Context;
 import javax.ws.rs.core.MediaType;
 import javax.ws.rs.core.MultivaluedMap;
+import javax.ws.rs.core.Response;
 import javax.ws.rs.ext.Provider;
 import javax.xml.bind.JAXBElement;
 import javax.xml.bind.JAXBException;
@@ -217,11 +218,11 @@ public class JSONProvider extends Abstra
         } catch (DepthExceededStaxException e) {
             throw new WebApplicationException(413);
         } catch (XMLStreamException e) {
-            throw new WebApplicationException(e);
+            handleXMLStreamException(e, true); 
         } catch (WebApplicationException e) {
             throw e;
         } catch (Exception e) {
-            throw new WebApplicationException(e);
+            throw new WebApplicationException(e, Response.status(400).build());
         }
         // unreachable
         return null;
@@ -319,7 +320,7 @@ public class JSONProvider extends Abstra
         } catch (JAXBException e) {
             handleJAXBException(e, false);
         } catch (XMLStreamException e) {
-            throw new WebApplicationException(e);
+            handleXMLStreamException(e, false); 
         } catch (Exception e) {
             throw new WebApplicationException(e);
         }

Modified: cxf/branches/2.3.x-fixes/rt/frontend/jaxrs/src/test/java/org/apache/cxf/jaxrs/provider/JSONProviderTest.java
URL: http://svn.apache.org/viewvc/cxf/branches/2.3.x-fixes/rt/frontend/jaxrs/src/test/java/org/apache/cxf/jaxrs/provider/JSONProviderTest.java?rev=1333440&r1=1333439&r2=1333440&view=diff
==============================================================================
--- cxf/branches/2.3.x-fixes/rt/frontend/jaxrs/src/test/java/org/apache/cxf/jaxrs/provider/JSONProviderTest.java
(original)
+++ cxf/branches/2.3.x-fixes/rt/frontend/jaxrs/src/test/java/org/apache/cxf/jaxrs/provider/JSONProviderTest.java
Thu May  3 12:55:44 2012
@@ -35,7 +35,9 @@ import java.util.Map;
 import java.util.Set;
 import java.util.TreeSet;
 
+import javax.ws.rs.WebApplicationException; 
 import javax.ws.rs.core.MediaType;
+import javax.ws.rs.core.Response;
 import javax.ws.rs.ext.MessageBodyReader;
 import javax.xml.bind.JAXBContext;
 import javax.xml.bind.JAXBElement;
@@ -67,6 +69,21 @@ import org.junit.Test;
 
 public class JSONProviderTest extends Assert {
 
+    @Test
+    @SuppressWarnings("unchecked")
+    public void testReadMalformedJson() throws Exception {
+        MessageBodyReader<?> p = new JSONProvider();
+        byte[] bytes = "junk".getBytes();
+         
+        try {
+            p.readFrom((Class)Tags.class, null, null, 
+                                           null, null, new ByteArrayInputStream(bytes));
+            fail("404 is expected");
+        } catch (WebApplicationException ex) {
+            assertEquals(Response.Status.BAD_REQUEST.getStatusCode(), ex.getResponse().getStatus());
+        }
+    }
+
     @SuppressWarnings("unchecked")
     @Test
     public void testReadEmbeddedArray() throws Exception {



Mime
View raw message