cxf-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From serg...@apache.org
Subject cxf git commit: [CXF-6256] Returning 406 if the response type has a wildcard but its neither a wildcard nor application/*
Date Thu, 19 Feb 2015 17:23:48 GMT
Repository: cxf
Updated Branches:
  refs/heads/3.0.x-fixes 030c22d80 -> c2eb440d6


[CXF-6256] Returning 406 if the response type has a wildcard but its neither a wildcard nor
application/*


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

Branch: refs/heads/3.0.x-fixes
Commit: c2eb440d61da6ad228da5002a5a3bc79a13f35b0
Parents: 030c22d
Author: Sergey Beryozkin <sberyozkin@talend.com>
Authored: Thu Feb 19 17:22:19 2015 +0000
Committer: Sergey Beryozkin <sberyozkin@talend.com>
Committed: Thu Feb 19 17:23:30 2015 +0000

----------------------------------------------------------------------
 .../jaxrs/interceptor/JAXRSOutInterceptor.java  | 20 ++++++++++++++------
 .../org/apache/cxf/systest/jaxrs/BookStore.java |  6 ++++++
 .../jaxrs/JAXRSClientServerBookTest.java        | 10 +++++++++-
 .../jaxrs/websocket/BookStoreWebSocket.java     |  2 +-
 4 files changed, 30 insertions(+), 8 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/cxf/blob/c2eb440d/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/interceptor/JAXRSOutInterceptor.java
----------------------------------------------------------------------
diff --git a/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/interceptor/JAXRSOutInterceptor.java
b/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/interceptor/JAXRSOutInterceptor.java
index 13f0647..14df927 100644
--- a/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/interceptor/JAXRSOutInterceptor.java
+++ b/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/interceptor/JAXRSOutInterceptor.java
@@ -34,6 +34,7 @@ import java.util.logging.Logger;
 
 import javax.servlet.http.HttpServletResponse;
 import javax.ws.rs.HttpMethod;
+import javax.ws.rs.NotAcceptableException;
 import javax.ws.rs.Produces;
 import javax.ws.rs.core.HttpHeaders;
 import javax.ws.rs.core.MediaType;
@@ -229,7 +230,12 @@ public class JAXRSOutInterceptor extends AbstractOutDatabindingInterceptor
{
             writeResponseErrorMessage(message, outOriginal, "NO_MSG_WRITER", targetType,
responseMediaType);
             return;
         }
-        responseMediaType = checkFinalContentType(responseMediaType, writers);
+        try {
+            responseMediaType = checkFinalContentType(responseMediaType, writers);
+        } catch (Throwable ex) {
+            handleWriteException(providerFactory, message, ex, firstTry);
+            return;
+        }
         String finalResponseContentType = JAXRSUtils.mediaTypeToString(responseMediaType);
         if (LOG.isLoggable(Level.FINE)) {
             LOG.fine("Response content type is: " + finalResponseContentType);
@@ -384,7 +390,7 @@ public class JAXRSOutInterceptor extends AbstractOutDatabindingInterceptor
{
     
     
     private MediaType checkFinalContentType(MediaType mt, List<WriterInterceptor> writers)
{
-        if (mt.isWildcardType() || mt.isWildcardSubtype()) {
+        if (mt.isWildcardSubtype()) {
             int mbwIndex = writers.size() == 1 ? 0 : writers.size() - 1;
             MessageBodyWriter<Object> writer = ((WriterInterceptorMBW)writers.get(mbwIndex)).getMBW();
             Produces pm = writer.getClass().getAnnotation(Produces.class);
@@ -392,11 +398,13 @@ public class JAXRSOutInterceptor extends AbstractOutDatabindingInterceptor
{
                 List<MediaType> sorted = 
                     JAXRSUtils.sortMediaTypes(JAXRSUtils.getMediaTypes(pm.value()), JAXRSUtils.MEDIA_TYPE_QS_PARAM);
                 mt = JAXRSUtils.intersectMimeTypes(sorted, mt).get(0);
-                if (mt.isWildcardType() || mt.isWildcardSubtype()) {
-                    return MediaType.APPLICATION_OCTET_STREAM_TYPE;    
-                }
+            }
+        }
+        if (mt.isWildcardType() || mt.isWildcardSubtype()) {
+            if ("application".equals(mt.getType()) || mt.isWildcardType()) {
+                mt = MediaType.APPLICATION_OCTET_STREAM_TYPE;
             } else {
-                return MediaType.APPLICATION_OCTET_STREAM_TYPE;
+                throw new NotAcceptableException();
             }
         }
         return mt;

http://git-wip-us.apache.org/repos/asf/cxf/blob/c2eb440d/systests/jaxrs/src/test/java/org/apache/cxf/systest/jaxrs/BookStore.java
----------------------------------------------------------------------
diff --git a/systests/jaxrs/src/test/java/org/apache/cxf/systest/jaxrs/BookStore.java b/systests/jaxrs/src/test/java/org/apache/cxf/systest/jaxrs/BookStore.java
index 418f484..3bbf7c3 100644
--- a/systests/jaxrs/src/test/java/org/apache/cxf/systest/jaxrs/BookStore.java
+++ b/systests/jaxrs/src/test/java/org/apache/cxf/systest/jaxrs/BookStore.java
@@ -158,6 +158,12 @@ public class BookStore {
     public Book getBookRoot() {
         return new Book("root", 124L);
     }
+    @GET
+    @Path("/books/wildcard")
+    @Produces("text/*")
+    public String getBookTextWildcard() {
+        return "book";
+    }
     
     @GET
     @Path("/bookarray")

http://git-wip-us.apache.org/repos/asf/cxf/blob/c2eb440d/systests/jaxrs/src/test/java/org/apache/cxf/systest/jaxrs/JAXRSClientServerBookTest.java
----------------------------------------------------------------------
diff --git a/systests/jaxrs/src/test/java/org/apache/cxf/systest/jaxrs/JAXRSClientServerBookTest.java
b/systests/jaxrs/src/test/java/org/apache/cxf/systest/jaxrs/JAXRSClientServerBookTest.java
index 2249bbf..42546a0 100644
--- a/systests/jaxrs/src/test/java/org/apache/cxf/systest/jaxrs/JAXRSClientServerBookTest.java
+++ b/systests/jaxrs/src/test/java/org/apache/cxf/systest/jaxrs/JAXRSClientServerBookTest.java
@@ -143,6 +143,15 @@ public class JAXRSClientServerBookTest extends AbstractBusClientServerTestBase
{
     }
     
     @Test
+    public void testGetBookAcceptWildcard() throws Exception {
+        String address = "http://localhost:" + PORT + "/bookstore/books/wildcard";
+        WebClient wc = WebClient.create(address);
+        WebClient.getConfig(wc).getHttpConduit().getClient().setReceiveTimeout(1000000);
+        Response r = wc.accept("text/*").get();
+        assertEquals(406, r.getStatus());
+    }
+    
+    @Test
     public void testGetBookSameUriAutoRedirect() throws Exception {
         String address = "http://localhost:" + PORT + "/bookstore/redirect?sameuri=true";
         WebClient wc = WebClient.create(address);
@@ -287,7 +296,6 @@ public class JAXRSClientServerBookTest extends AbstractBusClientServerTestBase
{
     public void testGetBookNameAsByteArray() {
         String address = "http://localhost:" + PORT + "/bookstore/booknames/123";
         WebClient wc = WebClient.create(address);
-        WebClient.getConfig(wc).getHttpConduit().getClient().setReceiveTimeout(1000000);
         
         Response r = wc.accept("application/bar").get();
         String name = r.readEntity(String.class);

http://git-wip-us.apache.org/repos/asf/cxf/blob/c2eb440d/systests/jaxrs/src/test/java/org/apache/cxf/systest/jaxrs/websocket/BookStoreWebSocket.java
----------------------------------------------------------------------
diff --git a/systests/jaxrs/src/test/java/org/apache/cxf/systest/jaxrs/websocket/BookStoreWebSocket.java
b/systests/jaxrs/src/test/java/org/apache/cxf/systest/jaxrs/websocket/BookStoreWebSocket.java
index eed72a3..bc38f43 100644
--- a/systests/jaxrs/src/test/java/org/apache/cxf/systest/jaxrs/websocket/BookStoreWebSocket.java
+++ b/systests/jaxrs/src/test/java/org/apache/cxf/systest/jaxrs/websocket/BookStoreWebSocket.java
@@ -84,7 +84,7 @@ public class BookStoreWebSocket {
     
     @GET
     @Path("/bookbought")
-    @Produces("text/*")
+    @Produces("application/*")
     public StreamingOutput getBookBought() {
         return new StreamingOutput() {
             public void write(final OutputStream out) throws IOException, WebApplicationException
{


Mime
View raw message