cxf-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From dk...@apache.org
Subject svn commit: r1549694 - in /cxf/trunk: core/src/main/java/org/apache/cxf/staxutils/ rt/bindings/soap/src/main/java/org/apache/cxf/binding/soap/interceptor/ rt/bindings/soap/src/test/java/org/apache/cxf/binding/soap/saaj/
Date Mon, 09 Dec 2013 22:30:58 GMT
Author: dkulp
Date: Mon Dec  9 22:30:57 2013
New Revision: 1549694

URL: http://svn.apache.org/r1549694
Log:
[CXF-5450] Fix some issues with SAAJ + Provider/Dispatch + Headers causing out of memory errors

Added:
    cxf/trunk/rt/bindings/soap/src/test/java/org/apache/cxf/binding/soap/saaj/SAAJOutInterceptorTest.java
  (with props)
Modified:
    cxf/trunk/core/src/main/java/org/apache/cxf/staxutils/OverlayW3CDOMStreamWriter.java
    cxf/trunk/rt/bindings/soap/src/main/java/org/apache/cxf/binding/soap/interceptor/SoapOutInterceptor.java

Modified: cxf/trunk/core/src/main/java/org/apache/cxf/staxutils/OverlayW3CDOMStreamWriter.java
URL: http://svn.apache.org/viewvc/cxf/trunk/core/src/main/java/org/apache/cxf/staxutils/OverlayW3CDOMStreamWriter.java?rev=1549694&r1=1549693&r2=1549694&view=diff
==============================================================================
--- cxf/trunk/core/src/main/java/org/apache/cxf/staxutils/OverlayW3CDOMStreamWriter.java (original)
+++ cxf/trunk/core/src/main/java/org/apache/cxf/staxutils/OverlayW3CDOMStreamWriter.java Mon
Dec  9 22:30:57 2013
@@ -27,6 +27,7 @@ import javax.xml.stream.XMLStreamExcepti
 import org.w3c.dom.Document;
 import org.w3c.dom.Element;
 import org.w3c.dom.Node;
+import org.w3c.dom.Text;
 
 import org.apache.cxf.common.util.StringUtils;
 
@@ -40,6 +41,7 @@ public class OverlayW3CDOMStreamWriter e
 
     List<Boolean> isOverlaidStack = new LinkedList<Boolean>();
     boolean isOverlaid = true;
+    boolean textOverlay = false;
     
     public OverlayW3CDOMStreamWriter(Document document) {
         super(document);
@@ -80,6 +82,7 @@ public class OverlayW3CDOMStreamWriter e
         }
         isOverlaid = isOverlaidStack.remove(0);
         super.writeEndElement();
+        textOverlay = false;
     }
     public void writeStartElement(String local) throws XMLStreamException {
         isOverlaidStack.add(0, isOverlaid);
@@ -198,4 +201,21 @@ public class OverlayW3CDOMStreamWriter e
         }
     }
     
+    public void writeCharacters(String text) throws XMLStreamException {
+        if (!isOverlaid) {
+            super.writeCharacters(text); 
+        } else if (!textOverlay) {
+            Element nd = getCurrentNode();
+            Node txt = nd.getFirstChild();
+            if (txt instanceof Text
+                && ((Text)txt).getTextContent().startsWith(text)) {
+                textOverlay = true;
+                return;
+            }
+            super.writeCharacters(text);
+        }
+        
+    }
+
+    
 }

Modified: cxf/trunk/rt/bindings/soap/src/main/java/org/apache/cxf/binding/soap/interceptor/SoapOutInterceptor.java
URL: http://svn.apache.org/viewvc/cxf/trunk/rt/bindings/soap/src/main/java/org/apache/cxf/binding/soap/interceptor/SoapOutInterceptor.java?rev=1549694&r1=1549693&r2=1549694&view=diff
==============================================================================
--- cxf/trunk/rt/bindings/soap/src/main/java/org/apache/cxf/binding/soap/interceptor/SoapOutInterceptor.java
(original)
+++ cxf/trunk/rt/bindings/soap/src/main/java/org/apache/cxf/binding/soap/interceptor/SoapOutInterceptor.java
Mon Dec  9 22:30:57 2013
@@ -60,6 +60,7 @@ import org.apache.cxf.service.model.Mess
 import org.apache.cxf.service.model.ServiceModelUtil;
 import org.apache.cxf.staxutils.DelegatingXMLStreamWriter;
 import org.apache.cxf.staxutils.StaxUtils;
