cxf-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From serg...@apache.org
Subject svn commit: r1083826 - in /cxf/trunk: rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/interceptor/ systests/jaxrs/src/test/java/org/apache/cxf/systest/jaxrs/
Date Mon, 21 Mar 2011 15:17:57 GMT
Author: sergeyb
Date: Mon Mar 21 15:17:56 2011
New Revision: 1083826

URL: http://svn.apache.org/viewvc?rev=1083826&view=rev
Log:
[CXF-3408] Minor updates to the way custom response headers are handled

Modified:
    cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/interceptor/JAXRSOutInterceptor.java
    cxf/trunk/systests/jaxrs/src/test/java/org/apache/cxf/systest/jaxrs/CustomOutInterceptor.java
    cxf/trunk/systests/jaxrs/src/test/java/org/apache/cxf/systest/jaxrs/JAXRSClientServerBookTest.java

Modified: cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/interceptor/JAXRSOutInterceptor.java
URL: http://svn.apache.org/viewvc/cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/interceptor/JAXRSOutInterceptor.java?rev=1083826&r1=1083825&r2=1083826&view=diff
==============================================================================
--- cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/interceptor/JAXRSOutInterceptor.java
(original)
+++ cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/interceptor/JAXRSOutInterceptor.java
Mon Mar 21 15:17:56 2011
@@ -169,23 +169,23 @@ public class JAXRSOutInterceptor extends
         boolean responseHeadersCopied = isResponseHeadersCopied(message);
         setResponseStatus(message, status, responseHeadersCopied);
         
-        Map<String, List<String>> theHeaders = 
-            (Map<String, List<String>>)message.get(Message.PROTOCOL_HEADERS);
+        Map<String, List<Object>> theHeaders = 
+            (Map<String, List<Object>>)message.get(Message.PROTOCOL_HEADERS);
         if (firstTry && theHeaders != null) {
             // some headers might've been setup by custom cxf interceptors
             theHeaders.putAll((Map)response.getMetadata());
         } else {
-            message.put(Message.PROTOCOL_HEADERS, response.getMetadata());
+            theHeaders = response.getMetadata();
         }
-        Map<String, List<Object>> rh = 
-            (Map<String, List<Object>>)message.get(Message.PROTOCOL_HEADERS);
         MultivaluedMap<String, Object> responseHeaders;
-        if (!(rh instanceof MultivaluedMap)) {
-            responseHeaders = new MetadataMap<String, Object>(rh);
+        if (!(theHeaders instanceof MultivaluedMap)) {
+            responseHeaders = new MetadataMap<String, Object>(theHeaders);
         } else {
-            responseHeaders = (MultivaluedMap)rh;
+            responseHeaders = (MultivaluedMap)theHeaders;
         }
-        setResponseDate((MultivaluedMap)responseHeaders, firstTry);
+        message.put(Message.PROTOCOL_HEADERS, responseHeaders);
+        
+        setResponseDate(responseHeaders, firstTry);
         if (isResponseNull(responseObj)) {
             return;
         }

Modified: cxf/trunk/systests/jaxrs/src/test/java/org/apache/cxf/systest/jaxrs/CustomOutInterceptor.java
URL: http://svn.apache.org/viewvc/cxf/trunk/systests/jaxrs/src/test/java/org/apache/cxf/systest/jaxrs/CustomOutInterceptor.java?rev=1083826&r1=1083825&r2=1083826&view=diff
==============================================================================
--- cxf/trunk/systests/jaxrs/src/test/java/org/apache/cxf/systest/jaxrs/CustomOutInterceptor.java
(original)
+++ cxf/trunk/systests/jaxrs/src/test/java/org/apache/cxf/systest/jaxrs/CustomOutInterceptor.java
Mon Mar 21 15:17:56 2011
@@ -18,9 +18,16 @@
  */
 package org.apache.cxf.systest.jaxrs;
 
+import java.util.Arrays;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+
+import javax.ws.rs.core.HttpHeaders;
 import javax.ws.rs.core.MultivaluedMap;
 
 import org.apache.cxf.interceptor.Fault;
+import org.apache.cxf.jaxrs.impl.HttpHeadersImpl;
 import org.apache.cxf.jaxrs.impl.MetadataMap;
 import org.apache.cxf.message.Message;
 import org.apache.cxf.phase.AbstractPhaseInterceptor;
@@ -32,10 +39,28 @@ public class CustomOutInterceptor extend
         super(Phase.MARSHAL);
     }
 
