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

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


The following commit(s) were added to refs/heads/3.1.x-fixes by this push:
     new 594cd07  [CXF-7682] context.get(MessageContext.HTTP_REQUEST_HEADERS) 
always returns null for client
594cd07 is described below

commit 594cd0721c535f5e4705207d09351060a8a80c86
Author: Saisha Naik <san...@redhat.com>
AuthorDate: Tue Apr 10 11:45:46 2018 +0530

    [CXF-7682] context.get(MessageContext.HTTP_REQUEST_HEADERS) always returns 
null for client
---
 .../handler/logical/LogicalMessageContextImpl.java |  4 +-
 .../java/org/apache/cxf/jaxws/JaxWsClientTest.java | 94 ++++++++++++++++++++++
 2 files changed, 96 insertions(+), 2 deletions(-)

diff --git 
a/rt/frontend/jaxws/src/main/java/org/apache/cxf/jaxws/handler/logical/LogicalMessageContextImpl.java
 
b/rt/frontend/jaxws/src/main/java/org/apache/cxf/jaxws/handler/logical/LogicalMessageContextImpl.java
index dc5da54..7d4808d 100644
--- 
a/rt/frontend/jaxws/src/main/java/org/apache/cxf/jaxws/handler/logical/LogicalMessageContextImpl.java
+++ 
b/rt/frontend/jaxws/src/main/java/org/apache/cxf/jaxws/handler/logical/LogicalMessageContextImpl.java
@@ -47,10 +47,10 @@ public class LogicalMessageContextImpl extends 
WrappedMessageContext implements
             if (((Map<?, ?>)o).isEmpty()) {
                 return null;
             }