+import org.apache.cxf.staxutils.W3CDOMStreamWriter;
 import org.apache.cxf.ws.addressing.EndpointReferenceUtils;
 
 public class SoapOutInterceptor extends AbstractSoapInterceptor {
@@ -142,6 +143,13 @@ public class SoapOutInterceptor extends 
                 List<Header> hdrList = message.getHeaders();
                 for (Header header : hdrList) {
                     XMLStreamWriter writer = xtw;
+                    if (xtw instanceof W3CDOMStreamWriter) {
+                        Element nd = ((W3CDOMStreamWriter)xtw).getCurrentNode();
+                        if (header.getObject() instanceof Element
+                            && nd.isSameNode(((Element)header.getObject()).getParentNode()))
{
+                            continue;
+                        }
+                    }
                     if (header instanceof SoapHeader) {
                         SoapHeader soapHeader = (SoapHeader)header;
                         writer = new SOAPHeaderWriter(xtw, soapHeader, soapVersion, soapPrefix);

Added: cxf/trunk/rt/bindings/soap/src/test/java/org/apache/cxf/binding/soap/saaj/SAAJOutInterceptorTest.java
URL: http://svn.apache.org/viewvc/cxf/trunk/rt/bindings/soap/src/test/java/org/apache/cxf/binding/soap/saaj/SAAJOutInterceptorTest.java?rev=1549694&view=auto
==============================================================================
--- cxf/trunk/rt/bindings/soap/src/test/java/org/apache/cxf/binding/soap/saaj/SAAJOutInterceptorTest.java
(added)
+++ cxf/trunk/rt/bindings/soap/src/test/java/org/apache/cxf/binding/soap/saaj/SAAJOutInterceptorTest.java
Mon Dec  9 22:30:57 2013
@@ -0,0 +1,81 @@
+/**
+ * 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.binding.soap.saaj;
+
+import java.io.ByteArrayOutputStream;
+import java.io.InputStream;
+import java.io.OutputStream;
+import java.util.List;
+
+import javax.xml.soap.SOAPMessage;
+import javax.xml.stream.XMLStreamWriter;
+import javax.xml.transform.stream.StreamSource;
+
+import org.w3c.dom.Element;
+
+import org.apache.cxf.BusFactory;
+import org.apache.cxf.binding.soap.Soap11;
+import org.apache.cxf.binding.soap.SoapHeader;
+import org.apache.cxf.binding.soap.TestBase;
+import org.apache.cxf.binding.soap.TestUtil;
+import org.apache.cxf.binding.soap.interceptor.SoapOutInterceptor;
+import org.apache.cxf.headers.Header;
+import org.apache.cxf.helpers.DOMUtils;
+import org.apache.cxf.staxutils.W3CDOMStreamWriter;
+
+import org.junit.Before;
+import org.junit.Test;
+
+
+public class SAAJOutInterceptorTest extends TestBase {
+
+    private SoapOutInterceptor soi;
+
+    @Before
+    public void setUp() throws Exception {
+        super.setUp();
+
+        soi = new SoapOutInterceptor(BusFactory.getDefaultBus());
+    }
+
+    @Test
+    public void testHandleHeader() throws Exception {
+        soapMessage = TestUtil.createEmptySoapMessage(Soap11.getInstance(), chain);
+        soapMessage.setContent(OutputStream.class, new ByteArrayOutputStream());
+        
+        SOAPMessage m = SAAJFactoryResolver.createMessageFactory(soapMessage.getVersion()).createMessage();
+
+        InputStream ins = getClass().getResourceAsStream("../test-soap-header.xml");
+        m.getSOAPPart().setContent(new StreamSource(ins));
+        
+        Element el = DOMUtils.getFirstElement(m.getSOAPPart().getEnvelope().getHeader());
+        List<Header> h = soapMessage.getHeaders();
+        while (el != null) {
+            h.add(new SoapHeader(DOMUtils.getElementQName(el), el));
+            el = DOMUtils.getNextElement(el);
+        }
+        soapMessage.setContent(SOAPMessage.class, m);
+        W3CDOMStreamWriter writer = new SAAJStreamWriter(m.getSOAPPart());
+        soapMessage.setContent(XMLStreamWriter.class, writer);
+        soi.handleMessage(soapMessage);
+        
+        m.writeTo(System.out);
+    }
+}

Propchange: cxf/trunk/rt/bindings/soap/src/test/java/org/apache/cxf/binding/soap/saaj/SAAJOutInterceptorTest.java
------------------------------------------------------------------------------
    svn:eol-style = native



Mime
View raw message