+    @SuppressWarnings("unchecked")
     public void handleMessage(Message message) throws Fault {
-        MultivaluedMap<String, Object> headers = new MetadataMap<String, Object>();
-        headers.putSingle("BookId", "123");
-        message.put(Message.PROTOCOL_HEADERS, headers);
+        
+        HttpHeaders requestHeaders = new HttpHeadersImpl(message.getExchange().getInMessage());
+        if (!requestHeaders.getRequestHeader("PLAIN-MAP").isEmpty()) {
+            Map<String, List<String>> headers = (Map<String, List<String>>)
+                message.get(Message.PROTOCOL_HEADERS);
+            if (headers == null) {
+                headers = new HashMap<String, List<String>>();
+                message.put(Message.PROTOCOL_HEADERS, headers);
+            }
+            headers.put("BookId", Arrays.asList("321"));
+            headers.put("MAP-NAME", Arrays.asList(Map.class.getName()));
+            message.put(Message.PROTOCOL_HEADERS, headers);
+        } else {
+
+            MultivaluedMap<String, Object> headers = new MetadataMap<String, Object>();
+            headers.putSingle("BookId", "123");
+            headers.putSingle("MAP-NAME", MultivaluedMap.class.getName());
+            message.put(Message.PROTOCOL_HEADERS, headers);
+        }
+        
     }
 
 }

Modified: cxf/trunk/systests/jaxrs/src/test/java/org/apache/cxf/systest/jaxrs/JAXRSClientServerBookTest.java
URL: http://svn.apache.org/viewvc/cxf/trunk/systests/jaxrs/src/test/java/org/apache/cxf/systest/jaxrs/JAXRSClientServerBookTest.java?rev=1083826&r1=1083825&r2=1083826&view=diff
==============================================================================
--- cxf/trunk/systests/jaxrs/src/test/java/org/apache/cxf/systest/jaxrs/JAXRSClientServerBookTest.java
(original)
+++ cxf/trunk/systests/jaxrs/src/test/java/org/apache/cxf/systest/jaxrs/JAXRSClientServerBookTest.java
Mon Mar 21 15:17:56 2011
@@ -68,6 +68,32 @@ public class JAXRSClientServerBookTest e
     }
     
     @Test
+    public void testGetBookWithCustomHeader() throws Exception {
+        
+        String endpointAddress =
+            "http://localhost:" + PORT + "/bookstore/books/123"; 
+        WebClient wc = WebClient.create(endpointAddress);
+        Book b = wc.get(Book.class);
+        assertEquals(123L, b.getId());
+        
+        MultivaluedMap<String, Object> headers = wc.getResponse().getMetadata();
+        assertEquals("123", headers.getFirst("BookId"));
+        assertEquals(MultivaluedMap.class.getName(), headers.getFirst("MAP-NAME"));
+        
+        assertNotNull(headers.getFirst("Date"));
+        
+        wc.header("PLAIN-MAP", "true");
+        b = wc.get(Book.class);
+        assertEquals(123L, b.getId());
+        
+        headers = wc.getResponse().getMetadata();
+        assertEquals("321", headers.getFirst("BookId"));
+        assertEquals(Map.class.getName(), headers.getFirst("MAP-NAME"));
+        
+        assertNotNull(headers.getFirst("Date"));
+    }
+    
+    @Test
     public void testGetBookWithNameInQuery() throws Exception {
         
         String endpointAddress =



Mime
View raw message