You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@cxf.apache.org by se...@apache.org on 2011/05/18 20:03:23 UTC

svn commit: r1124357 - in /cxf/trunk: rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/utils/JAXRSUtils.java systests/jaxrs/src/test/java/org/apache/cxf/systest/jaxrs/JAXRSClientServerBookTest.java

Author: sergeyb
Date: Wed May 18 18:03:23 2011
New Revision: 1124357

URL: http://svn.apache.org/viewvc?rev=1124357&view=rev
Log:
[CXF-3531] Returning 415 in case of malformed Content-Types

Modified:
    cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/utils/JAXRSUtils.java
    cxf/trunk/systests/jaxrs/src/test/java/org/apache/cxf/systest/jaxrs/JAXRSClientServerBookTest.java

Modified: cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/utils/JAXRSUtils.java
URL: http://svn.apache.org/viewvc/cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/utils/JAXRSUtils.java?rev=1124357&r1=1124356&r2=1124357&view=diff
==============================================================================
--- cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/utils/JAXRSUtils.java (original)
+++ cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/utils/JAXRSUtils.java Wed May 18 18:03:23 2011
@@ -303,9 +303,14 @@ public final class JAXRSUtils {
             new TreeMap<OperationResourceInfo, MultivaluedMap<String, String>>(
                 new OperationResourceInfoComparator(message, httpMethod));
 
-        MediaType requestType = requestContentType == null 
+        MediaType requestType;
+        try {
+            requestType = requestContentType == null
                                 ? ALL_TYPES : MediaType.valueOf(requestContentType);
-        
+        } catch (IllegalArgumentException ex) {
+            throw new WebApplicationException(ex, 415);
+        }
+
         int pathMatched = 0;
         int methodMatched = 0;
         int consumeMatched = 0;

Modified: cxf/trunk/systests/jaxrs/src/test/java/org/apache/cxf/systest/jaxrs/JAXRSClientServerBookTest.java
URL: http://svn.apache.org/viewvc/cxf/trunk/systests/jaxrs/src/test/java/org/apache/cxf/systest/jaxrs/JAXRSClientServerBookTest.java?rev=1124357&r1=1124356&r2=1124357&view=diff
==============================================================================
--- cxf/trunk/systests/jaxrs/src/test/java/org/apache/cxf/systest/jaxrs/JAXRSClientServerBookTest.java (original)
+++ cxf/trunk/systests/jaxrs/src/test/java/org/apache/cxf/systest/jaxrs/JAXRSClientServerBookTest.java Wed May 18 18:03:23 2011
@@ -21,6 +21,7 @@ package org.apache.cxf.systest.jaxrs;
 
 import java.io.File;
 import java.io.InputStream;
+import java.net.HttpURLConnection;
 import java.net.URL;
 import java.net.URLConnection;
 import java.net.URLEncoder;
@@ -581,7 +582,21 @@ public class JAXRSClientServerBookTest e
                       + "parameter, static valueOf(String) or fromString(String) methods",
                       "*/*", 500);
     }
-    
+
+    @Test
+    public void testWrongContentType() throws Exception {
+        // can't use WebClient here because WebClient plays around with the Content-Type
+        // (and makes sure it's syntactically correct) before sending it to the server
+        String endpointAddress = "http://localhost:" + PORT + "/bookstore/unsupportedcontenttype";
+        URL url = new URL(endpointAddress);
+        HttpURLConnection urlConnection = (HttpURLConnection)url.openConnection();
+        urlConnection.setReadTimeout(30000); // 30 seconds tops
+        urlConnection.setConnectTimeout(30000); // 30 second tops
+        urlConnection.addRequestProperty("Content-Type", "MissingSeparator");
+        urlConnection.setRequestMethod("POST");
+        assertEquals(415, urlConnection.getResponseCode());
+    }
+
     @Test
     public void testExceptionDuringConstruction() throws Exception {
         getAndCompare("http://localhost:" + PORT + "/bookstore/exceptionconstruction?p=1",