cxf-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From dk...@apache.org
Subject svn commit: r766116 - in /cxf/branches/2.1.x-fixes: ./ rt/frontend/jaxws/src/main/java/org/apache/cxf/jaxws/context/ rt/transports/http/src/main/java/org/apache/cxf/transport/http/ systests/src/test/java/org/apache/cxf/systest/http/
Date Fri, 17 Apr 2009 18:58:48 GMT
Author: dkulp
Date: Fri Apr 17 18:58:47 2009
New Revision: 766116

URL: http://svn.apache.org/viewvc?rev=766116&view=rev
Log:
Merged revisions 766058 via svnmerge from 
https://svn.apache.org/repos/asf/cxf/trunk

........
  r766058 | dkulp | 2009-04-17 11:41:33 -0400 (Fri, 17 Apr 2009) | 2 lines
  
  [CXF-2178] Fix issues with not being able to set http headers with 2.2
........

Modified:
    cxf/branches/2.1.x-fixes/   (props changed)
    cxf/branches/2.1.x-fixes/rt/frontend/jaxws/src/main/java/org/apache/cxf/jaxws/context/WrappedMessageContext.java
    cxf/branches/2.1.x-fixes/rt/transports/http/src/main/java/org/apache/cxf/transport/http/HTTPConduit.java
    cxf/branches/2.1.x-fixes/systests/src/test/java/org/apache/cxf/systest/http/ClientServerSessionTest.java
    cxf/branches/2.1.x-fixes/systests/src/test/java/org/apache/cxf/systest/http/GreeterSessionImpl.java

Propchange: cxf/branches/2.1.x-fixes/
------------------------------------------------------------------------------
--- svn:mergeinfo (original)
+++ svn:mergeinfo Fri Apr 17 18:58:47 2009
@@ -1 +1 @@
-/cxf/trunk:743446,753380,753397,753421,754585,755365,757499,757859,757899,757935,757951,758195,758303,758308,758378,758690,758910,759890,759961,759963-759964,759966,760029,760073,760150,760171,760178,760198,760212,760456,760468,760582,760938,761094,761113,761120,761317,761759,761789,762393,762518,762567,763200,763272,763495,763854,763931,763942,763953,764033-764034,764581,764599-764606,764887,765357,766013
+/cxf/trunk:743446,753380,753397,753421,754585,755365,757499,757859,757899,757935,757951,758195,758303,758308,758378,758690,758910,759890,759961,759963-759964,759966,760029,760073,760150,760171,760178,760198,760212,760456,760468,760582,760938,761094,761113,761120,761317,761759,761789,762393,762518,762567,763200,763272,763495,763854,763931,763942,763953,764033-764034,764581,764599-764606,764887,765357,766013,766058

Propchange: cxf/branches/2.1.x-fixes/
------------------------------------------------------------------------------
Binary property 'svnmerge-integrated' - no diff available.

Modified: cxf/branches/2.1.x-fixes/rt/frontend/jaxws/src/main/java/org/apache/cxf/jaxws/context/WrappedMessageContext.java
URL: http://svn.apache.org/viewvc/cxf/branches/2.1.x-fixes/rt/frontend/jaxws/src/main/java/org/apache/cxf/jaxws/context/WrappedMessageContext.java?rev=766116&r1=766115&r2=766116&view=diff
==============================================================================
--- cxf/branches/2.1.x-fixes/rt/frontend/jaxws/src/main/java/org/apache/cxf/jaxws/context/WrappedMessageContext.java
(original)
+++ cxf/branches/2.1.x-fixes/rt/frontend/jaxws/src/main/java/org/apache/cxf/jaxws/context/WrappedMessageContext.java
Fri Apr 17 18:58:47 2009
@@ -343,6 +343,7 @@
         if (!MessageContext.MESSAGE_OUTBOUND_PROPERTY.equals(mappedKey)) {
             scopes.put(mappedKey, scope);
         }
