cxf-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From dk...@apache.org
Subject svn commit: r1428655 - in /cxf/branches/2.5.x-fixes/rt/frontend/jaxws/src: main/java/org/apache/cxf/jaxws/JAXWSMethodInvoker.java test/java/org/apache/cxf/jaxws/JAXWSMethodInvokerTest.java
Date Thu, 03 Jan 2013 22:52:19 GMT
Author: dkulp
Date: Thu Jan  3 22:52:19 2013
New Revision: 1428655

URL: http://svn.apache.org/viewvc?rev=1428655&view=rev
Log:
Merged revisions 1428405 via  git cherry-pick from
https://svn.apache.org/repos/asf/cxf/branches/2.6.x-fixes

........
  r1428405 | dkulp | 2013-01-03 10:38:48 -0500 (Thu, 03 Jan 2013) | 10 lines

  Merged revisions 1426594 via  git cherry-pick from
  https://svn.apache.org/repos/asf/cxf/trunk

  ........
    r1426594 | ashakirin | 2012-12-28 12:52:03 -0500 (Fri, 28 Dec 2012) | 2 lines

    Fix for CXF-4289 (disable copying soap headers to fault through property)

  ........

........

Modified:
    cxf/branches/2.5.x-fixes/rt/frontend/jaxws/src/main/java/org/apache/cxf/jaxws/JAXWSMethodInvoker.java
    cxf/branches/2.5.x-fixes/rt/frontend/jaxws/src/test/java/org/apache/cxf/jaxws/JAXWSMethodInvokerTest.java

