You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@cxf.apache.org by GitBox <gi...@apache.org> on 2018/04/26 15:53:16 UTC

[GitHub] dkulp closed pull request #394: CXF-7682: context.get(MessageContext.HTTP_REQUEST_HEADERS) always ret…

dkulp closed pull request #394: CXF-7682: context.get(MessageContext.HTTP_REQUEST_HEADERS) always ret…
URL: https://github.com/apache/cxf/pull/394
 
 
   

This is a PR merged from a forked repository.
As GitHub hides the original diff on merge, it is displayed below for
the sake of provenance:

As this is a foreign pull request (from a fork), the diff is supplied
below (as it won't show otherwise due to GitHub magic):

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 5fd99dcda3b..f3722f40598 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 Object get(Object key) {
             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 d8cab8dfb8c..62bc3ce6e00 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 @@
 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.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;
@@ -63,6 +73,7 @@
                     "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 {
@@ -319,6 +330,89 @@ public void testClientProxyFactory() {
         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> {
 


 

----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on GitHub and use the
URL above to go to the specific comment.
 
For queries about this service, please contact Infrastructure at:
users@infra.apache.org


With regards,
Apache Git Services