You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@cxf.apache.org by eg...@apache.org on 2008/11/06 10:22:37 UTC

svn commit: r711805 - in /cxf/branches/2.0.x-fixes: rt/frontend/jaxws/src/main/java/org/apache/cxf/jaxws/handler/soap/ systests/src/test/java/org/apache/cxf/systest/ws/security/

Author: eglynn
Date: Thu Nov  6 01:22:36 2008
New Revision: 711805

URL: http://svn.apache.org/viewvc?rev=711805&view=rev
Log:
Fix to allow the JAX-WS SoapHandlerInterceptor peacefully co-exist with an explicitly configured SAAJOutInterceptor - previously installing a JAX-WS SoapHandler in a (WS-)secure CXF application caused outgoing SOAP bodies to be truncated.


Added:
    cxf/branches/2.0.x-fixes/systests/src/test/java/org/apache/cxf/systest/ws/security/TestOutHandler.java   (with props)
Modified:
    cxf/branches/2.0.x-fixes/rt/frontend/jaxws/src/main/java/org/apache/cxf/jaxws/handler/soap/SOAPHandlerInterceptor.java
    cxf/branches/2.0.x-fixes/systests/src/test/java/org/apache/cxf/systest/ws/security/WSSecurityClientTest.java

Modified: cxf/branches/2.0.x-fixes/rt/frontend/jaxws/src/main/java/org/apache/cxf/jaxws/handler/soap/SOAPHandlerInterceptor.java
URL: http://svn.apache.org/viewvc/cxf/branches/2.0.x-fixes/rt/frontend/jaxws/src/main/java/org/apache/cxf/jaxws/handler/soap/SOAPHandlerInterceptor.java?rev=711805&r1=711804&r2=711805&view=diff
==============================================================================
--- cxf/branches/2.0.x-fixes/rt/frontend/jaxws/src/main/java/org/apache/cxf/jaxws/handler/soap/SOAPHandlerInterceptor.java (original)
+++ cxf/branches/2.0.x-fixes/rt/frontend/jaxws/src/main/java/org/apache/cxf/jaxws/handler/soap/SOAPHandlerInterceptor.java Thu Nov  6 01:22:36 2008
@@ -21,6 +21,7 @@
 
 import java.net.URI;
 import java.util.HashSet;
+import java.util.ListIterator;
 import java.util.Set;
 
 import javax.xml.namespace.QName;
@@ -46,6 +47,7 @@
 import org.apache.cxf.endpoint.Endpoint;
 import org.apache.cxf.helpers.CastUtils;
 import org.apache.cxf.interceptor.Fault;
+import org.apache.cxf.interceptor.Interceptor;
 import org.apache.cxf.interceptor.InterceptorChain;
 import org.apache.cxf.interceptor.OutgoingChainInterceptor;
 import org.apache.cxf.jaxws.handler.AbstractProtocolHandlerInterceptor;
@@ -103,10 +105,12 @@
         }
 
         if (getInvoker(message).isOutbound()) {
+            if (!chainAlreadyContainsSAAJ(message)) {
 
-            SAAJ_OUT.handleMessage(message);
+                SAAJ_OUT.handleMessage(message);
 
-            message.getInterceptorChain().add(ending);
+                message.getInterceptorChain().add(ending);
+            }
         } else {
             boolean isFault = handleMessageInternal(message);
             SOAPMessage msg = message.getContent(SOAPMessage.class);
@@ -283,4 +287,14 @@
         return null;
     }
 
+    private static boolean chainAlreadyContainsSAAJ(SoapMessage message) {
+        ListIterator<Interceptor<? extends Message>> listIterator =
+            message.getInterceptorChain().getIterator();
+        while (listIterator.hasNext()) {
+            if (listIterator.next() instanceof SAAJOutInterceptor) {
+                return true;
+            }
+        }
+        return false;
+    }
 }

