SWS-502
This commit is contained in:
@@ -18,7 +18,6 @@ package org.springframework.ws.soap.axiom;
|
||||
|
||||
import java.io.ByteArrayInputStream;
|
||||
import java.io.InputStream;
|
||||
import java.io.InputStreamReader;
|
||||
import javax.xml.transform.Transformer;
|
||||
import javax.xml.transform.TransformerException;
|
||||
import javax.xml.transform.TransformerFactory;
|
||||
@@ -26,9 +25,6 @@ import javax.xml.transform.TransformerFactory;
|
||||
import org.custommonkey.xmlunit.XMLAssert;
|
||||
import org.custommonkey.xmlunit.XMLUnit;
|
||||
|
||||
import org.springframework.core.io.ClassPathResource;
|
||||
import org.springframework.core.io.Resource;
|
||||
import org.springframework.util.FileCopyUtils;
|
||||
import org.springframework.ws.WebServiceMessage;
|
||||
import org.springframework.ws.WebServiceMessageFactory;
|
||||
import org.springframework.ws.soap.soap11.AbstractSoap11MessageFactoryTestCase;
|
||||
@@ -91,17 +87,26 @@ public class AxiomSoap11MessageFactoryTest extends AbstractSoap11MessageFactoryT
|
||||
messageFactory.setPayloadCaching(false);
|
||||
messageFactory.afterPropertiesSet();
|
||||
|
||||
Resource resource = new ClassPathResource("SWS-502.xml", getClass());
|
||||
String expected = FileCopyUtils.copyToString(new InputStreamReader(resource.getInputStream()));
|
||||
InputStream inputStream = resource.getInputStream();
|
||||
TransportInputStream tis = new MockTransportInputStream(inputStream);
|
||||
AxiomSoapMessage message = (AxiomSoapMessage) messageFactory.createWebServiceMessage(tis);
|
||||
String payload =
|
||||
"<ns1:sendMessageResponse xmlns:ns1='urn:Sole' xmlns:soapenv='http://schemas.xmlsoap.org/soap/envelope/' xmlns:xsi='http://www.w3.org/2001/XMLSchema-instance' soapenv:encodingStyle='http://schemas.xmlsoap.org/soap/encoding/'>" +
|
||||
"<sendMessageReturn xsi:type='soapenc:string' xmlns:soapenc='http://schemas.xmlsoap.org/soap/encoding/'>" +
|
||||
"<![CDATA[<?xml version='1.0' encoding='UTF-8'?>" + "<PDresponse>" +
|
||||
"<isStatusOK>true</isStatusOK>" + "<status>0</status>" +
|
||||
"<payLoad><![CDATA[<?xml version='1.0' encoding='UTF-8'?><response>ok</response>]]]]>><![CDATA[</payLoad>" +
|
||||
"</PDresponse>]]></sendMessageReturn>" + "</ns1:sendMessageResponse>";
|
||||
String envelope =
|
||||
"<soapenv:Envelope xmlns:soapenv='http://schemas.xmlsoap.org/soap/envelope/' xmlns:xsd='http://www.w3.org/2001/XMLSchema' xmlns:xsi='http://www.w3.org/2001/XMLSchema-instance'><soapenv:Body>" +
|
||||
payload + "</soapenv:Body></soapenv:Envelope>";
|
||||
|
||||
InputStream inputStream = new ByteArrayInputStream(envelope.getBytes("UTF-8"));
|
||||
AxiomSoapMessage message =
|
||||
(AxiomSoapMessage) messageFactory.createWebServiceMessage(new MockTransportInputStream(inputStream));
|
||||
|
||||
StringResult result = new StringResult();
|
||||
transformer.transform(message.getEnvelope().getSource(), result);
|
||||
transformer.transform(message.getPayloadSource(), result);
|
||||
|
||||
XMLUnit.setIgnoreWhitespace(true);
|
||||
XMLAssert.assertXMLEqual(expected, result.toString());
|
||||
XMLAssert.assertXMLEqual(payload, result.toString());
|
||||
|
||||
}
|
||||
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2006 the original author or authors.
|
||||
* Copyright 2002-2009 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
@@ -27,6 +27,7 @@ import org.xml.sax.helpers.AttributesImpl;
|
||||
|
||||
import org.springframework.util.StringUtils;
|
||||
import org.springframework.xml.namespace.QNameUtils;
|
||||
import org.springframework.xml.namespace.SimpleNamespaceContext;
|
||||
|
||||
/**
|
||||
* SAX <code>XMLReader</code> that reads from a StAX <code>XMLStreamReader</code>. Reads from an
|
||||
@@ -44,6 +45,8 @@ public class StaxStreamXmlReader extends AbstractStaxXmlReader {
|
||||
|
||||
private final XMLStreamReader reader;
|
||||
|
||||
private final SimpleNamespaceContext namespaceContext = new SimpleNamespaceContext();
|
||||
|
||||
/**
|
||||
* Constructs a new instance of the <code>StaxStreamXmlReader</code> that reads from the given
|
||||
* <code>XMLStreamReader</code>. The supplied stream reader must be in <code>XMLStreamConstants.START_DOCUMENT</code>
|
||||
@@ -139,10 +142,22 @@ public class StaxStreamXmlReader extends AbstractStaxXmlReader {
|
||||
if (prefix == null) {
|
||||
prefix = "";
|
||||
}
|
||||
getContentHandler().startPrefixMapping(prefix, reader.getNamespaceURI(i));
|
||||
startPrefixMapping(prefix, reader.getNamespaceURI(i));
|
||||
}
|
||||
getContentHandler().startElement(qName.getNamespaceURI(), qName.getLocalPart(),
|
||||
QNameUtils.toQualifiedName(qName), getAttributes());
|
||||
for (int i = 0; i < reader.getAttributeCount(); i++) {
|
||||
String prefix = reader.getAttributePrefix(i);
|
||||
if (prefix == null) {
|
||||
prefix = "";
|
||||
}
|
||||
String namespace = reader.getAttributeNamespace(i);
|
||||
if (namespace == null) {
|
||||
continue;
|
||||
}
|
||||
startPrefixMapping(prefix, namespace);
|
||||
}
|
||||
getContentHandler()
|
||||
.startElement(qName.getNamespaceURI(), qName.getLocalPart(), QNameUtils.toQualifiedName(qName),
|
||||
getAttributes());
|
||||
}
|
||||
else {
|
||||
getContentHandler().startElement("", "", QNameUtils.toQualifiedName(qName), getAttributes());
|
||||
@@ -150,6 +165,13 @@ public class StaxStreamXmlReader extends AbstractStaxXmlReader {
|
||||
}
|
||||
}
|
||||
|
||||
private void startPrefixMapping(String prefix, String namespace) throws SAXException {
|
||||
if (!namespaceContext.getNamespaceURI(prefix).equals(namespace)) {
|
||||
getContentHandler().startPrefixMapping(prefix, namespace);
|
||||
namespaceContext.bindNamespaceUri(prefix, namespace);
|
||||
}
|
||||
}
|
||||
|
||||
private void handleEndElement() throws SAXException {
|
||||
if (getContentHandler() != null) {
|
||||
QName qName = reader.getName();
|
||||
@@ -162,6 +184,7 @@ public class StaxStreamXmlReader extends AbstractStaxXmlReader {
|
||||
prefix = "";
|
||||
}
|
||||
getContentHandler().endPrefixMapping(prefix);
|
||||
namespaceContext.removeBinding(prefix);
|
||||
}
|
||||
}
|
||||
else {
|
||||
@@ -180,8 +203,7 @@ public class StaxStreamXmlReader extends AbstractStaxXmlReader {
|
||||
getLexicalHandler().startCDATA();
|
||||
}
|
||||
if (getContentHandler() != null) {
|
||||
getContentHandler()
|
||||
.characters(reader.getTextCharacters(), reader.getTextStart(), reader.getTextLength());
|
||||
getContentHandler().characters(reader.getTextCharacters(), reader.getTextStart(), reader.getTextLength());
|
||||
}
|
||||
if (XMLStreamConstants.CDATA == reader.getEventType() && getLexicalHandler() != null) {
|
||||
getLexicalHandler().endCDATA();
|
||||
|
||||
Reference in New Issue
Block a user