cxf-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From serg...@apache.org
Subject svn commit: r1171291 - in /cxf/trunk/rt/frontend/jaxrs/src: main/java/org/apache/cxf/jaxrs/client/WebClient.java test/java/org/apache/cxf/jaxrs/client/WebClientTest.java
Date Thu, 15 Sep 2011 22:09:13 GMT
Author: sergeyb
Date: Thu Sep 15 22:09:13 2011
New Revision: 1171291

URL: http://svn.apache.org/viewvc?rev=1171291&view=rev
Log:
[CXF-3806] Adding replaceHeader method to WebClient

Modified:
    cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/client/WebClient.java
    cxf/trunk/rt/frontend/jaxrs/src/test/java/org/apache/cxf/jaxrs/client/WebClientTest.java

Modified: cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/client/WebClient.java
URL: http://svn.apache.org/viewvc/cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/client/WebClient.java?rev=1171291&r1=1171290&r2=1171291&view=diff
==============================================================================
--- cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/client/WebClient.java (original)
+++ cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/client/WebClient.java Thu
Sep 15 22:09:13 2011
@@ -565,6 +565,21 @@ public class WebClient extends AbstractC
     }
     
     /**
+     * Replaces the header value with the new values.
+     * @param headerName headerValues
+     * @param value new values, null is equivalent to removing the header
+     * @return updated WebClient
+     */
+    public WebClient replaceHeader(String headerName, String value) {
+        MultivaluedMap<String, String> headers = getState().getRequestHeaders();
+        headers.remove(headerName);
+        if (value != null) {
+            headers.add(headerName, value);
+        }
+        return this;
+    }
+    
+    /**
      * Replaces the current query with the new value.
      * @param queryString the new value, providing a null is
      *        equivalent to calling resetQuery().  

Modified: cxf/trunk/rt/frontend/jaxrs/src/test/java/org/apache/cxf/jaxrs/client/WebClientTest.java
URL: http://svn.apache.org/viewvc/cxf/trunk/rt/frontend/jaxrs/src/test/java/org/apache/cxf/jaxrs/client/WebClientTest.java?rev=1171291&r1=1171290&r2=1171291&view=diff
==============================================================================
--- cxf/trunk/rt/frontend/jaxrs/src/test/java/org/apache/cxf/jaxrs/client/WebClientTest.java
(original)
+++ cxf/trunk/rt/frontend/jaxrs/src/test/java/org/apache/cxf/jaxrs/client/WebClientTest.java
Thu Sep 15 22:09:13 2011
@@ -31,6 +31,25 @@ import org.junit.Test;
 public class WebClientTest extends Assert {
 
     @Test
+    public void testReplaceHeader() {
+        WebClient wc = WebClient.create("http://foo").header("a", "b");
+        assertEquals(1, wc.getHeaders().size());
+        assertEquals("b", wc.getHeaders().getFirst("a"));
+        wc.replaceHeader("a", "c");
+        assertEquals(1, wc.getHeaders().size());
+        assertEquals("c", wc.getHeaders().getFirst("a"));
+    }
+    
+    @Test
+    public void testRemoveHeader() {
+        WebClient wc = WebClient.create("http://foo").header("a", "b");
+        assertEquals(1, wc.getHeaders().size());
+        assertEquals("b", wc.getHeaders().getFirst("a"));
+        wc.replaceHeader("a", null);
+        assertEquals(0, wc.getHeaders().size());
+    }
+    
+    @Test
     public void testEncoding() {
         URI u = WebClient.create("http://foo").path("bar+ %2B").matrix("a", "value+ ")
             .query("b", "bv+ %2B").getCurrentURI();



Mime
View raw message