Added: cxf/branches/2.0.x-fixes/systests/src/test/java/org/apache/cxf/systest/ws/security/TestOutHandler.java
URL: http://svn.apache.org/viewvc/cxf/branches/2.0.x-fixes/systests/src/test/java/org/apache/cxf/systest/ws/security/TestOutHandler.java?rev=711805&view=auto
==============================================================================
--- cxf/branches/2.0.x-fixes/systests/src/test/java/org/apache/cxf/systest/ws/security/TestOutHandler.java (added)
+++ cxf/branches/2.0.x-fixes/systests/src/test/java/org/apache/cxf/systest/ws/security/TestOutHandler.java Thu Nov  6 01:22:36 2008
@@ -0,0 +1,45 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+package org.apache.cxf.systest.ws.security;
+
+import java.util.Set;
+
+import javax.xml.namespace.QName;
+import javax.xml.ws.handler.MessageContext;
+import javax.xml.ws.handler.soap.SOAPHandler;
+import javax.xml.ws.handler.soap.SOAPMessageContext;
+
+public class TestOutHandler implements SOAPHandler<SOAPMessageContext> {
+    public Set<QName> getHeaders() {
+        return null;
+    }
+
+    public void close(MessageContext mc) {
+    }
+
+    public boolean handleFault(SOAPMessageContext smc) {
+        return true;
+    }
+
+    public boolean handleMessage(SOAPMessageContext smc) {
+        return true;
+    }
+
+}

Propchange: cxf/branches/2.0.x-fixes/systests/src/test/java/org/apache/cxf/systest/ws/security/TestOutHandler.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: cxf/branches/2.0.x-fixes/systests/src/test/java/org/apache/cxf/systest/ws/security/TestOutHandler.java
------------------------------------------------------------------------------
    svn:keywords = Rev Date

Modified: cxf/branches/2.0.x-fixes/systests/src/test/java/org/apache/cxf/systest/ws/security/WSSecurityClientTest.java
URL: http://svn.apache.org/viewvc/cxf/branches/2.0.x-fixes/systests/src/test/java/org/apache/cxf/systest/ws/security/WSSecurityClientTest.java?rev=711805&r1=711804&r2=711805&view=diff
==============================================================================
--- cxf/branches/2.0.x-fixes/systests/src/test/java/org/apache/cxf/systest/ws/security/WSSecurityClientTest.java (original)
+++ cxf/branches/2.0.x-fixes/systests/src/test/java/org/apache/cxf/systest/ws/security/WSSecurityClientTest.java Thu Nov  6 01:22:36 2008
@@ -19,6 +19,9 @@
 
 package org.apache.cxf.systest.ws.security;
 
+import java.util.ArrayList;
+import java.util.List;
+
 import javax.xml.namespace.QName;
 import javax.xml.transform.OutputKeys;
 import javax.xml.transform.Source;
@@ -26,8 +29,11 @@
 import javax.xml.transform.TransformerFactory;
 import javax.xml.transform.stream.StreamResult;
 import javax.xml.transform.stream.StreamSource;
+import javax.xml.ws.Binding;
+import javax.xml.ws.BindingProvider;
 import javax.xml.ws.Dispatch;
 import javax.xml.ws.Service;
+import javax.xml.ws.handler.Handler;
 import javax.xml.ws.handler.MessageContext;
 import javax.xml.ws.http.HTTPBinding;
 
@@ -107,6 +113,18 @@
             TIMESTAMP_SIGN_ENCRYPT_PORT_QNAME,
             Greeter.class
         );
+
+        // Add a No-Op JAX-WS SoapHandler to the dispatch chain to
+        // verify that the SoapHandlerInterceptor can peacefully co-exist
+        // with the explicitly configured SAAJOutInterceptor
+        //
+        List<Handler> handlerChain = new ArrayList<Handler>();
+        Binding binding = ((BindingProvider)greeter).getBinding();
+        Handler handler;
+        handler = new TestOutHandler();
+        handlerChain.add(handler);
+        binding.setHandlerChain(handlerChain);
+
         greeter.sayHi();
     }