+        Object ret = null;
         if ((MessageContext.HTTP_RESPONSE_HEADERS.equals(key)
             || MessageContext.HTTP_RESPONSE_CODE.equals(key)
             || MessageContext.OUTBOUND_MESSAGE_ATTACHMENTS.equals(key)
@@ -356,7 +357,6 @@
                     return tmp.put(mappedKey, value);
                 }
             }
-            return null;
         } else if (BindingProvider.USERNAME_PROPERTY.equals(key)) {
             AuthorizationPolicy authPolicy =
                 (AuthorizationPolicy)message.get(AuthorizationPolicy.class.getName());
@@ -364,9 +364,8 @@
                 authPolicy = new AuthorizationPolicy();
                 message.put(AuthorizationPolicy.class.getName(), authPolicy);
             }
-            String ret = authPolicy.getUserName();
+            ret = authPolicy.getUserName();
             authPolicy.setUserName((String)value);
-            return ret;
         } else if (BindingProvider.PASSWORD_PROPERTY.equals(key)) {
             AuthorizationPolicy authPolicy =
                 (AuthorizationPolicy)message.get(AuthorizationPolicy.class.getName());
@@ -374,12 +373,14 @@
                 authPolicy = new AuthorizationPolicy();
                 message.put(AuthorizationPolicy.class.getName(), authPolicy);
             }
-            String ret = authPolicy.getPassword();
+            ret = authPolicy.getPassword();
             authPolicy.setPassword((String)value);
-            return ret;
+        } else if (MessageContext.HTTP_REQUEST_HEADERS.equals(key)) {
+            ret = message.put(Message.PROTOCOL_HEADERS, value);
         } else {
-            return message.put(mappedKey, value);
+            ret = message.put(mappedKey, value);
         }
+        return ret;
     }
 
     public final void putAll(Map<? extends String, ? extends Object> t) {

Modified: cxf/branches/2.1.x-fixes/rt/transports/http/src/main/java/org/apache/cxf/transport/http/HTTPConduit.java
URL: http://svn.apache.org/viewvc/cxf/branches/2.1.x-fixes/rt/transports/http/src/main/java/org/apache/cxf/transport/http/HTTPConduit.java?rev=766116&r1=766115&r2=766116&view=diff
==============================================================================
--- cxf/branches/2.1.x-fixes/rt/transports/http/src/main/java/org/apache/cxf/transport/http/HTTPConduit.java
(original)
+++ cxf/branches/2.1.x-fixes/rt/transports/http/src/main/java/org/apache/cxf/transport/http/HTTPConduit.java
Fri Apr 17 18:58:47 2009
@@ -564,11 +564,23 @@
         //Do we need to maintain a session?
         maintainSession = Boolean.TRUE.equals((Boolean)message.get(Message.MAINTAIN_SESSION));
         
-        //If we have any cookies and we are maintaining sessions, then use them
+        //If we have any cookies and we are maintaining sessions, then use them        
         if (maintainSession && sessionCookies.size() > 0) {
+            List<String> cookies = null;
+            for (String s : headers.keySet()) {
+                if (HttpHeaderHelper.COOKIE.equalsIgnoreCase(s)) {
+                    cookies = headers.remove(s);
+                    break;
+                }
+            }
+            if (cookies == null) {
+                cookies = new ArrayList<String>();
+            } else {
+                cookies = new ArrayList<String>(cookies);
+            }
+            headers.put(HttpHeaderHelper.COOKIE, cookies);
             for (Cookie c : sessionCookies.values()) {
-                connection.addRequestProperty(HttpHeaderHelper.COOKIE, 
-                                              c.requestCookieHeader());
+                cookies.add(c.requestCookieHeader());
             }
         }
 
@@ -805,8 +817,10 @@
             CastUtils.cast((Map<?, ?>)message.get(Message.PROTOCOL_HEADERS));     
  
         if (null == headers) {
             headers = new LinkedHashMap<String, List<String>>();
-            message.put(Message.PROTOCOL_HEADERS, headers);
+        } else {
+            headers = new LinkedHashMap<String, List<String>>(headers);
         }
+        message.put(Message.PROTOCOL_HEADERS, headers);
         return headers;
     }
     
