cxf-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From serg...@apache.org
Subject svn commit: r1212514 - in /cxf/branches/2.3.x-fixes: ./ rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/provider/ rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/utils/ rt/frontend/jaxrs/src/test/java/org/apache/cxf/jaxrs/provider/
Date Fri, 09 Dec 2011 16:53:51 GMT
Author: sergeyb
Date: Fri Dec  9 16:53:50 2011
New Revision: 1212514

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

................
  r1212512 | sergeyb | 2011-12-09 16:50:36 +0000 (Fri, 09 Dec 2011) | 9 lines
  
  Merged revisions 1212509 via svnmerge from 
  https://svn.apache.org/repos/asf/cxf/trunk
  
  ........
    r1212509 | sergeyb | 2011-12-09 16:46:16 +0000 (Fri, 09 Dec 2011) | 1 line
    
    [CXF-3966] Getting JAXB providers to throw 400 in case of read errors
  ........
................

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/main/java/org/apache/cxf/jaxrs/utils/InjectionUtils.java
    cxf/branches/2.3.x-fixes/rt/frontend/jaxrs/src/test/java/org/apache/cxf/jaxrs/provider/JAXBElementProviderTest.java

Propchange: cxf/branches/2.3.x-fixes/
------------------------------------------------------------------------------
--- svn:mergeinfo (added)
+++ svn:mergeinfo Fri Dec  9 16:53:50 2011
@@ -0,0 +1,2 @@
+/cxf/branches/2.4.x-fixes:1212512
+/cxf/trunk:1212509

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=1212514&r1=1212513&r2=1212514&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
Fri Dec  9 16:53:50 2011
@@ -539,7 +539,7 @@ public abstract class AbstractJAXBProvid
         return sw.toString();
     }
     
-    protected static void handleJAXBException(JAXBException e) {
+    protected static void handleJAXBException(JAXBException e, boolean read) {
         LOG.warning(getStackTrace(e));
         StringBuilder sb = new StringBuilder();
         if (e.getMessage() != null) {
@@ -555,7 +555,9 @@ 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 r = Response.status(Response.Status.INTERNAL_SERVER_ERROR)
+        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);
     }

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=1212514&r1=1212513&r2=1212514&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
Fri Dec  9 16:53:50 2011
@@ -157,7 +157,7 @@ public class JAXBElementProvider extends
             return response;
             
         } catch (JAXBException e) {
-            handleJAXBException(e);
+            handleJAXBException(e, true);
         } catch (WebApplicationException e) {
             throw e;
         } catch (Exception e) {
@@ -230,7 +230,7 @@ public class JAXBElementProvider extends
                 marshal(actualObject, actualClass, genericType, encoding, os, m);
             }
         } catch (JAXBException e) {
-            handleJAXBException(e);
+            handleJAXBException(e, true);
         }  catch (WebApplicationException e) {
             throw e;
         } catch (Exception e) {

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=1212514&r1=1212513&r2=1212514&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
Fri Dec  9 16:53:50 2011
@@ -212,7 +212,7 @@ public class JSONProvider extends Abstra
             return response;
             
         } catch (JAXBException e) {
-            handleJAXBException(e);
+            handleJAXBException(e, true);
         } catch (XMLStreamException e) {
             throw new WebApplicationException(e);
         } catch (WebApplicationException e) {
@@ -311,7 +311,7 @@ public class JSONProvider extends Abstra
             }
             
         } catch (JAXBException e) {
-            handleJAXBException(e);
+            handleJAXBException(e, false);
         } catch (XMLStreamException e) {
             throw new WebApplicationException(e);
         } catch (Exception e) {

Modified: cxf/branches/2.3.x-fixes/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/utils/InjectionUtils.java
URL: http://svn.apache.org/viewvc/cxf/branches/2.3.x-fixes/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/utils/InjectionUtils.java?rev=1212514&r1=1212513&r2=1212514&view=diff
==============================================================================
--- cxf/branches/2.3.x-fixes/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/utils/InjectionUtils.java
(original)
+++ cxf/branches/2.3.x-fixes/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/utils/InjectionUtils.java
Fri Dec  9 16:53:50 2011
@@ -305,10 +305,11 @@ public final class InjectionUtils {
                 return PrimitiveUtils.read(value, pClass);
             } catch (NumberFormatException nfe) {
                 //
-                //  For a path parameter this is probably a 404,
-                //  for others a 400...
+                //  For path, query & matrix parameters this is 404,
+                //  for others 400...
                 //
-                if (pType == ParameterType.PATH) {
+                if (pType == ParameterType.PATH || pType == ParameterType.QUERY
+                    || pType == ParameterType.MATRIX) {
                     throw new WebApplicationException(nfe, Response.Status.NOT_FOUND);
                 }
                 throw new WebApplicationException(nfe, Response.Status.BAD_REQUEST);

Modified: cxf/branches/2.3.x-fixes/rt/frontend/jaxrs/src/test/java/org/apache/cxf/jaxrs/provider/JAXBElementProviderTest.java
URL: http://svn.apache.org/viewvc/cxf/branches/2.3.x-fixes/rt/frontend/jaxrs/src/test/java/org/apache/cxf/jaxrs/provider/JAXBElementProviderTest.java?rev=1212514&r1=1212513&r2=1212514&view=diff
==============================================================================
--- cxf/branches/2.3.x-fixes/rt/frontend/jaxrs/src/test/java/org/apache/cxf/jaxrs/provider/JAXBElementProviderTest.java
(original)
+++ cxf/branches/2.3.x-fixes/rt/frontend/jaxrs/src/test/java/org/apache/cxf/jaxrs/provider/JAXBElementProviderTest.java
Fri Dec  9 16:53:50 2011
@@ -41,6 +41,7 @@ import java.util.TreeSet;
 
 import javax.ws.rs.GET;
 import javax.ws.rs.Path;
+import javax.ws.rs.WebApplicationException;
 import javax.ws.rs.core.MediaType;
 import javax.ws.rs.core.Response;
 import javax.xml.bind.JAXBContext;
@@ -441,7 +442,7 @@ public class JAXBElementProviderTest ext
                          new MetadataMap<String, Object>(), bos);
         assertTrue(bos.toString().contains("thebook2"));
         assertTrue(bos.toString().contains("http://superbooks"));
-        
+        System.out.println(bos.toString());
         ByteArrayInputStream is = new ByteArrayInputStream(bos.toByteArray());
         Book2 book2 = 
             (Book2)provider.readFrom(
@@ -993,6 +994,20 @@ public class JAXBElementProviderTest ext
         doReadUnqualifiedCollection(data, "setBooks", List.class);
     }
     
+    @Test
+    @SuppressWarnings("unchecked")
+    public void testReadMalformedXML() throws Exception {
+        JAXBElementProvider provider = new JAXBElementProvider();
+        try {
+            provider.readFrom((Class)Book.class, Book.class,
+                       new Annotation[0], MediaType.TEXT_XML_TYPE, new MetadataMap<String,
String>(), 
+                       new ByteArrayInputStream("<Book>".getBytes()));
+            fail("404 is expected");
+        } catch (WebApplicationException ex) {
+            assertEquals(400, ex.getResponse().getStatus());
+        }
+    }
+    
     @SuppressWarnings("unchecked")
     private void doReadUnqualifiedCollection(String data, String mName, Class<?> type)
throws Exception {
         JAXBElementProvider provider = new JAXBElementProvider();



Mime
View raw message