metro-jax-ws icon indicating copy to clipboard operation
metro-jax-ws copied to clipboard

cookies are overwritten when case of Set-Cookie header is not the same for all response-headers

Open Tomas-Kraus opened this issue 2 years ago • 0 comments

When a Webservice-endpoints response contains multiple set-cookie-headers that are different in case (e.g. 'set-cookie' vs 'Set-Cookie' vs 'seT-cOOkie') they will override each other when being transfered from the URLConnections request-header-map to the HttpClientTransports responseHeaders map (which uses case-insensitive keys) by using method 'putAll()' (https://github.com/gf-metro/jaxws/blob/master/jaxws-ri/rt/src/main/java/com/sun/xml/ws/transport/http/client/HttpClientTransport.java#L171)

JDKs HttpURLConnection does preserve the case of header-names and treats them as case-sensitives keys in its response header-map. The HttpClientTransports Header-class (https://github.com/gf-metro/jaxws/blob/master/jaxws-ri/rt/src/main/java/com/sun/xml/ws/transport/Headers.java) does interpret header-names that are not the same case as equal resulting in put replacing any preexisting header. As a fix all Header-values should be transfered from the HTTPURLConnections response-header-map to the HttpClientTransports equivalent using the Header.add()-method:

(remark: this is not a duplicate of https://java.net/jira/browse/JAX_WS-916)

diff --git a/jaxws-ri/rt/src/main/java/com/sun/xml/ws/transport/http/client/HttpClientTransport.java b/jaxws-ri/rt/src/main/java/com/sun/xml/ws/transport/http/client/HttpClientTransport.java
index a8598af..ea336fd 100644
--- a/jaxws-ri/rt/src/main/java/com/sun/xml/ws/transport/http/client/HttpClientTransport.java
+++ b/jaxws-ri/rt/src/main/java/com/sun/xml/ws/transport/http/client/HttpClientTransport.java
@@ -166,10 +166,16 @@
     public Map<String, List<String>> getHeaders() {
         if (respHeaders != null) {
             return respHeaders;
         }
-        respHeaders = new Headers();
-        respHeaders.putAll(httpConnection.getHeaderFields());
+        Headers headers = new Headers();
+        for(Map.Entry<String,List<String>> header : httpConnection.getHeaderFields().entrySet()) {
+            String key = header.getKey();
+            for (String value : header.getValue()) {
+headers.add(key,value);
+            }
+        }
+        respHeaders = headers;
         return respHeaders;
     }

     protected @Nullable InputStream readResponse() {

Environment

identified on Linux64bit, but should be all available Plattforms the JDK ships for.

Affected Versions

[2.2.8]

Source: https://github.com/javaee/metro-jax-ws/issues/1170 Author: glassfishrobot

Tomas-Kraus avatar Jun 02 '22 17:06 Tomas-Kraus