cxf-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From serg...@apache.org
Subject svn commit: r1366371 - in /cxf/branches/2.4.x-fixes: rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/client/ systests/jaxrs/src/test/java/org/apache/cxf/systest/jaxrs/
Date Fri, 27 Jul 2012 12:51:13 GMT
Author: sergeyb
Date: Fri Jul 27 12:51:12 2012
New Revision: 1366371

URL: http://svn.apache.org/viewvc?rev=1366371&view=rev
Log:
Fixing malformed media type tests in 2.4.x

Modified:
    cxf/branches/2.4.x-fixes/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/client/AbstractClient.java
    cxf/branches/2.4.x-fixes/systests/jaxrs/src/test/java/org/apache/cxf/systest/jaxrs/BookServer.java
    cxf/branches/2.4.x-fixes/systests/jaxrs/src/test/java/org/apache/cxf/systest/jaxrs/BookStore.java
    cxf/branches/2.4.x-fixes/systests/jaxrs/src/test/java/org/apache/cxf/systest/jaxrs/JAXRSClientServerBookTest.java

Modified: cxf/branches/2.4.x-fixes/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/client/AbstractClient.java
URL: http://svn.apache.org/viewvc/cxf/branches/2.4.x-fixes/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/client/AbstractClient.java?rev=1366371&r1=1366370&r2=1366371&view=diff
==============================================================================
--- cxf/branches/2.4.x-fixes/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/client/AbstractClient.java
(original)
+++ cxf/branches/2.4.x-fixes/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/client/AbstractClient.java
Fri Jul 27 12:51:12 2012
@@ -430,7 +430,7 @@ public abstract class AbstractClient imp
             }
         }
         
-        MediaType contentType = getResponseContentType(r);
+        MediaType contentType = getResponseContentType(inMessage, r);
         
         MessageBodyReader mbr = ProviderFactory.getInstance(inMessage).createMessageBodyReader(
             cls, type, anns, contentType, inMessage);
@@ -595,10 +595,19 @@ public abstract class AbstractClient imp
         throw new ClientWebApplicationException(errorMsg.toString(), cause, response);
     }
     
-    private static MediaType getResponseContentType(Response r) {
+    private static MediaType getResponseContentType(Message m, Response r) {
         MultivaluedMap<String, Object> map = r.getMetadata();
         if (map.containsKey(HttpHeaders.CONTENT_TYPE)) {
-            return MediaType.valueOf(map.getFirst(HttpHeaders.CONTENT_TYPE).toString());
+            try {
+                return MediaType.valueOf(map.getFirst(HttpHeaders.CONTENT_TYPE).toString());
+            } catch (IllegalArgumentException ex) {
+                String error = ex.getMessage();
+                if (error != null && error.contains("separator") && m.containsKey(Message.CONTENT_TYPE))
{ 
+                    return MediaType.valueOf((String)m.get(Message.CONTENT_TYPE));
+                } else {
+                    throw ex;
+                }
+            }
         }
         return MediaType.WILDCARD_TYPE;
     }

Modified: cxf/branches/2.4.x-fixes/systests/jaxrs/src/test/java/org/apache/cxf/systest/jaxrs/BookServer.java
URL: http://svn.apache.org/viewvc/cxf/branches/2.4.x-fixes/systests/jaxrs/src/test/java/org/apache/cxf/systest/jaxrs/BookServer.java?rev=1366371&r1=1366370&r2=1366371&view=diff
==============================================================================
--- cxf/branches/2.4.x-fixes/systests/jaxrs/src/test/java/org/apache/cxf/systest/jaxrs/BookServer.java
(original)
+++ cxf/branches/2.4.x-fixes/systests/jaxrs/src/test/java/org/apache/cxf/systest/jaxrs/BookServer.java
Fri Jul 27 12:51:12 2012
@@ -65,7 +65,7 @@ public class BookServer extends Abstract
         sf.setResourceProvider(BookStore.class,
                                new SingletonResourceProvider(new BookStore(), true));
         sf.setAddress("http://localhost:" + PORT + "/");
-
+        sf.getProperties(true).put("org.apache.cxf.jaxrs.mediaTypeCheck.strict", true);
         sf.create();        
     }
 

Modified: cxf/branches/2.4.x-fixes/systests/jaxrs/src/test/java/org/apache/cxf/systest/jaxrs/BookStore.java
URL: http://svn.apache.org/viewvc/cxf/branches/2.4.x-fixes/systests/jaxrs/src/test/java/org/apache/cxf/systest/jaxrs/BookStore.java?rev=1366371&r1=1366370&r2=1366371&view=diff
==============================================================================
--- cxf/branches/2.4.x-fixes/systests/jaxrs/src/test/java/org/apache/cxf/systest/jaxrs/BookStore.java
(original)
+++ cxf/branches/2.4.x-fixes/systests/jaxrs/src/test/java/org/apache/cxf/systest/jaxrs/BookStore.java
Fri Jul 27 12:51:12 2012
@@ -75,6 +75,7 @@ import javax.xml.transform.dom.DOMSource
 import org.apache.cxf.annotations.GZIP;
 import org.apache.cxf.common.util.ProxyHelper;
 import org.apache.cxf.helpers.XMLUtils;
