Return-Path: Delivered-To: apmail-cxf-commits-archive@www.apache.org Received: (qmail 58746 invoked from network); 10 Nov 2009 15:39:24 -0000 Received: from hermes.apache.org (HELO mail.apache.org) (140.211.11.3) by minotaur.apache.org with SMTP; 10 Nov 2009 15:39:24 -0000 Received: (qmail 43487 invoked by uid 500); 10 Nov 2009 15:39:23 -0000 Delivered-To: apmail-cxf-commits-archive@cxf.apache.org Received: (qmail 43381 invoked by uid 500); 10 Nov 2009 15:39:23 -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 43372 invoked by uid 99); 10 Nov 2009 15:39:23 -0000 Received: from athena.apache.org (HELO athena.apache.org) (140.211.11.136) by apache.org (qpsmtpd/0.29) with ESMTP; Tue, 10 Nov 2009 15:39:23 +0000 X-ASF-Spam-Status: No, hits=-2.6 required=5.0 tests=AWL,BAYES_00 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; Tue, 10 Nov 2009 15:39:20 +0000 Received: by eris.apache.org (Postfix, from userid 65534) id 91CC72388906; Tue, 10 Nov 2009 15:39:00 +0000 (UTC) Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Subject: svn commit: r834507 - in /cxf/trunk: rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/utils/ rt/frontend/jaxrs/src/test/java/org/apache/cxf/jaxrs/ rt/frontend/jaxrs/src/test/java/org/apache/cxf/jaxrs/utils/ rt/transports/http/src/main/java/org/apac... Date: Tue, 10 Nov 2009 15:39:00 -0000 To: commits@cxf.apache.org From: sergeyb@apache.org X-Mailer: svnmailer-1.0.8 Message-Id: <20091110153900.91CC72388906@eris.apache.org> Author: sergeyb Date: Tue Nov 10 15:39:00 2009 New Revision: 834507 URL: http://svn.apache.org/viewvc?rev=834507&view=rev Log: JAXRS: fixing CXF 2529 and a minor update to AbstractHTTPServlet (a better longer term update will be to add a properties resource for static content types) Modified: cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/utils/JAXRSUtils.java cxf/trunk/rt/frontend/jaxrs/src/test/java/org/apache/cxf/jaxrs/Customer.java cxf/trunk/rt/frontend/jaxrs/src/test/java/org/apache/cxf/jaxrs/utils/JAXRSUtilsTest.java cxf/trunk/rt/transports/http/src/main/java/org/apache/cxf/transport/servlet/AbstractHTTPServlet.java cxf/trunk/systests/jaxrs/src/test/java/org/apache/cxf/systest/jaxrs/JAXRSRequestDispatcherTest.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=834507&r1=834506&r2=834507&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 Tue Nov 10 15:39:00 2009 @@ -745,14 +745,21 @@ private static Object processCookieParam(Message m, String cookieName, Class pClass, Type genericType, String defaultValue) { List values = new HttpHeadersImpl(m).getRequestHeader(HttpHeaders.COOKIE); - String value = values.size() == 1 && values.get(0).contains(cookieName + '=') - ? values.get(0) : defaultValue != null ? cookieName + '=' + defaultValue : null; - - if (value == null) { + String theValue = null; + for (String s : values) { + if (s.startsWith(cookieName)) { + theValue = s; + break; + } + } + if (theValue == null && defaultValue != null) { + theValue = cookieName + '=' + defaultValue; + } + if (theValue == null) { return null; } - Cookie c = Cookie.valueOf(value); + Cookie c = Cookie.valueOf(theValue); if (pClass.isAssignableFrom(Cookie.class)) { return c; } Modified: cxf/trunk/rt/frontend/jaxrs/src/test/java/org/apache/cxf/jaxrs/Customer.java URL: http://svn.apache.org/viewvc/cxf/trunk/rt/frontend/jaxrs/src/test/java/org/apache/cxf/jaxrs/Customer.java?rev=834507&r1=834506&r2=834507&view=diff ============================================================================== --- cxf/trunk/rt/frontend/jaxrs/src/test/java/org/apache/cxf/jaxrs/Customer.java (original) +++ cxf/trunk/rt/frontend/jaxrs/src/test/java/org/apache/cxf/jaxrs/Customer.java Tue Nov 10 15:39:00 2009 @@ -332,6 +332,11 @@ // complete } + public void testMultipleCookieParam(@CookieParam("c1") String c1, + @CookieParam("c2") String c2) { + // complete + } + public void testParams(@Context UriInfo info, @Context HttpHeaders hs, @Context Request r, Modified: cxf/trunk/rt/frontend/jaxrs/src/test/java/org/apache/cxf/jaxrs/utils/JAXRSUtilsTest.java URL: http://svn.apache.org/viewvc/cxf/trunk/rt/frontend/jaxrs/src/test/java/org/apache/cxf/jaxrs/utils/JAXRSUtilsTest.java?rev=834507&r1=834506&r2=834507&view=diff ============================================================================== --- cxf/trunk/rt/frontend/jaxrs/src/test/java/org/apache/cxf/jaxrs/utils/JAXRSUtilsTest.java (original) +++ cxf/trunk/rt/frontend/jaxrs/src/test/java/org/apache/cxf/jaxrs/utils/JAXRSUtilsTest.java Tue Nov 10 15:39:00 2009 @@ -556,6 +556,22 @@ } @Test + public void testMultipleCookieParameters() throws Exception { + Class[] argType = {String.class, String.class}; + Method m = Customer.class.getMethod("testMultipleCookieParam", argType); + MessageImpl messageImpl = new MessageImpl(); + MultivaluedMap headers = new MetadataMap(); + headers.add("Cookie", "c1=c1Value, c2=c2Value, c3=c3Value"); + messageImpl.put(Message.PROTOCOL_HEADERS, headers); + List params = JAXRSUtils.processParameters(new OperationResourceInfo(m, null), + null, + messageImpl); + assertEquals(params.size(), 2); + assertEquals("c1Value", params.get(0)); + assertEquals("c2Value", params.get(1)); + } + + @Test public void testFromStringParameters() throws Exception { Class[] argType = {UUID.class, CustomerGender.class, CustomerGender.class}; Method m = Customer.class.getMethod("testFromStringParam", argType); Modified: cxf/trunk/rt/transports/http/src/main/java/org/apache/cxf/transport/servlet/AbstractHTTPServlet.java URL: http://svn.apache.org/viewvc/cxf/trunk/rt/transports/http/src/main/java/org/apache/cxf/transport/servlet/AbstractHTTPServlet.java?rev=834507&r1=834506&r2=834507&view=diff ============================================================================== --- cxf/trunk/rt/transports/http/src/main/java/org/apache/cxf/transport/servlet/AbstractHTTPServlet.java (original) +++ cxf/trunk/rt/transports/http/src/main/java/org/apache/cxf/transport/servlet/AbstractHTTPServlet.java Tue Nov 10 15:39:00 2009 @@ -21,8 +21,10 @@ import java.io.IOException; import java.io.InputStream; import java.util.Arrays; +import java.util.HashMap; import java.util.LinkedList; import java.util.List; +import java.util.Map; import javax.servlet.RequestDispatcher; import javax.servlet.ServletConfig; @@ -54,6 +56,17 @@ private static final String REDIRECT_SERVLET_NAME_PARAMETER = "redirect-servlet-name"; private static final String REDIRECT_SERVLET_PATH_PARAMETER = "redirect-servlet-path"; + private static final Map STATIC_CONTENT_TYPES; + + static { + STATIC_CONTENT_TYPES = new HashMap(); + STATIC_CONTENT_TYPES.put("html", "text/html"); + STATIC_CONTENT_TYPES.put("txt", "text/plain"); + STATIC_CONTENT_TYPES.put("css", "text/css"); + STATIC_CONTENT_TYPES.put("pdf", "application/pdf"); + // TODO : add more types if needed + } + private List staticResourcesList; private List redirectList; private String dispatcherServletPath; @@ -151,16 +164,18 @@ protected void handleRequest(HttpServletRequest request, HttpServletResponse response) throws ServletException { - if (staticResourcesList != null - && matchPath(staticResourcesList, request.getPathInfo())) { - serveStaticContent(request, response, request.getPathInfo()); - return; - } + if (redirectList != null && matchPath(redirectList, request.getPathInfo())) { redirect(request, response, request.getPathInfo()); return; } + + if (staticResourcesList != null + && matchPath(staticResourcesList, request.getPathInfo())) { + serveStaticContent(request, response, request.getPathInfo()); + return; + } invoke(request, response); } @@ -181,6 +196,14 @@ throw new ServletException("Static resource " + pathInfo + " is not available"); } try { + int ind = pathInfo.lastIndexOf("."); + if (ind != -1 && ind < pathInfo.length()) { + String type = STATIC_CONTENT_TYPES.get(pathInfo.substring(ind + 1)); + if (type != null) { + response.setContentType(type); + } + } + ServletOutputStream os = response.getOutputStream(); IOUtils.copy(is, os); os.flush(); Modified: cxf/trunk/systests/jaxrs/src/test/java/org/apache/cxf/systest/jaxrs/JAXRSRequestDispatcherTest.java URL: http://svn.apache.org/viewvc/cxf/trunk/systests/jaxrs/src/test/java/org/apache/cxf/systest/jaxrs/JAXRSRequestDispatcherTest.java?rev=834507&r1=834506&r2=834507&view=diff ============================================================================== --- cxf/trunk/systests/jaxrs/src/test/java/org/apache/cxf/systest/jaxrs/JAXRSRequestDispatcherTest.java (original) +++ cxf/trunk/systests/jaxrs/src/test/java/org/apache/cxf/systest/jaxrs/JAXRSRequestDispatcherTest.java Tue Nov 10 15:39:00 2009 @@ -51,6 +51,8 @@ namespaces.put("books", "http://www.w3.org/books"); String value = source.getValue("xhtml:html/xhtml:body/xhtml:ul/books:bookTag", namespaces); assertEquals("CXF Rocks", value); + String ct = client.getResponse().getMetadata().getFirst("Content-Type").toString(); + assertEquals("text/html", ct); } @Test