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 368D1D6C3 for ; Fri, 27 Jul 2012 12:52:02 +0000 (UTC) Received: (qmail 69972 invoked by uid 500); 27 Jul 2012 12:52:02 -0000 Delivered-To: apmail-cxf-commits-archive@cxf.apache.org Received: (qmail 69925 invoked by uid 500); 27 Jul 2012 12:52:02 -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 69918 invoked by uid 99); 27 Jul 2012 12:52:02 -0000 Received: from nike.apache.org (HELO nike.apache.org) (192.87.106.230) by apache.org (qpsmtpd/0.29) with ESMTP; Fri, 27 Jul 2012 12:52:01 +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, 27 Jul 2012 12:51:58 +0000 Received: from eris.apache.org (localhost [127.0.0.1]) by eris.apache.org (Postfix) with ESMTP id 72EB723888CD; Fri, 27 Jul 2012 12:51:13 +0000 (UTC) Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit 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 -0000 To: commits@cxf.apache.org From: sergeyb@apache.org X-Mailer: svnmailer-1.0.8-patched Message-Id: <20120727125113.72EB723888CD@eris.apache.org> 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 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 { + public ReplaceContentTypeInterceptor() { + super(Phase.READ); + } + + public void handleMessage(Message message) throws Fault { + message.put(Message.CONTENT_TYPE, "text/plain"); + } + } }