@@ -822,14 +836,20 @@
         Map<String, List<String>> headers = getSetProtocolHeaders(message);
         for (String header : headers.keySet()) {
             List<String> headerList = headers.get(header);
-            StringBuilder b = new StringBuilder();
-            for (int i = 0; i < headerList.size(); i++) {
-                b.append(headerList.get(i));
-                if (i + 1 < headerList.size()) {
-                    b.append(',');
+            if (HttpHeaderHelper.COOKIE.equalsIgnoreCase(header)) {
+                for (String s : headerList) {
+                    connection.addRequestProperty(HttpHeaderHelper.COOKIE, s);
+                }
+            } else {
+                StringBuilder b = new StringBuilder();
+                for (int i = 0; i < headerList.size(); i++) {
+                    b.append(headerList.get(i));
+                    if (i + 1 < headerList.size()) {
+                        b.append(',');
+                    }
                 }
+                connection.setRequestProperty(header, b.toString());
             }
-            connection.setRequestProperty(header, b.toString());
         }
         if (!connection.getRequestProperties().containsKey("User-Agent")) {
             connection.addRequestProperty("User-Agent", Version.getCompleteVersionString());

Modified: cxf/branches/2.1.x-fixes/systests/src/test/java/org/apache/cxf/systest/http/ClientServerSessionTest.java
URL: http://svn.apache.org/viewvc/cxf/branches/2.1.x-fixes/systests/src/test/java/org/apache/cxf/systest/http/ClientServerSessionTest.java?rev=766116&r1=766115&r2=766116&view=diff
==============================================================================
--- cxf/branches/2.1.x-fixes/systests/src/test/java/org/apache/cxf/systest/http/ClientServerSessionTest.java
(original)
+++ cxf/branches/2.1.x-fixes/systests/src/test/java/org/apache/cxf/systest/http/ClientServerSessionTest.java
Fri Apr 17 18:58:47 2009
@@ -20,6 +20,10 @@
 package org.apache.cxf.systest.http;
 
 import java.lang.reflect.UndeclaredThrowableException;
+import java.util.Arrays;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
 
 import javax.xml.ws.BindingProvider;
 import javax.xml.ws.Endpoint;
@@ -27,6 +31,7 @@
 
 import org.apache.cxf.greeter_control.Greeter;
 import org.apache.cxf.greeter_control.GreeterService;
+import org.apache.cxf.helpers.CastUtils;
 import org.apache.cxf.testutil.common.AbstractBusClientServerTestBase;
 import org.junit.BeforeClass;
 import org.junit.Test;
@@ -49,22 +54,56 @@
 
         try {
             Greeter greeter = service.getGreeterPort();
-            ((BindingProvider)greeter).getRequestContext().put(BindingProvider.SESSION_MAINTAIN_PROPERTY,
-                                                                   true);
-            String greeting = greeter.greetMe("Bonjour");
             
+            BindingProvider bp = (BindingProvider)greeter;
+            bp.getRequestContext().put(BindingProvider.SESSION_MAINTAIN_PROPERTY, true);
+            
+            
+            Map<String, List<String>> headers 
+                = CastUtils.cast((Map)bp.getRequestContext().get("javax.xml.ws.http.request.headers"));
+
+            if (headers == null) {
+                headers = new HashMap<String, List<String>>();
+                bp.getRequestContext().put("javax.xml.ws.http.request.headers", headers);
+            }
+
+            List<String> cookies = Arrays.asList(new String[] {"a=a", "b=b"});
+            headers.put("Cookie", cookies);
+            
+            String greeting = greeter.greetMe("Bonjour");
+            String cookie = "";
+            if (greeting.indexOf(';') != -1) {
+                cookie = greeting.substring(greeting.indexOf(';'));
+                greeting = greeting.substring(0, greeting.indexOf(';'));
+            }
             assertNotNull("no response received from service", greeting);
             assertEquals("Hello Bonjour", greeting);
-            
+            assertTrue(cookie.contains("a=a"));
+            assertTrue(cookie.contains("b=b"));
+
             greeting = greeter.greetMe("Hello");
+            cookie = "";
+            if (greeting.indexOf(';') != -1) {
+                cookie = greeting.substring(greeting.indexOf(';'));
+                greeting = greeting.substring(0, greeting.indexOf(';'));
+            }
+
             assertNotNull("no response received from service", greeting);
             assertEquals("Hello Bonjour", greeting);
+            assertTrue(cookie.contains("a=a"));
+            assertTrue(cookie.contains("b=b"));
             
             
             greeting = greeter.greetMe("NiHao");
+            cookie = "";
+            if (greeting.indexOf(';') != -1) {
+                cookie = greeting.substring(greeting.indexOf(';'));
+                greeting = greeting.substring(0, greeting.indexOf(';'));
+            }
             assertNotNull("no response received from service", greeting);
             assertEquals("Hello Hello", greeting);
-
+            assertTrue(cookie.contains("a=a"));
+            assertTrue(cookie.contains("b=b"));
         } catch (UndeclaredThrowableException ex) {
             throw (Exception)ex.getCause();
         }

Modified: cxf/branches/2.1.x-fixes/systests/src/test/java/org/apache/cxf/systest/http/GreeterSessionImpl.java
URL: http://svn.apache.org/viewvc/cxf/branches/2.1.x-fixes/systests/src/test/java/org/apache/cxf/systest/http/GreeterSessionImpl.java?rev=766116&r1=766115&r2=766116&view=diff
==============================================================================
--- cxf/branches/2.1.x-fixes/systests/src/test/java/org/apache/cxf/systest/http/GreeterSessionImpl.java
(original)
+++ cxf/branches/2.1.x-fixes/systests/src/test/java/org/apache/cxf/systest/http/GreeterSessionImpl.java
Fri Apr 17 18:58:47 2009
@@ -24,6 +24,8 @@
 
 import javax.annotation.Resource;
 import javax.jws.WebService;
+import javax.servlet.http.Cookie;
+import javax.servlet.http.HttpServletRequest;
 import javax.servlet.http.HttpSession;
 import javax.xml.ws.AsyncHandler;
 import javax.xml.ws.Response;
@@ -31,6 +33,7 @@
 import javax.xml.ws.WebServiceException;
 import javax.xml.ws.handler.MessageContext;
 
+
 import org.apache.cxf.common.logging.LogUtils;
 import org.apache.cxf.greeter_control.Greeter;
 import org.apache.cxf.greeter_control.types.GreetMeResponse;
@@ -55,8 +58,16 @@
         LOG.info("Executing operation greetMe");        
         LOG.info("Message received: " + me);
         MessageContext mc = context.getMessageContext();
-        HttpSession session = ((javax.servlet.http.HttpServletRequest)mc.get(MessageContext.SERVLET_REQUEST))
-            .getSession();
+        HttpServletRequest req = (HttpServletRequest)mc.get(MessageContext.SERVLET_REQUEST);
+        Cookie cookies[] = req.getCookies();
+        String val = "";
+        if (cookies != null) {
+            for (Cookie cookie : cookies) {
+                val += ";" + cookie.getName() + "=" + cookie.getValue();
+            }
+        }
+        
+        HttpSession session = req.getSession();
         // Get a session property "counter" from context
         if (session == null) {
             throw new WebServiceException("No session in WebServiceContext");
@@ -69,7 +80,7 @@
         
         session.setAttribute("name", me);
         
-        return "Hello " + name;
+        return "Hello " + name + val;
     }
     
 



Mime
View raw message