+import org.apache.cxf.jaxrs.ext.MessageContext;
 import org.apache.cxf.jaxrs.ext.Nullable;
 import org.apache.cxf.jaxrs.ext.Oneway;
 import org.apache.cxf.jaxrs.ext.search.SearchCondition;
@@ -251,6 +252,15 @@ public class BookStore {
         return books.containsKey(id);
     }
     
+    @GET
+    @Path("books/check/malformedmt/{id}")
+    @Produces("text/plain")
+    public Response checkBookMalformedMT(@PathParam("id") Long id,
+                                         @Context MessageContext mc) {
+        mc.put("org.apache.cxf.jaxrs.mediaTypeCheck.strict", false);
+        return Response.ok(books.containsKey(id)).type("text").build();
+    }
+    
     @POST
     @Path("books/check2")
     @Produces("text/plain")

Modified: cxf/branches/2.4.x-fixes/systests/jaxrs/src/test/java/org/apache/cxf/systest/jaxrs/JAXRSClientServerBookTest.java
URL: http://svn.apache.org/viewvc/cxf/branches/2.4.x-fixes/systests/jaxrs/src/test/java/org/apache/cxf/systest/jaxrs/JAXRSClientServerBookTest.java?rev=1366371&r1=1366370&r2=1366371&view=diff
==============================================================================
--- cxf/branches/2.4.x-fixes/systests/jaxrs/src/test/java/org/apache/cxf/systest/jaxrs/JAXRSClientServerBookTest.java
(original)
+++ cxf/branches/2.4.x-fixes/systests/jaxrs/src/test/java/org/apache/cxf/systest/jaxrs/JAXRSClientServerBookTest.java
Fri Jul 27 12:51:12 2012
@@ -31,6 +31,7 @@ import java.util.HashMap;
 import java.util.List;
 import java.util.Map;
 
+import javax.ws.rs.core.MediaType;
 import javax.ws.rs.core.MultivaluedMap;
 import javax.ws.rs.core.Response;
 import javax.xml.bind.JAXBElement;
@@ -45,6 +46,7 @@ import org.apache.commons.httpclient.met
 import org.apache.commons.httpclient.methods.PutMethod;
 import org.apache.commons.httpclient.methods.RequestEntity;
 import org.apache.cxf.helpers.IOUtils;
+import org.apache.cxf.interceptor.Fault;
 import org.apache.cxf.io.CachedOutputStream;
 import org.apache.cxf.jaxrs.client.ClientWebApplicationException;
 import org.apache.cxf.jaxrs.client.JAXRSClientFactory;
@@ -55,6 +57,9 @@ import org.apache.cxf.jaxrs.client.WebCl
 import org.apache.cxf.jaxrs.ext.xml.XMLSource;
 import org.apache.cxf.jaxrs.provider.JAXBElementProvider;
 import org.apache.cxf.jaxrs.provider.XSLTJaxbProvider;
+import org.apache.cxf.message.Message;
+import org.apache.cxf.phase.AbstractPhaseInterceptor;
+import org.apache.cxf.phase.Phase;
 import org.apache.cxf.systest.jaxrs.BookStore.BookInfo;
 import org.apache.cxf.systest.jaxrs.BookStore.BookInfoInterface;
 import org.apache.cxf.testutil.common.AbstractBusClientServerTestBase;
@@ -845,6 +850,15 @@ public class JAXRSClientServerBookTest e
     }
     
     @Test
+    public void testBookExistsMalformedMt() throws Exception {
+        WebClient wc = 
+            WebClient.create("http://localhost:" + PORT + "/bookstore/books/check/malformedmt/123");
+        wc.accept(MediaType.TEXT_PLAIN);
+        WebClient.getConfig(wc).getInInterceptors().add(new ReplaceContentTypeInterceptor());
+        assertTrue(wc.get(Boolean.class));
+    }
+    
+    @Test
     public void testBookExists2() throws Exception {
         BookStore proxy = JAXRSClientFactory.create("http://localhost:" + PORT, BookStore.class);
         assertTrue(proxy.checkBook2(123L));
@@ -1816,5 +1830,13 @@ public class JAXRSClientServerBookTest e
         return bos.getOut().toString();        
     }
 
-    
+    public static class ReplaceContentTypeInterceptor extends AbstractPhaseInterceptor<Message>
{
+        public ReplaceContentTypeInterceptor() {
+            super(Phase.READ);
+        }
+
+        public void handleMessage(Message message) throws Fault {
+            message.put(Message.CONTENT_TYPE, "text/plain");
+        }
+    }
 }



Mime
View raw message