Modified: cxf/branches/2.5.x-fixes/rt/frontend/jaxws/src/main/java/org/apache/cxf/jaxws/JAXWSMethodInvoker.java
URL: http://svn.apache.org/viewvc/cxf/branches/2.5.x-fixes/rt/frontend/jaxws/src/main/java/org/apache/cxf/jaxws/JAXWSMethodInvoker.java?rev=1428655&r1=1428654&r2=1428655&view=diff
==============================================================================
--- cxf/branches/2.5.x-fixes/rt/frontend/jaxws/src/main/java/org/apache/cxf/jaxws/JAXWSMethodInvoker.java
(original)
+++ cxf/branches/2.5.x-fixes/rt/frontend/jaxws/src/main/java/org/apache/cxf/jaxws/JAXWSMethodInvoker.java
Thu Jan  3 22:52:19 2013
@@ -38,6 +38,8 @@ import org.apache.cxf.service.invoker.Si
 
 public class JAXWSMethodInvoker extends AbstractJAXWSMethodInvoker {
 
+    public static final String COPY_SOAP_HEADERS_BY_FAULT = "org.apache.cxf.fault.copySoapHeaders";
+
     public JAXWSMethodInvoker(final Object bean) {
         super(new SingletonFactory(bean));
     }
@@ -74,7 +76,9 @@ public class JAXWSMethodInvoker extends 
             updateWebServiceContext(exchange, ctx);
         } catch (Fault f) {
             //get chance to copy over customer's header
-            updateHeader(exchange, ctx);
+            if (MessageUtils.getContextualBoolean(exchange.getInMessage(), COPY_SOAP_HEADERS_BY_FAULT,
true)) {
+                updateHeader(exchange, ctx);
+            }
             throw f;
         } finally {
             //clear the WebServiceContextImpl's ThreadLocal variable

Modified: cxf/branches/2.5.x-fixes/rt/frontend/jaxws/src/test/java/org/apache/cxf/jaxws/JAXWSMethodInvokerTest.java
URL: http://svn.apache.org/viewvc/cxf/branches/2.5.x-fixes/rt/frontend/jaxws/src/test/java/org/apache/cxf/jaxws/JAXWSMethodInvokerTest.java?rev=1428655&r1=1428654&r2=1428655&view=diff
==============================================================================
--- cxf/branches/2.5.x-fixes/rt/frontend/jaxws/src/test/java/org/apache/cxf/jaxws/JAXWSMethodInvokerTest.java
(original)
+++ cxf/branches/2.5.x-fixes/rt/frontend/jaxws/src/test/java/org/apache/cxf/jaxws/JAXWSMethodInvokerTest.java
Thu Jan  3 22:52:19 2013
@@ -18,15 +18,28 @@
  */
 package org.apache.cxf.jaxws;
 
-
+import java.io.ByteArrayInputStream;
+import java.io.IOException;
 import java.lang.reflect.Method;
+import java.util.ArrayList;
+import java.util.List;
 
+import javax.xml.namespace.QName;
+import javax.xml.parsers.DocumentBuilder;
+import javax.xml.parsers.DocumentBuilderFactory;
+import javax.xml.parsers.ParserConfigurationException;
 import javax.xml.transform.Source;
 import javax.xml.transform.stream.StreamSource;
 import javax.xml.ws.Provider;
 
+import org.w3c.dom.Document;
+import org.xml.sax.SAXException;
+
+import org.apache.cxf.binding.soap.SoapMessage;
 import org.apache.cxf.continuations.SuspendedInvocationException;
 import org.apache.cxf.frontend.MethodDispatcher;
+import org.apache.cxf.headers.Header;
+import org.apache.cxf.interceptor.Fault;
 import org.apache.cxf.jaxws.service.Hello;
 import org.apache.cxf.message.Exchange;
 import org.apache.cxf.message.ExchangeImpl;
@@ -41,6 +54,7 @@ import org.junit.Assert;
 import org.junit.Test;
 
 public class JAXWSMethodInvokerTest extends Assert {
+    private static final QName TEST_HEADER_NAME = new QName("testHeader");
     Factory factory = EasyMock.createMock(Factory.class);
     Object target = EasyMock.createMock(Hello.class);
         
@@ -82,6 +96,51 @@ public class JAXWSMethodInvokerTest exte
     }
     
     @Test
+    public void testFaultAvoidHeadersCopy() throws Throwable {
+        ExceptionService serviceObject = new ExceptionService();
+        Method serviceMethod = ExceptionService.class.getMethod("invoke", new Class[]{});
+        
+        Exchange ex = new ExchangeImpl();
+        prepareInMessage(ex, false);
+        
+
+        JAXWSMethodInvoker jaxwsMethodInvoker = prepareJAXWSMethodInvoker(ex, serviceObject,
serviceMethod);
+        try {
+            jaxwsMethodInvoker.invoke(ex, new MessageContentsList(new Object[]{}));
+            fail("Expected fault");
+        } catch (Fault fault) {
+            Message outMsg = ex.getOutMessage();
+            Assert.assertNull(outMsg);
+        }
+    }
+
+    @Test
+    public void testFaultHeadersCopy() throws Throwable {
+        ExceptionService serviceObject = new ExceptionService();
+        Method serviceMethod = ExceptionService.class.getMethod("invoke", new Class[]{});
+        
+        Exchange ex = new ExchangeImpl();
+        prepareInMessage(ex, true);
+        Message msg = new MessageImpl();
+        SoapMessage outMessage = new SoapMessage(msg);
+        ex.setOutMessage(outMessage);
+
+        JAXWSMethodInvoker jaxwsMethodInvoker = prepareJAXWSMethodInvoker(ex, serviceObject,
serviceMethod);
+
+        try {
+            jaxwsMethodInvoker.invoke(ex, new MessageContentsList(new Object[]{}));
+            fail("Expected fault");
+        } catch (Fault fault) {
+            Message outMsg = ex.getOutMessage();
+            Assert.assertNotNull(outMsg);
+            @SuppressWarnings("unchecked")
+            List<Header> headers = (List<Header>)outMsg.get(Header.HEADER_LIST);
+            Assert.assertEquals(1, headers.size());
+            Assert.assertEquals(TEST_HEADER_NAME, headers.get(0).getName());
+        }
+    }
+
+    @Test
     public void testProviderInterpretNullAsOneway() throws Throwable {
         NullableProviderService serviceObject = new NullableProviderService();
         Method serviceMethod = NullableProviderService.class.getMethod("invoke", new Class[]{Source.class});
@@ -190,4 +249,30 @@ public class JAXWSMethodInvokerTest exte
             return nullable ? null : request;
         }
     }
+
+    public static class ExceptionService {
+        private Throwable ex = new RuntimeException("Test Exception");
+        
+        public void invoke() {
+            throw new Fault(ex);
+        }
+        
+    }
+
+    private Message prepareInMessage(Exchange ex, boolean copyHeadersByFault)
+        throws ParserConfigurationException, SAXException, IOException {
+        Message inMessage = new MessageImpl();
+        inMessage.setExchange(ex);
+        inMessage.put(JAXWSMethodInvoker.COPY_SOAP_HEADERS_BY_FAULT, Boolean.valueOf(copyHeadersByFault));
+        List<Header> headers = new ArrayList<Header>();
+        DocumentBuilder builder = DocumentBuilderFactory.newInstance().newDocumentBuilder();
+        Document headerDoc = builder.parse(new ByteArrayInputStream("<test:testValue xmlns:test=\"test\"/>"
+            .getBytes()));
+        Header testHeader = new Header(TEST_HEADER_NAME, headerDoc.getDocumentElement());
+        headers.add(testHeader);
+        inMessage.put(Header.HEADER_LIST, headers);
+        ex.setInMessage(inMessage);
+        return inMessage;
+    }
+
 }



Mime
View raw message