Uploaded image for project: 'CXF'
  1. CXF
  2. CXF-7682

context.get(MessageContext.HTTP_REQUEST_HEADERS) always returns null for client

Details

    • Bug
    • Status: Closed
    • Major
    • Resolution: Fixed
    • None
    • 3.1.16, 3.2.5
    • JAX-WS Runtime
    • None
    • Unknown

    Description

      I have a client-side LogicalHandler that adds some HTTP headers and am noticing it causes the existing SOAPAction HTTP header (already added automatically by the JAX-WS runtime) to be removed.

      My handler code looks like this:

      public boolean handleMessage(LogicalMessageContext context) {
        Boolean outbound = (Boolean) context.get(MessageContext.MESSAGE_OUTBOUND_PROPERTY);
        if (outbound) {
          Map<String, List<String>> 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);
          }
          for (Map.Entry<String, String> entry : Tracer.getEntries().entrySet()) {
            headers.put(entry.getKey(), Collections.singletonList(entry.getValue()));
          }
        }
        return true;
      }
      

      I had a quick look at the code and noticed the LogicalMessageContextImpl#get(Object) always returns null on the client side (isRequestor() = true).

      So my handler will create a new header map and put it on the context, which is internally mapped to key "org.apache.cxf.message.Message.PROTOCOL_HEADERS" here.

      Attachments

        Activity

          githubbot ASF GitHub Bot added a comment -

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

          …urns null for client

          ----------------------------------------------------------------
          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

          githubbot ASF GitHub Bot added a comment - sanaik22 opened a new pull request #394: CXF-7682 : context.get(MessageContext.HTTP_REQUEST_HEADERS) always ret… URL: https://github.com/apache/cxf/pull/394 …urns null for client ---------------------------------------------------------------- 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
          githubbot ASF GitHub Bot added a comment -

          jimma commented on issue #394: CXF-7682: context.get(MessageContext.HTTP_REQUEST_HEADERS) always ret…
          URL: https://github.com/apache/cxf/pull/394#issuecomment-377180533

          @sanaik22 Can you please add a test for this change ?

          ----------------------------------------------------------------
          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

          githubbot ASF GitHub Bot added a comment - jimma commented on issue #394: CXF-7682 : context.get(MessageContext.HTTP_REQUEST_HEADERS) always ret… URL: https://github.com/apache/cxf/pull/394#issuecomment-377180533 @sanaik22 Can you please add a test for this change ? ---------------------------------------------------------------- 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
          githubbot ASF GitHub Bot added a comment -

          TomasHofman commented on issue #394: CXF-7682: context.get(MessageContext.HTTP_REQUEST_HEADERS) always ret…
          URL: https://github.com/apache/cxf/pull/394#issuecomment-380432747

          retest this please

          ----------------------------------------------------------------
          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

          githubbot ASF GitHub Bot added a comment - TomasHofman commented on issue #394: CXF-7682 : context.get(MessageContext.HTTP_REQUEST_HEADERS) always ret… URL: https://github.com/apache/cxf/pull/394#issuecomment-380432747 retest this please ---------------------------------------------------------------- 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
          githubbot ASF GitHub Bot added a comment -

          TomasHofman opened a new pull request #403: CXF-7682 context.get(MessageContext.HTTP_REQUEST_HEADERS) always re…
          URL: https://github.com/apache/cxf/pull/403

          …turns null for client

          https://issues.apache.org/jira/browse/CXF-7682
          7.1 JBEAP: https://issues.jboss.org/browse/JBEAP-14460
          Upstream PR: https://github.com/apache/cxf/pull/394

          ----------------------------------------------------------------
          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

          githubbot ASF GitHub Bot added a comment - TomasHofman opened a new pull request #403: CXF-7682 context.get(MessageContext.HTTP_REQUEST_HEADERS) always re… URL: https://github.com/apache/cxf/pull/403 …turns null for client https://issues.apache.org/jira/browse/CXF-7682 7.1 JBEAP: https://issues.jboss.org/browse/JBEAP-14460 Upstream PR: https://github.com/apache/cxf/pull/394 ---------------------------------------------------------------- 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
          githubbot ASF GitHub Bot added a comment -

          asoldano commented on issue #394: CXF-7682: context.get(MessageContext.HTTP_REQUEST_HEADERS) always ret…
          URL: https://github.com/apache/cxf/pull/394#issuecomment-380483106

          @TomasHofman I've triggered another run, let's see how it goes..

          ----------------------------------------------------------------
          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

          githubbot ASF GitHub Bot added a comment - asoldano commented on issue #394: CXF-7682 : context.get(MessageContext.HTTP_REQUEST_HEADERS) always ret… URL: https://github.com/apache/cxf/pull/394#issuecomment-380483106 @TomasHofman I've triggered another run, let's see how it goes.. ---------------------------------------------------------------- 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
          githubbot ASF GitHub Bot added a comment -

          dkulp commented on issue #394: CXF-7682: context.get(MessageContext.HTTP_REQUEST_HEADERS) always ret…
          URL: https://github.com/apache/cxf/pull/394#issuecomment-380497841

          @asoldano : If this clears, I'll merge it, but you may want to do a TCK run with the change prior to our next CXF release. For some reason, I seem to remember some weird context return value issues that the TCK hit for the various handler types.

          ----------------------------------------------------------------
          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

          githubbot ASF GitHub Bot added a comment - dkulp commented on issue #394: CXF-7682 : context.get(MessageContext.HTTP_REQUEST_HEADERS) always ret… URL: https://github.com/apache/cxf/pull/394#issuecomment-380497841 @asoldano : If this clears, I'll merge it, but you may want to do a TCK run with the change prior to our next CXF release. For some reason, I seem to remember some weird context return value issues that the TCK hit for the various handler types. ---------------------------------------------------------------- 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
          githubbot ASF GitHub Bot added a comment -

          asoldano commented on issue #394: CXF-7682: context.get(MessageContext.HTTP_REQUEST_HEADERS) always ret…
          URL: https://github.com/apache/cxf/pull/394#issuecomment-380503815

          @dkulp yes, definitely (@jimma FYI)

          ----------------------------------------------------------------
          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

          githubbot ASF GitHub Bot added a comment - asoldano commented on issue #394: CXF-7682 : context.get(MessageContext.HTTP_REQUEST_HEADERS) always ret… URL: https://github.com/apache/cxf/pull/394#issuecomment-380503815 @dkulp yes, definitely (@jimma FYI) ---------------------------------------------------------------- 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
          githubbot ASF GitHub Bot added a comment -

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

          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 dc5da549c25..7d4808d34f0 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))
            Unknown macro: {+ 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 e9b68781da8..2c4a8aba8d7 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;
          @@ -65,6 +75,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 {
          @@ -320,6 +331,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

          githubbot ASF GitHub Bot added a comment - dkulp closed pull request #403: CXF-7682 context.get(MessageContext.HTTP_REQUEST_HEADERS) always re… URL: https://github.com/apache/cxf/pull/403 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 dc5da549c25..7d4808d34f0 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)) Unknown macro: {+ 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 e9b68781da8..2c4a8aba8d7 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; @@ -65,6 +75,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 { @@ -320,6 +331,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
          githubbot ASF GitHub Bot added a comment -

          dkulp commented on issue #394: CXF-7682: context.get(MessageContext.HTTP_REQUEST_HEADERS) always ret…
          URL: https://github.com/apache/cxf/pull/394#issuecomment-384693086

          Merging, lgtm.

          ----------------------------------------------------------------
          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

          githubbot ASF GitHub Bot added a comment - dkulp commented on issue #394: CXF-7682 : context.get(MessageContext.HTTP_REQUEST_HEADERS) always ret… URL: https://github.com/apache/cxf/pull/394#issuecomment-384693086 Merging, lgtm. ---------------------------------------------------------------- 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
          githubbot ASF GitHub Bot added a comment -

          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))
            Unknown macro: {+ 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

          githubbot ASF GitHub Bot added a comment - 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)) Unknown macro: {+ 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
          githubbot ASF GitHub Bot added a comment -

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

          …urns null for client

          ----------------------------------------------------------------
          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

          githubbot ASF GitHub Bot added a comment - sanaik22 opened a new pull request #394: CXF-7682 : context.get(MessageContext.HTTP_REQUEST_HEADERS) always ret… URL: https://github.com/apache/cxf/pull/394 …urns null for client ---------------------------------------------------------------- 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
          githubbot ASF GitHub Bot added a comment -

          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))
            Unknown macro: {+ 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

          githubbot ASF GitHub Bot added a comment - 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)) Unknown macro: {+ 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

          People

            Unassigned Unassigned
            jpraet Jimmy Praet
            Votes:
            0 Vote for this issue
            Watchers:
            3 Start watching this issue

            Dates

              Created:
              Updated:
              Resolved: