This commit is contained in:
Arjen Poutsma
2008-05-14 14:31:49 +00:00
parent 2cb0b52ecb
commit ec3c0e9d7c
17 changed files with 619 additions and 56 deletions

View File

@@ -28,6 +28,7 @@ import org.apache.axiom.soap.SOAPFault;
import org.apache.axiom.soap.SOAPFaultCode;
import org.apache.axiom.soap.SOAPFaultReason;
import org.apache.axiom.soap.SOAPProcessingException;
import org.springframework.util.Assert;
import org.springframework.util.StringUtils;
import org.springframework.ws.soap.SoapFault;
@@ -76,7 +77,7 @@ class AxiomSoap11Body extends AxiomSoapBody implements Soap11Body {
"A fault code with namespace and local part must be specific for a custom fault code");
}
try {
detachAllBodyChildren();
AxiomUtils.removeContents(getAxiomBody());
SOAPFault fault = getAxiomFactory().createSOAPFault(getAxiomBody());
SOAPFaultCode faultCode = getAxiomFactory().createSOAPFaultCode(fault);
setValueText(code, fault, faultCode);
@@ -115,7 +116,7 @@ class AxiomSoap11Body extends AxiomSoapBody implements Soap11Body {
private SOAPFault addStandardFault(String localName, String faultString, Locale locale) {
Assert.notNull(faultString, "No faultString given");
try {
detachAllBodyChildren();
AxiomUtils.removeContents(getAxiomBody());
SOAPFault fault = getAxiomFactory().createSOAPFault(getAxiomBody());
SOAPFaultCode faultCode = getAxiomFactory().createSOAPFaultCode(fault);
faultCode.setText(QNameUtils.createQName(fault.getNamespace().getNamespaceURI(), localName,

View File

@@ -28,6 +28,7 @@ import org.apache.axiom.soap.SOAPFaultReason;
import org.apache.axiom.soap.SOAPFaultText;
import org.apache.axiom.soap.SOAPFaultValue;
import org.apache.axiom.soap.SOAPProcessingException;
import org.springframework.util.Assert;
import org.springframework.ws.soap.SoapFault;
import org.springframework.ws.soap.axiom.support.AxiomUtils;
@@ -79,7 +80,7 @@ class AxiomSoap12Body extends AxiomSoapBody implements Soap12Body {
private SOAPFault addStandardFault(String localName, String faultStringOrReason, Locale locale) {
Assert.notNull(faultStringOrReason, "No faultStringOrReason given");
try {
detachAllBodyChildren();
AxiomUtils.removeContents(getAxiomBody());
SOAPFault fault = getAxiomFactory().createSOAPFault(getAxiomBody());
SOAPFaultCode code = getAxiomFactory().createSOAPFaultCode(fault);
SOAPFaultValue value = getAxiomFactory().createSOAPFaultValue(code);

View File

@@ -16,21 +16,15 @@
package org.springframework.ws.soap.axiom;
import java.util.Iterator;
import javax.xml.stream.XMLStreamReader;
import javax.xml.transform.Result;
import javax.xml.transform.Source;
import org.apache.axiom.om.OMElement;
import org.apache.axiom.om.OMException;
import org.apache.axiom.soap.SOAPBody;
import org.apache.axiom.soap.SOAPFactory;
import org.apache.axiom.soap.SOAPFault;
import org.springframework.ws.soap.SoapBody;
import org.springframework.ws.soap.SoapFault;
import org.springframework.ws.soap.axiom.support.AxiomUtils;
import org.springframework.xml.transform.StaxSource;
/**
* Axiom-specific version of <code>org.springframework.ws.soap.Soap11Body</code>.
@@ -40,36 +34,24 @@ import org.springframework.xml.transform.StaxSource;
*/
abstract class AxiomSoapBody extends AxiomSoapElement implements SoapBody {
private boolean payloadCaching;
private final Payload payload;
protected AxiomSoapBody(SOAPBody axiomBody, SOAPFactory axiomFactory, boolean payloadCaching) {
super(axiomBody, axiomFactory);
this.payloadCaching = payloadCaching;
if (payloadCaching) {
payload = new CachingPayload(axiomBody, axiomFactory);
}
else {
payload = new NonCachingPayload(axiomBody, axiomFactory);
}
}
public Source getPayloadSource() {
try {
OMElement payloadElement = getPayloadElement();
XMLStreamReader streamReader;
if (payloadElement == null) {
return null;
}
else if (payloadCaching) {
streamReader = payloadElement.getXMLStreamReader();
}
else {
streamReader = payloadElement.getXMLStreamReaderWithoutCaching();
}
return new StaxSource(streamReader);
}
catch (OMException ex) {
throw new AxiomSoapBodyException(ex);
}
return payload.getSource();
}
public Result getPayloadResult() {
AxiomUtils.removeContents(getAxiomBody());
return new AxiomResult(getAxiomBody(), getAxiomFactory());
return payload.getResult();
}
public boolean hasFault() {
@@ -81,23 +63,6 @@ abstract class AxiomSoapBody extends AxiomSoapElement implements SoapBody {
return axiomFault != null ? new AxiomSoap11Fault(axiomFault, getAxiomFactory()) : null;
}
private OMElement getPayloadElement() throws OMException {
return getAxiomBody().getFirstElement();
}
protected void detachAllBodyChildren() {
try {
for (Iterator iterator = getAxiomBody().getChildElements(); iterator.hasNext();) {
OMElement child = (OMElement) iterator.next();
child.detach();
}
}
catch (OMException ex) {
throw new AxiomSoapBodyException(ex);
}
}
protected final SOAPBody getAxiomBody() {
return (SOAPBody) getAxiomElement();
}

View File

@@ -7,6 +7,7 @@ import org.apache.axiom.soap.SOAPBody;
import org.apache.axiom.soap.SOAPEnvelope;
import org.apache.axiom.soap.SOAPFactory;
import org.apache.axiom.soap.SOAPHeader;
import org.springframework.ws.soap.SoapBody;
import org.springframework.ws.soap.SoapEnvelope;
import org.springframework.ws.soap.SoapHeader;
@@ -23,7 +24,7 @@ class AxiomSoapEnvelope extends AxiomSoapElement implements SoapEnvelope {
private AxiomSoapBody body;
public AxiomSoapEnvelope(SOAPEnvelope axiomEnvelope, SOAPFactory axiomFactory, boolean payloadCaching) {
AxiomSoapEnvelope(SOAPEnvelope axiomEnvelope, SOAPFactory axiomFactory, boolean payloadCaching) {
super(axiomEnvelope, axiomFactory);
this.payloadCaching = payloadCaching;
}

View File

@@ -214,6 +214,7 @@ public class AxiomSoapMessage extends AbstractSoapMessage {
transportOutputStream.addHeader(TransportConstants.HEADER_CONTENT_TYPE, contentType);
transportOutputStream.addHeader(TransportConstants.HEADER_SOAP_ACTION, soapAction);
}
if (payloadCaching) {
axiomMessage.serialize(outputStream, format);
}

View File

@@ -0,0 +1,44 @@
/*
* Copyright 2008 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.
* 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.springframework.ws.soap.axiom;
import javax.xml.stream.XMLStreamReader;
import javax.xml.transform.Result;
import org.apache.axiom.om.OMElement;
import org.apache.axiom.soap.SOAPBody;
import org.apache.axiom.soap.SOAPFactory;
/**
* @author Arjen Poutsma
* @since 1.5.2
*/
class CachingPayload extends Payload {
CachingPayload(SOAPBody axiomBody, SOAPFactory axiomFactory) {
super(axiomBody, axiomFactory);
}
protected XMLStreamReader getStreamReader(OMElement payloadElement) {
return payloadElement.getXMLStreamReader();
}
public Result getResultInternal() {
return new AxiomResult(getAxiomBody(), getAxiomFactory());
}
}

View File

@@ -0,0 +1,236 @@
/*
* Copyright 2008 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.
* 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.springframework.ws.soap.axiom;
import java.io.ByteArrayOutputStream;
import javax.xml.namespace.NamespaceContext;
import javax.xml.namespace.QName;
import javax.xml.stream.XMLStreamException;
import javax.xml.stream.XMLStreamReader;
import javax.xml.stream.XMLStreamWriter;
import javax.xml.transform.Result;
import org.apache.axiom.om.OMDataSource;
import org.apache.axiom.om.OMElement;
import org.apache.axiom.om.OMNamespace;
import org.apache.axiom.om.ds.ByteArrayDataSource;
import org.apache.axiom.om.util.StAXUtils;
import org.apache.axiom.soap.SOAPBody;
import org.apache.axiom.soap.SOAPFactory;
import org.springframework.xml.transform.StaxResult;
/**
* @author Jim Cummings
* @author Arjen Poutsma
* @since 1.5.2
*/
class NonCachingPayload extends Payload {
private static final int BUF_SIZE = 1024;
NonCachingPayload(SOAPBody axiomBody, SOAPFactory axiomFactory) {
super(axiomBody, axiomFactory);
}
public Result getResultInternal() {
return new StaxResult(new DelegatingStreamWriter());
}
protected XMLStreamReader getStreamReader(OMElement payloadElement) {
return payloadElement.getXMLStreamReaderWithoutCaching();
}
private class DelegatingStreamWriter implements XMLStreamWriter {
private final ByteArrayOutputStream baos = new ByteArrayOutputStream(BUF_SIZE);
private final XMLStreamWriter delegate;
private QName name;
private String encoding;
private DelegatingStreamWriter() {
try {
this.delegate = StAXUtils.createXMLStreamWriter(baos);
}
catch (XMLStreamException ex) {
throw new AxiomSoapBodyException("Could not determine payload root element", ex);
}
}
public void writeStartDocument() throws XMLStreamException {
this.encoding = "UTF-8";
}
public void writeStartDocument(String version) throws XMLStreamException {
this.encoding = "UTF-8";
}
public void writeStartDocument(String encoding, String version) throws XMLStreamException {
this.encoding = encoding;
}
public void writeEndDocument() throws XMLStreamException {
delegate.writeEndDocument();
delegate.flush();
if (baos.size() > 0) {
byte[] buf = baos.toByteArray();
OMDataSource dataSource = new ByteArrayDataSource(buf, encoding);
OMNamespace namespace = getAxiomFactory().createOMNamespace(name.getNamespaceURI(), name.getPrefix());
OMElement payloadElement =
getAxiomFactory().createOMElement(dataSource, name.getLocalPart(), namespace);
getAxiomBody().addChild(payloadElement);
}
}
public void writeStartElement(String localName) throws XMLStreamException {
if (name == null) {
name = new QName(localName);
}
delegate.writeStartElement(localName);
}
public void writeStartElement(String namespaceURI, String localName) throws XMLStreamException {
if (name == null) {
name = new QName(namespaceURI, localName);
}
delegate.writeStartElement(namespaceURI, localName);
}
public void writeStartElement(String prefix, String localName, String namespaceURI) throws XMLStreamException {
if (name == null) {
name = new QName(namespaceURI, localName, prefix);
}
delegate.writeStartElement(prefix, localName, namespaceURI);
}
public void writeEmptyElement(String localName) throws XMLStreamException {
if (name == null) {
name = new QName(localName);
}
delegate.writeEmptyElement(localName);
}
public void writeEmptyElement(String namespaceURI, String localName) throws XMLStreamException {
if (name == null) {
name = new QName(namespaceURI, localName);
}
delegate.writeEmptyElement(namespaceURI, localName);
}
public void writeEmptyElement(String prefix, String localName, String namespaceURI) throws XMLStreamException {
if (name == null) {
name = new QName(namespaceURI, localName, prefix);
}
delegate.writeEmptyElement(prefix, localName, namespaceURI);
}
// Delegation
public void close() throws XMLStreamException {
delegate.close();
}
public void flush() throws XMLStreamException {
delegate.flush();
}
public NamespaceContext getNamespaceContext() {
return delegate.getNamespaceContext();
}
public String getPrefix(String uri) throws XMLStreamException {
return delegate.getPrefix(uri);
}
public Object getProperty(String name) throws IllegalArgumentException {
return delegate.getProperty(name);
}
public void setDefaultNamespace(String uri) throws XMLStreamException {
delegate.setDefaultNamespace(uri);
}
public void setNamespaceContext(NamespaceContext context) throws XMLStreamException {
delegate.setNamespaceContext(context);
}
public void setPrefix(String prefix, String uri) throws XMLStreamException {
delegate.setPrefix(prefix, uri);
}
public void writeAttribute(String localName, String value) throws XMLStreamException {
delegate.writeAttribute(localName, value);
}
public void writeAttribute(String namespaceURI, String localName, String value) throws XMLStreamException {
delegate.writeAttribute(namespaceURI, localName, value);
}
public void writeAttribute(String prefix, String namespaceURI, String localName, String value)
throws XMLStreamException {
delegate.writeAttribute(prefix, namespaceURI, localName, value);
}
public void writeCData(String data) throws XMLStreamException {
delegate.writeCData(data);
}
public void writeCharacters(char[] text, int start, int len) throws XMLStreamException {
delegate.writeCharacters(text, start, len);
}
public void writeCharacters(String text) throws XMLStreamException {
delegate.writeCharacters(text);
}
public void writeComment(String data) throws XMLStreamException {
delegate.writeComment(data);
}
public void writeDefaultNamespace(String namespaceURI) throws XMLStreamException {
delegate.writeDefaultNamespace(namespaceURI);
}
public void writeDTD(String dtd) throws XMLStreamException {
delegate.writeDTD(dtd);
}
public void writeEndElement() throws XMLStreamException {
delegate.writeEndElement();
}
public void writeEntityRef(String name) throws XMLStreamException {
delegate.writeEntityRef(name);
}
public void writeNamespace(String prefix, String namespaceURI) throws XMLStreamException {
delegate.writeNamespace(prefix, namespaceURI);
}
public void writeProcessingInstruction(String target) throws XMLStreamException {
delegate.writeProcessingInstruction(target);
}
public void writeProcessingInstruction(String target, String data) throws XMLStreamException {
delegate.writeProcessingInstruction(target, data);
}
}
}

View File

@@ -0,0 +1,86 @@
/*
* Copyright 2008 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.
* 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.springframework.ws.soap.axiom;
import javax.xml.stream.XMLStreamReader;
import javax.xml.transform.Result;
import javax.xml.transform.Source;
import org.apache.axiom.om.OMElement;
import org.apache.axiom.om.OMException;
import org.apache.axiom.soap.SOAPBody;
import org.apache.axiom.soap.SOAPFactory;
import org.springframework.util.Assert;
import org.springframework.ws.soap.axiom.support.AxiomUtils;
import org.springframework.xml.transform.StaxSource;
/**
* @author Arjen Poutsma
* @since 1.5.2
*/
abstract class Payload {
private final SOAPBody axiomBody;
private final SOAPFactory axiomFactory;
protected Payload(SOAPBody axiomBody, SOAPFactory axiomFactory) {
Assert.notNull(axiomBody, "'axiomBody' must not be null");
Assert.notNull(axiomFactory, "'axiomFactory' must not be null");
this.axiomBody = axiomBody;
this.axiomFactory = axiomFactory;
}
public final Source getSource() {
try {
OMElement payloadElement = getPayloadElement();
if (payloadElement != null) {
XMLStreamReader streamReader = getStreamReader(payloadElement);
return new StaxSource(streamReader);
}
else {
return null;
}
}
catch (OMException ex) {
throw new AxiomSoapBodyException(ex);
}
}
protected abstract XMLStreamReader getStreamReader(OMElement payloadElement);
public final Result getResult() {
AxiomUtils.removeContents(getAxiomBody());
return getResultInternal();
}
protected abstract Result getResultInternal();
public SOAPFactory getAxiomFactory() {
return axiomFactory;
}
protected SOAPBody getAxiomBody() {
return axiomBody;
}
protected OMElement getPayloadElement() throws OMException {
return getAxiomBody().getFirstElement();
}
}

View File

@@ -62,7 +62,6 @@ import org.springframework.ws.pox.dom.DomPoxMessageFactory;
import org.springframework.ws.soap.SoapMessageFactory;
import org.springframework.ws.soap.axiom.AxiomSoapMessageFactory;
import org.springframework.ws.soap.client.SoapFaultClientException;
import org.springframework.ws.soap.saaj.SaajSoapMessageFactory;
import org.springframework.ws.transport.http.CommonsHttpMessageSender;
import org.springframework.xml.transform.StringResult;
import org.springframework.xml.transform.StringSource;
@@ -83,8 +82,10 @@ public class WebServiceTemplateIntegrationTest extends XMLTestCase {
doSoap(new AxiomSoapMessageFactory());
}
public void testWithSaaj() throws Exception {
doSoap(new SaajSoapMessageFactory(MessageFactory.newInstance()));
public void testAxiomNonCaching() throws Exception {
AxiomSoapMessageFactory axiomFactory = new AxiomSoapMessageFactory();
axiomFactory.setPayloadCaching(false);
doSoap(axiomFactory);
}
public void testPox() throws Exception {

View File

@@ -1,9 +1,28 @@
/*
* Copyright 2008 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.
* 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.springframework.ws.soap.axiom;
import org.apache.axiom.om.OMAbstractFactory;
import org.apache.axiom.soap.SOAPFactory;
import org.springframework.ws.soap.SoapBody;
import org.springframework.ws.soap.SoapVersion;
import org.springframework.ws.soap.soap11.AbstractSoap11BodyTestCase;
import org.springframework.xml.transform.StringSource;
public class AxiomSoap11BodyTest extends AbstractSoap11BodyTestCase {
@@ -13,4 +32,16 @@ public class AxiomSoap11BodyTest extends AbstractSoap11BodyTestCase {
return axiomSoapMessage.getSoapBody();
}
public void testPayloadNoCaching() throws Exception {
AxiomSoapMessageFactory messageFactory = new AxiomSoapMessageFactory();
messageFactory.setPayloadCaching(false);
messageFactory.setSoapVersion(SoapVersion.SOAP_11);
AxiomSoapMessage axiomSoapMessage = (AxiomSoapMessage) messageFactory.createWebServiceMessage();
soapBody = axiomSoapMessage.getSoapBody();
String payload = "<payload xmlns='http://www.springframework.org' />";
transformer.transform(new StringSource(payload), soapBody.getPayloadResult());
assertPayloadEqual(payload);
}
}

View File

@@ -0,0 +1,54 @@
/*
* Copyright 2008 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.
* 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.springframework.ws.soap.axiom;
import javax.xml.transform.dom.DOMResult;
import org.w3c.dom.Document;
import org.w3c.dom.Element;
import org.springframework.ws.soap.SoapBody;
import org.springframework.ws.soap.SoapVersion;
import org.springframework.ws.soap.soap11.AbstractSoap11BodyTestCase;
import org.springframework.xml.transform.StringSource;
public class AxiomSoap11NonCachingBodyTest extends AbstractSoap11BodyTestCase {
protected SoapBody createSoapBody() throws Exception {
AxiomSoapMessageFactory messageFactory = new AxiomSoapMessageFactory();
messageFactory.setPayloadCaching(false);
messageFactory.setSoapVersion(SoapVersion.SOAP_11);
AxiomSoapMessage axiomSoapMessage = (AxiomSoapMessage) messageFactory.createWebServiceMessage();
return axiomSoapMessage.getSoapBody();
}
// overload the parent class version since it assumes the body has a payload ele after calling
// getPayloadResult, which is not true without payload caching. The paylaod ele doesn't exist until
// the axiomSoapMessage.writeTo() method is called in the normal call flow
public void testGetPayloadResultTwice() throws Exception {
SoapBody soapBody = createSoapBody();
String payload = "<payload xmlns='http://www.springframework.org' />";
transformer.transform(new StringSource(payload), soapBody.getPayloadResult());
transformer.transform(new StringSource(payload), soapBody.getPayloadResult());
DOMResult domResult = new DOMResult();
transformer.transform(soapBody.getPayloadSource(), domResult);
Element payloadElement = ((Document) domResult.getNode()).getDocumentElement();
assertTrue("No payload node was found", payloadElement != null);
assertTrue("Invalid payload local name", "payload".equals(payloadElement.getLocalName()));
}
}

View File

@@ -0,0 +1,31 @@
package org.springframework.ws.soap.axiom;
import org.apache.axiom.om.impl.llom.OMSourcedElementImpl;
import org.springframework.ws.soap.SoapBody;
import org.springframework.ws.soap.SoapMessage;
import org.springframework.ws.soap.SoapVersion;
import org.springframework.ws.soap.soap11.AbstractSoap11MessageTestCase;
public class AxiomSoap11NonCachingMessageTest extends AbstractSoap11MessageTestCase {
protected SoapMessage createSoapMessage() throws Exception {
AxiomSoapMessageFactory messageFactory = new AxiomSoapMessageFactory();
messageFactory.setPayloadCaching(false);
messageFactory.setSoapVersion(SoapVersion.SOAP_11);
return (SoapMessage) messageFactory.createWebServiceMessage();
}
public void testWriteToTransportOutputStream() throws Exception {
super.testWriteToTransportOutputStream();
SoapBody body = soapMessage.getSoapBody();
OMSourcedElementImpl axiomPayloadEle =
(OMSourcedElementImpl) ((AxiomSoapBody) body).getAxiomElement().getFirstElement();
assertFalse("Non-cached body should not be expanded now", axiomPayloadEle.isExpanded());
axiomPayloadEle.getFirstElement();
assertTrue("Non-cached body should now be expanded", axiomPayloadEle.isExpanded());
assertEquals("Invalid payload", "payload", axiomPayloadEle.getLocalName());
}
}

View File

@@ -18,8 +18,11 @@ package org.springframework.ws.soap.axiom;
import org.apache.axiom.om.OMAbstractFactory;
import org.apache.axiom.soap.SOAPFactory;
import org.springframework.ws.soap.SoapBody;
import org.springframework.ws.soap.SoapVersion;
import org.springframework.ws.soap.soap12.AbstractSoap12BodyTestCase;
import org.springframework.xml.transform.StringSource;
public class AxiomSoap12BodyTest extends AbstractSoap12BodyTestCase {
@@ -29,4 +32,16 @@ public class AxiomSoap12BodyTest extends AbstractSoap12BodyTestCase {
return axiomSoapMessage.getSoapBody();
}
public void testPayloadNoCaching() throws Exception {
AxiomSoapMessageFactory messageFactory = new AxiomSoapMessageFactory();
messageFactory.setPayloadCaching(false);
messageFactory.setSoapVersion(SoapVersion.SOAP_12);
AxiomSoapMessage axiomSoapMessage = (AxiomSoapMessage) messageFactory.createWebServiceMessage();
soapBody = axiomSoapMessage.getSoapBody();
String payload = "<payload xmlns='http://www.springframework.org' />";
transformer.transform(new StringSource(payload), soapBody.getPayloadResult());
assertPayloadEqual(payload);
}
}

View File

@@ -0,0 +1,50 @@
/*
* Copyright 2006 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.
* 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.springframework.ws.soap.axiom;
import org.springframework.ws.soap.SoapBody;
import org.springframework.ws.soap.SoapVersion;
import org.springframework.ws.soap.soap12.AbstractSoap12BodyTestCase;
public class AxiomSoap12NonCachingBodyTest extends AbstractSoap12BodyTestCase {
protected SoapBody createSoapBody() throws Exception {
AxiomSoapMessageFactory messageFactory = new AxiomSoapMessageFactory();
messageFactory.setPayloadCaching(false);
messageFactory.setSoapVersion(SoapVersion.SOAP_12);
AxiomSoapMessage axiomSoapMessage = (AxiomSoapMessage) messageFactory.createWebServiceMessage();
return axiomSoapMessage.getSoapBody();
}
// overload the parent class version since it assumes the body has a payload ele after calling
// getPayloadResult, which is not true without payload caching. The paylaod ele doesn't exist until
// the axiomSoapMessage.writeTo() method is called in the normal call flow
/*
public void testGetPayloadResultTwice() throws Exception {
SoapBody soapBody = createSoapBody();
String payload = "<payload xmlns='http://www.springframework.org' />";
transformer.transform(new StringSource(payload), soapBody.getPayloadResult());
transformer.transform(new StringSource(payload), soapBody.getPayloadResult());
DOMResult domResult = new DOMResult();
transformer.transform(soapBody.getPayloadSource(), domResult);
Element payloadElement = ((Document) domResult.getNode()).getDocumentElement();
assertTrue("No payload node was found", payloadElement != null);
assertTrue("Invalid payload local name", "payload".equals(payloadElement.getLocalName()));
}
*/
}

View File

@@ -0,0 +1,31 @@
package org.springframework.ws.soap.axiom;
import org.apache.axiom.om.impl.llom.OMSourcedElementImpl;
import org.springframework.ws.soap.SoapBody;
import org.springframework.ws.soap.SoapMessage;
import org.springframework.ws.soap.SoapVersion;
import org.springframework.ws.soap.soap12.AbstractSoap12MessageTestCase;
public class AxiomSoap12NonCachingMessageTest extends AbstractSoap12MessageTestCase {
protected SoapMessage createSoapMessage() throws Exception {
AxiomSoapMessageFactory messageFactory = new AxiomSoapMessageFactory();
messageFactory.setPayloadCaching(false);
messageFactory.setSoapVersion(SoapVersion.SOAP_12);
return (SoapMessage) messageFactory.createWebServiceMessage();
}
public void testWriteToTransportOutputStream() throws Exception {
super.testWriteToTransportOutputStream();
SoapBody body = soapMessage.getSoapBody();
OMSourcedElementImpl axiomPayloadEle =
(OMSourcedElementImpl) ((AxiomSoapBody) body).getAxiomElement().getFirstElement();
assertFalse("Non-cached body should not be expanded now", axiomPayloadEle.isExpanded());
axiomPayloadEle.getFirstElement();
assertTrue("Non-cached body should now be expanded", axiomPayloadEle.isExpanded());
assertEquals("Invalid payload", "payload", axiomPayloadEle.getLocalName());
}
}

View File

@@ -19,13 +19,16 @@ package org.springframework.ws.soap.soap11;
import java.io.ByteArrayOutputStream;
import junit.framework.Assert;
import org.springframework.core.io.ByteArrayResource;
import org.springframework.core.io.ClassPathResource;
import org.springframework.core.io.InputStreamSource;
import org.springframework.core.io.Resource;
import org.springframework.ws.soap.AbstractSoapMessageTestCase;
import org.springframework.ws.soap.SoapBody;
import org.springframework.ws.soap.SoapVersion;
import org.springframework.ws.transport.MockTransportOutputStream;
import org.springframework.xml.transform.StringSource;
public abstract class AbstractSoap11MessageTestCase extends AbstractSoapMessageTestCase {
@@ -38,13 +41,19 @@ public abstract class AbstractSoap11MessageTestCase extends AbstractSoapMessageT
}
public void testWriteToTransportOutputStream() throws Exception {
SoapBody body = soapMessage.getSoapBody();
String payload = "<payload xmlns='http://www.springframework.org' />";
transformer.transform(new StringSource(payload), body.getPayloadResult());
ByteArrayOutputStream bos = new ByteArrayOutputStream();
MockTransportOutputStream tos = new MockTransportOutputStream(bos);
String soapAction = "http://springframework.org/spring-ws/Action";
soapMessage.setSoapAction(soapAction);
soapMessage.writeTo(tos);
String result = bos.toString("UTF-8");
assertXMLEqual("<Envelope xmlns='http://schemas.xmlsoap.org/soap/envelope/'><Body/></Envelope>", result);
assertXMLEqual(
"<Envelope xmlns='http://schemas.xmlsoap.org/soap/envelope/'><Body><payload xmlns='http://www.springframework.org' /></Body></Envelope>",
result);
String contentType = (String) tos.getHeaders().get("Content-Type");
assertTrue("Invalid Content-Type set", contentType.indexOf(SoapVersion.SOAP_11.getContentType()) != -1);
String resultSoapAction = (String) tos.getHeaders().get("SOAPAction");
@@ -63,6 +72,4 @@ public abstract class AbstractSoap11MessageTestCase extends AbstractSoapMessageT
assertTrue("Content-Type for attachment message does not contains type=\"text/xml\"",
contentType.indexOf("type=\"text/xml\"") != -1);
}
}

View File

@@ -19,13 +19,16 @@ package org.springframework.ws.soap.soap12;
import java.io.ByteArrayOutputStream;
import junit.framework.Assert;
import org.springframework.core.io.ByteArrayResource;
import org.springframework.core.io.ClassPathResource;
import org.springframework.core.io.InputStreamSource;
import org.springframework.core.io.Resource;
import org.springframework.ws.soap.AbstractSoapMessageTestCase;
import org.springframework.ws.soap.SoapBody;
import org.springframework.ws.soap.SoapVersion;
import org.springframework.ws.transport.MockTransportOutputStream;
import org.springframework.xml.transform.StringSource;
public abstract class AbstractSoap12MessageTestCase extends AbstractSoapMessageTestCase {
@@ -39,12 +42,17 @@ public abstract class AbstractSoap12MessageTestCase extends AbstractSoapMessageT
}
public void testWriteToTransportOutputStream() throws Exception {
SoapBody body = soapMessage.getSoapBody();
String payload = "<payload xmlns='http://www.springframework.org' />";
transformer.transform(new StringSource(payload), body.getPayloadResult());
final ByteArrayOutputStream bos = new ByteArrayOutputStream();
MockTransportOutputStream tos = new MockTransportOutputStream(bos);
soapMessage.writeTo(tos);
String result = bos.toString("UTF-8");
assertXMLEqual("<Envelope xmlns='http://www.w3.org/2003/05/soap-envelope'><Body/></Envelope>", result);
assertXMLEqual(
"<Envelope xmlns='http://www.w3.org/2003/05/soap-envelope'><Body><payload xmlns='http://www.springframework.org' /></Body></Envelope>",
result);
String contentType = (String) tos.getHeaders().get("Content-Type");
assertTrue("Invalid Content-Type set", contentType.indexOf(SoapVersion.SOAP_12.getContentType()) != -1);
}