-            if (!isResponse() && 
MessageContext.HTTP_RESPONSE_HEADERS.equals(key)) {
+            if (!isResponse() && isOutbound() && 
MessageContext.HTTP_RESPONSE_HEADERS.equals(key)) {
                 return null;
             }
-            if (isRequestor() && 
MessageContext.HTTP_REQUEST_HEADERS.equals(key)) {
+            if (isRequestor() && !isOutbound() && 
MessageContext.HTTP_REQUEST_HEADERS.equals(key)) {
                 return null;
             }
         }
diff --git 
a/rt/frontend/jaxws/src/test/java/org/apache/cxf/jaxws/JaxWsClientTest.java 
b/rt/frontend/jaxws/src/test/java/org/apache/cxf/jaxws/JaxWsClientTest.java
index e9b6878..2c4a8ab 100644
--- a/rt/frontend/jaxws/src/test/java/org/apache/cxf/jaxws/JaxWsClientTest.java
+++ b/rt/frontend/jaxws/src/test/java/org/apache/cxf/jaxws/JaxWsClientTest.java
@@ -22,8 +22,12 @@ package org.apache.cxf.jaxws;
 import java.lang.reflect.InvocationHandler;
 import java.lang.reflect.Proxy;
 import java.net.URL;
+import java.util.Collections;
+import java.util.HashMap;
+import java.util.List;
 import java.util.Map;
 import java.util.ResourceBundle;
+import java.util.Set;
 import java.util.concurrent.atomic.AtomicBoolean;
 
 import javax.xml.namespace.QName;
@@ -31,6 +35,12 @@ import javax.xml.transform.dom.DOMSource;
 import javax.xml.ws.BindingProvider;
 import javax.xml.ws.Dispatch;
 import javax.xml.ws.WebServiceException;
+import javax.xml.ws.handler.Handler;
+import javax.xml.ws.handler.LogicalHandler;
+import javax.xml.ws.handler.LogicalMessageContext;
+import javax.xml.ws.handler.MessageContext;
+import javax.xml.ws.handler.soap.SOAPHandler;
+import javax.xml.ws.handler.soap.SOAPMessageContext;
 
 import org.apache.cxf.endpoint.Client;
 import org.apache.cxf.endpoint.ClientImpl;
@@ -65,6 +75,7 @@ public class JaxWsClientTest extends AbstractJaxWsTest {
                     "SoapPort");
     private final String address = 
"http://localhost:9000/SoapContext/SoapPort";;
     private Destination d;
+    private Map<String, List<String>> headers = new HashMap<>();
 
     @Before
     public void setUp() throws Exception {
@@ -320,6 +331,89 @@ public class JaxWsClientTest extends AbstractJaxWsTest {
         assertEquals("jack", 
((BindingProvider)greeter3).getRequestContext().get("test"));
     }
 
+    @Test
+    public void testLogicalHandler() {
+        URL url = getClass().getResource("/wsdl/hello_world.wsdl");
+        javax.xml.ws.Service s = javax.xml.ws.Service
+            .create(url, serviceName);
+        Greeter greeter = s.getPort(portName, Greeter.class);
+        d.setMessageObserver(new MessageReplayObserver("sayHiResponse.xml"));
+
+        List<Handler> chain = 
((BindingProvider)greeter).getBinding().getHandlerChain();
+        chain.add(new LogicalHandler<LogicalMessageContext>() {
+            public void close(MessageContext arg0) {
+            }
+
+            public boolean handleFault(LogicalMessageContext arg0) {
+                return true;
+            }
+
+            public boolean handleMessage(LogicalMessageContext context) {
+
+                Boolean outbound = (Boolean) 
context.get(MessageContext.MESSAGE_OUTBOUND_PROPERTY);
+                if (outbound) {
+                    headers = (Map<String, List<String>>) 
context.get(MessageContext.HTTP_REQUEST_HEADERS);
+                    if (headers == null) {
+                        headers = new HashMap<String, List<String>>();
+                        context.put(MessageContext.HTTP_REQUEST_HEADERS, 
headers);
+                    }
+                    headers.put("My-Custom-Header", 
Collections.singletonList("value"));
+                }
+                return true;
+            }
+        });
+        ((BindingProvider)greeter).getBinding().setHandlerChain(chain);
+
+        String response = greeter.sayHi();
+        assertNotNull(response);
+        assertTrue("custom header should be present", 
headers.containsKey("My-Custom-Header"));
+        assertTrue("existing SOAPAction header should not be removed", 
headers.containsKey("SOAPAction"));
+    }
+
+    @Test
+    public void testSoapHandler() {
+        URL url = getClass().getResource("/wsdl/hello_world.wsdl");
+        javax.xml.ws.Service s = javax.xml.ws.Service
+            .create(url, serviceName);
+        Greeter greeter = s.getPort(portName, Greeter.class);
+        d.setMessageObserver(new MessageReplayObserver("sayHiResponse.xml"));
+
+        List<Handler> chain = 
((BindingProvider)greeter).getBinding().getHandlerChain();
+        chain.add(new SOAPHandler<SOAPMessageContext>() {
+
+                public boolean handleMessage(SOAPMessageContext context) {
+
+                    Boolean outbound = (Boolean) 
context.get(MessageContext.MESSAGE_OUTBOUND_PROPERTY);
+                    if (outbound) {
+                        headers = (Map<String, List<String>>) 
context.get(MessageContext.HTTP_REQUEST_HEADERS);
+                        if (headers == null) {
+                            headers = new HashMap<String, List<String>>();
+                            context.put(MessageContext.HTTP_REQUEST_HEADERS, 
headers);
+                        }
+                        headers.put("My-Custom-Header", 
Collections.singletonList("value"));
+                    }
+                    return true;
+                }
+
+                public boolean handleFault(SOAPMessageContext smc) {
+                    return true;
+                }
+
+                public Set<QName> getHeaders() {
+                    return null;
+                }
+
+                public void close(MessageContext messageContext) {
+                }
+        });
+        ((BindingProvider)greeter).getBinding().setHandlerChain(chain);
+
+        String response = greeter.sayHi();
+        assertNotNull(response);
+        assertTrue("custom header should be present", 
headers.containsKey("My-Custom-Header"));
+        assertTrue("existing SOAPAction header should not be removed", 
headers.containsKey("SOAPAction"));
+
+    }
 
     public static class FaultThrower extends AbstractPhaseInterceptor<Message> 
{
 

-- 
To stop receiving notification emails like this one, please contact
dk...@apache.org.

Reply via email to