Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

StaxStreamXMLReader ignores significant whitespace [SPR-12000] #16616

Closed
spring-projects-issues opened this issue Jul 15, 2014 · 5 comments
Closed
Assignees
Labels
in: core status: backported type: bug
Milestone

Comments

@spring-projects-issues
Copy link
Collaborator

@spring-projects-issues spring-projects-issues commented Jul 15, 2014

Sergei Lilichenko opened SPR-12000 and commented

It appears that org.springframework.util.xml.StaxStreamXMLReader ignores important whitespace in XML. It manifests in the latest version of Spring Web Services, but I report it hear because it looks like it's a generic problem with this core class. When replaced with JDK's SAXParser the tests run green.

The following test fails on the first assert statement:

import org.apache.axiom.om.OMElement;
import org.apache.axiom.om.OMXMLBuilderFactory;
import org.junit.Test;
import org.springframework.util.xml.StaxUtils;
import org.xml.sax.InputSource;

import javax.xml.parsers.SAXParser;
import javax.xml.parsers.SAXParserFactory;
import javax.xml.stream.XMLStreamReader;
import javax.xml.transform.Source;
import javax.xml.transform.Transformer;
import javax.xml.transform.TransformerConfigurationException;
import javax.xml.transform.TransformerException;
import javax.xml.transform.TransformerFactory;
import javax.xml.transform.dom.DOMResult;
import javax.xml.transform.sax.SAXSource;
import java.io.StringReader;

import static org.junit.Assert.*;

/**
 *
 */
public class TransformationTest {
    @Test
    public void testTransformation() throws TransformerException {
        String xml = "<test>" +
                "<node1> </node1>" +
                "<node2> Some text </node2>" +
                "</test>";

        Transformer transformer = TransformerFactory.newInstance().newTransformer();

        DOMResult result = new DOMResult();

        OMElement root = OMXMLBuilderFactory.createOMBuilder(new StringReader(xml)).getDocumentElement();
// code from org.springframework.ws.soap.axiom.AbstractPayload:
        XMLStreamReader streamReader = root.getXMLStreamReader();
        Source source = StaxUtils.createCustomStaxSource(streamReader);
        transformer.transform(source, result);

        assertEquals(" ", result.getNode().getFirstChild().getFirstChild().getTextContent());
        assertEquals(" Some text ", result.getNode().getFirstChild().getFirstChild().getNextSibling().getTextContent());
    }
}

Affects: 3.2.10, 4.0.5

Referenced from: commits b6f13b8, fca72f6, 8fb5927, d6950d8

Backported to: 3.2.11

@spring-projects-issues
Copy link
Collaborator Author

@spring-projects-issues spring-projects-issues commented Jul 16, 2014

Arjen Poutsma commented

Fixed and tested under Spring-WS. Pull request available at #593.

It might be useful to backport this fix to the 4.0 branch.

@spring-projects-issues
Copy link
Collaborator Author

@spring-projects-issues spring-projects-issues commented Jul 16, 2014

Juergen Hoeller commented

I'll backport this to 4.0.7 along with a few others.

Juergen

@spring-projects-issues
Copy link
Collaborator Author

@spring-projects-issues spring-projects-issues commented Jul 16, 2014

Sergei Lilichenko commented

Thank you, gentlemen, for the quick fix! Do you have the estimated date for 4.0.7 release by any chance?

@spring-projects-issues
Copy link
Collaborator Author

@spring-projects-issues spring-projects-issues commented Jul 16, 2014

Juergen Hoeller commented

We've just released 4.0.6 last week, so 4.0.7 won't go out for a while. In all likelihood, it's going to be co-released with 4.1 GA around August 20th, or with 4.1.1 in September.

That said, a 4.0.7.BUILD-SNAPSHOT including this change will be available some time tomorrow. Would be great if you could give it a try once available... I'll keep you posted.

Juergen

@spring-projects-issues
Copy link
Collaborator Author

@spring-projects-issues spring-projects-issues commented Jul 16, 2014

Sergei Lilichenko commented

Confirmed on my side that the fix solved the problem with Spring WS removing white space from the elements in the incoming payload. I had to put the patch in my code, but it's relatively straightforward. Will be waiting for the new release to remove that patch.

Thank you for doing a great job!

Sergei

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
in: core status: backported type: bug
Projects
None yet
Development

No branches or pull requests

2 participants