cxf-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From serg...@apache.org
Subject svn commit: r1461457 - in /cxf/trunk: rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/impl/ rt/frontend/jaxrs/src/test/java/org/apache/cxf/jaxrs/impl/ systests/jaxrs/src/test/java/org/apache/cxf/systest/jaxrs/
Date Wed, 27 Mar 2013 09:04:57 GMT
Author: sergeyb
Date: Wed Mar 27 09:04:57 2013
New Revision: 1461457

URL: http://svn.apache.org/r1461457
Log:
[CXF-4927] HttpHeaders.getRequestHeader needs to return null for missing headers

Modified:
    cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/impl/HttpHeadersImpl.java
    cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/impl/RequestPreprocessor.java
    cxf/trunk/rt/frontend/jaxrs/src/test/java/org/apache/cxf/jaxrs/impl/HttpHeadersImplTest.java
    cxf/trunk/systests/jaxrs/src/test/java/org/apache/cxf/systest/jaxrs/BookStoreNoAnnotationsImpl.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/JAXRSClientServerStreamingTest.java

Modified: cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/impl/HttpHeadersImpl.java
URL: http://svn.apache.org/viewvc/cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/impl/HttpHeadersImpl.java?rev=1461457&r1=1461456&r2=1461457&view=diff
==============================================================================
--- cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/impl/HttpHeadersImpl.java
(original)
+++ cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/impl/HttpHeadersImpl.java
Wed Mar 27 09:04:57 2013
@@ -187,16 +187,16 @@ public class HttpHeadersImpl implements 
     }
 
     public List<String> getRequestHeader(String name) {
-        List<String> values = headers.get(name);
-        if (values == null || values.isEmpty() || values.get(0) == null) {
-            return Collections.emptyList();
-        }
         boolean splitIndividualValue 
             = MessageUtils.isTrue(message.getContextualProperty(HEADER_SPLIT_PROPERTY));
+        
+        List<String> values = headers.get(name);
         if (!splitIndividualValue
+            || values == null
             || HttpUtils.isDateRelatedHeader(name)) {
             return values;
         }
+        
         List<String> ls = new LinkedList<String>();
         for (String value : values) {
             if (value == null) {

Modified: cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/impl/RequestPreprocessor.java
URL: http://svn.apache.org/viewvc/cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/impl/RequestPreprocessor.java?rev=1461457&r1=1461456&r2=1461457&view=diff
==============================================================================
--- cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/impl/RequestPreprocessor.java
(original)
+++ cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/impl/RequestPreprocessor.java
Wed Mar 27 09:04:57 2013
@@ -137,10 +137,7 @@ public class RequestPreprocessor {
                               HttpHeaders headers) {
         String method = queries.getFirst(METHOD_QUERY);
         if (method == null) {
-            List<String> values = headers.getRequestHeader(METHOD_HEADER);
-            if (values.size() == 1) {
-                method = values.get(0);
-            }
+            method = headers.getHeaderString(METHOD_HEADER);
         }
         if (method != null) {
             m.put(Message.HTTP_REQUEST_METHOD, method);

Modified: cxf/trunk/rt/frontend/jaxrs/src/test/java/org/apache/cxf/jaxrs/impl/HttpHeadersImplTest.java
URL: http://svn.apache.org/viewvc/cxf/trunk/rt/frontend/jaxrs/src/test/java/org/apache/cxf/jaxrs/impl/HttpHeadersImplTest.java?rev=1461457&r1=1461456&r2=1461457&view=diff
==============================================================================
--- cxf/trunk/rt/frontend/jaxrs/src/test/java/org/apache/cxf/jaxrs/impl/HttpHeadersImplTest.java
(original)
+++ cxf/trunk/rt/frontend/jaxrs/src/test/java/org/apache/cxf/jaxrs/impl/HttpHeadersImplTest.java
Wed Mar 27 09:04:57 2013
@@ -55,6 +55,22 @@ public class HttpHeadersImplTest extends
     }
 
     @Test
+    public void testNoRequestHeader() throws Exception {
+        
+        Message m = control.createMock(Message.class);
+        m.get(Message.PROTOCOL_HEADERS);
+        MetadataMap<String, String> headers = 
+            createHeader("COMPLEX_HEADER",  "b=c; param=c, a=b;param=b");
+        EasyMock.expectLastCall().andReturn(headers);
+        m.getContextualProperty("org.apache.cxf.http.header.split");
+        EasyMock.expectLastCall().andReturn("true");
+        control.replay();
+        HttpHeaders h = new HttpHeadersImpl(m);
+        List<String> values = h.getRequestHeader("HEADER");
+        assertNull(values);
+    }
+    
+    @Test
     public void testGetHeaderNameValue() throws Exception {
         
         Message m = control.createMock(Message.class);
@@ -204,6 +220,20 @@ public class HttpHeadersImplTest extends
     }
     
     @Test
+    public void testGetEmptyHeader() throws Exception {
+        
+        Message m = new MessageImpl();
+        // this is what happens at runtime and is tested in the system tests
+        Map<String, List<String>> headers = 
+            new TreeMap<String, List<String>>(String.CASE_INSENSITIVE_ORDER);
+        headers.put("A", Collections.<String>emptyList());
+        m.put(Message.PROTOCOL_HEADERS, headers);
+        HttpHeaders h = new HttpHeadersImpl(m);
+        List<String> values = h.getRequestHeader("A");
+        assertTrue(values.isEmpty());
+    }
+    
+    @Test
     public void testGetDate() throws Exception {
         
         Message m = new MessageImpl();

Modified: cxf/trunk/systests/jaxrs/src/test/java/org/apache/cxf/systest/jaxrs/BookStoreNoAnnotationsImpl.java
URL: http://svn.apache.org/viewvc/cxf/trunk/systests/jaxrs/src/test/java/org/apache/cxf/systest/jaxrs/BookStoreNoAnnotationsImpl.java?rev=1461457&r1=1461456&r2=1461457&view=diff
==============================================================================
--- cxf/trunk/systests/jaxrs/src/test/java/org/apache/cxf/systest/jaxrs/BookStoreNoAnnotationsImpl.java
(original)
+++ cxf/trunk/systests/jaxrs/src/test/java/org/apache/cxf/systest/jaxrs/BookStoreNoAnnotationsImpl.java
Wed Mar 27 09:04:57 2013
@@ -29,6 +29,8 @@ import javax.ws.rs.core.HttpHeaders;
 import javax.ws.rs.core.Response;
 import javax.ws.rs.core.UriInfo;
 
+import org.apache.cxf.message.MessageUtils;
+
 public class BookStoreNoAnnotationsImpl implements BookStoreNoAnnotationsInterface,
     HttpHeadersContext {
 
@@ -53,7 +55,7 @@ public class BookStoreNoAnnotationsImpl 
         if (hs == null) {
             throw new WebApplicationException(Response.serverError().build());
         }
-        boolean springProxy = hs.getRequestHeader("SpringProxy").contains("true");
+        boolean springProxy = MessageUtils.isTrue(hs.getHeaderString("SpringProxy"));
         if (!springProxy && ui == null) {
             throw new WebApplicationException(Response.serverError().build());
         }

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=1461457&r1=1461456&r2=1461457&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
Wed Mar 27 09:04:57 2013
@@ -43,7 +43,7 @@ public class CustomOutInterceptor extend
     public void handleMessage(Message message) throws Fault {
         
         HttpHeaders requestHeaders = new HttpHeadersImpl(message.getExchange().getInMessage());
-        if (!requestHeaders.getRequestHeader("PLAIN-MAP").isEmpty()) {
+        if (requestHeaders.getHeaderString("PLAIN-MAP") != null) {
             Map<String, List<String>> headers = (Map<String, List<String>>)
                 message.get(Message.PROTOCOL_HEADERS);
             if (headers == null) {

Modified: cxf/trunk/systests/jaxrs/src/test/java/org/apache/cxf/systest/jaxrs/JAXRSClientServerStreamingTest.java
URL: http://svn.apache.org/viewvc/cxf/trunk/systests/jaxrs/src/test/java/org/apache/cxf/systest/jaxrs/JAXRSClientServerStreamingTest.java?rev=1461457&r1=1461456&r2=1461457&view=diff
==============================================================================
--- cxf/trunk/systests/jaxrs/src/test/java/org/apache/cxf/systest/jaxrs/JAXRSClientServerStreamingTest.java
(original)
+++ cxf/trunk/systests/jaxrs/src/test/java/org/apache/cxf/systest/jaxrs/JAXRSClientServerStreamingTest.java
Wed Mar 27 09:04:57 2013
@@ -162,7 +162,7 @@ public class JAXRSClientServerStreamingT
         public void writeTo(Object obj, Class<?> cls, Type genericType, Annotation[]
anns,  
             MediaType m, MultivaluedMap<String, Object> headers, OutputStream os) throws
IOException {
             List<String> failHeaders = getContext().getHttpHeaders().getRequestHeader("fail-write");
-            if (failHeaders.size() > 0) {
+            if (failHeaders != null && failHeaders.size() > 0) {
                 os.write("fail".getBytes());
                 throw new IOException();
             } else {



Mime
View raw message