Return-Path: X-Original-To: apmail-cxf-commits-archive@www.apache.org Delivered-To: apmail-cxf-commits-archive@www.apache.org Received: from mail.apache.org (hermes.apache.org [140.211.11.3]) by minotaur.apache.org (Postfix) with SMTP id 64CE87069 for ; Fri, 9 Dec 2011 16:54:17 +0000 (UTC) Received: (qmail 79036 invoked by uid 500); 9 Dec 2011 16:54:17 -0000 Delivered-To: apmail-cxf-commits-archive@cxf.apache.org Received: (qmail 78984 invoked by uid 500); 9 Dec 2011 16:54:17 -0000 Mailing-List: contact commits-help@cxf.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: dev@cxf.apache.org Delivered-To: mailing list commits@cxf.apache.org Received: (qmail 78977 invoked by uid 99); 9 Dec 2011 16:54:17 -0000 Received: from nike.apache.org (HELO nike.apache.org) (192.87.106.230) by apache.org (qpsmtpd/0.29) with ESMTP; Fri, 09 Dec 2011 16:54:17 +0000 X-ASF-Spam-Status: No, hits=-2000.0 required=5.0 tests=ALL_TRUSTED X-Spam-Check-By: apache.org Received: from [140.211.11.4] (HELO eris.apache.org) (140.211.11.4) by apache.org (qpsmtpd/0.29) with ESMTP; Fri, 09 Dec 2011 16:54:13 +0000 Received: from eris.apache.org (localhost [127.0.0.1]) by eris.apache.org (Postfix) with ESMTP id D17AB238897F for ; Fri, 9 Dec 2011 16:53:51 +0000 (UTC) Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit 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 -0000 To: commits@cxf.apache.org From: sergeyb@apache.org X-Mailer: svnmailer-1.0.8-patched Message-Id: <20111209165351.D17AB238897F@eris.apache.org> X-Virus-Checked: Checked by ClamAV on apache.org 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(), 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(), + new ByteArrayInputStream("".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();