cxf-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From serg...@apache.org
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 GMT
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<String> 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<String, String> headers = new MetadataMap<String, String>();
+        headers.add("Cookie", "c1=c1Value, c2=c2Value, c3=c3Value");
+        messageImpl.put(Message.PROTOCOL_HEADERS, headers);
+        List<Object> 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<String, String> STATIC_CONTENT_TYPES;
+    
+    static {
+        STATIC_CONTENT_TYPES = new HashMap<String, String>();
+        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<String> staticResourcesList;
     private List<String> 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



Mime
View raw message