You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@cxf.apache.org by re...@apache.org on 2020/02/09 02:28:44 UTC

[cxf] 01/02: CXF-7959: WebClient invocation builder header(name, value) method is not implemented according to interface specification

This is an automated email from the ASF dual-hosted git repository.

reta pushed a commit to branch 3.3.x-fixes
in repository https://gitbox.apache.org/repos/asf/cxf.git

commit 37904869536ab94471314505ffcfecb2c838f83e
Author: reta <dr...@gmail.com>
AuthorDate: Sat Feb 8 15:36:18 2020 -0500

    CXF-7959: WebClient invocation builder header(name, value) method is not implemented according to interface specification
    
    (cherry picked from commit a2296f2e54dff0b353581d2e6fb0d72fbc8368a3)
---
 .../org/apache/cxf/jaxrs/client/spec/InvocationBuilderImpl.java  | 8 +++++++-
 .../apache/cxf/jaxrs/client/spec/InvocationBuilderImplTest.java  | 9 +++++++++
 2 files changed, 16 insertions(+), 1 deletion(-)

diff --git a/rt/rs/client/src/main/java/org/apache/cxf/jaxrs/client/spec/InvocationBuilderImpl.java b/rt/rs/client/src/main/java/org/apache/cxf/jaxrs/client/spec/InvocationBuilderImpl.java
index 3e623ef..471a9ec 100644
--- a/rt/rs/client/src/main/java/org/apache/cxf/jaxrs/client/spec/InvocationBuilderImpl.java
+++ b/rt/rs/client/src/main/java/org/apache/cxf/jaxrs/client/spec/InvocationBuilderImpl.java
@@ -270,7 +270,13 @@ public class InvocationBuilderImpl implements Invocation.Builder {
         if (hd != null) {
             value = hd.toString(value);
         }
-        webClient.header(name, value);
+        
+        // If value is null then all current headers of the same name should be removed
+        if (value == null) {
+            webClient.replaceHeader(name, value);
+        } else {
+            webClient.header(name, value);
+        }
     }
 
     @Override
diff --git a/rt/rs/client/src/test/java/org/apache/cxf/jaxrs/client/spec/InvocationBuilderImplTest.java b/rt/rs/client/src/test/java/org/apache/cxf/jaxrs/client/spec/InvocationBuilderImplTest.java
index 9d81127..4bd6dc4 100644
--- a/rt/rs/client/src/test/java/org/apache/cxf/jaxrs/client/spec/InvocationBuilderImplTest.java
+++ b/rt/rs/client/src/test/java/org/apache/cxf/jaxrs/client/spec/InvocationBuilderImplTest.java
@@ -68,6 +68,15 @@ public class InvocationBuilderImplTest {
         String sentHeaders = response.readEntity(String.class);
         assertTrue(sentHeaders.contains("Header1=b"));
         assertFalse(sentHeaders.contains("UnexpectedHeader"));
+
+        // If value is null then all current headers of the same name 
+        // should be removed.
+        builder.header("Header1", null);
+        builder.header("Header2", "b");
+        response = builder.get();
+        sentHeaders = response.readEntity(String.class);
+        assertTrue(sentHeaders.contains("Header2=b"));
+        assertFalse(sentHeaders.contains("Header1"));
         
         // null headers map should clear all headers
         builder.headers(null);