Remove deprecated endpoint base classes
This deprecates the programming model of extending from base endpoint class in favor of the `@Endpoint` programming model introduced in Spring-WS 2.0. This also removes any reference <sws:marshalling-endpoints/> and <sws:xpath-endpoints/> that are no longer part of the XSD since 2.0 as well. Closes gh-1487
This commit is contained in:
@@ -1,71 +0,0 @@
|
||||
/*
|
||||
* Copyright 2005-2025 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
|
||||
*
|
||||
* https://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.config;
|
||||
|
||||
import org.w3c.dom.Element;
|
||||
|
||||
import org.springframework.beans.factory.support.BeanDefinitionBuilder;
|
||||
import org.springframework.beans.factory.xml.AbstractSimpleBeanDefinitionParser;
|
||||
import org.springframework.beans.factory.xml.ParserContext;
|
||||
import org.springframework.util.ClassUtils;
|
||||
import org.springframework.util.StringUtils;
|
||||
|
||||
/**
|
||||
* Parser for the {@code <sws:marshalling-endpoints/>} element.
|
||||
*
|
||||
* @author Arjen Poutsma
|
||||
* @since 1.5.0
|
||||
* @deprecated as of Spring Web Services 2.0, in favor of
|
||||
* {@link AnnotationDrivenBeanDefinitionParser}
|
||||
*/
|
||||
@Deprecated
|
||||
class MarshallingEndpointsBeanDefinitionParser extends AbstractSimpleBeanDefinitionParser {
|
||||
|
||||
private static final String GENERIC_MARSHALLING_METHOD_ENDPOINT_ADAPTER_CLASS_NAME = "org.springframework.ws.server.endpoint.adapter.GenericMarshallingMethodEndpointAdapter";
|
||||
|
||||
private static final boolean genericAdapterPresent = ClassUtils.isPresent(
|
||||
GENERIC_MARSHALLING_METHOD_ENDPOINT_ADAPTER_CLASS_NAME,
|
||||
MarshallingEndpointsBeanDefinitionParser.class.getClassLoader());
|
||||
|
||||
private static final String MARSHALLING_METHOD_ENDPOINT_ADAPTER_CLASS_NAME = "org.springframework.ws.server.endpoint.adapter.MarshallingMethodEndpointAdapter";
|
||||
|
||||
@Override
|
||||
protected boolean shouldGenerateIdAsFallback() {
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected String getBeanClassName(Element element) {
|
||||
if (genericAdapterPresent) {
|
||||
return GENERIC_MARSHALLING_METHOD_ENDPOINT_ADAPTER_CLASS_NAME;
|
||||
}
|
||||
return MARSHALLING_METHOD_ENDPOINT_ADAPTER_CLASS_NAME;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void doParse(Element element, ParserContext parserContext, BeanDefinitionBuilder beanDefinitionBuilder) {
|
||||
String marshallerName = element.getAttribute("marshaller");
|
||||
if (StringUtils.hasText(marshallerName)) {
|
||||
beanDefinitionBuilder.addPropertyReference("marshaller", marshallerName);
|
||||
}
|
||||
String unmarshallerName = element.getAttribute("unmarshaller");
|
||||
if (StringUtils.hasText(unmarshallerName)) {
|
||||
beanDefinitionBuilder.addPropertyReference("unmarshaller", unmarshallerName);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
@@ -28,14 +28,11 @@ import org.springframework.beans.factory.xml.NamespaceHandlerSupport;
|
||||
public class WebServicesNamespaceHandler extends NamespaceHandlerSupport {
|
||||
|
||||
@Override
|
||||
@SuppressWarnings("deprecation")
|
||||
public void init() {
|
||||
registerBeanDefinitionParser("annotation-driven", new AnnotationDrivenBeanDefinitionParser());
|
||||
registerBeanDefinitionParser("interceptors", new InterceptorsBeanDefinitionParser());
|
||||
registerBeanDefinitionParser("static-wsdl", new StaticWsdlBeanDefinitionParser());
|
||||
registerBeanDefinitionParser("dynamic-wsdl", new DynamicWsdlBeanDefinitionParser());
|
||||
registerBeanDefinitionParser("marshalling-endpoints", new MarshallingEndpointsBeanDefinitionParser());
|
||||
registerBeanDefinitionParser("xpath-endpoints", new XPathEndpointsBeanDefinitionParser());
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -1,66 +0,0 @@
|
||||
/*
|
||||
* Copyright 2005-2025 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
|
||||
*
|
||||
* https://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.config;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.Properties;
|
||||
|
||||
import org.w3c.dom.Element;
|
||||
|
||||
import org.springframework.beans.factory.support.BeanDefinitionBuilder;
|
||||
import org.springframework.beans.factory.xml.AbstractSimpleBeanDefinitionParser;
|
||||
import org.springframework.beans.factory.xml.ParserContext;
|
||||
import org.springframework.util.xml.DomUtils;
|
||||
|
||||
/**
|
||||
* Parser for the {@code <sws:xpath-endpoints>} element.
|
||||
*
|
||||
* @author Arjen Poutsma
|
||||
* @since 1.5.0
|
||||
* @deprecated as of Spring Web Services 2.0, in favor of
|
||||
* {@link AnnotationDrivenBeanDefinitionParser}
|
||||
*/
|
||||
@Deprecated
|
||||
class XPathEndpointsBeanDefinitionParser extends AbstractSimpleBeanDefinitionParser {
|
||||
|
||||
private static final String XPATH_PARAM_ANNOTATION_METHOD_ENDPOINT_ADAPTER_CLASS_NAME = "org.springframework.ws.server.endpoint.adapter.XPathParamAnnotationMethodEndpointAdapter";
|
||||
|
||||
@Override
|
||||
protected boolean shouldGenerateIdAsFallback() {
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected String getBeanClassName(Element element) {
|
||||
return XPATH_PARAM_ANNOTATION_METHOD_ENDPOINT_ADAPTER_CLASS_NAME;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void doParse(Element element, ParserContext parserContext, BeanDefinitionBuilder beanDefinitionBuilder) {
|
||||
List<Element> namespaceElements = DomUtils.getChildElementsByTagName(element, "namespace");
|
||||
if (!namespaceElements.isEmpty()) {
|
||||
Properties namespaces = new Properties();
|
||||
for (Element namespaceElement : namespaceElements) {
|
||||
String prefix = namespaceElement.getAttribute("prefix");
|
||||
String uri = namespaceElement.getAttribute("uri");
|
||||
namespaces.setProperty(prefix, uri);
|
||||
}
|
||||
beanDefinitionBuilder.addPropertyValue("namespaces", namespaces);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
@@ -62,12 +62,8 @@ import org.springframework.ws.transport.WebServiceMessageReceiver;
|
||||
* <li>It can use any {@link EndpointAdapter}; this allows one to use any endpoint
|
||||
* interface or form. Defaults to the {@link MessageEndpointAdapter} and
|
||||
* {@link PayloadEndpointAdapter}, for {@link MessageEndpoint} and
|
||||
* {@link PayloadEndpoint}, respectively, and the
|
||||
* {@link org.springframework.ws.server.endpoint.adapter.MessageMethodEndpointAdapter
|
||||
* MessageMethodEndpointAdapter} and
|
||||
* {@link org.springframework.ws.server.endpoint.adapter.PayloadMethodEndpointAdapter
|
||||
* PayloadMethodEndpointAdapter}. Additional endpoint adapters can be added through the
|
||||
* {@link #setEndpointAdapters(List) endpointAdapters} property.</li>
|
||||
* {@link PayloadEndpoint}, respectively. Additional endpoint adapters can be added
|
||||
* through the {@link #setEndpointAdapters(List) endpointAdapters} property.</li>
|
||||
* <li>Its exception resolution strategy can be specified via a
|
||||
* {@link EndpointExceptionResolver}, for example mapping certain exceptions to SOAP
|
||||
* Faults. Default is none. Additional exception resolvers can be added through the
|
||||
|
||||
@@ -1,118 +0,0 @@
|
||||
/*
|
||||
* Copyright 2005-2025 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
|
||||
*
|
||||
* https://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.server.endpoint;
|
||||
|
||||
import javax.xml.transform.Source;
|
||||
import javax.xml.transform.TransformerException;
|
||||
import javax.xml.transform.dom.DOMSource;
|
||||
|
||||
import org.dom4j.Document;
|
||||
import org.dom4j.DocumentHelper;
|
||||
import org.dom4j.Element;
|
||||
import org.dom4j.io.DOMReader;
|
||||
import org.dom4j.io.DocumentResult;
|
||||
import org.dom4j.io.DocumentSource;
|
||||
import org.w3c.dom.Node;
|
||||
|
||||
import org.springframework.xml.transform.TransformerObjectSupport;
|
||||
|
||||
/**
|
||||
* Abstract base class for endpoints that handle the message payload as dom4j elements.
|
||||
* Offers the message payload as a dom4j {@code Element}, and allows subclasses to create
|
||||
* a response by returning an {@code Element}.
|
||||
* <p>
|
||||
* An {@code AbstractDom4JPayloadEndpoint} only accept one payload element. Multiple
|
||||
* payload elements are not in accordance with WS-I.
|
||||
*
|
||||
* @author Arjen Poutsma
|
||||
* @since 1.0.0
|
||||
* @see org.dom4j.Element
|
||||
* @deprecated as of Spring Web Services 2.0, in favor of annotated endpoints
|
||||
*/
|
||||
@Deprecated
|
||||
public abstract class AbstractDom4jPayloadEndpoint extends TransformerObjectSupport implements PayloadEndpoint {
|
||||
|
||||
private boolean alwaysTransform = false;
|
||||
|
||||
/**
|
||||
* Set if the request {@link Source} should always be transformed into a new
|
||||
* {@link DocumentResult}.
|
||||
* <p>
|
||||
* Default is {@code false}, which is faster.
|
||||
*/
|
||||
public void setAlwaysTransform(boolean alwaysTransform) {
|
||||
this.alwaysTransform = alwaysTransform;
|
||||
}
|
||||
|
||||
@Override
|
||||
public final Source invoke(Source request) throws Exception {
|
||||
Element requestElement = null;
|
||||
if (request != null) {
|
||||
DocumentResult dom4jResult = new DocumentResult();
|
||||
transform(request, dom4jResult);
|
||||
requestElement = dom4jResult.getDocument().getRootElement();
|
||||
}
|
||||
Document responseDocument = DocumentHelper.createDocument();
|
||||
Element responseElement = invokeInternal(requestElement, responseDocument);
|
||||
return (responseElement != null) ? new DocumentSource(responseElement) : null;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the payload element of the given source.
|
||||
* <p>
|
||||
* Default implementation checks whether the source is a
|
||||
* {@link javax.xml.transform.dom.DOMSource}, and uses a
|
||||
* {@link org.dom4j.io.DOMReader} to create a JDOM {@link org.dom4j.Element}. In all
|
||||
* other cases, or when {@linkplain #setAlwaysTransform(boolean) alwaysTransform} is
|
||||
* {@code true}, the source is transformed into a {@link org.dom4j.io.DocumentResult},
|
||||
* which is more expensive. If the passed source is {@code null}, {@code
|
||||
* null} is returned.
|
||||
* @param source the source to return the root element of; can be {@code null}
|
||||
* @return the document element
|
||||
* @throws javax.xml.transform.TransformerException in case of errors
|
||||
*/
|
||||
protected Element getDocumentElement(Source source) throws TransformerException {
|
||||
if (source == null) {
|
||||
return null;
|
||||
}
|
||||
if (!this.alwaysTransform && source instanceof DOMSource) {
|
||||
Node node = ((DOMSource) source).getNode();
|
||||
if (node.getNodeType() == Node.DOCUMENT_NODE) {
|
||||
DOMReader domReader = new DOMReader();
|
||||
Document document = domReader.read((org.w3c.dom.Document) node);
|
||||
return document.getRootElement();
|
||||
}
|
||||
}
|
||||
// we have no other option than to transform
|
||||
DocumentResult dom4jResult = new DocumentResult();
|
||||
transform(source, dom4jResult);
|
||||
return dom4jResult.getDocument().getRootElement();
|
||||
}
|
||||
|
||||
/**
|
||||
* Template method. Subclasses must implement this. Offers the request payload as a
|
||||
* dom4j {@code Element}, and allows subclasses to return a response {@code Element}.
|
||||
* <p>
|
||||
* The given dom4j {@code Document} is to be used for constructing a response element,
|
||||
* by using {@code addElement}.
|
||||
* @param requestElement the contents of the SOAP message as dom4j elements
|
||||
* @param responseDocument a dom4j document to be used for constructing a response
|
||||
* @return the response element. Can be {@code null} to specify no response.
|
||||
*/
|
||||
protected abstract Element invokeInternal(Element requestElement, Document responseDocument) throws Exception;
|
||||
|
||||
}
|
||||
@@ -1,182 +0,0 @@
|
||||
/*
|
||||
* Copyright 2005-2025 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
|
||||
*
|
||||
* https://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.server.endpoint;
|
||||
|
||||
import javax.xml.parsers.DocumentBuilder;
|
||||
import javax.xml.parsers.DocumentBuilderFactory;
|
||||
import javax.xml.parsers.ParserConfigurationException;
|
||||
import javax.xml.transform.Source;
|
||||
import javax.xml.transform.TransformerException;
|
||||
import javax.xml.transform.dom.DOMResult;
|
||||
import javax.xml.transform.dom.DOMSource;
|
||||
|
||||
import org.w3c.dom.Document;
|
||||
import org.w3c.dom.Element;
|
||||
import org.w3c.dom.Node;
|
||||
|
||||
import org.springframework.xml.DocumentBuilderFactoryUtils;
|
||||
import org.springframework.xml.transform.TransformerObjectSupport;
|
||||
|
||||
/**
|
||||
* Abstract base class for endpoints that handle the message payload as DOM elements.
|
||||
* <p>
|
||||
* Offers the message payload as a DOM {@code Element}, and allows subclasses to create a
|
||||
* response by returning an {@code Element}.
|
||||
* <p>
|
||||
* An {@code AbstractDomPayloadEndpoint} only accept <em>one</em> payload element.
|
||||
* Multiple payload elements are not in accordance with WS-I.
|
||||
*
|
||||
* @author Arjen Poutsma
|
||||
* @author Alef Arendsen
|
||||
* @since 1.0.0
|
||||
* @see #invokeInternal(org.w3c.dom.Element,org.w3c.dom.Document)
|
||||
* @deprecated as of Spring Web Services 2.0, in favor of annotated endpoints
|
||||
*/
|
||||
@Deprecated
|
||||
public abstract class AbstractDomPayloadEndpoint extends TransformerObjectSupport implements PayloadEndpoint {
|
||||
|
||||
private DocumentBuilderFactory documentBuilderFactory;
|
||||
|
||||
private boolean validating = false;
|
||||
|
||||
private boolean namespaceAware = true;
|
||||
|
||||
private boolean expandEntityReferences = false;
|
||||
|
||||
private boolean alwaysTransform = false;
|
||||
|
||||
/**
|
||||
* Set whether or not the XML parser should be XML namespace aware. Default is
|
||||
* {@code true}.
|
||||
*/
|
||||
public void setNamespaceAware(boolean namespaceAware) {
|
||||
this.namespaceAware = namespaceAware;
|
||||
}
|
||||
|
||||
/** Set if the XML parser should validate the document. Default is {@code false}. */
|
||||
public void setValidating(boolean validating) {
|
||||
this.validating = validating;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set if the XML parser should expand entity reference nodes. Default is
|
||||
* {@code false}.
|
||||
*/
|
||||
public void setExpandEntityReferences(boolean expandEntityRef) {
|
||||
this.documentBuilderFactory.setExpandEntityReferences(expandEntityRef);
|
||||
}
|
||||
|
||||
/**
|
||||
* Set if the request {@link Source} should always be transformed into a new
|
||||
* {@link DOMResult}.
|
||||
* <p>
|
||||
* Default is {@code false}, which is faster.
|
||||
*/
|
||||
public void setAlwaysTransform(boolean alwaysTransform) {
|
||||
this.alwaysTransform = alwaysTransform;
|
||||
}
|
||||
|
||||
@Override
|
||||
public final Source invoke(Source request) throws Exception {
|
||||
if (this.documentBuilderFactory == null) {
|
||||
this.documentBuilderFactory = createDocumentBuilderFactory();
|
||||
}
|
||||
DocumentBuilder documentBuilder = createDocumentBuilder(this.documentBuilderFactory);
|
||||
Element requestElement = getDocumentElement(request, documentBuilder);
|
||||
Document responseDocument = documentBuilder.newDocument();
|
||||
Element responseElement = invokeInternal(requestElement, responseDocument);
|
||||
return (responseElement != null) ? new DOMSource(responseElement) : null;
|
||||
}
|
||||
|
||||
/**
|
||||
* Create a {@code DocumentBuilder} that this endpoint will use for parsing XML
|
||||
* documents. Can be overridden in subclasses, adding further initialization of the
|
||||
* builder.
|
||||
* @param factory the {@code DocumentBuilderFactory} that the DocumentBuilder should
|
||||
* be created with
|
||||
* @return the {@code DocumentBuilder}
|
||||
* @throws ParserConfigurationException if thrown by JAXP methods
|
||||
*/
|
||||
protected DocumentBuilder createDocumentBuilder(DocumentBuilderFactory factory)
|
||||
throws ParserConfigurationException {
|
||||
return factory.newDocumentBuilder();
|
||||
}
|
||||
|
||||
/**
|
||||
* Create a {@code DocumentBuilderFactory} that this endpoint will use for
|
||||
* constructing XML documents. Can be overridden in subclasses, adding further
|
||||
* initialization of the factory. The resulting {@code DocumentBuilderFactory} is
|
||||
* cached, so this method will only be called once.
|
||||
* @return the DocumentBuilderFactory
|
||||
* @throws ParserConfigurationException if thrown by JAXP methods
|
||||
*/
|
||||
protected DocumentBuilderFactory createDocumentBuilderFactory() throws ParserConfigurationException {
|
||||
DocumentBuilderFactory factory = DocumentBuilderFactoryUtils.newInstance();
|
||||
factory.setValidating(this.validating);
|
||||
factory.setNamespaceAware(this.namespaceAware);
|
||||
factory.setExpandEntityReferences(this.expandEntityReferences);
|
||||
return factory;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the payload element of the given source.
|
||||
* <p>
|
||||
* Default implementation checks whether the source is a {@link DOMSource}, and
|
||||
* returns the {@linkplain DOMSource#getNode() node} of that. In all other cases, or
|
||||
* when {@linkplain #setAlwaysTransform(boolean) alwaysTransform} is {@code true}, the
|
||||
* source is transformed into a {@link DOMResult}, which is more expensive. If the
|
||||
* passed source is {@code null}, {@code null} is returned.
|
||||
* @param source the source to return the root element of; can be {@code null}
|
||||
* @param documentBuilder the document builder to be used for transformations
|
||||
* @return the document element
|
||||
* @throws TransformerException in case of errors
|
||||
*/
|
||||
protected Element getDocumentElement(Source source, DocumentBuilder documentBuilder) throws TransformerException {
|
||||
if (source == null) {
|
||||
return null;
|
||||
}
|
||||
if (!this.alwaysTransform && source instanceof DOMSource) {
|
||||
Node node = ((DOMSource) source).getNode();
|
||||
if (node.getNodeType() == Node.ELEMENT_NODE) {
|
||||
return (Element) node;
|
||||
}
|
||||
else if (node.getNodeType() == Node.DOCUMENT_NODE) {
|
||||
return ((Document) node).getDocumentElement();
|
||||
}
|
||||
}
|
||||
// we have no other option than to transform
|
||||
Document requestDocument = documentBuilder.newDocument();
|
||||
DOMResult domResult = new DOMResult(requestDocument);
|
||||
transform(source, domResult);
|
||||
return requestDocument.getDocumentElement();
|
||||
}
|
||||
|
||||
/**
|
||||
* Template method that subclasses must implement to process the request.
|
||||
* <p>
|
||||
* Offers the request payload as a DOM {@code Element}, and allows subclasses to
|
||||
* return a response {@code Element}.
|
||||
* <p>
|
||||
* The given DOM {@code Document} is to be used for constructing {@code Node}s, by
|
||||
* using the various {@code create} methods.
|
||||
* @param requestElement the contents of the SOAP message as DOM elements
|
||||
* @param responseDocument a DOM document to be used for constructing {@code Node}s
|
||||
* @return the response element. Can be {@code null} to specify no response.
|
||||
*/
|
||||
protected abstract Element invokeInternal(Element requestElement, Document responseDocument) throws Exception;
|
||||
|
||||
}
|
||||
@@ -1,107 +0,0 @@
|
||||
/*
|
||||
* Copyright 2005-2025 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
|
||||
*
|
||||
* https://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.server.endpoint;
|
||||
|
||||
import javax.xml.transform.Source;
|
||||
import javax.xml.transform.TransformerException;
|
||||
import javax.xml.transform.dom.DOMSource;
|
||||
|
||||
import org.jdom2.Document;
|
||||
import org.jdom2.Element;
|
||||
import org.jdom2.input.DOMBuilder;
|
||||
import org.jdom2.transform.JDOMResult;
|
||||
import org.jdom2.transform.JDOMSource;
|
||||
import org.w3c.dom.Node;
|
||||
|
||||
import org.springframework.xml.transform.TransformerObjectSupport;
|
||||
|
||||
/**
|
||||
* Abstract base class for endpoints that handle the message payload as JDOM elements.
|
||||
* <p>
|
||||
* Offers the message payload as a JDOM {@link Element}, and allows subclasses to create a
|
||||
* response by returning an {@code Element}. An {@code AbstractJDomPayloadEndpoint} can
|
||||
* accept only <i>one</i> payload element. Multiple payload elements are not in accordance
|
||||
* with WS-I.
|
||||
*
|
||||
* @author Arjen Poutsma
|
||||
* @since 1.0.0
|
||||
* @deprecated as of Spring Web Services 2.0, in favor of annotated endpoints
|
||||
*/
|
||||
@Deprecated
|
||||
public abstract class AbstractJDomPayloadEndpoint extends TransformerObjectSupport implements PayloadEndpoint {
|
||||
|
||||
private boolean alwaysTransform = false;
|
||||
|
||||
/**
|
||||
* Set if the request {@link Source} should always be transformed into a new
|
||||
* {@link JDOMResult}.
|
||||
* <p>
|
||||
* Default is {@code false}, which is faster.
|
||||
*/
|
||||
public void setAlwaysTransform(boolean alwaysTransform) {
|
||||
this.alwaysTransform = alwaysTransform;
|
||||
}
|
||||
|
||||
@Override
|
||||
public final Source invoke(Source request) throws Exception {
|
||||
Element requestElement = getDocumentElement(request);
|
||||
Element responseElement = invokeInternal(requestElement);
|
||||
return (responseElement != null) ? new JDOMSource(responseElement) : null;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the payload element of the given source.
|
||||
* <p>
|
||||
* Default implementation checks whether the source is a {@link DOMSource}, and uses a
|
||||
* {@link DOMBuilder} to create a JDOM {@link Element}. In all other cases, or when
|
||||
* {@linkplain #setAlwaysTransform(boolean) alwaysTransform} is {@code true}, the
|
||||
* source is transformed into a {@link JDOMResult}, which is more expensive. If the
|
||||
* passed source is {@code null}, {@code null} is returned.
|
||||
* @param source the source to return the root element of; can be {@code null}
|
||||
* @return the document element
|
||||
* @throws TransformerException in case of errors
|
||||
*/
|
||||
protected Element getDocumentElement(Source source) throws TransformerException {
|
||||
if (source == null) {
|
||||
return null;
|
||||
}
|
||||
if (!this.alwaysTransform && source instanceof DOMSource) {
|
||||
Node node = ((DOMSource) source).getNode();
|
||||
DOMBuilder domBuilder = new DOMBuilder();
|
||||
if (node.getNodeType() == Node.ELEMENT_NODE) {
|
||||
return domBuilder.build((org.w3c.dom.Element) node);
|
||||
}
|
||||
else if (node.getNodeType() == Node.DOCUMENT_NODE) {
|
||||
Document document = domBuilder.build((org.w3c.dom.Document) node);
|
||||
return document.getRootElement();
|
||||
}
|
||||
}
|
||||
// we have no other option than to transform
|
||||
JDOMResult jdomResult = new JDOMResult();
|
||||
transform(source, jdomResult);
|
||||
return jdomResult.getDocument().getRootElement();
|
||||
}
|
||||
|
||||
/**
|
||||
* Template method. Subclasses must implement this. Offers the request payload as a
|
||||
* JDOM {@code Element}, and allows subclasses to return a response {@code Element}.
|
||||
* @param requestElement the contents of the SOAP message as JDOM element
|
||||
* @return the response element. Can be {@code null} to specify no response.
|
||||
*/
|
||||
protected abstract Element invokeInternal(Element requestElement) throws Exception;
|
||||
|
||||
}
|
||||
@@ -1,216 +0,0 @@
|
||||
/*
|
||||
* Copyright 2005-2025 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
|
||||
*
|
||||
* https://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.server.endpoint;
|
||||
|
||||
import java.io.IOException;
|
||||
|
||||
import org.apache.commons.logging.Log;
|
||||
import org.apache.commons.logging.LogFactory;
|
||||
|
||||
import org.springframework.beans.factory.InitializingBean;
|
||||
import org.springframework.oxm.Marshaller;
|
||||
import org.springframework.oxm.Unmarshaller;
|
||||
import org.springframework.util.Assert;
|
||||
import org.springframework.ws.WebServiceMessage;
|
||||
import org.springframework.ws.context.MessageContext;
|
||||
import org.springframework.ws.support.MarshallingUtils;
|
||||
|
||||
/**
|
||||
* Endpoint that unmarshals the request payload, and marshals the response object. This
|
||||
* endpoint needs a {@code Marshaller} and {@code Unmarshaller}, both of which can be set
|
||||
* using properties. An abstract template method is invoked using the request object as a
|
||||
* parameter, and allows for a response object to be returned.
|
||||
*
|
||||
* @author Arjen Poutsma
|
||||
* @since 1.0.0
|
||||
* @see #setMarshaller(org.springframework.oxm.Marshaller)
|
||||
* @see Marshaller
|
||||
* @see #setUnmarshaller(org.springframework.oxm.Unmarshaller)
|
||||
* @see Unmarshaller
|
||||
* @see #invokeInternal(Object)
|
||||
* @deprecated as of Spring Web Services 2.0, in favor of annotated endpoints
|
||||
*/
|
||||
@Deprecated
|
||||
public abstract class AbstractMarshallingPayloadEndpoint implements MessageEndpoint, InitializingBean {
|
||||
|
||||
/** Logger available to subclasses. */
|
||||
protected final Log logger = LogFactory.getLog(getClass());
|
||||
|
||||
private Marshaller marshaller;
|
||||
|
||||
private Unmarshaller unmarshaller;
|
||||
|
||||
/**
|
||||
* Creates a new {@code AbstractMarshallingPayloadEndpoint}. The {@link Marshaller}
|
||||
* and {@link Unmarshaller} must be injected using properties.
|
||||
* @see #setMarshaller(org.springframework.oxm.Marshaller)
|
||||
* @see #setUnmarshaller(org.springframework.oxm.Unmarshaller)
|
||||
*/
|
||||
protected AbstractMarshallingPayloadEndpoint() {
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates a new {@code AbstractMarshallingPayloadEndpoint} with the given marshaller.
|
||||
* The given {@link Marshaller} should also implements the {@link Unmarshaller}, since
|
||||
* it is used for both marshalling and unmarshalling. If it is not, an exception is
|
||||
* thrown.
|
||||
* <p>
|
||||
* Note that all {@link Marshaller} implementations in Spring-WS also implement the
|
||||
* {@link Unmarshaller} interface, so that you can safely use this constructor.
|
||||
* @param marshaller object used as marshaller and unmarshaller
|
||||
* @throws IllegalArgumentException when {@code marshaller} does not implement the
|
||||
* {@link Unmarshaller} interface
|
||||
* @see #AbstractMarshallingPayloadEndpoint(Marshaller,Unmarshaller)
|
||||
*/
|
||||
protected AbstractMarshallingPayloadEndpoint(Marshaller marshaller) {
|
||||
Assert.notNull(marshaller, "marshaller must not be null");
|
||||
if (!(marshaller instanceof Unmarshaller)) {
|
||||
throw new IllegalArgumentException("Marshaller [" + marshaller + "] does not implement the Unmarshaller "
|
||||
+ "interface. Please set an Unmarshaller explicitly by using the "
|
||||
+ "AbstractMarshallingPayloadEndpoint(Marshaller, Unmarshaller) constructor.");
|
||||
}
|
||||
else {
|
||||
setMarshaller(marshaller);
|
||||
setUnmarshaller((Unmarshaller) marshaller);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates a new {@code AbstractMarshallingPayloadEndpoint} with the given marshaller
|
||||
* and unmarshaller.
|
||||
* @param marshaller the marshaller to use
|
||||
* @param unmarshaller the unmarshaller to use
|
||||
*/
|
||||
protected AbstractMarshallingPayloadEndpoint(Marshaller marshaller, Unmarshaller unmarshaller) {
|
||||
Assert.notNull(marshaller, "marshaller must not be null");
|
||||
Assert.notNull(unmarshaller, "unmarshaller must not be null");
|
||||
setMarshaller(marshaller);
|
||||
setUnmarshaller(unmarshaller);
|
||||
}
|
||||
|
||||
/** Returns the marshaller used for transforming objects into XML. */
|
||||
public Marshaller getMarshaller() {
|
||||
return this.marshaller;
|
||||
}
|
||||
|
||||
/** Sets the marshaller used for transforming objects into XML. */
|
||||
public final void setMarshaller(Marshaller marshaller) {
|
||||
this.marshaller = marshaller;
|
||||
}
|
||||
|
||||
/** Returns the unmarshaller used for transforming XML into objects. */
|
||||
public Unmarshaller getUnmarshaller() {
|
||||
return this.unmarshaller;
|
||||
}
|
||||
|
||||
/** Sets the unmarshaller used for transforming XML into objects. */
|
||||
public final void setUnmarshaller(Unmarshaller unmarshaller) {
|
||||
this.unmarshaller = unmarshaller;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void afterPropertiesSet() throws Exception {
|
||||
afterMarshallerSet();
|
||||
}
|
||||
|
||||
@Override
|
||||
public final void invoke(MessageContext messageContext) throws Exception {
|
||||
WebServiceMessage request = messageContext.getRequest();
|
||||
Object requestObject = unmarshalRequest(request);
|
||||
if (onUnmarshalRequest(messageContext, requestObject)) {
|
||||
Object responseObject = invokeInternal(requestObject);
|
||||
if (responseObject != null) {
|
||||
WebServiceMessage response = messageContext.getResponse();
|
||||
marshalResponse(responseObject, response);
|
||||
onMarshalResponse(messageContext, requestObject, responseObject);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private Object unmarshalRequest(WebServiceMessage request) throws IOException {
|
||||
Unmarshaller unmarshaller = getUnmarshaller();
|
||||
Assert.notNull(unmarshaller, "No unmarshaller registered. Check configuration of endpoint.");
|
||||
Object requestObject = MarshallingUtils.unmarshal(unmarshaller, request);
|
||||
if (this.logger.isDebugEnabled()) {
|
||||
this.logger.debug("Unmarshalled payload request to [" + requestObject + "]");
|
||||
}
|
||||
return requestObject;
|
||||
}
|
||||
|
||||
/**
|
||||
* Callback for post-processing in terms of unmarshalling. Called on each message
|
||||
* request, after standard unmarshalling.
|
||||
* <p>
|
||||
* Default implementation returns {@code true}.
|
||||
* @param messageContext the message context
|
||||
* @param requestObject the object unmarshalled from the
|
||||
* {@link MessageContext#getRequest() request}
|
||||
* @return {@code true} to continue and call {@link #invokeInternal(Object)};
|
||||
* {@code false} otherwise
|
||||
*/
|
||||
protected boolean onUnmarshalRequest(MessageContext messageContext, Object requestObject) throws Exception {
|
||||
return true;
|
||||
}
|
||||
|
||||
private void marshalResponse(Object responseObject, WebServiceMessage response) throws IOException {
|
||||
Marshaller marshaller = getMarshaller();
|
||||
Assert.notNull(marshaller, "No marshaller registered. Check configuration of endpoint.");
|
||||
if (this.logger.isDebugEnabled()) {
|
||||
this.logger.debug("Marshalling [" + responseObject + "] to response payload");
|
||||
}
|
||||
MarshallingUtils.marshal(marshaller, responseObject, response);
|
||||
}
|
||||
|
||||
/**
|
||||
* Callback for post-processing in terms of marshalling. Called on each message
|
||||
* request, after standard marshalling of the response. Only invoked when
|
||||
* {@link #invokeInternal(Object)} returns an object.
|
||||
* <p>
|
||||
* Default implementation is empty.
|
||||
* @param messageContext the message context
|
||||
* @param requestObject the object unmarshalled from the
|
||||
* {@link MessageContext#getRequest() request}
|
||||
* @param responseObject the object marshalled to the
|
||||
* {@link MessageContext#getResponse()} request}
|
||||
*/
|
||||
protected void onMarshalResponse(MessageContext messageContext, Object requestObject, Object responseObject) {
|
||||
}
|
||||
|
||||
/**
|
||||
* Template method that gets called after the marshaller and unmarshaller have been
|
||||
* set.
|
||||
* <p>
|
||||
* The default implementation does nothing.
|
||||
* @deprecated as of Spring Web Services 1.5: {@link #afterPropertiesSet()} is no
|
||||
* longer final, so this can safely be overridden in subclasses
|
||||
*/
|
||||
@Deprecated
|
||||
public void afterMarshallerSet() throws Exception {
|
||||
}
|
||||
|
||||
/**
|
||||
* Template method that subclasses must implement to process a request.
|
||||
* <p>
|
||||
* The unmarshalled request object is passed as a parameter, and the returned object
|
||||
* is marshalled to a response. If no response is required, return {@code null}.
|
||||
* @param requestObject the unmarshalled message payload as an object
|
||||
* @return the object to be marshalled as response, or {@code null} if a response is
|
||||
* not required
|
||||
*/
|
||||
protected abstract Object invokeInternal(Object requestObject) throws Exception;
|
||||
|
||||
}
|
||||
@@ -1,83 +0,0 @@
|
||||
/*
|
||||
* Copyright 2005-2025 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
|
||||
*
|
||||
* https://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.server.endpoint;
|
||||
|
||||
import javax.xml.transform.Source;
|
||||
import javax.xml.transform.sax.SAXResult;
|
||||
|
||||
import org.xml.sax.ContentHandler;
|
||||
|
||||
import org.springframework.xml.transform.TransformerObjectSupport;
|
||||
|
||||
/**
|
||||
* Abstract base class for endpoints that handle the message payload with a SAX
|
||||
* {@code ContentHandler}. Allows subclasses to create a response by returning a
|
||||
* {@code Source}.
|
||||
* <p>
|
||||
* Implementations of this class should create a new handler for each call of
|
||||
* {@code createContentHandler}, because of thread safety. The handlers is later passed on
|
||||
* to {@code createResponse}, so it can be used for holding request-specific state.
|
||||
*
|
||||
* @author Arjen Poutsma
|
||||
* @since 1.0.0
|
||||
* @see #createContentHandler()
|
||||
* @see #getResponse(org.xml.sax.ContentHandler)
|
||||
* @deprecated as of Spring Web Services 2.0, in favor of annotated endpoints
|
||||
*/
|
||||
@Deprecated
|
||||
public abstract class AbstractSaxPayloadEndpoint extends TransformerObjectSupport implements PayloadEndpoint {
|
||||
|
||||
/**
|
||||
* Invokes the provided {@code ContentHandler} on the given request. After parsing has
|
||||
* been done, the provided response is returned.
|
||||
* @see #createContentHandler()
|
||||
* @see #getResponse(org.xml.sax.ContentHandler)
|
||||
*/
|
||||
@Override
|
||||
public final Source invoke(Source request) throws Exception {
|
||||
ContentHandler contentHandler = null;
|
||||
if (request != null) {
|
||||
contentHandler = createContentHandler();
|
||||
SAXResult result = new SAXResult(contentHandler);
|
||||
transform(request, result);
|
||||
}
|
||||
return getResponse(contentHandler);
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the SAX {@code ContentHandler} used to parse the incoming request payload.
|
||||
* A new instance should be created for each call, because of thread-safety. The
|
||||
* content handler can be used to hold request-specific state.
|
||||
* <p>
|
||||
* If an incoming message does not contain a payload, this method will not be invoked.
|
||||
* @return a SAX content handler to be used for parsing
|
||||
*/
|
||||
protected abstract ContentHandler createContentHandler() throws Exception;
|
||||
|
||||
/**
|
||||
* Returns the response to be given, if any. This method is called after the request
|
||||
* payload has been parsed using the SAX {@code ContentHandler}. The passed
|
||||
* {@code ContentHandler} is created by {@link #createContentHandler()}: it can be
|
||||
* used to hold request-specific state.
|
||||
* <p>
|
||||
* If an incoming message does not contain a payload, this method will be invoked with
|
||||
* {@code null} as content handler.
|
||||
* @param contentHandler the content handler used to parse the request
|
||||
*/
|
||||
protected abstract Source getResponse(ContentHandler contentHandler) throws Exception;
|
||||
|
||||
}
|
||||
@@ -1,252 +0,0 @@
|
||||
/*
|
||||
* Copyright 2005-2025 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
|
||||
*
|
||||
* https://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.server.endpoint;
|
||||
|
||||
import java.io.ByteArrayInputStream;
|
||||
import java.io.ByteArrayOutputStream;
|
||||
|
||||
import javax.xml.namespace.NamespaceContext;
|
||||
import javax.xml.stream.XMLEventFactory;
|
||||
import javax.xml.stream.XMLEventReader;
|
||||
import javax.xml.stream.XMLEventWriter;
|
||||
import javax.xml.stream.XMLStreamException;
|
||||
import javax.xml.stream.XMLStreamReader;
|
||||
import javax.xml.stream.events.XMLEvent;
|
||||
import javax.xml.stream.util.XMLEventConsumer;
|
||||
import javax.xml.transform.Result;
|
||||
import javax.xml.transform.Source;
|
||||
import javax.xml.transform.TransformerException;
|
||||
import javax.xml.transform.stream.StreamResult;
|
||||
import javax.xml.transform.stream.StreamSource;
|
||||
|
||||
import org.springframework.util.xml.StaxUtils;
|
||||
import org.springframework.ws.WebServiceMessage;
|
||||
import org.springframework.ws.context.MessageContext;
|
||||
|
||||
/**
|
||||
* Abstract base class for endpoints that handle the message payload with event-based
|
||||
* StAX. Allows subclasses to read the request with a {@code XMLEventReader}, and to
|
||||
* create a response using a {@code XMLEventWriter}.
|
||||
*
|
||||
* @author Arjen Poutsma
|
||||
* @since 1.0.0
|
||||
* @see #invokeInternal(javax.xml.stream.XMLEventReader,javax.xml.stream.util.XMLEventConsumer,
|
||||
* javax.xml.stream.XMLEventFactory)
|
||||
* @see XMLEventReader
|
||||
* @see XMLEventWriter
|
||||
* @deprecated as of Spring Web Services 2.0, in favor of annotated endpoints
|
||||
*/
|
||||
@Deprecated
|
||||
public abstract class AbstractStaxEventPayloadEndpoint extends AbstractStaxPayloadEndpoint implements MessageEndpoint {
|
||||
|
||||
private XMLEventFactory eventFactory;
|
||||
|
||||
@Override
|
||||
public final void invoke(MessageContext messageContext) throws Exception {
|
||||
XMLEventReader eventReader = getEventReader(messageContext.getRequest().getPayloadSource());
|
||||
XMLEventWriter streamWriter = new ResponseCreatingEventWriter(messageContext);
|
||||
invokeInternal(eventReader, streamWriter, getEventFactory());
|
||||
streamWriter.flush();
|
||||
}
|
||||
|
||||
/**
|
||||
* Create a {@code XMLEventFactory} that this endpoint will use to create
|
||||
* {@code XMLEvent}s. Can be overridden in subclasses, adding further initialization
|
||||
* of the factory. The resulting {@code XMLEventFactory} is cached, so this method
|
||||
* will only be called once.
|
||||
* @return the created {@code XMLEventFactory}
|
||||
*/
|
||||
protected XMLEventFactory createXmlEventFactory() {
|
||||
return XMLEventFactory.newInstance();
|
||||
}
|
||||
|
||||
/** Returns an {@code XMLEventFactory} to read XML from. */
|
||||
private XMLEventFactory getEventFactory() {
|
||||
if (this.eventFactory == null) {
|
||||
this.eventFactory = createXmlEventFactory();
|
||||
}
|
||||
return this.eventFactory;
|
||||
}
|
||||
|
||||
private XMLEventReader getEventReader(Source source) throws XMLStreamException, TransformerException {
|
||||
if (source == null) {
|
||||
return null;
|
||||
}
|
||||
XMLEventReader eventReader = null;
|
||||
if (StaxUtils.isStaxSource(source)) {
|
||||
eventReader = StaxUtils.getXMLEventReader(source);
|
||||
if (eventReader == null) {
|
||||
XMLStreamReader streamReader = StaxUtils.getXMLStreamReader(source);
|
||||
if (streamReader != null) {
|
||||
try {
|
||||
eventReader = getInputFactory().createXMLEventReader(streamReader);
|
||||
}
|
||||
catch (XMLStreamException ex) {
|
||||
eventReader = null;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
if (eventReader == null) {
|
||||
try {
|
||||
eventReader = getInputFactory().createXMLEventReader(source);
|
||||
}
|
||||
catch (XMLStreamException | UnsupportedOperationException ex) {
|
||||
eventReader = null;
|
||||
}
|
||||
}
|
||||
if (eventReader == null) {
|
||||
// as a final resort, transform the source to a stream, and read from that
|
||||
ByteArrayOutputStream os = new ByteArrayOutputStream();
|
||||
transform(source, new StreamResult(os));
|
||||
ByteArrayInputStream is = new ByteArrayInputStream(os.toByteArray());
|
||||
eventReader = getInputFactory().createXMLEventReader(is);
|
||||
}
|
||||
return eventReader;
|
||||
}
|
||||
|
||||
private XMLEventWriter getEventWriter(Result result) {
|
||||
XMLEventWriter eventWriter = null;
|
||||
if (StaxUtils.isStaxResult(result)) {
|
||||
eventWriter = StaxUtils.getXMLEventWriter(result);
|
||||
}
|
||||
if (eventWriter == null) {
|
||||
try {
|
||||
eventWriter = getOutputFactory().createXMLEventWriter(result);
|
||||
}
|
||||
catch (XMLStreamException ex) {
|
||||
// ignore
|
||||
}
|
||||
}
|
||||
return eventWriter;
|
||||
}
|
||||
|
||||
/**
|
||||
* Template method. Subclasses must implement this. Offers the request payload as a
|
||||
* {@code XMLEventReader}, and a {@code XMLEventWriter} to write the response payload
|
||||
* to.
|
||||
* @param eventReader the reader to read the payload events from
|
||||
* @param eventWriter the writer to write payload events to
|
||||
* @param eventFactory an {@code XMLEventFactory} that can be used to create events
|
||||
*/
|
||||
protected abstract void invokeInternal(XMLEventReader eventReader, XMLEventConsumer eventWriter,
|
||||
XMLEventFactory eventFactory) throws Exception;
|
||||
|
||||
/**
|
||||
* Implementation of the {@code XMLEventWriter} interface that creates a response
|
||||
* {@code WebServiceMessage} as soon as any method is called, thus lazily creating the
|
||||
* response.
|
||||
*/
|
||||
private final class ResponseCreatingEventWriter implements XMLEventWriter {
|
||||
|
||||
private XMLEventWriter eventWriter;
|
||||
|
||||
private MessageContext messageContext;
|
||||
|
||||
private ByteArrayOutputStream os;
|
||||
|
||||
ResponseCreatingEventWriter(MessageContext messageContext) {
|
||||
this.messageContext = messageContext;
|
||||
}
|
||||
|
||||
@Override
|
||||
public NamespaceContext getNamespaceContext() {
|
||||
return this.eventWriter.getNamespaceContext();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setNamespaceContext(NamespaceContext context) throws XMLStreamException {
|
||||
createEventWriter();
|
||||
this.eventWriter.setNamespaceContext(context);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void add(XMLEventReader reader) throws XMLStreamException {
|
||||
createEventWriter();
|
||||
while (reader.hasNext()) {
|
||||
add(reader.nextEvent());
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void add(XMLEvent event) throws XMLStreamException {
|
||||
createEventWriter();
|
||||
this.eventWriter.add(event);
|
||||
if (event.isEndDocument()) {
|
||||
if (this.os != null) {
|
||||
this.eventWriter.flush();
|
||||
// if we used an output stream cache, we have to transform it to the
|
||||
// response again
|
||||
try {
|
||||
ByteArrayInputStream is = new ByteArrayInputStream(this.os.toByteArray());
|
||||
transform(new StreamSource(is), this.messageContext.getResponse().getPayloadResult());
|
||||
}
|
||||
catch (TransformerException ex) {
|
||||
throw new XMLStreamException(ex);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void close() throws XMLStreamException {
|
||||
if (this.eventWriter != null) {
|
||||
this.eventWriter.close();
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void flush() throws XMLStreamException {
|
||||
if (this.eventWriter != null) {
|
||||
this.eventWriter.flush();
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getPrefix(String uri) throws XMLStreamException {
|
||||
createEventWriter();
|
||||
return this.eventWriter.getPrefix(uri);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setDefaultNamespace(String uri) throws XMLStreamException {
|
||||
createEventWriter();
|
||||
this.eventWriter.setDefaultNamespace(uri);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setPrefix(String prefix, String uri) throws XMLStreamException {
|
||||
createEventWriter();
|
||||
this.eventWriter.setPrefix(prefix, uri);
|
||||
}
|
||||
|
||||
private void createEventWriter() throws XMLStreamException {
|
||||
if (this.eventWriter == null) {
|
||||
WebServiceMessage response = this.messageContext.getResponse();
|
||||
this.eventWriter = getEventWriter(response.getPayloadResult());
|
||||
if (this.eventWriter == null) {
|
||||
// as a final resort, use a stream, and transform that at
|
||||
// endDocument()
|
||||
this.os = new ByteArrayOutputStream();
|
||||
this.eventWriter = getOutputFactory().createXMLEventWriter(this.os);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
@@ -1,81 +0,0 @@
|
||||
/*
|
||||
* Copyright 2005-2025 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
|
||||
*
|
||||
* https://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.server.endpoint;
|
||||
|
||||
import javax.xml.stream.XMLInputFactory;
|
||||
import javax.xml.stream.XMLOutputFactory;
|
||||
|
||||
import org.springframework.xml.XMLInputFactoryUtils;
|
||||
import org.springframework.xml.transform.TransformerObjectSupport;
|
||||
|
||||
/**
|
||||
* Abstract base class for endpoints use StAX. Provides an {@code XMLInputFactory} and an
|
||||
* {@code XMLOutputFactory}.
|
||||
*
|
||||
* @author Arjen Poutsma
|
||||
* @since 1.0.0
|
||||
* @see XMLInputFactory
|
||||
* @see XMLOutputFactory
|
||||
* @deprecated as of Spring Web Services 2.0, in favor of annotated endpoints
|
||||
*/
|
||||
@Deprecated
|
||||
@SuppressWarnings("Since15")
|
||||
public abstract class AbstractStaxPayloadEndpoint extends TransformerObjectSupport {
|
||||
|
||||
private XMLInputFactory inputFactory;
|
||||
|
||||
private XMLOutputFactory outputFactory;
|
||||
|
||||
/** Returns an {@code XMLInputFactory} to read XML from. */
|
||||
protected final XMLInputFactory getInputFactory() {
|
||||
if (this.inputFactory == null) {
|
||||
this.inputFactory = createXmlInputFactory();
|
||||
}
|
||||
return this.inputFactory;
|
||||
}
|
||||
|
||||
/** Returns an {@code XMLOutputFactory} to write XML to. */
|
||||
protected final XMLOutputFactory getOutputFactory() {
|
||||
if (this.outputFactory == null) {
|
||||
this.outputFactory = createXmlOutputFactory();
|
||||
}
|
||||
return this.outputFactory;
|
||||
}
|
||||
|
||||
/**
|
||||
* Create a {@code XMLInputFactory} that this endpoint will use to create
|
||||
* {@code XMLStreamReader}s or {@code XMLEventReader}. Can be overridden in
|
||||
* subclasses, adding further initialization of the factory. The resulting
|
||||
* {@code XMLInputFactory} is cached, so this method will only be called once.
|
||||
* @return the created {@code XMLInputFactory}
|
||||
*/
|
||||
protected XMLInputFactory createXmlInputFactory() {
|
||||
return XMLInputFactoryUtils.newInstance();
|
||||
}
|
||||
|
||||
/**
|
||||
* Create a {@code XMLOutputFactory} that this endpoint will use to create
|
||||
* {@code XMLStreamWriters}s or {@code XMLEventWriters}. Can be overridden in
|
||||
* subclasses, adding further initialization of the factory. The resulting
|
||||
* {@code XMLOutputFactory} is cached, so this method will only be called once.
|
||||
* @return the created {@code XMLOutputFactory}
|
||||
*/
|
||||
protected XMLOutputFactory createXmlOutputFactory() {
|
||||
return XMLOutputFactory.newInstance();
|
||||
}
|
||||
|
||||
}
|
||||
@@ -1,364 +0,0 @@
|
||||
/*
|
||||
* Copyright 2005-2025 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
|
||||
*
|
||||
* https://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.server.endpoint;
|
||||
|
||||
import java.io.ByteArrayInputStream;
|
||||
import java.io.ByteArrayOutputStream;
|
||||
|
||||
import javax.xml.namespace.NamespaceContext;
|
||||
import javax.xml.stream.XMLEventReader;
|
||||
import javax.xml.stream.XMLStreamException;
|
||||
import javax.xml.stream.XMLStreamReader;
|
||||
import javax.xml.stream.XMLStreamWriter;
|
||||
import javax.xml.transform.Result;
|
||||
import javax.xml.transform.Source;
|
||||
import javax.xml.transform.TransformerException;
|
||||
import javax.xml.transform.stream.StreamResult;
|
||||
import javax.xml.transform.stream.StreamSource;
|
||||
|
||||
import org.springframework.util.xml.StaxUtils;
|
||||
import org.springframework.ws.WebServiceMessage;
|
||||
import org.springframework.ws.context.MessageContext;
|
||||
|
||||
/**
|
||||
* Abstract base class for endpoints that handle the message payload with streaming StAX.
|
||||
* Allows subclasses to read the request with a {@code XMLStreamReader}, and to create a
|
||||
* response using a {@code XMLStreamWriter}.
|
||||
*
|
||||
* @author Arjen Poutsma
|
||||
* @since 1.0.0
|
||||
* @see #invokeInternal(javax.xml.stream.XMLStreamReader,javax.xml.stream.XMLStreamWriter)
|
||||
* @see XMLStreamReader
|
||||
* @see XMLStreamWriter
|
||||
* @deprecated as of Spring Web Services 2.0, in favor of annotated endpoints
|
||||
*/
|
||||
@Deprecated
|
||||
@SuppressWarnings("Since15")
|
||||
public abstract class AbstractStaxStreamPayloadEndpoint extends AbstractStaxPayloadEndpoint implements MessageEndpoint {
|
||||
|
||||
@Override
|
||||
public final void invoke(MessageContext messageContext) throws Exception {
|
||||
XMLStreamReader streamReader = getStreamReader(messageContext.getRequest().getPayloadSource());
|
||||
XMLStreamWriter streamWriter = new ResponseCreatingStreamWriter(messageContext);
|
||||
invokeInternal(streamReader, streamWriter);
|
||||
streamWriter.close();
|
||||
}
|
||||
|
||||
private XMLStreamReader getStreamReader(Source source) throws XMLStreamException, TransformerException {
|
||||
if (source == null) {
|
||||
return null;
|
||||
}
|
||||
XMLStreamReader streamReader = null;
|
||||
if (StaxUtils.isStaxSource(source)) {
|
||||
streamReader = StaxUtils.getXMLStreamReader(source);
|
||||
if (streamReader == null) {
|
||||
XMLEventReader eventReader = StaxUtils.getXMLEventReader(source);
|
||||
if (eventReader != null) {
|
||||
try {
|
||||
streamReader = StaxUtils.createEventStreamReader(eventReader);
|
||||
}
|
||||
catch (XMLStreamException ex) {
|
||||
streamReader = null;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
if (streamReader == null) {
|
||||
try {
|
||||
streamReader = getInputFactory().createXMLStreamReader(source);
|
||||
}
|
||||
catch (XMLStreamException | UnsupportedOperationException ex) {
|
||||
// ignore
|
||||
}
|
||||
}
|
||||
if (streamReader == null) {
|
||||
// as a final resort, transform the source to a stream, and read from that
|
||||
ByteArrayOutputStream os = new ByteArrayOutputStream();
|
||||
transform(source, new StreamResult(os));
|
||||
ByteArrayInputStream is = new ByteArrayInputStream(os.toByteArray());
|
||||
streamReader = getInputFactory().createXMLStreamReader(is);
|
||||
}
|
||||
return streamReader;
|
||||
}
|
||||
|
||||
private XMLStreamWriter getStreamWriter(Result result) {
|
||||
XMLStreamWriter streamWriter = null;
|
||||
if (StaxUtils.isStaxResult(result)) {
|
||||
streamWriter = StaxUtils.getXMLStreamWriter(result);
|
||||
}
|
||||
if (streamWriter == null) {
|
||||
try {
|
||||
streamWriter = getOutputFactory().createXMLStreamWriter(result);
|
||||
}
|
||||
catch (XMLStreamException ex) {
|
||||
// ignore
|
||||
}
|
||||
}
|
||||
return streamWriter;
|
||||
}
|
||||
|
||||
/**
|
||||
* Template method. Subclasses must implement this. Offers the request payload as a
|
||||
* {@code XMLStreamReader}, and a {@code XMLStreamWriter} to write the response
|
||||
* payload to.
|
||||
* @param streamReader the reader to read the payload from
|
||||
* @param streamWriter the writer to write the payload to
|
||||
*/
|
||||
protected abstract void invokeInternal(XMLStreamReader streamReader, XMLStreamWriter streamWriter) throws Exception;
|
||||
|
||||
/**
|
||||
* Implementation of the {@code XMLStreamWriter} interface that creates a response
|
||||
* {@code WebServiceMessage} as soon as any method is called, thus lazily creating the
|
||||
* response.
|
||||
*/
|
||||
private final class ResponseCreatingStreamWriter implements XMLStreamWriter {
|
||||
|
||||
private MessageContext messageContext;
|
||||
|
||||
private XMLStreamWriter streamWriter;
|
||||
|
||||
private ByteArrayOutputStream os;
|
||||
|
||||
private ResponseCreatingStreamWriter(MessageContext messageContext) {
|
||||
this.messageContext = messageContext;
|
||||
}
|
||||
|
||||
@Override
|
||||
public NamespaceContext getNamespaceContext() {
|
||||
return this.streamWriter.getNamespaceContext();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setNamespaceContext(NamespaceContext context) throws XMLStreamException {
|
||||
createStreamWriter();
|
||||
this.streamWriter.setNamespaceContext(context);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void close() throws XMLStreamException {
|
||||
if (this.streamWriter != null) {
|
||||
this.streamWriter.close();
|
||||
if (this.os != null) {
|
||||
this.streamWriter.flush();
|
||||
// if we used an output stream cache, we have to transform it to the
|
||||
// response again
|
||||
try {
|
||||
ByteArrayInputStream is = new ByteArrayInputStream(this.os.toByteArray());
|
||||
transform(new StreamSource(is), this.messageContext.getResponse().getPayloadResult());
|
||||
this.os = null;
|
||||
}
|
||||
catch (TransformerException ex) {
|
||||
throw new XMLStreamException(ex);
|
||||
}
|
||||
}
|
||||
this.streamWriter = null;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void flush() throws XMLStreamException {
|
||||
if (this.streamWriter != null) {
|
||||
this.streamWriter.flush();
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getPrefix(String uri) throws XMLStreamException {
|
||||
createStreamWriter();
|
||||
return this.streamWriter.getPrefix(uri);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Object getProperty(String name) throws IllegalArgumentException {
|
||||
return this.streamWriter.getProperty(name);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setDefaultNamespace(String uri) throws XMLStreamException {
|
||||
createStreamWriter();
|
||||
this.streamWriter.setDefaultNamespace(uri);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setPrefix(String prefix, String uri) throws XMLStreamException {
|
||||
createStreamWriter();
|
||||
this.streamWriter.setPrefix(prefix, uri);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void writeAttribute(String localName, String value) throws XMLStreamException {
|
||||
createStreamWriter();
|
||||
this.streamWriter.writeAttribute(localName, value);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void writeAttribute(String namespaceURI, String localName, String value) throws XMLStreamException {
|
||||
createStreamWriter();
|
||||
this.streamWriter.writeAttribute(namespaceURI, localName, value);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void writeAttribute(String prefix, String namespaceURI, String localName, String value)
|
||||
throws XMLStreamException {
|
||||
createStreamWriter();
|
||||
this.streamWriter.writeAttribute(prefix, namespaceURI, localName, value);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void writeCData(String data) throws XMLStreamException {
|
||||
createStreamWriter();
|
||||
this.streamWriter.writeCData(data);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void writeCharacters(String text) throws XMLStreamException {
|
||||
createStreamWriter();
|
||||
this.streamWriter.writeCharacters(text);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void writeCharacters(char[] text, int start, int len) throws XMLStreamException {
|
||||
createStreamWriter();
|
||||
this.streamWriter.writeCharacters(text, start, len);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void writeComment(String data) throws XMLStreamException {
|
||||
createStreamWriter();
|
||||
this.streamWriter.writeComment(data);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void writeDTD(String dtd) throws XMLStreamException {
|
||||
createStreamWriter();
|
||||
this.streamWriter.writeDTD(dtd);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void writeDefaultNamespace(String namespaceURI) throws XMLStreamException {
|
||||
createStreamWriter();
|
||||
this.streamWriter.writeDefaultNamespace(namespaceURI);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void writeEmptyElement(String localName) throws XMLStreamException {
|
||||
createStreamWriter();
|
||||
this.streamWriter.writeEmptyElement(localName);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void writeEmptyElement(String namespaceURI, String localName) throws XMLStreamException {
|
||||
createStreamWriter();
|
||||
this.streamWriter.writeEmptyElement(namespaceURI, localName);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void writeEmptyElement(String prefix, String localName, String namespaceURI) throws XMLStreamException {
|
||||
createStreamWriter();
|
||||
this.streamWriter.writeEmptyElement(prefix, localName, namespaceURI);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void writeEndDocument() throws XMLStreamException {
|
||||
createStreamWriter();
|
||||
this.streamWriter.writeEndDocument();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void writeEndElement() throws XMLStreamException {
|
||||
createStreamWriter();
|
||||
this.streamWriter.writeEndElement();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void writeEntityRef(String name) throws XMLStreamException {
|
||||
createStreamWriter();
|
||||
this.streamWriter.writeEntityRef(name);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void writeNamespace(String prefix, String namespaceURI) throws XMLStreamException {
|
||||
createStreamWriter();
|
||||
this.streamWriter.writeNamespace(prefix, namespaceURI);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void writeProcessingInstruction(String target) throws XMLStreamException {
|
||||
createStreamWriter();
|
||||
this.streamWriter.writeProcessingInstruction(target);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void writeProcessingInstruction(String target, String data) throws XMLStreamException {
|
||||
createStreamWriter();
|
||||
this.streamWriter.writeProcessingInstruction(target, data);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void writeStartDocument() throws XMLStreamException {
|
||||
createStreamWriter();
|
||||
this.streamWriter.writeStartDocument();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void writeStartDocument(String version) throws XMLStreamException {
|
||||
createStreamWriter();
|
||||
this.streamWriter.writeStartDocument(version);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void writeStartDocument(String encoding, String version) throws XMLStreamException {
|
||||
createStreamWriter();
|
||||
this.streamWriter.writeStartDocument(encoding, version);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void writeStartElement(String localName) throws XMLStreamException {
|
||||
createStreamWriter();
|
||||
this.streamWriter.writeStartElement(localName);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void writeStartElement(String namespaceURI, String localName) throws XMLStreamException {
|
||||
createStreamWriter();
|
||||
this.streamWriter.writeStartElement(namespaceURI, localName);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void writeStartElement(String prefix, String localName, String namespaceURI) throws XMLStreamException {
|
||||
createStreamWriter();
|
||||
this.streamWriter.writeStartElement(prefix, localName, namespaceURI);
|
||||
}
|
||||
|
||||
private void createStreamWriter() throws XMLStreamException {
|
||||
if (this.streamWriter == null) {
|
||||
WebServiceMessage response = this.messageContext.getResponse();
|
||||
this.streamWriter = getStreamWriter(response.getPayloadResult());
|
||||
if (this.streamWriter == null) {
|
||||
// as a final resort, use a stream, and transform that at
|
||||
// endDocument()
|
||||
this.os = new ByteArrayOutputStream();
|
||||
this.streamWriter = getOutputFactory().createXMLStreamWriter(this.os);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
@@ -1,110 +0,0 @@
|
||||
/*
|
||||
* Copyright 2005-2025 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
|
||||
*
|
||||
* https://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.server.endpoint;
|
||||
|
||||
import org.springframework.validation.BindException;
|
||||
import org.springframework.validation.Errors;
|
||||
import org.springframework.validation.ValidationUtils;
|
||||
import org.springframework.validation.Validator;
|
||||
import org.springframework.ws.context.MessageContext;
|
||||
|
||||
/**
|
||||
* Extension of the {@link AbstractMarshallingPayloadEndpoint} which validates the request
|
||||
* payload with {@link Validator}(s). The desired validators can be set using properties,
|
||||
* and <strong>must</strong> {@link Validator#supports(Class) support} the request object.
|
||||
*
|
||||
* @author Arjen Poutsma
|
||||
* @since 1.0.2
|
||||
* @deprecated as of Spring Web Services 2.0, in favor of annotated endpoints
|
||||
*/
|
||||
@Deprecated
|
||||
public abstract class AbstractValidatingMarshallingPayloadEndpoint extends AbstractMarshallingPayloadEndpoint {
|
||||
|
||||
/** Default request object name used for validating request objects. */
|
||||
public static final String DEFAULT_REQUEST_NAME = "request";
|
||||
|
||||
private String requestName = DEFAULT_REQUEST_NAME;
|
||||
|
||||
private Validator[] validators;
|
||||
|
||||
/** Return the name of the request object for validation error codes. */
|
||||
public String getRequestName() {
|
||||
return this.requestName;
|
||||
}
|
||||
|
||||
/** Set the name of the request object user for validation errors. */
|
||||
public void setRequestName(String requestName) {
|
||||
this.requestName = requestName;
|
||||
}
|
||||
|
||||
/** Return the primary Validator for this controller. */
|
||||
public Validator getValidator() {
|
||||
Validator[] validators = getValidators();
|
||||
return (validators != null && validators.length > 0) ? validators[0] : null;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set the primary {@link Validator} for this endpoint. The {@link Validator} is must
|
||||
* support the unmarshalled class. If there are one or more existing validators set
|
||||
* already when this method is called, only the specified validator will be kept. Use
|
||||
* {@link #setValidators(Validator[])} to set multiple validators.
|
||||
*/
|
||||
public void setValidator(Validator validator) {
|
||||
this.validators = new Validator[] { validator };
|
||||
}
|
||||
|
||||
/** Return the Validators for this controller. */
|
||||
public Validator[] getValidators() {
|
||||
return this.validators;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set the Validators for this controller. The Validator must support the specified
|
||||
* command class.
|
||||
*/
|
||||
public void setValidators(Validator[] validators) {
|
||||
this.validators = validators;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected boolean onUnmarshalRequest(MessageContext messageContext, Object requestObject) throws Exception {
|
||||
Validator[] validators = getValidators();
|
||||
if (validators != null) {
|
||||
Errors errors = new BindException(requestObject, getRequestName());
|
||||
for (Validator validator : validators) {
|
||||
ValidationUtils.invokeValidator(validator, requestObject, errors);
|
||||
}
|
||||
if (errors.hasErrors()) {
|
||||
return onValidationErrors(messageContext, requestObject, errors);
|
||||
}
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* Callback for post-processing validation errors. Called when validator(s) have been
|
||||
* specified, and validation fails.
|
||||
* @param messageContext the message context
|
||||
* @param requestObject the object unmarshalled from the
|
||||
* {@link MessageContext#getRequest() request}
|
||||
* @param errors validation errors holder
|
||||
* @return {@code true} to continue and call {@link #invokeInternal(Object)};
|
||||
* {@code false} otherwise
|
||||
*/
|
||||
protected abstract boolean onValidationErrors(MessageContext messageContext, Object requestObject, Errors errors);
|
||||
|
||||
}
|
||||
@@ -1,317 +0,0 @@
|
||||
/*
|
||||
* Copyright 2005-2025 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
|
||||
*
|
||||
* https://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.server.endpoint;
|
||||
|
||||
import java.io.ByteArrayInputStream;
|
||||
import java.io.ByteArrayOutputStream;
|
||||
import java.io.IOException;
|
||||
import java.io.InputStream;
|
||||
import java.io.OutputStream;
|
||||
import java.io.Reader;
|
||||
import java.util.Locale;
|
||||
|
||||
import javax.xml.stream.XMLEventReader;
|
||||
import javax.xml.stream.XMLStreamConstants;
|
||||
import javax.xml.stream.XMLStreamException;
|
||||
import javax.xml.stream.XMLStreamReader;
|
||||
import javax.xml.transform.Source;
|
||||
import javax.xml.transform.stream.StreamSource;
|
||||
|
||||
import nu.xom.Attribute;
|
||||
import nu.xom.Builder;
|
||||
import nu.xom.Document;
|
||||
import nu.xom.Element;
|
||||
import nu.xom.NodeFactory;
|
||||
import nu.xom.ParentNode;
|
||||
import nu.xom.ParsingException;
|
||||
import nu.xom.Serializer;
|
||||
import nu.xom.converters.DOMConverter;
|
||||
import org.w3c.dom.Node;
|
||||
import org.xml.sax.InputSource;
|
||||
import org.xml.sax.SAXException;
|
||||
import org.xml.sax.XMLReader;
|
||||
|
||||
import org.springframework.core.NestedRuntimeException;
|
||||
import org.springframework.xml.namespace.QNameUtils;
|
||||
import org.springframework.xml.transform.TransformerObjectSupport;
|
||||
import org.springframework.xml.transform.TraxUtils;
|
||||
|
||||
/**
|
||||
* Abstract base class for endpoints that handle the message payload as XOM elements.
|
||||
* Offers the message payload as a XOM {@code Element}, and allows subclasses to create a
|
||||
* response by returning an {@code Element}.
|
||||
* <p>
|
||||
* An {@code AbstractXomPayloadEndpoint} only accept one payload element. Multiple payload
|
||||
* elements are not in accordance with WS-I.
|
||||
*
|
||||
* @author Arjen Poutsma
|
||||
* @since 1.0.0
|
||||
* @see Element
|
||||
* @deprecated as of Spring Web Services 2.0, in favor of annotated endpoints
|
||||
*/
|
||||
@Deprecated
|
||||
@SuppressWarnings("Since15")
|
||||
public abstract class AbstractXomPayloadEndpoint extends TransformerObjectSupport implements PayloadEndpoint {
|
||||
|
||||
@Override
|
||||
public final Source invoke(Source request) throws Exception {
|
||||
Element requestElement = null;
|
||||
if (request != null) {
|
||||
XomSourceCallback sourceCallback = new XomSourceCallback();
|
||||
try {
|
||||
TraxUtils.doWithSource(request, sourceCallback);
|
||||
}
|
||||
catch (XomParsingException ex) {
|
||||
throw (ParsingException) ex.getCause();
|
||||
}
|
||||
requestElement = sourceCallback.element;
|
||||
}
|
||||
Element responseElement = invokeInternal(requestElement);
|
||||
return (responseElement != null) ? convertResponse(responseElement) : null;
|
||||
}
|
||||
|
||||
private Source convertResponse(Element responseElement) throws IOException {
|
||||
ByteArrayOutputStream os = new ByteArrayOutputStream();
|
||||
Serializer serializer = createSerializer(os);
|
||||
Document document = responseElement.getDocument();
|
||||
if (document == null) {
|
||||
document = new Document(responseElement);
|
||||
}
|
||||
serializer.write(document);
|
||||
byte[] bytes = os.toByteArray();
|
||||
return new StreamSource(new ByteArrayInputStream(bytes));
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates a {@link Serializer} to be used for writing the response to.
|
||||
* <p>
|
||||
* Default implementation uses the UTF-8 encoding and does not set any options, but
|
||||
* this may be changed in subclasses.
|
||||
* @param outputStream the output stream to serialize to
|
||||
* @return the serializer
|
||||
*/
|
||||
protected Serializer createSerializer(OutputStream outputStream) {
|
||||
return new Serializer(outputStream);
|
||||
}
|
||||
|
||||
/**
|
||||
* Template method. Subclasses must implement this. Offers the request payload as a
|
||||
* XOM {@code Element}, and allows subclasses to return a response {@code Element}.
|
||||
* @param requestElement the contents of the SOAP message as XOM element
|
||||
* @return the response element. Can be {@code null} to specify no response.
|
||||
*/
|
||||
protected abstract Element invokeInternal(Element requestElement) throws Exception;
|
||||
|
||||
private static final class XomSourceCallback implements TraxUtils.SourceCallback {
|
||||
|
||||
private Element element;
|
||||
|
||||
@Override
|
||||
public void domSource(Node node) {
|
||||
if (node.getNodeType() == Node.ELEMENT_NODE) {
|
||||
this.element = DOMConverter.convert((org.w3c.dom.Element) node);
|
||||
}
|
||||
else if (node.getNodeType() == Node.DOCUMENT_NODE) {
|
||||
Document document = DOMConverter.convert((org.w3c.dom.Document) node);
|
||||
this.element = document.getRootElement();
|
||||
}
|
||||
else {
|
||||
throw new IllegalArgumentException("DOMSource contains neither Document nor Element");
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void saxSource(XMLReader reader, InputSource inputSource) throws IOException, SAXException {
|
||||
try {
|
||||
Builder builder = new Builder(reader);
|
||||
Document document;
|
||||
if (inputSource.getByteStream() != null) {
|
||||
document = builder.build(inputSource.getByteStream());
|
||||
}
|
||||
else if (inputSource.getCharacterStream() != null) {
|
||||
document = builder.build(inputSource.getCharacterStream());
|
||||
}
|
||||
else {
|
||||
throw new IllegalArgumentException(
|
||||
"InputSource in SAXSource contains neither byte stream nor character stream");
|
||||
}
|
||||
this.element = document.getRootElement();
|
||||
}
|
||||
catch (ParsingException ex) {
|
||||
throw new XomParsingException(ex);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void staxSource(XMLEventReader eventReader) throws XMLStreamException {
|
||||
throw new IllegalArgumentException("XMLEventReader not supported");
|
||||
}
|
||||
|
||||
@Override
|
||||
public void staxSource(XMLStreamReader streamReader) throws XMLStreamException {
|
||||
Document document = StaxStreamConverter.convert(streamReader);
|
||||
this.element = document.getRootElement();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void streamSource(InputStream inputStream) throws IOException {
|
||||
try {
|
||||
Builder builder = new Builder();
|
||||
Document document = builder.build(inputStream);
|
||||
this.element = document.getRootElement();
|
||||
}
|
||||
catch (ParsingException ex) {
|
||||
throw new XomParsingException(ex);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void streamSource(Reader reader) throws IOException {
|
||||
try {
|
||||
Builder builder = new Builder();
|
||||
Document document = builder.build(reader);
|
||||
this.element = document.getRootElement();
|
||||
}
|
||||
catch (ParsingException ex) {
|
||||
throw new XomParsingException(ex);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void source(String systemId) throws Exception {
|
||||
try {
|
||||
Builder builder = new Builder();
|
||||
Document document = builder.build(systemId);
|
||||
this.element = document.getRootElement();
|
||||
}
|
||||
catch (ParsingException ex) {
|
||||
throw new XomParsingException(ex);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@SuppressWarnings("serial")
|
||||
private static final class XomParsingException extends NestedRuntimeException {
|
||||
|
||||
private XomParsingException(ParsingException ex) {
|
||||
super(ex.getMessage(), ex);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
private static final class StaxStreamConverter {
|
||||
|
||||
private static Document convert(XMLStreamReader streamReader) throws XMLStreamException {
|
||||
NodeFactory nodeFactory = new NodeFactory();
|
||||
Document document = null;
|
||||
Element element = null;
|
||||
ParentNode parent = null;
|
||||
boolean documentFinished = false;
|
||||
while (streamReader.hasNext()) {
|
||||
int event = streamReader.next();
|
||||
switch (event) {
|
||||
case XMLStreamConstants.START_DOCUMENT:
|
||||
document = nodeFactory.startMakingDocument();
|
||||
parent = document;
|
||||
break;
|
||||
case XMLStreamConstants.END_DOCUMENT:
|
||||
nodeFactory.finishMakingDocument(document);
|
||||
documentFinished = true;
|
||||
break;
|
||||
case XMLStreamConstants.START_ELEMENT:
|
||||
if (document == null) {
|
||||
document = nodeFactory.startMakingDocument();
|
||||
parent = document;
|
||||
}
|
||||
String name = QNameUtils.toQualifiedName(streamReader.getName());
|
||||
if (element == null) {
|
||||
element = nodeFactory.makeRootElement(name, streamReader.getNamespaceURI());
|
||||
document.setRootElement(element);
|
||||
}
|
||||
else {
|
||||
element = nodeFactory.startMakingElement(name, streamReader.getNamespaceURI());
|
||||
parent.appendChild(element);
|
||||
}
|
||||
convertNamespaces(streamReader, element);
|
||||
convertAttributes(streamReader, nodeFactory);
|
||||
parent = element;
|
||||
break;
|
||||
case XMLStreamConstants.END_ELEMENT:
|
||||
nodeFactory.finishMakingElement(element);
|
||||
parent = parent.getParent();
|
||||
break;
|
||||
case XMLStreamConstants.ATTRIBUTE:
|
||||
convertAttributes(streamReader, nodeFactory);
|
||||
break;
|
||||
case XMLStreamConstants.CHARACTERS:
|
||||
nodeFactory.makeText(streamReader.getText());
|
||||
break;
|
||||
case XMLStreamConstants.COMMENT:
|
||||
nodeFactory.makeComment(streamReader.getText());
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
}
|
||||
if (!documentFinished) {
|
||||
nodeFactory.finishMakingDocument(document);
|
||||
}
|
||||
return document;
|
||||
}
|
||||
|
||||
private static void convertNamespaces(XMLStreamReader streamReader, Element element) {
|
||||
for (int i = 0; i < streamReader.getNamespaceCount(); i++) {
|
||||
String uri = streamReader.getNamespaceURI(i);
|
||||
String prefix = streamReader.getNamespacePrefix(i);
|
||||
|
||||
element.addNamespaceDeclaration(prefix, uri);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
private static void convertAttributes(XMLStreamReader streamReader, NodeFactory nodeFactory) {
|
||||
for (int i = 0; i < streamReader.getAttributeCount(); i++) {
|
||||
String name = QNameUtils.toQualifiedName(streamReader.getAttributeName(i));
|
||||
String uri = streamReader.getAttributeNamespace(i);
|
||||
String value = streamReader.getAttributeValue(i);
|
||||
Attribute.Type type = convertAttributeType(streamReader.getAttributeType(i));
|
||||
|
||||
nodeFactory.makeAttribute(name, uri, value, type);
|
||||
}
|
||||
}
|
||||
|
||||
private static Attribute.Type convertAttributeType(String type) {
|
||||
type = type.toUpperCase(Locale.ENGLISH);
|
||||
return switch (type) {
|
||||
case "CDATA" -> Attribute.Type.CDATA;
|
||||
case "ENTITIES" -> Attribute.Type.ENTITIES;
|
||||
case "ENTITY" -> Attribute.Type.ENTITY;
|
||||
case "ENUMERATION" -> Attribute.Type.ENUMERATION;
|
||||
case "ID" -> Attribute.Type.ID;
|
||||
case "IDREF" -> Attribute.Type.IDREF;
|
||||
case "IDREFS" -> Attribute.Type.IDREFS;
|
||||
case "NMTOKEN" -> Attribute.Type.NMTOKEN;
|
||||
case "NMTOKENS" -> Attribute.Type.NMTOKENS;
|
||||
case "NOTATION" -> Attribute.Type.NOTATION;
|
||||
default -> Attribute.Type.UNDECLARED;
|
||||
};
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
@@ -1,115 +0,0 @@
|
||||
/*
|
||||
* Copyright 2005-2025 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
|
||||
*
|
||||
* https://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.server.endpoint.adapter;
|
||||
|
||||
import java.lang.reflect.Method;
|
||||
|
||||
import org.springframework.oxm.GenericMarshaller;
|
||||
import org.springframework.oxm.GenericUnmarshaller;
|
||||
import org.springframework.oxm.Marshaller;
|
||||
import org.springframework.oxm.Unmarshaller;
|
||||
import org.springframework.oxm.jaxb.Jaxb2Marshaller;
|
||||
import org.springframework.ws.server.endpoint.MethodEndpoint;
|
||||
|
||||
/**
|
||||
* Subclass of {@link MarshallingMethodEndpointAdapter} that supports
|
||||
* {@link GenericMarshaller} and {@link GenericUnmarshaller}. More specifically, this
|
||||
* adapter is aware of the {@link Method#getGenericParameterTypes()} and
|
||||
* {@link Method#getGenericReturnType()}.
|
||||
* <p>
|
||||
* Prefer to use this adapter rather than the plain
|
||||
* {@link MarshallingMethodEndpointAdapter} in combination with Java 5 marshallers, such
|
||||
* as the {@link Jaxb2Marshaller}.
|
||||
*
|
||||
* @author Arjen Poutsma
|
||||
* @since 1.0.2
|
||||
* @deprecated as of Spring Web Services 2.0, in favor of
|
||||
* {@link DefaultMethodEndpointAdapter} and
|
||||
* {@link org.springframework.ws.server.endpoint.adapter.method.MarshallingPayloadMethodProcessor
|
||||
* MarshallingPayloadMethodProcessor}.
|
||||
*/
|
||||
@Deprecated
|
||||
public class GenericMarshallingMethodEndpointAdapter extends MarshallingMethodEndpointAdapter {
|
||||
|
||||
/**
|
||||
* Creates a new {@code GenericMarshallingMethodEndpointAdapter}. The
|
||||
* {@link Marshaller} and {@link Unmarshaller} must be injected using properties.
|
||||
* @see #setMarshaller(org.springframework.oxm.Marshaller)
|
||||
* @see #setUnmarshaller(org.springframework.oxm.Unmarshaller)
|
||||
*/
|
||||
public GenericMarshallingMethodEndpointAdapter() {
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates a new {@code GenericMarshallingMethodEndpointAdapter} with the given
|
||||
* marshaller. If the given {@link Marshaller} also implements the
|
||||
* {@link Unmarshaller} interface, it is used for both marshalling and unmarshalling.
|
||||
* Otherwise, an exception is thrown.
|
||||
* <p>
|
||||
* Note that all {@link Marshaller} implementations in Spring-WS also implement the
|
||||
* {@link Unmarshaller} interface, so that you can safely use this constructor.
|
||||
* @param marshaller object used as marshaller and unmarshaller
|
||||
* @throws IllegalArgumentException when {@code marshaller} does not implement the
|
||||
* {@link Unmarshaller} interface
|
||||
*/
|
||||
public GenericMarshallingMethodEndpointAdapter(Marshaller marshaller) {
|
||||
super(marshaller);
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates a new {@code GenericMarshallingMethodEndpointAdapter} with the given
|
||||
* marshaller and unmarshaller.
|
||||
* @param marshaller the marshaller to use
|
||||
* @param unmarshaller the unmarshaller to use
|
||||
*/
|
||||
public GenericMarshallingMethodEndpointAdapter(Marshaller marshaller, Unmarshaller unmarshaller) {
|
||||
super(marshaller, unmarshaller);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected boolean supportsInternal(MethodEndpoint methodEndpoint) {
|
||||
Method method = methodEndpoint.getMethod();
|
||||
return supportsReturnType(method) && supportsParameters(method);
|
||||
}
|
||||
|
||||
private boolean supportsReturnType(Method method) {
|
||||
if (Void.TYPE.equals(method.getReturnType())) {
|
||||
return true;
|
||||
}
|
||||
else {
|
||||
if (getMarshaller() instanceof GenericMarshaller) {
|
||||
return ((GenericMarshaller) getMarshaller()).supports(method.getGenericReturnType());
|
||||
}
|
||||
else {
|
||||
return getMarshaller().supports(method.getReturnType());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private boolean supportsParameters(Method method) {
|
||||
if (method.getParameterTypes().length != 1) {
|
||||
return false;
|
||||
}
|
||||
else if (getUnmarshaller() instanceof GenericUnmarshaller genericUnmarshaller) {
|
||||
return genericUnmarshaller.supports(method.getGenericParameterTypes()[0]);
|
||||
}
|
||||
else {
|
||||
return getUnmarshaller().supports(method.getParameterTypes()[0]);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
@@ -1,189 +0,0 @@
|
||||
/*
|
||||
* Copyright 2005-2025 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
|
||||
*
|
||||
* https://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.server.endpoint.adapter;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.lang.reflect.Method;
|
||||
|
||||
import org.springframework.beans.factory.InitializingBean;
|
||||
import org.springframework.oxm.Marshaller;
|
||||
import org.springframework.oxm.Unmarshaller;
|
||||
import org.springframework.util.Assert;
|
||||
import org.springframework.ws.WebServiceMessage;
|
||||
import org.springframework.ws.context.MessageContext;
|
||||
import org.springframework.ws.server.EndpointMapping;
|
||||
import org.springframework.ws.server.endpoint.MethodEndpoint;
|
||||
import org.springframework.ws.support.MarshallingUtils;
|
||||
|
||||
/**
|
||||
* Adapter that supports endpoint methods that use marshalling. Supports methods with the
|
||||
* following signature:
|
||||
*
|
||||
* <pre><code class='java'>
|
||||
* void handleMyMessage(MyUnmarshalledType request);</code></pre> or
|
||||
* <pre><code class='java'>
|
||||
* MyMarshalledType handleMyMessage(MyUnmarshalledType request);</code></pre>
|
||||
*
|
||||
* I.e. methods that take a single parameter that {@link Unmarshaller#supports(Class) is
|
||||
* supported} by the {@link Unmarshaller}, and return either {@code void} or a type
|
||||
* {@link Marshaller#supports(Class) supported} by the {@link Marshaller}. The method can
|
||||
* have any name, as long as it is mapped by an {@link EndpointMapping}.
|
||||
* <p>
|
||||
* This endpoint needs a {@code Marshaller} and {@code Unmarshaller}, both of which can be
|
||||
* set using properties.
|
||||
*
|
||||
* @author Arjen Poutsma
|
||||
* @since 1.0.0
|
||||
* @see #setMarshaller(org.springframework.oxm.Marshaller)
|
||||
* @see #setUnmarshaller(org.springframework.oxm.Unmarshaller)
|
||||
* @deprecated as of Spring Web Services 2.0, in favor of
|
||||
* {@link DefaultMethodEndpointAdapter} and
|
||||
* {@link org.springframework.ws.server.endpoint.adapter.method.MarshallingPayloadMethodProcessor
|
||||
* MarshallingPayloadMethodProcessor}.
|
||||
*/
|
||||
@Deprecated
|
||||
public class MarshallingMethodEndpointAdapter extends AbstractMethodEndpointAdapter implements InitializingBean {
|
||||
|
||||
private Marshaller marshaller;
|
||||
|
||||
private Unmarshaller unmarshaller;
|
||||
|
||||
/**
|
||||
* Creates a new {@code MarshallingMethodEndpointAdapter}. The {@link Marshaller} and
|
||||
* {@link Unmarshaller} must be injected using properties.
|
||||
* @see #setMarshaller(org.springframework.oxm.Marshaller)
|
||||
* @see #setUnmarshaller(org.springframework.oxm.Unmarshaller)
|
||||
*/
|
||||
public MarshallingMethodEndpointAdapter() {
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates a new {@code MarshallingMethodEndpointAdapter} with the given marshaller.
|
||||
* If the given {@link Marshaller} also implements the {@link Unmarshaller} interface,
|
||||
* it is used for both marshalling and unmarshalling. Otherwise, an exception is
|
||||
* thrown.
|
||||
* <p>
|
||||
* Note that all {@link Marshaller} implementations in Spring also implement the
|
||||
* {@link Unmarshaller} interface, so that you can safely use this constructor.
|
||||
* @param marshaller object used as marshaller and unmarshaller
|
||||
* @throws IllegalArgumentException when {@code marshaller} does not implement the
|
||||
* {@link Unmarshaller} interface
|
||||
*/
|
||||
public MarshallingMethodEndpointAdapter(Marshaller marshaller) {
|
||||
Assert.notNull(marshaller, "marshaller must not be null");
|
||||
if (!(marshaller instanceof Unmarshaller)) {
|
||||
throw new IllegalArgumentException("Marshaller [" + marshaller + "] does not implement the Unmarshaller "
|
||||
+ "interface. Please set an Unmarshaller explicitly by using the "
|
||||
+ "MarshallingMethodEndpointAdapter(Marshaller, Unmarshaller) constructor.");
|
||||
}
|
||||
else {
|
||||
this.setMarshaller(marshaller);
|
||||
this.setUnmarshaller((Unmarshaller) marshaller);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates a new {@code MarshallingMethodEndpointAdapter} with the given marshaller
|
||||
* and unmarshaller.
|
||||
* @param marshaller the marshaller to use
|
||||
* @param unmarshaller the unmarshaller to use
|
||||
*/
|
||||
public MarshallingMethodEndpointAdapter(Marshaller marshaller, Unmarshaller unmarshaller) {
|
||||
Assert.notNull(marshaller, "marshaller must not be null");
|
||||
Assert.notNull(unmarshaller, "unmarshaller must not be null");
|
||||
this.setMarshaller(marshaller);
|
||||
this.setUnmarshaller(unmarshaller);
|
||||
}
|
||||
|
||||
/** Returns the marshaller used for transforming objects into XML. */
|
||||
public Marshaller getMarshaller() {
|
||||
return this.marshaller;
|
||||
}
|
||||
|
||||
/** Sets the marshaller used for transforming objects into XML. */
|
||||
public final void setMarshaller(Marshaller marshaller) {
|
||||
this.marshaller = marshaller;
|
||||
}
|
||||
|
||||
/** Returns the unmarshaller used for transforming XML into objects. */
|
||||
public Unmarshaller getUnmarshaller() {
|
||||
return this.unmarshaller;
|
||||
}
|
||||
|
||||
/** Sets the unmarshaller used for transforming XML into objects. */
|
||||
public final void setUnmarshaller(Unmarshaller unmarshaller) {
|
||||
this.unmarshaller = unmarshaller;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void afterPropertiesSet() throws Exception {
|
||||
Assert.notNull(getMarshaller(), "marshaller is required");
|
||||
Assert.notNull(getUnmarshaller(), "unmarshaller is required");
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void invokeInternal(MessageContext messageContext, MethodEndpoint methodEndpoint) throws Exception {
|
||||
WebServiceMessage request = messageContext.getRequest();
|
||||
Object requestObject = unmarshalRequest(request);
|
||||
Object responseObject = methodEndpoint.invoke(requestObject);
|
||||
if (responseObject != null) {
|
||||
WebServiceMessage response = messageContext.getResponse();
|
||||
marshalResponse(responseObject, response);
|
||||
}
|
||||
}
|
||||
|
||||
private Object unmarshalRequest(WebServiceMessage request) throws IOException {
|
||||
Object requestObject = MarshallingUtils.unmarshal(getUnmarshaller(), request);
|
||||
if (this.logger.isDebugEnabled()) {
|
||||
this.logger.debug("Unmarshalled payload request to [" + requestObject + "]");
|
||||
}
|
||||
return requestObject;
|
||||
}
|
||||
|
||||
private void marshalResponse(Object responseObject, WebServiceMessage response) throws IOException {
|
||||
if (this.logger.isDebugEnabled()) {
|
||||
this.logger.debug("Marshalling [" + responseObject + "] to response payload");
|
||||
}
|
||||
MarshallingUtils.marshal(getMarshaller(), responseObject, response);
|
||||
}
|
||||
|
||||
/**
|
||||
* Supports a method with a single, unmarshallable parameter, and that return
|
||||
* {@code void} or a marshallable type.
|
||||
* @see Marshaller#supports(Class)
|
||||
* @see Unmarshaller#supports(Class)
|
||||
*/
|
||||
@Override
|
||||
protected boolean supportsInternal(MethodEndpoint methodEndpoint) {
|
||||
Method method = methodEndpoint.getMethod();
|
||||
return supportsReturnType(method) && supportsParameters(method);
|
||||
}
|
||||
|
||||
private boolean supportsReturnType(Method method) {
|
||||
return (Void.TYPE.equals(method.getReturnType()) || getMarshaller().supports(method.getReturnType()));
|
||||
}
|
||||
|
||||
private boolean supportsParameters(Method method) {
|
||||
if (method.getParameterTypes().length != 1) {
|
||||
return false;
|
||||
}
|
||||
else {
|
||||
return getUnmarshaller().supports(method.getParameterTypes()[0]);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
@@ -1,62 +0,0 @@
|
||||
/*
|
||||
* Copyright 2005-2025 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
|
||||
*
|
||||
* https://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.server.endpoint.adapter;
|
||||
|
||||
import java.lang.reflect.Method;
|
||||
|
||||
import org.springframework.ws.context.MessageContext;
|
||||
import org.springframework.ws.server.MessageDispatcher;
|
||||
import org.springframework.ws.server.endpoint.MethodEndpoint;
|
||||
import org.springframework.ws.soap.server.SoapMessageDispatcher;
|
||||
|
||||
/**
|
||||
* Adapter that supports endpoint methods with message contexts. Supports methods with the
|
||||
* following signature:
|
||||
*
|
||||
* <pre><code class='java'>
|
||||
* void handleMyMessage(MessageContext request);</code></pre>
|
||||
*
|
||||
* I.e. methods that take a single {@link MessageContext} parameter, and return
|
||||
* {@code void}. The method can have any name, as long as it is mapped by an
|
||||
* {@link org.springframework.ws.server.EndpointMapping}.
|
||||
* <p>
|
||||
* This adapter is registered by default by the {@link MessageDispatcher} and
|
||||
* {@link SoapMessageDispatcher}.
|
||||
*
|
||||
* @author Arjen Poutsma
|
||||
* @since 1.0.0
|
||||
* @deprecated as of Spring Web Services 2.0, in favor of
|
||||
* {@link DefaultMethodEndpointAdapter} and
|
||||
* {@link org.springframework.ws.server.endpoint.adapter.method.MessageContextMethodArgumentResolver
|
||||
* MessageContextMethodArgumentResolver}.
|
||||
*/
|
||||
@Deprecated
|
||||
public class MessageMethodEndpointAdapter extends AbstractMethodEndpointAdapter {
|
||||
|
||||
@Override
|
||||
protected boolean supportsInternal(MethodEndpoint methodEndpoint) {
|
||||
Method method = methodEndpoint.getMethod();
|
||||
return Void.TYPE.isAssignableFrom(method.getReturnType()) && method.getParameterTypes().length == 1
|
||||
&& MessageContext.class.isAssignableFrom(method.getParameterTypes()[0]);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void invokeInternal(MessageContext messageContext, MethodEndpoint methodEndpoint) throws Exception {
|
||||
methodEndpoint.invoke(messageContext);
|
||||
}
|
||||
|
||||
}
|
||||
@@ -1,71 +0,0 @@
|
||||
/*
|
||||
* Copyright 2005-2025 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
|
||||
*
|
||||
* https://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.server.endpoint.adapter;
|
||||
|
||||
import java.lang.reflect.Method;
|
||||
|
||||
import javax.xml.transform.Source;
|
||||
|
||||
import org.springframework.ws.WebServiceMessage;
|
||||
import org.springframework.ws.context.MessageContext;
|
||||
import org.springframework.ws.server.MessageDispatcher;
|
||||
import org.springframework.ws.server.endpoint.MethodEndpoint;
|
||||
import org.springframework.ws.soap.server.SoapMessageDispatcher;
|
||||
|
||||
/**
|
||||
* Adapter that supports endpoint methods that use marshalling. Supports methods with the
|
||||
* following signature: <pre><code class='java'>
|
||||
* void handleMyMessage(Source request);</code></pre> or <pre><code class='java'>
|
||||
* Source handleMyMessage(Source request);</code></pre> I.e. methods that take a single
|
||||
* {@link Source} parameter, and return either {@code void} or a {@link Source}. The
|
||||
* method can have any name, as long as it is mapped by an
|
||||
* {@link org.springframework.ws.server.EndpointMapping}.
|
||||
* <p>
|
||||
* This adapter is registered by default by the {@link MessageDispatcher} and
|
||||
* {@link SoapMessageDispatcher}.
|
||||
*
|
||||
* @author Arjen Poutsma
|
||||
* @since 1.0.0
|
||||
* @deprecated as of Spring Web Services 2.0, in favor of
|
||||
* {@link DefaultMethodEndpointAdapter} and
|
||||
* {@link org.springframework.ws.server.endpoint.adapter.method.SourcePayloadMethodProcessor
|
||||
* SourcePayloadMethodProcessor}.
|
||||
*/
|
||||
@Deprecated
|
||||
public class PayloadMethodEndpointAdapter extends AbstractMethodEndpointAdapter {
|
||||
|
||||
@Override
|
||||
protected boolean supportsInternal(MethodEndpoint methodEndpoint) {
|
||||
Method method = methodEndpoint.getMethod();
|
||||
return (Void.TYPE.isAssignableFrom(method.getReturnType())
|
||||
|| Source.class.isAssignableFrom(method.getReturnType())) && method.getParameterTypes().length == 1
|
||||
&& Source.class.isAssignableFrom(method.getParameterTypes()[0]);
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void invokeInternal(MessageContext messageContext, MethodEndpoint methodEndpoint) throws Exception {
|
||||
Source requestSource = messageContext.getRequest().getPayloadSource();
|
||||
Object result = methodEndpoint.invoke(requestSource);
|
||||
if (result != null) {
|
||||
Source responseSource = (Source) result;
|
||||
WebServiceMessage response = messageContext.getResponse();
|
||||
transform(responseSource, response.getPayloadResult());
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
@@ -1,190 +0,0 @@
|
||||
/*
|
||||
* Copyright 2005-2025 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
|
||||
*
|
||||
* https://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.server.endpoint.adapter;
|
||||
|
||||
import java.lang.annotation.Annotation;
|
||||
import java.lang.reflect.Method;
|
||||
import java.util.Map;
|
||||
|
||||
import javax.xml.namespace.QName;
|
||||
import javax.xml.transform.Source;
|
||||
import javax.xml.transform.TransformerException;
|
||||
import javax.xml.transform.dom.DOMResult;
|
||||
import javax.xml.xpath.XPath;
|
||||
import javax.xml.xpath.XPathConstants;
|
||||
import javax.xml.xpath.XPathExpressionException;
|
||||
import javax.xml.xpath.XPathFactory;
|
||||
|
||||
import org.w3c.dom.Document;
|
||||
import org.w3c.dom.Element;
|
||||
import org.w3c.dom.Node;
|
||||
import org.w3c.dom.NodeList;
|
||||
|
||||
import org.springframework.beans.factory.InitializingBean;
|
||||
import org.springframework.ws.WebServiceMessage;
|
||||
import org.springframework.ws.context.MessageContext;
|
||||
import org.springframework.ws.server.endpoint.MethodEndpoint;
|
||||
import org.springframework.ws.server.endpoint.annotation.XPathParam;
|
||||
import org.springframework.xml.namespace.SimpleNamespaceContext;
|
||||
|
||||
/**
|
||||
* Adapter that supports endpoint methods that use XPath expressions. Supports methods
|
||||
* with the following signature:
|
||||
*
|
||||
* <pre><code class='java'>
|
||||
* void handleMyMessage(@XPathParam("/root/child/text") String param);</code></pre> or
|
||||
* <pre><code class='java'>
|
||||
* Source handleMyMessage(@XPathParam("/root/child/text") String param1,
|
||||
* @XPathParam("/root/child/number") double param2);</code></pre> I.e. methods
|
||||
* that return either {@code void} or a {@link Source}, and have parameters annotated with
|
||||
* {@link XPathParam} that specify the XPath expression that should be bound to that
|
||||
* parameter. The parameter can be of the following types:
|
||||
* <ul>
|
||||
* <li>{@code boolean}, or {@link Boolean}</li>
|
||||
* <li>{@code double}, or {@link Double}</li>
|
||||
* <li>{@link String}</li>
|
||||
* <li>{@link Node}</li>
|
||||
* <li>{@link NodeList}</li>
|
||||
* </ul>
|
||||
*
|
||||
* @author Arjen Poutsma
|
||||
* @since 1.0.0
|
||||
* @deprecated as of Spring Web Services 2.0, in favor of
|
||||
* {@link DefaultMethodEndpointAdapter} and
|
||||
* {@link org.springframework.ws.server.endpoint.adapter.method.XPathParamMethodArgumentResolver
|
||||
* XPathParamMethodArgumentResolver}.
|
||||
*/
|
||||
@Deprecated
|
||||
public class XPathParamAnnotationMethodEndpointAdapter extends AbstractMethodEndpointAdapter
|
||||
implements InitializingBean {
|
||||
|
||||
private XPathFactory xpathFactory;
|
||||
|
||||
private Map<String, String> namespaces;
|
||||
|
||||
/** Sets namespaces used in the XPath expression. Maps prefixes to namespaces. */
|
||||
public void setNamespaces(Map<String, String> namespaces) {
|
||||
this.namespaces = namespaces;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void afterPropertiesSet() throws Exception {
|
||||
this.xpathFactory = XPathFactory.newInstance();
|
||||
}
|
||||
|
||||
/**
|
||||
* Supports methods with @XPathParam parameters, and return either {@code Source} or
|
||||
* nothing.
|
||||
*/
|
||||
@Override
|
||||
protected boolean supportsInternal(MethodEndpoint methodEndpoint) {
|
||||
Method method = methodEndpoint.getMethod();
|
||||
if (!(Source.class.isAssignableFrom(method.getReturnType()) || Void.TYPE.equals(method.getReturnType()))) {
|
||||
return false;
|
||||
}
|
||||
Class<?>[] parameterTypes = method.getParameterTypes();
|
||||
for (int i = 0; i < parameterTypes.length; i++) {
|
||||
if (getXPathParamAnnotation(method, i) == null || !isSupportedType(parameterTypes[i])) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
private XPathParam getXPathParamAnnotation(Method method, int paramIdx) {
|
||||
Annotation[][] paramAnnotations = method.getParameterAnnotations();
|
||||
for (int annIdx = 0; annIdx < paramAnnotations[paramIdx].length; annIdx++) {
|
||||
if (paramAnnotations[paramIdx][annIdx].annotationType().equals(XPathParam.class)) {
|
||||
return (XPathParam) paramAnnotations[paramIdx][annIdx];
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
private boolean isSupportedType(Class<?> clazz) {
|
||||
return Boolean.class.isAssignableFrom(clazz) || Boolean.TYPE.isAssignableFrom(clazz)
|
||||
|| Double.class.isAssignableFrom(clazz) || Double.TYPE.isAssignableFrom(clazz)
|
||||
|| Node.class.isAssignableFrom(clazz) || NodeList.class.isAssignableFrom(clazz)
|
||||
|| String.class.isAssignableFrom(clazz);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void invokeInternal(MessageContext messageContext, MethodEndpoint methodEndpoint) throws Exception {
|
||||
Element payloadElement = getRootElement(messageContext.getRequest().getPayloadSource());
|
||||
Object[] args = getMethodArguments(payloadElement, methodEndpoint.getMethod());
|
||||
Object result = methodEndpoint.invoke(args);
|
||||
if (result instanceof Source responseSource) {
|
||||
WebServiceMessage response = messageContext.getResponse();
|
||||
transform(responseSource, response.getPayloadResult());
|
||||
}
|
||||
}
|
||||
|
||||
private Object[] getMethodArguments(Element payloadElement, Method method) throws XPathExpressionException {
|
||||
Class<?>[] parameterTypes = method.getParameterTypes();
|
||||
XPath xpath = createXPath();
|
||||
Object[] args = new Object[parameterTypes.length];
|
||||
for (int i = 0; i < parameterTypes.length; i++) {
|
||||
String expression = getXPathParamAnnotation(method, i).value();
|
||||
QName conversionType;
|
||||
if (Boolean.class.isAssignableFrom(parameterTypes[i]) || Boolean.TYPE.isAssignableFrom(parameterTypes[i])) {
|
||||
conversionType = XPathConstants.BOOLEAN;
|
||||
}
|
||||
else if (Double.class.isAssignableFrom(parameterTypes[i])
|
||||
|| Double.TYPE.isAssignableFrom(parameterTypes[i])) {
|
||||
conversionType = XPathConstants.NUMBER;
|
||||
}
|
||||
else if (Node.class.isAssignableFrom(parameterTypes[i])) {
|
||||
conversionType = XPathConstants.NODE;
|
||||
}
|
||||
else if (NodeList.class.isAssignableFrom(parameterTypes[i])) {
|
||||
conversionType = XPathConstants.NODESET;
|
||||
}
|
||||
else if (String.class.isAssignableFrom(parameterTypes[i])) {
|
||||
conversionType = XPathConstants.STRING;
|
||||
}
|
||||
else {
|
||||
throw new IllegalArgumentException("Invalid parameter type [" + parameterTypes[i] + "]. "
|
||||
+ "Supported are: Boolean, Double, Node, NodeList, and String.");
|
||||
}
|
||||
args[i] = xpath.evaluate(expression, payloadElement, conversionType);
|
||||
}
|
||||
return args;
|
||||
}
|
||||
|
||||
private synchronized XPath createXPath() {
|
||||
XPath xpath = this.xpathFactory.newXPath();
|
||||
if (this.namespaces != null) {
|
||||
SimpleNamespaceContext namespaceContext = new SimpleNamespaceContext();
|
||||
namespaceContext.setBindings(this.namespaces);
|
||||
xpath.setNamespaceContext(namespaceContext);
|
||||
}
|
||||
return xpath;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the root element of the given source.
|
||||
* @param source the source to get the root element from
|
||||
* @return the root element
|
||||
*/
|
||||
private Element getRootElement(Source source) throws TransformerException {
|
||||
DOMResult domResult = new DOMResult();
|
||||
transform(source, domResult);
|
||||
Document document = (Document) domResult.getNode();
|
||||
return document.getDocumentElement();
|
||||
}
|
||||
|
||||
}
|
||||
@@ -1,188 +0,0 @@
|
||||
/*
|
||||
* Copyright 2005-2025 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
|
||||
*
|
||||
* https://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.server.endpoint;
|
||||
|
||||
import java.util.Locale;
|
||||
|
||||
import javax.xml.namespace.QName;
|
||||
|
||||
import org.springframework.context.MessageSource;
|
||||
import org.springframework.context.MessageSourceAware;
|
||||
import org.springframework.validation.Errors;
|
||||
import org.springframework.validation.ObjectError;
|
||||
import org.springframework.validation.Validator;
|
||||
import org.springframework.ws.context.MessageContext;
|
||||
import org.springframework.ws.soap.SoapBody;
|
||||
import org.springframework.ws.soap.SoapFault;
|
||||
import org.springframework.ws.soap.SoapFaultDetail;
|
||||
import org.springframework.ws.soap.SoapFaultDetailElement;
|
||||
import org.springframework.ws.soap.SoapMessage;
|
||||
|
||||
/**
|
||||
* Extension of the
|
||||
* {@link org.springframework.ws.server.endpoint.AbstractValidatingMarshallingPayloadEndpoint}
|
||||
* which validates the request payload with {@link Validator}(s), and creates a SOAP Fault
|
||||
* whenever the request message cannot be validated. The desired validators can be set
|
||||
* using properties, and <strong>must</strong> {@link Validator#supports(Class) support}
|
||||
* the request object.
|
||||
* <p>
|
||||
* The contents of the SOAP Fault can be specified by setting the
|
||||
* {@link #setAddValidationErrorDetail(boolean) addValidationErrorDetail},
|
||||
* {@link #setFaultStringOrReason(String) faultStringOrReason}, or
|
||||
* {@link #setDetailElementName(QName) detailElementName} properties.
|
||||
*
|
||||
* @author Arjen Poutsma
|
||||
* @since 1.0.2
|
||||
* @deprecated as of Spring Web Services 2.0, in favor of annotated endpoints
|
||||
*/
|
||||
@Deprecated
|
||||
public abstract class AbstractFaultCreatingValidatingMarshallingPayloadEndpoint
|
||||
extends org.springframework.ws.server.endpoint.AbstractValidatingMarshallingPayloadEndpoint
|
||||
implements MessageSourceAware {
|
||||
|
||||
/**
|
||||
* Default SOAP Fault Detail name used when a global validation error occur on the
|
||||
* request.
|
||||
* @see #setDetailElementName(javax.xml.namespace.QName)
|
||||
*/
|
||||
public static final QName DEFAULT_DETAIL_ELEMENT_NAME = new QName("http://springframework.org/spring-ws",
|
||||
"ValidationError", "spring-ws");
|
||||
|
||||
/**
|
||||
* Default SOAP Fault string used when a validation errors occur on the request.
|
||||
* @see #setFaultStringOrReason(String)
|
||||
*/
|
||||
public static final String DEFAULT_FAULTSTRING_OR_REASON = "Validation error";
|
||||
|
||||
private boolean addValidationErrorDetail = true;
|
||||
|
||||
private QName detailElementName = DEFAULT_DETAIL_ELEMENT_NAME;
|
||||
|
||||
private String faultStringOrReason = DEFAULT_FAULTSTRING_OR_REASON;
|
||||
|
||||
private Locale faultStringOrReasonLocale = Locale.ENGLISH;
|
||||
|
||||
private MessageSource messageSource;
|
||||
|
||||
/**
|
||||
* Returns whether a SOAP Fault detail element should be created when a validation
|
||||
* error occurs. This detail element will contain the exact validation errors. It is
|
||||
* only added when the underlying message is a {@code SoapMessage}. Defaults to
|
||||
* {@code true}.
|
||||
* @see org.springframework.ws.soap.SoapFault#addFaultDetail()
|
||||
*/
|
||||
public boolean getAddValidationErrorDetail() {
|
||||
return this.addValidationErrorDetail;
|
||||
}
|
||||
|
||||
/**
|
||||
* Indicates whether a SOAP Fault detail element should be created when a validation
|
||||
* error occurs. This detail element will contain the exact validation errors. It is
|
||||
* only added when the underlying message is a {@code SoapMessage}. Defaults to
|
||||
* {@code true}.
|
||||
* @see org.springframework.ws.soap.SoapFault#addFaultDetail()
|
||||
*/
|
||||
public void setAddValidationErrorDetail(boolean addValidationErrorDetail) {
|
||||
this.addValidationErrorDetail = addValidationErrorDetail;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the fault detail element name when validation errors occur on the request.
|
||||
*/
|
||||
public QName getDetailElementName() {
|
||||
return this.detailElementName;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the fault detail element name when validation errors occur on the request.
|
||||
* Defaults to {@code DEFAULT_DETAIL_ELEMENT_NAME}.
|
||||
* @see #DEFAULT_DETAIL_ELEMENT_NAME
|
||||
*/
|
||||
public void setDetailElementName(QName detailElementName) {
|
||||
this.detailElementName = detailElementName;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the SOAP {@code faultstring} or {@code Reason} used when validation errors
|
||||
* occur on the request.
|
||||
*/
|
||||
public String getFaultStringOrReason() {
|
||||
return this.faultStringOrReason;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the SOAP {@code faultstring} or {@code Reason} used when validation errors
|
||||
* occur on the request. It is only added when the underlying message is a
|
||||
* {@code SoapMessage}. Defaults to {@code DEFAULT_FAULTSTRING_OR_REASON}.
|
||||
* @see #DEFAULT_FAULTSTRING_OR_REASON
|
||||
*/
|
||||
public void setFaultStringOrReason(String faultStringOrReason) {
|
||||
this.faultStringOrReason = faultStringOrReason;
|
||||
}
|
||||
|
||||
/** Returns the locale for SOAP fault reason and validation message resolution. */
|
||||
public Locale getFaultLocale() {
|
||||
return this.faultStringOrReasonLocale;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the locale for SOAP fault reason and validation messages. It is only added
|
||||
* when the underlying message is a {@code SoapMessage}. Defaults to English.
|
||||
* @see java.util.Locale#ENGLISH
|
||||
*/
|
||||
public void setFaultStringOrReasonLocale(Locale faultStringOrReasonLocale) {
|
||||
this.faultStringOrReasonLocale = faultStringOrReasonLocale;
|
||||
}
|
||||
|
||||
@Override
|
||||
public final void setMessageSource(MessageSource messageSource) {
|
||||
this.messageSource = messageSource;
|
||||
}
|
||||
|
||||
/**
|
||||
* This implementation logs all errors, returns {@code false}, and creates a
|
||||
* {@link SoapBody#addClientOrSenderFault(String,Locale) client or sender}
|
||||
* {@link SoapFault}, adding a {@link SoapFaultDetail} with all errors if the
|
||||
* {@code addValidationErrorDetail} property is {@code true}.
|
||||
* @param messageContext the message context
|
||||
* @param errors the validation errors
|
||||
* @return {@code true} to continue processing the request, {@code false} (the
|
||||
* default) otherwise
|
||||
* @see Errors#getAllErrors()
|
||||
*/
|
||||
@Override
|
||||
protected final boolean onValidationErrors(MessageContext messageContext, Object requestObject, Errors errors) {
|
||||
for (ObjectError objectError : errors.getAllErrors()) {
|
||||
String msg = this.messageSource.getMessage(objectError, getFaultLocale());
|
||||
this.logger.warn("Validation error on request object[" + requestObject + "]: " + msg);
|
||||
}
|
||||
if (messageContext.getResponse() instanceof SoapMessage response) {
|
||||
SoapBody body = response.getSoapBody();
|
||||
SoapFault fault = body.addClientOrSenderFault(getFaultStringOrReason(), getFaultLocale());
|
||||
if (getAddValidationErrorDetail()) {
|
||||
SoapFaultDetail detail = fault.addFaultDetail();
|
||||
for (ObjectError objectError : errors.getAllErrors()) {
|
||||
String msg = this.messageSource.getMessage(objectError, getFaultLocale());
|
||||
SoapFaultDetailElement detailElement = detail.addFaultDetailElement(getDetailElementName());
|
||||
detailElement.addText(msg);
|
||||
}
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -4,6 +4,4 @@
|
||||
org.springframework.ws.server.EndpointAdapter=\
|
||||
org.springframework.ws.server.endpoint.adapter.MessageEndpointAdapter,\
|
||||
org.springframework.ws.server.endpoint.adapter.PayloadEndpointAdapter,\
|
||||
org.springframework.ws.server.endpoint.adapter.MessageMethodEndpointAdapter,\
|
||||
org.springframework.ws.server.endpoint.adapter.PayloadMethodEndpointAdapter,\
|
||||
org.springframework.ws.server.endpoint.adapter.DefaultMethodEndpointAdapter
|
||||
|
||||
@@ -4,8 +4,6 @@
|
||||
org.springframework.ws.server.EndpointAdapter=\
|
||||
org.springframework.ws.server.endpoint.adapter.MessageEndpointAdapter,\
|
||||
org.springframework.ws.server.endpoint.adapter.PayloadEndpointAdapter,\
|
||||
org.springframework.ws.server.endpoint.adapter.MessageMethodEndpointAdapter,\
|
||||
org.springframework.ws.server.endpoint.adapter.PayloadMethodEndpointAdapter,\
|
||||
org.springframework.ws.server.endpoint.adapter.DefaultMethodEndpointAdapter
|
||||
|
||||
org.springframework.ws.server.EndpointExceptionResolver=\
|
||||
|
||||
@@ -1,49 +0,0 @@
|
||||
/*
|
||||
* Copyright 2005-2025 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
|
||||
*
|
||||
* https://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.config;
|
||||
|
||||
import java.util.Map;
|
||||
|
||||
import org.junit.jupiter.api.BeforeEach;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
import org.springframework.context.ApplicationContext;
|
||||
import org.springframework.context.support.ClassPathXmlApplicationContext;
|
||||
import org.springframework.ws.server.endpoint.adapter.MarshallingMethodEndpointAdapter;
|
||||
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
|
||||
@Deprecated
|
||||
public class WebServiceNamespaceHandlerTest {
|
||||
|
||||
private ApplicationContext applicationContext;
|
||||
|
||||
@BeforeEach
|
||||
public void setUp() throws Exception {
|
||||
this.applicationContext = new ClassPathXmlApplicationContext("webServiceNamespaceHandlerTest.xml", getClass());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testMarshallingMethods() throws Exception {
|
||||
|
||||
Map<String, MarshallingMethodEndpointAdapter> result = this.applicationContext
|
||||
.getBeansOfType(MarshallingMethodEndpointAdapter.class);
|
||||
|
||||
assertThat(result).isNotEmpty();
|
||||
}
|
||||
|
||||
}
|
||||
@@ -1,60 +0,0 @@
|
||||
/*
|
||||
* Copyright 2005-2025 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
|
||||
*
|
||||
* https://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.config;
|
||||
|
||||
import java.util.Map;
|
||||
|
||||
import org.junit.jupiter.api.BeforeEach;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
import org.springframework.context.ApplicationContext;
|
||||
import org.springframework.context.support.ClassPathXmlApplicationContext;
|
||||
import org.springframework.ws.server.endpoint.adapter.GenericMarshallingMethodEndpointAdapter;
|
||||
import org.springframework.ws.server.endpoint.adapter.XPathParamAnnotationMethodEndpointAdapter;
|
||||
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
|
||||
@Deprecated
|
||||
public class WebServicesNamespaceHandlerTigerTest {
|
||||
|
||||
private ApplicationContext applicationContext;
|
||||
|
||||
@BeforeEach
|
||||
public void setUp() {
|
||||
this.applicationContext = new ClassPathXmlApplicationContext("webServicesNamespaceHandlerTest-tiger.xml",
|
||||
getClass());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testMarshallingEndpoints() {
|
||||
|
||||
Map<String, GenericMarshallingMethodEndpointAdapter> result = this.applicationContext
|
||||
.getBeansOfType(GenericMarshallingMethodEndpointAdapter.class);
|
||||
|
||||
assertThat(result).isNotEmpty();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testXpathEndpoints() {
|
||||
|
||||
Map<String, XPathParamAnnotationMethodEndpointAdapter> result = this.applicationContext
|
||||
.getBeansOfType(XPathParamAnnotationMethodEndpointAdapter.class);
|
||||
|
||||
assertThat(result).isNotEmpty();
|
||||
}
|
||||
|
||||
}
|
||||
@@ -1,70 +0,0 @@
|
||||
/*
|
||||
* Copyright 2005-2025 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
|
||||
*
|
||||
* https://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.server.endpoint;
|
||||
|
||||
import org.dom4j.Document;
|
||||
import org.dom4j.Element;
|
||||
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
|
||||
@Deprecated
|
||||
public class Dom4jPayloadEndpointTest extends AbstractPayloadEndpointTest {
|
||||
|
||||
@Override
|
||||
protected PayloadEndpoint createResponseEndpoint() {
|
||||
|
||||
return new AbstractDom4jPayloadEndpoint() {
|
||||
|
||||
@Override
|
||||
protected Element invokeInternal(Element requestElement, Document responseDocument) {
|
||||
|
||||
assertThat(requestElement).isNotNull();
|
||||
assertThat(responseDocument).isNotNull();
|
||||
assertThat(requestElement.getName()).isEqualTo(REQUEST_ELEMENT);
|
||||
assertThat(requestElement.getNamespaceURI()).isEqualTo(NAMESPACE_URI);
|
||||
|
||||
return responseDocument.addElement(RESPONSE_ELEMENT, NAMESPACE_URI);
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
@Override
|
||||
protected PayloadEndpoint createNoResponseEndpoint() throws Exception {
|
||||
return new AbstractDom4jPayloadEndpoint() {
|
||||
|
||||
@Override
|
||||
protected Element invokeInternal(Element requestElement, Document responseDocument) {
|
||||
return null;
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
@Override
|
||||
protected PayloadEndpoint createNoRequestEndpoint() throws Exception {
|
||||
|
||||
return new AbstractDom4jPayloadEndpoint() {
|
||||
|
||||
@Override
|
||||
protected Element invokeInternal(Element requestElement, Document responseDocument) {
|
||||
|
||||
assertThat(requestElement).isNull();
|
||||
return null;
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
}
|
||||
@@ -1,70 +0,0 @@
|
||||
/*
|
||||
* Copyright 2005-2025 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
|
||||
*
|
||||
* https://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.server.endpoint;
|
||||
|
||||
import org.w3c.dom.Document;
|
||||
import org.w3c.dom.Element;
|
||||
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
|
||||
@Deprecated
|
||||
public class DomPayloadEndpointTest extends AbstractPayloadEndpointTest {
|
||||
|
||||
@Override
|
||||
protected PayloadEndpoint createNoResponseEndpoint() throws Exception {
|
||||
return new AbstractDomPayloadEndpoint() {
|
||||
|
||||
@Override
|
||||
protected Element invokeInternal(Element requestElement, Document document) {
|
||||
return null;
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
@Override
|
||||
protected PayloadEndpoint createResponseEndpoint() throws Exception {
|
||||
|
||||
return new AbstractDomPayloadEndpoint() {
|
||||
|
||||
@Override
|
||||
protected Element invokeInternal(Element requestElement, Document responseDocument) {
|
||||
|
||||
assertThat(requestElement).isNotNull();
|
||||
assertThat(responseDocument).isNotNull();
|
||||
assertThat(requestElement.getLocalName()).isEqualTo(REQUEST_ELEMENT);
|
||||
assertThat(requestElement.getNamespaceURI()).isEqualTo(NAMESPACE_URI);
|
||||
|
||||
return responseDocument.createElementNS(NAMESPACE_URI, RESPONSE_ELEMENT);
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
@Override
|
||||
protected PayloadEndpoint createNoRequestEndpoint() throws Exception {
|
||||
|
||||
return new AbstractDomPayloadEndpoint() {
|
||||
|
||||
@Override
|
||||
protected Element invokeInternal(Element requestElement, Document responseDocument) {
|
||||
|
||||
assertThat(requestElement).isNull();
|
||||
return null;
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
}
|
||||
@@ -1,69 +0,0 @@
|
||||
/*
|
||||
* Copyright 2005-2025 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
|
||||
*
|
||||
* https://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.server.endpoint;
|
||||
|
||||
import org.jdom2.Element;
|
||||
import org.jdom2.Namespace;
|
||||
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
|
||||
@Deprecated
|
||||
public class JDomPayloadEndpointTest extends AbstractPayloadEndpointTest {
|
||||
|
||||
@Override
|
||||
protected PayloadEndpoint createNoResponseEndpoint() throws Exception {
|
||||
return new AbstractJDomPayloadEndpoint() {
|
||||
|
||||
@Override
|
||||
protected Element invokeInternal(Element requestElement) {
|
||||
return null;
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
@Override
|
||||
protected PayloadEndpoint createResponseEndpoint() throws Exception {
|
||||
|
||||
return new AbstractJDomPayloadEndpoint() {
|
||||
|
||||
@Override
|
||||
protected Element invokeInternal(Element requestElement) {
|
||||
|
||||
assertThat(requestElement).isNotNull();
|
||||
assertThat(requestElement.getName()).isEqualTo(REQUEST_ELEMENT);
|
||||
assertThat(requestElement.getNamespaceURI()).isEqualTo(NAMESPACE_URI);
|
||||
|
||||
return new Element(RESPONSE_ELEMENT, Namespace.getNamespace("tns", NAMESPACE_URI));
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
@Override
|
||||
protected PayloadEndpoint createNoRequestEndpoint() throws Exception {
|
||||
|
||||
return new AbstractJDomPayloadEndpoint() {
|
||||
|
||||
@Override
|
||||
protected Element invokeInternal(Element requestElement) {
|
||||
|
||||
assertThat(requestElement).isNull();
|
||||
return null;
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
}
|
||||
@@ -1,281 +0,0 @@
|
||||
/*
|
||||
* Copyright 2005-2025 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
|
||||
*
|
||||
* https://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.server.endpoint;
|
||||
|
||||
import java.io.StringReader;
|
||||
import java.io.StringWriter;
|
||||
|
||||
import javax.xml.transform.Result;
|
||||
import javax.xml.transform.Source;
|
||||
import javax.xml.transform.Transformer;
|
||||
import javax.xml.transform.TransformerException;
|
||||
import javax.xml.transform.stream.StreamResult;
|
||||
import javax.xml.transform.stream.StreamSource;
|
||||
|
||||
import org.junit.jupiter.api.BeforeEach;
|
||||
import org.junit.jupiter.api.Test;
|
||||
import org.xmlunit.assertj.XmlAssert;
|
||||
|
||||
import org.springframework.oxm.Marshaller;
|
||||
import org.springframework.oxm.Unmarshaller;
|
||||
import org.springframework.oxm.XmlMappingException;
|
||||
import org.springframework.oxm.mime.MimeContainer;
|
||||
import org.springframework.oxm.mime.MimeMarshaller;
|
||||
import org.springframework.oxm.mime.MimeUnmarshaller;
|
||||
import org.springframework.ws.MockWebServiceMessage;
|
||||
import org.springframework.ws.WebServiceMessageFactory;
|
||||
import org.springframework.ws.context.DefaultMessageContext;
|
||||
import org.springframework.ws.context.MessageContext;
|
||||
import org.springframework.ws.mime.MimeMessage;
|
||||
import org.springframework.xml.transform.StringResult;
|
||||
import org.springframework.xml.transform.StringSource;
|
||||
import org.springframework.xml.transform.TransformerFactoryUtils;
|
||||
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
import static org.assertj.core.api.Assertions.fail;
|
||||
import static org.easymock.EasyMock.createMock;
|
||||
import static org.easymock.EasyMock.eq;
|
||||
import static org.easymock.EasyMock.expect;
|
||||
import static org.easymock.EasyMock.isA;
|
||||
import static org.easymock.EasyMock.replay;
|
||||
import static org.easymock.EasyMock.verify;
|
||||
|
||||
@Deprecated
|
||||
public class MarshallingPayloadEndpointTest {
|
||||
|
||||
private Transformer transformer;
|
||||
|
||||
private MessageContext context;
|
||||
|
||||
private WebServiceMessageFactory factoryMock;
|
||||
|
||||
@BeforeEach
|
||||
public void setUp() throws Exception {
|
||||
|
||||
MockWebServiceMessage request = new MockWebServiceMessage("<request/>");
|
||||
this.transformer = TransformerFactoryUtils.newInstance().newTransformer();
|
||||
this.factoryMock = createMock(WebServiceMessageFactory.class);
|
||||
this.context = new DefaultMessageContext(request, this.factoryMock);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testInvoke() throws Exception {
|
||||
|
||||
Unmarshaller unmarshaller = new SimpleMarshaller() {
|
||||
|
||||
@Override
|
||||
public Object unmarshal(Source source) throws XmlMappingException {
|
||||
|
||||
try {
|
||||
StringWriter writer = new StringWriter();
|
||||
MarshallingPayloadEndpointTest.this.transformer.transform(source, new StreamResult(writer));
|
||||
|
||||
XmlAssert.assertThat(writer.toString()).and("<request/>").ignoreWhitespace().areIdentical();
|
||||
|
||||
return 42L;
|
||||
}
|
||||
catch (Exception e) {
|
||||
|
||||
fail(e.getMessage());
|
||||
return null;
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
Marshaller marshaller = new SimpleMarshaller() {
|
||||
|
||||
@Override
|
||||
public void marshal(Object graph, Result result) throws XmlMappingException {
|
||||
|
||||
assertThat(graph).isEqualTo("result");
|
||||
|
||||
try {
|
||||
MarshallingPayloadEndpointTest.this.transformer
|
||||
.transform(new StreamSource(new StringReader("<result/>")), result);
|
||||
}
|
||||
catch (TransformerException e) {
|
||||
fail(e.getMessage());
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
AbstractMarshallingPayloadEndpoint endpoint = new AbstractMarshallingPayloadEndpoint() {
|
||||
|
||||
@Override
|
||||
protected Object invokeInternal(Object requestObject) {
|
||||
|
||||
assertThat(requestObject).isEqualTo(42L);
|
||||
return "result";
|
||||
}
|
||||
};
|
||||
|
||||
endpoint.setMarshaller(marshaller);
|
||||
endpoint.setUnmarshaller(unmarshaller);
|
||||
endpoint.afterPropertiesSet();
|
||||
|
||||
expect(this.factoryMock.createWebServiceMessage()).andReturn(new MockWebServiceMessage());
|
||||
|
||||
replay(this.factoryMock);
|
||||
|
||||
endpoint.invoke(this.context);
|
||||
MockWebServiceMessage response = (MockWebServiceMessage) this.context.getResponse();
|
||||
|
||||
assertThat(response).isNotNull();
|
||||
XmlAssert.assertThat(response.getPayloadAsString()).and("<result/>").ignoreWhitespace().areIdentical();
|
||||
|
||||
verify(this.factoryMock);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testInvokeNullResponse() throws Exception {
|
||||
|
||||
Unmarshaller unmarshaller = new SimpleMarshaller() {
|
||||
|
||||
@Override
|
||||
public Object unmarshal(Source source) throws XmlMappingException {
|
||||
|
||||
try {
|
||||
StringWriter writer = new StringWriter();
|
||||
MarshallingPayloadEndpointTest.this.transformer.transform(source, new StreamResult(writer));
|
||||
|
||||
XmlAssert.assertThat(writer.toString()).and("<request/>").ignoreWhitespace().areIdentical();
|
||||
|
||||
return (long) 42;
|
||||
}
|
||||
catch (Exception e) {
|
||||
fail(e.getMessage());
|
||||
return null;
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
Marshaller marshaller = new SimpleMarshaller() {
|
||||
|
||||
@Override
|
||||
public void marshal(Object graph, Result result) throws XmlMappingException {
|
||||
fail("marshal not expected");
|
||||
}
|
||||
};
|
||||
|
||||
AbstractMarshallingPayloadEndpoint endpoint = new AbstractMarshallingPayloadEndpoint() {
|
||||
|
||||
@Override
|
||||
protected Object invokeInternal(Object requestObject) {
|
||||
|
||||
assertThat(requestObject).isEqualTo(42L);
|
||||
return null;
|
||||
}
|
||||
};
|
||||
|
||||
endpoint.setMarshaller(marshaller);
|
||||
endpoint.setUnmarshaller(unmarshaller);
|
||||
endpoint.afterPropertiesSet();
|
||||
replay(this.factoryMock);
|
||||
endpoint.invoke(this.context);
|
||||
|
||||
assertThat(this.context.hasResponse()).isFalse();
|
||||
|
||||
verify(this.factoryMock);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testInvokeNoRequest() throws Exception {
|
||||
|
||||
MockWebServiceMessage request = new MockWebServiceMessage((StringBuilder) null);
|
||||
this.context = new DefaultMessageContext(request, this.factoryMock);
|
||||
|
||||
AbstractMarshallingPayloadEndpoint endpoint = new AbstractMarshallingPayloadEndpoint() {
|
||||
|
||||
@Override
|
||||
protected Object invokeInternal(Object requestObject) {
|
||||
|
||||
assertThat(requestObject).isNull();
|
||||
return null;
|
||||
}
|
||||
};
|
||||
|
||||
endpoint.setMarshaller(new SimpleMarshaller());
|
||||
endpoint.setUnmarshaller(new SimpleMarshaller());
|
||||
endpoint.afterPropertiesSet();
|
||||
replay(this.factoryMock);
|
||||
endpoint.invoke(this.context);
|
||||
|
||||
assertThat(this.context.hasResponse()).isFalse();
|
||||
|
||||
verify(this.factoryMock);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testInvokeMimeMarshaller() throws Exception {
|
||||
|
||||
MimeUnmarshaller unmarshaller = createMock(MimeUnmarshaller.class);
|
||||
MimeMarshaller marshaller = createMock(MimeMarshaller.class);
|
||||
MimeMessage request = createMock("request", MimeMessage.class);
|
||||
MimeMessage response = createMock("response", MimeMessage.class);
|
||||
Source requestSource = new StringSource("<request/>");
|
||||
expect(request.getPayloadSource()).andReturn(requestSource);
|
||||
expect(this.factoryMock.createWebServiceMessage()).andReturn(response);
|
||||
expect(unmarshaller.unmarshal(eq(requestSource), isA(MimeContainer.class))).andReturn(42L);
|
||||
Result responseResult = new StringResult();
|
||||
expect(response.getPayloadResult()).andReturn(responseResult);
|
||||
marshaller.marshal(eq("result"), eq(responseResult), isA(MimeContainer.class));
|
||||
|
||||
replay(this.factoryMock, unmarshaller, marshaller, request, response);
|
||||
|
||||
AbstractMarshallingPayloadEndpoint endpoint = new AbstractMarshallingPayloadEndpoint() {
|
||||
|
||||
@Override
|
||||
protected Object invokeInternal(Object requestObject) {
|
||||
|
||||
assertThat(requestObject).isEqualTo(42L);
|
||||
return "result";
|
||||
}
|
||||
};
|
||||
|
||||
endpoint.setMarshaller(marshaller);
|
||||
endpoint.setUnmarshaller(unmarshaller);
|
||||
endpoint.afterPropertiesSet();
|
||||
|
||||
this.context = new DefaultMessageContext(request, this.factoryMock);
|
||||
endpoint.invoke(this.context);
|
||||
|
||||
assertThat(response).isNotNull();
|
||||
|
||||
verify(this.factoryMock, unmarshaller, marshaller, request, response);
|
||||
}
|
||||
|
||||
static class SimpleMarshaller implements Marshaller, Unmarshaller {
|
||||
|
||||
@Override
|
||||
public void marshal(Object graph, Result result) throws XmlMappingException {
|
||||
fail("Not expected");
|
||||
}
|
||||
|
||||
@Override
|
||||
public Object unmarshal(Source source) throws XmlMappingException {
|
||||
fail("Not expected");
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean supports(Class<?> clazz) {
|
||||
return false;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
@@ -1,106 +0,0 @@
|
||||
/*
|
||||
* Copyright 2005-2025 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
|
||||
*
|
||||
* https://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.server.endpoint;
|
||||
|
||||
import javax.xml.transform.Source;
|
||||
|
||||
import org.xml.sax.Attributes;
|
||||
import org.xml.sax.ContentHandler;
|
||||
import org.xml.sax.helpers.DefaultHandler;
|
||||
|
||||
import org.springframework.xml.transform.StringSource;
|
||||
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
import static org.assertj.core.api.Assertions.fail;
|
||||
|
||||
@Deprecated
|
||||
public class SaxPayloadEndpointTest extends AbstractPayloadEndpointTest {
|
||||
|
||||
@Override
|
||||
protected PayloadEndpoint createNoResponseEndpoint() {
|
||||
|
||||
return new AbstractSaxPayloadEndpoint() {
|
||||
|
||||
@Override
|
||||
protected Source getResponse(ContentHandler contentHandler) {
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected ContentHandler createContentHandler() {
|
||||
return new DefaultHandler();
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
@Override
|
||||
protected PayloadEndpoint createResponseEndpoint() {
|
||||
|
||||
return new AbstractSaxPayloadEndpoint() {
|
||||
|
||||
@Override
|
||||
protected ContentHandler createContentHandler() {
|
||||
return new TestContentHandler();
|
||||
}
|
||||
|
||||
@Override
|
||||
protected Source getResponse(ContentHandler contentHandler) {
|
||||
return new StringSource(RESPONSE);
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
@Override
|
||||
protected PayloadEndpoint createNoRequestEndpoint() {
|
||||
|
||||
return new AbstractSaxPayloadEndpoint() {
|
||||
|
||||
@Override
|
||||
protected ContentHandler createContentHandler() {
|
||||
|
||||
fail("Not expected");
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected Source getResponse(ContentHandler contentHandler) {
|
||||
return null;
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
private static final class TestContentHandler extends DefaultHandler {
|
||||
|
||||
@Override
|
||||
public void endElement(String uri, String localName, String qName) {
|
||||
|
||||
assertThat(localName).isEqualTo(REQUEST_ELEMENT);
|
||||
assertThat(qName).isEqualTo(localName);
|
||||
assertThat(uri).isEqualTo(NAMESPACE_URI);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void startElement(String uri, String localName, String qName, Attributes attributes) {
|
||||
|
||||
assertThat(localName).isEqualTo(REQUEST_ELEMENT);
|
||||
assertThat(qName).isEqualTo(localName);
|
||||
assertThat(uri).isEqualTo(NAMESPACE_URI);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
@@ -1,106 +0,0 @@
|
||||
/*
|
||||
* Copyright 2005-2025 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
|
||||
*
|
||||
* https://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.server.endpoint;
|
||||
|
||||
import java.util.Collections;
|
||||
|
||||
import javax.xml.namespace.QName;
|
||||
import javax.xml.stream.XMLEventFactory;
|
||||
import javax.xml.stream.XMLEventReader;
|
||||
import javax.xml.stream.XMLStreamException;
|
||||
import javax.xml.stream.events.Namespace;
|
||||
import javax.xml.stream.events.XMLEvent;
|
||||
import javax.xml.stream.util.XMLEventConsumer;
|
||||
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
|
||||
/**
|
||||
* Test case for AbstractStaxEventPayloadEndpoint.
|
||||
*
|
||||
* @see AbstractStaxEventPayloadEndpoint
|
||||
*/
|
||||
@Deprecated
|
||||
public class StaxEventPayloadEndpointTest extends AbstractMessageEndpointTest {
|
||||
|
||||
@Override
|
||||
protected MessageEndpoint createNoResponseEndpoint() {
|
||||
|
||||
return new AbstractStaxEventPayloadEndpoint() {
|
||||
@Override
|
||||
protected void invokeInternal(XMLEventReader eventReader, XMLEventConsumer eventWriter,
|
||||
XMLEventFactory eventFactory) {
|
||||
assertThat(eventReader).isNotNull();
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
@Override
|
||||
protected MessageEndpoint createNoRequestPayloadEndpoint() {
|
||||
|
||||
return new AbstractStaxEventPayloadEndpoint() {
|
||||
|
||||
@Override
|
||||
protected void invokeInternal(XMLEventReader eventReader, XMLEventConsumer eventWriter,
|
||||
XMLEventFactory eventFactory) {
|
||||
assertThat(eventReader).isNull();
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
@Override
|
||||
protected MessageEndpoint createResponseEndpoint() {
|
||||
|
||||
return new AbstractStaxEventPayloadEndpoint() {
|
||||
|
||||
@Override
|
||||
protected void invokeInternal(XMLEventReader eventReader, XMLEventConsumer eventWriter,
|
||||
XMLEventFactory eventFactory) throws XMLStreamException {
|
||||
|
||||
assertThat(eventReader).isNotNull();
|
||||
assertThat(eventWriter).isNotNull();
|
||||
assertThat(eventFactory).isNotNull();
|
||||
assertThat(eventReader.hasNext()).isTrue();
|
||||
|
||||
XMLEvent event = eventReader.nextEvent();
|
||||
|
||||
assertThat(event.isStartDocument()).isTrue();
|
||||
|
||||
event = eventReader.nextEvent();
|
||||
|
||||
assertThat(event.isStartElement()).isTrue();
|
||||
assertThat(event.asStartElement().getName().getLocalPart()).isEqualTo(REQUEST_ELEMENT);
|
||||
assertThat(event.asStartElement().getName().getNamespaceURI()).isEqualTo(NAMESPACE_URI);
|
||||
assertThat(eventReader.hasNext()).isTrue();
|
||||
|
||||
event = eventReader.nextEvent();
|
||||
|
||||
assertThat(event.isEndElement()).isTrue();
|
||||
assertThat(event.asEndElement().getName().getLocalPart()).isEqualTo(REQUEST_ELEMENT);
|
||||
assertThat(event.asEndElement().getName().getNamespaceURI()).isEqualTo(NAMESPACE_URI);
|
||||
|
||||
Namespace namespace = eventFactory.createNamespace(NAMESPACE_URI);
|
||||
QName name = new QName(NAMESPACE_URI, RESPONSE_ELEMENT);
|
||||
|
||||
eventWriter
|
||||
.add(eventFactory.createStartElement(name, null, Collections.singleton(namespace).iterator()));
|
||||
eventWriter.add(eventFactory.createEndElement(name, Collections.singleton(namespace).iterator()));
|
||||
eventWriter.add(eventFactory.createEndDocument());
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
}
|
||||
@@ -1,166 +0,0 @@
|
||||
/*
|
||||
* Copyright 2005-2025 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
|
||||
*
|
||||
* https://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.server.endpoint;
|
||||
|
||||
import javax.xml.stream.XMLOutputFactory;
|
||||
import javax.xml.stream.XMLStreamConstants;
|
||||
import javax.xml.stream.XMLStreamReader;
|
||||
import javax.xml.stream.XMLStreamWriter;
|
||||
import javax.xml.transform.Transformer;
|
||||
|
||||
import jakarta.xml.soap.MessageFactory;
|
||||
import org.junit.jupiter.api.Test;
|
||||
import org.xmlunit.assertj.XmlAssert;
|
||||
|
||||
import org.springframework.ws.context.DefaultMessageContext;
|
||||
import org.springframework.ws.context.MessageContext;
|
||||
import org.springframework.ws.soap.saaj.SaajSoapMessage;
|
||||
import org.springframework.ws.soap.saaj.SaajSoapMessageFactory;
|
||||
import org.springframework.xml.transform.StringResult;
|
||||
import org.springframework.xml.transform.StringSource;
|
||||
import org.springframework.xml.transform.TransformerFactoryUtils;
|
||||
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
|
||||
/**
|
||||
* Test case for AbstractStaxStreamPayloadEndpoint.
|
||||
*
|
||||
* @see AbstractStaxStreamPayloadEndpoint
|
||||
*/
|
||||
@Deprecated
|
||||
public class StaxStreamPayloadEndpointTest extends AbstractMessageEndpointTest {
|
||||
|
||||
@Override
|
||||
protected MessageEndpoint createNoResponseEndpoint() {
|
||||
|
||||
return new AbstractStaxStreamPayloadEndpoint() {
|
||||
@Override
|
||||
protected void invokeInternal(XMLStreamReader streamReader, XMLStreamWriter streamWriter) throws Exception {
|
||||
assertThat(streamReader).isNotNull();
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
@Override
|
||||
protected MessageEndpoint createNoRequestPayloadEndpoint() {
|
||||
|
||||
return new AbstractStaxStreamPayloadEndpoint() {
|
||||
@Override
|
||||
protected void invokeInternal(XMLStreamReader streamReader, XMLStreamWriter streamWriter) throws Exception {
|
||||
assertThat(streamReader).isNull();
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
@Override
|
||||
protected MessageEndpoint createResponseEndpoint() {
|
||||
|
||||
return new AbstractStaxStreamPayloadEndpoint() {
|
||||
@Override
|
||||
protected void invokeInternal(XMLStreamReader streamReader, XMLStreamWriter streamWriter) throws Exception {
|
||||
|
||||
assertThat(streamReader).isNotNull();
|
||||
assertThat(streamWriter).isNotNull();
|
||||
assertThat(streamReader.next()).isEqualTo(XMLStreamConstants.START_ELEMENT);
|
||||
assertThat(streamReader.getLocalName()).isEqualTo(REQUEST_ELEMENT);
|
||||
assertThat(streamReader.getNamespaceURI()).isEqualTo(NAMESPACE_URI);
|
||||
assertThat(streamReader.hasNext()).isTrue();
|
||||
assertThat(streamReader.next()).isEqualTo(XMLStreamConstants.END_ELEMENT);
|
||||
assertThat(streamReader.getLocalName()).isEqualTo(REQUEST_ELEMENT);
|
||||
assertThat(streamReader.getNamespaceURI()).isEqualTo(NAMESPACE_URI);
|
||||
|
||||
streamWriter.setDefaultNamespace(NAMESPACE_URI);
|
||||
streamWriter.writeStartElement(NAMESPACE_URI, RESPONSE_ELEMENT);
|
||||
streamWriter.writeDefaultNamespace(NAMESPACE_URI);
|
||||
streamWriter.writeEndElement();
|
||||
streamWriter.flush();
|
||||
streamWriter.close();
|
||||
}
|
||||
|
||||
@Override
|
||||
protected XMLOutputFactory createXmlOutputFactory() {
|
||||
|
||||
XMLOutputFactory outputFactory = XMLOutputFactory.newInstance();
|
||||
outputFactory.setProperty("javax.xml.stream.isRepairingNamespaces", Boolean.TRUE);
|
||||
|
||||
return outputFactory;
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testSaajResponse() throws Exception {
|
||||
|
||||
Transformer transformer = TransformerFactoryUtils.newInstance().newTransformer();
|
||||
MessageFactory messageFactory = MessageFactory.newInstance();
|
||||
SaajSoapMessage request = new SaajSoapMessage(messageFactory.createMessage());
|
||||
transformer.transform(new StringSource(REQUEST), request.getPayloadResult());
|
||||
SaajSoapMessageFactory soapMessageFactory = new SaajSoapMessageFactory();
|
||||
soapMessageFactory.afterPropertiesSet();
|
||||
MessageContext context = new DefaultMessageContext(request, soapMessageFactory);
|
||||
|
||||
MessageEndpoint endpoint = createResponseEndpoint();
|
||||
endpoint.invoke(context);
|
||||
|
||||
assertThat(context.hasResponse()).isTrue();
|
||||
|
||||
StringResult stringResult = new StringResult();
|
||||
transformer.transform(context.getResponse().getPayloadSource(), stringResult);
|
||||
|
||||
XmlAssert.assertThat(stringResult.toString()).and(RESPONSE).ignoreWhitespace().areIdentical();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testAxiomResponse() throws Exception {
|
||||
|
||||
Transformer transformer = TransformerFactoryUtils.newInstance().newTransformer();
|
||||
MessageFactory messageFactory = MessageFactory.newInstance();
|
||||
SaajSoapMessage request = new SaajSoapMessage(messageFactory.createMessage(), true, messageFactory);
|
||||
transformer.transform(new StringSource(REQUEST), request.getPayloadResult());
|
||||
SaajSoapMessageFactory soapMessageFactory = new SaajSoapMessageFactory();
|
||||
soapMessageFactory.afterPropertiesSet();
|
||||
MessageContext context = new DefaultMessageContext(request, soapMessageFactory);
|
||||
|
||||
MessageEndpoint endpoint = createResponseEndpoint();
|
||||
endpoint.invoke(context);
|
||||
|
||||
assertThat(context.hasResponse()).isTrue();
|
||||
|
||||
StringResult stringResult = new StringResult();
|
||||
transformer.transform(context.getResponse().getPayloadSource(), stringResult);
|
||||
|
||||
XmlAssert.assertThat(stringResult.toString()).and(RESPONSE).ignoreWhitespace().areIdentical();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testAxiomNoResponse() throws Exception {
|
||||
|
||||
Transformer transformer = TransformerFactoryUtils.newInstance().newTransformer();
|
||||
MessageFactory messageFactory = MessageFactory.newInstance();
|
||||
SaajSoapMessage request = new SaajSoapMessage(messageFactory.createMessage(), true, messageFactory);
|
||||
transformer.transform(new StringSource(REQUEST), request.getPayloadResult());
|
||||
SaajSoapMessageFactory soapMessageFactory = new SaajSoapMessageFactory();
|
||||
soapMessageFactory.afterPropertiesSet();
|
||||
MessageContext context = new DefaultMessageContext(request, soapMessageFactory);
|
||||
|
||||
MessageEndpoint endpoint = createNoResponseEndpoint();
|
||||
endpoint.invoke(context);
|
||||
|
||||
assertThat(context.hasResponse()).isFalse();
|
||||
}
|
||||
|
||||
}
|
||||
@@ -1,79 +0,0 @@
|
||||
/*
|
||||
* Copyright 2005-2025 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
|
||||
*
|
||||
* https://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.server.endpoint;
|
||||
|
||||
import nu.xom.Element;
|
||||
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
|
||||
@Deprecated
|
||||
public class XomPayloadEndpointTest extends AbstractPayloadEndpointTest {
|
||||
|
||||
@Override
|
||||
protected PayloadEndpoint createNoResponseEndpoint() {
|
||||
|
||||
return new AbstractXomPayloadEndpoint() {
|
||||
|
||||
@Override
|
||||
protected Element invokeInternal(Element requestElement) {
|
||||
return null;
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
@Override
|
||||
protected PayloadEndpoint createResponseEndpoint() {
|
||||
|
||||
return new AbstractXomPayloadEndpoint() {
|
||||
|
||||
@Override
|
||||
protected Element invokeInternal(Element requestElement) {
|
||||
|
||||
assertThat(requestElement).isNotNull();
|
||||
assertThat(requestElement.getLocalName()).isEqualTo(REQUEST_ELEMENT);
|
||||
assertThat(requestElement.getNamespaceURI()).isEqualTo(NAMESPACE_URI);
|
||||
|
||||
return new Element(RESPONSE_ELEMENT, NAMESPACE_URI);
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
@Override
|
||||
protected PayloadEndpoint createNoRequestEndpoint() {
|
||||
|
||||
return new AbstractXomPayloadEndpoint() {
|
||||
|
||||
@Override
|
||||
protected Element invokeInternal(Element requestElement) {
|
||||
|
||||
assertThat(requestElement).isNull();
|
||||
return null;
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
@Override
|
||||
public void testStaxSourceEventReader() {
|
||||
// overriden, because XOM doesn't not support it
|
||||
}
|
||||
|
||||
@Override
|
||||
public void testStaxSourceStreamReader() {
|
||||
// overriden, because XOM doesn't not support it
|
||||
}
|
||||
|
||||
}
|
||||
@@ -1,235 +0,0 @@
|
||||
/*
|
||||
* Copyright 2005-2025 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
|
||||
*
|
||||
* https://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.server.endpoint.adapter;
|
||||
|
||||
import java.lang.reflect.Method;
|
||||
|
||||
import javax.xml.transform.Result;
|
||||
import javax.xml.transform.Source;
|
||||
|
||||
import org.junit.jupiter.api.BeforeEach;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
import org.springframework.oxm.GenericMarshaller;
|
||||
import org.springframework.oxm.GenericUnmarshaller;
|
||||
import org.springframework.ws.WebServiceMessage;
|
||||
import org.springframework.ws.WebServiceMessageFactory;
|
||||
import org.springframework.ws.context.DefaultMessageContext;
|
||||
import org.springframework.ws.context.MessageContext;
|
||||
import org.springframework.ws.server.endpoint.MethodEndpoint;
|
||||
import org.springframework.xml.transform.StringResult;
|
||||
import org.springframework.xml.transform.StringSource;
|
||||
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
import static org.easymock.EasyMock.createMock;
|
||||
import static org.easymock.EasyMock.expect;
|
||||
import static org.easymock.EasyMock.isA;
|
||||
import static org.easymock.EasyMock.replay;
|
||||
import static org.easymock.EasyMock.verify;
|
||||
|
||||
@Deprecated
|
||||
public class GenericMarshallingMethodEndpointAdapterTest {
|
||||
|
||||
private GenericMarshallingMethodEndpointAdapter adapter;
|
||||
|
||||
private boolean noResponseInvoked;
|
||||
|
||||
private GenericMarshaller marshallerMock;
|
||||
|
||||
private GenericUnmarshaller unmarshallerMock;
|
||||
|
||||
private boolean responseInvoked;
|
||||
|
||||
@BeforeEach
|
||||
public void setUp() throws Exception {
|
||||
|
||||
this.adapter = new GenericMarshallingMethodEndpointAdapter();
|
||||
this.marshallerMock = createMock(GenericMarshaller.class);
|
||||
this.adapter.setMarshaller(this.marshallerMock);
|
||||
this.unmarshallerMock = createMock(GenericUnmarshaller.class);
|
||||
this.adapter.setUnmarshaller(this.unmarshallerMock);
|
||||
this.adapter.afterPropertiesSet();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testNoResponse() throws Exception {
|
||||
|
||||
WebServiceMessage messageMock = createMock(WebServiceMessage.class);
|
||||
expect(messageMock.getPayloadSource()).andReturn(new StringSource("<request/>"));
|
||||
WebServiceMessageFactory factoryMock = createMock(WebServiceMessageFactory.class);
|
||||
MessageContext messageContext = new DefaultMessageContext(messageMock, factoryMock);
|
||||
|
||||
Method noResponse = getClass().getMethod("noResponse", MyGenericType.class);
|
||||
MethodEndpoint methodEndpoint = new MethodEndpoint(this, noResponse);
|
||||
expect(this.unmarshallerMock.unmarshal(isA(Source.class))).andReturn(new MyGenericType<MyType>());
|
||||
|
||||
replay(this.marshallerMock, this.unmarshallerMock, messageMock, factoryMock);
|
||||
|
||||
assertThat(this.noResponseInvoked).isFalse();
|
||||
|
||||
this.adapter.invoke(messageContext, methodEndpoint);
|
||||
|
||||
assertThat(this.noResponseInvoked).isTrue();
|
||||
|
||||
verify(this.marshallerMock, this.unmarshallerMock, messageMock, factoryMock);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testNoRequestPayload() throws Exception {
|
||||
|
||||
WebServiceMessage messageMock = createMock(WebServiceMessage.class);
|
||||
expect(messageMock.getPayloadSource()).andReturn(null);
|
||||
WebServiceMessageFactory factoryMock = createMock(WebServiceMessageFactory.class);
|
||||
MessageContext messageContext = new DefaultMessageContext(messageMock, factoryMock);
|
||||
|
||||
Method noResponse = getClass().getMethod("noResponse", MyGenericType.class);
|
||||
MethodEndpoint methodEndpoint = new MethodEndpoint(this, noResponse);
|
||||
|
||||
replay(this.marshallerMock, this.unmarshallerMock, messageMock, factoryMock);
|
||||
|
||||
assertThat(this.noResponseInvoked).isFalse();
|
||||
|
||||
this.adapter.invoke(messageContext, methodEndpoint);
|
||||
|
||||
assertThat(this.noResponseInvoked).isTrue();
|
||||
|
||||
verify(this.marshallerMock, this.unmarshallerMock, messageMock, factoryMock);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testResponse() throws Exception {
|
||||
|
||||
WebServiceMessage requestMock = createMock(WebServiceMessage.class);
|
||||
expect(requestMock.getPayloadSource()).andReturn(new StringSource("<request/>"));
|
||||
WebServiceMessage responseMock = createMock(WebServiceMessage.class);
|
||||
expect(responseMock.getPayloadResult()).andReturn(new StringResult());
|
||||
WebServiceMessageFactory factoryMock = createMock(WebServiceMessageFactory.class);
|
||||
expect(factoryMock.createWebServiceMessage()).andReturn(responseMock);
|
||||
MessageContext messageContext = new DefaultMessageContext(requestMock, factoryMock);
|
||||
|
||||
Method response = getClass().getMethod("response", MyGenericType.class);
|
||||
MethodEndpoint methodEndpoint = new MethodEndpoint(this, response);
|
||||
expect(this.unmarshallerMock.unmarshal(isA(Source.class))).andReturn(new MyGenericType<MyType>());
|
||||
this.marshallerMock.marshal(isA(MyGenericType.class), isA(Result.class));
|
||||
|
||||
replay(this.marshallerMock, this.unmarshallerMock, requestMock, responseMock, factoryMock);
|
||||
|
||||
assertThat(this.responseInvoked).isFalse();
|
||||
|
||||
this.adapter.invoke(messageContext, methodEndpoint);
|
||||
|
||||
assertThat(this.responseInvoked).isTrue();
|
||||
|
||||
verify(this.marshallerMock, this.unmarshallerMock, requestMock, responseMock, factoryMock);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testSupportedNoResponse() throws NoSuchMethodException {
|
||||
|
||||
Method noResponse = getClass().getMethod("noResponse", MyGenericType.class);
|
||||
MethodEndpoint methodEndpoint = new MethodEndpoint(this, noResponse);
|
||||
expect(this.unmarshallerMock.supports(noResponse.getGenericParameterTypes()[0])).andReturn(true);
|
||||
|
||||
replay(this.marshallerMock, this.unmarshallerMock);
|
||||
|
||||
assertThat(this.adapter.supportsInternal(methodEndpoint)).isTrue();
|
||||
|
||||
verify(this.marshallerMock, this.unmarshallerMock);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testSupportedResponse() throws NoSuchMethodException {
|
||||
|
||||
Method response = getClass().getMethod("response", MyGenericType.class);
|
||||
MethodEndpoint methodEndpoint = new MethodEndpoint(this, response);
|
||||
|
||||
expect(this.unmarshallerMock.supports(response.getGenericParameterTypes()[0])).andReturn(true);
|
||||
expect(this.marshallerMock.supports(response.getGenericReturnType())).andReturn(true);
|
||||
|
||||
replay(this.marshallerMock, this.unmarshallerMock);
|
||||
|
||||
assertThat(this.adapter.supportsInternal(methodEndpoint)).isTrue();
|
||||
|
||||
verify(this.marshallerMock, this.unmarshallerMock);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testUnsupportedMethodMultipleParams() throws NoSuchMethodException {
|
||||
|
||||
Method unsupported = getClass().getMethod("unsupportedMultipleParams", String.class, String.class);
|
||||
|
||||
replay(this.marshallerMock, this.unmarshallerMock);
|
||||
|
||||
assertThat(this.adapter.supportsInternal(new MethodEndpoint(this, unsupported))).isFalse();
|
||||
|
||||
verify(this.marshallerMock, this.unmarshallerMock);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testUnsupportedMethodWrongParam() throws NoSuchMethodException {
|
||||
|
||||
Method unsupported = getClass().getMethod("unsupportedWrongParam", String.class);
|
||||
expect(this.unmarshallerMock.supports(unsupported.getGenericParameterTypes()[0])).andReturn(false);
|
||||
expect(this.marshallerMock.supports(unsupported.getGenericReturnType())).andReturn(true);
|
||||
|
||||
replay(this.marshallerMock, this.unmarshallerMock);
|
||||
|
||||
assertThat(this.adapter.supportsInternal(new MethodEndpoint(this, unsupported))).isFalse();
|
||||
|
||||
verify(this.marshallerMock, this.unmarshallerMock);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testUnsupportedMethodWrongReturnType() throws NoSuchMethodException {
|
||||
|
||||
Method unsupported = getClass().getMethod("unsupportedWrongParam", String.class);
|
||||
expect(this.marshallerMock.supports(unsupported.getGenericReturnType())).andReturn(false);
|
||||
|
||||
replay(this.marshallerMock, this.unmarshallerMock);
|
||||
|
||||
assertThat(this.adapter.supportsInternal(new MethodEndpoint(this, unsupported))).isFalse();
|
||||
|
||||
verify(this.marshallerMock, this.unmarshallerMock);
|
||||
}
|
||||
|
||||
public void noResponse(MyGenericType<MyType> type) {
|
||||
this.noResponseInvoked = true;
|
||||
|
||||
}
|
||||
|
||||
public MyGenericType<MyType> response(MyGenericType<MyType> type) {
|
||||
|
||||
this.responseInvoked = true;
|
||||
return type;
|
||||
}
|
||||
|
||||
public void unsupportedMultipleParams(String s1, String s2) {
|
||||
}
|
||||
|
||||
public String unsupportedWrongParam(String s) {
|
||||
return s;
|
||||
}
|
||||
|
||||
private static final class MyType {
|
||||
|
||||
}
|
||||
|
||||
private static final class MyGenericType<T> {
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
@@ -1,215 +0,0 @@
|
||||
/*
|
||||
* Copyright 2005-2025 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
|
||||
*
|
||||
* https://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.server.endpoint.adapter;
|
||||
|
||||
import java.lang.reflect.Method;
|
||||
|
||||
import javax.xml.transform.Result;
|
||||
import javax.xml.transform.Source;
|
||||
|
||||
import org.junit.jupiter.api.BeforeEach;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
import org.springframework.oxm.Marshaller;
|
||||
import org.springframework.oxm.Unmarshaller;
|
||||
import org.springframework.ws.MockWebServiceMessage;
|
||||
import org.springframework.ws.MockWebServiceMessageFactory;
|
||||
import org.springframework.ws.context.DefaultMessageContext;
|
||||
import org.springframework.ws.context.MessageContext;
|
||||
import org.springframework.ws.server.endpoint.MethodEndpoint;
|
||||
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
import static org.easymock.EasyMock.createMock;
|
||||
import static org.easymock.EasyMock.expect;
|
||||
import static org.easymock.EasyMock.isA;
|
||||
import static org.easymock.EasyMock.replay;
|
||||
import static org.easymock.EasyMock.verify;
|
||||
|
||||
@Deprecated
|
||||
public class MarshallingMethodEndpointAdapterTest {
|
||||
|
||||
private MarshallingMethodEndpointAdapter adapter;
|
||||
|
||||
private boolean noResponseInvoked;
|
||||
|
||||
private Marshaller marshallerMock;
|
||||
|
||||
private Unmarshaller unmarshallerMock;
|
||||
|
||||
private MessageContext messageContext;
|
||||
|
||||
private boolean responseInvoked;
|
||||
|
||||
@BeforeEach
|
||||
public void setUp() throws Exception {
|
||||
|
||||
this.adapter = new MarshallingMethodEndpointAdapter();
|
||||
this.marshallerMock = createMock(Marshaller.class);
|
||||
this.adapter.setMarshaller(this.marshallerMock);
|
||||
this.unmarshallerMock = createMock(Unmarshaller.class);
|
||||
this.adapter.setUnmarshaller(this.unmarshallerMock);
|
||||
this.adapter.afterPropertiesSet();
|
||||
MockWebServiceMessage request = new MockWebServiceMessage("<request/>");
|
||||
this.messageContext = new DefaultMessageContext(request, new MockWebServiceMessageFactory());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testNoResponse() throws Exception {
|
||||
|
||||
Method noResponse = getClass().getMethod("noResponse", MyType.class);
|
||||
MethodEndpoint methodEndpoint = new MethodEndpoint(this, noResponse);
|
||||
expect(this.unmarshallerMock.unmarshal(isA(Source.class))).andReturn(new MyType());
|
||||
|
||||
replay(this.marshallerMock, this.unmarshallerMock);
|
||||
|
||||
assertThat(this.noResponseInvoked).isFalse();
|
||||
|
||||
this.adapter.invoke(this.messageContext, methodEndpoint);
|
||||
|
||||
assertThat(this.noResponseInvoked).isTrue();
|
||||
|
||||
verify(this.marshallerMock, this.unmarshallerMock);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testNoRequestPayload() throws Exception {
|
||||
|
||||
MockWebServiceMessage request = new MockWebServiceMessage();
|
||||
this.messageContext = new DefaultMessageContext(request, new MockWebServiceMessageFactory());
|
||||
Method noResponse = getClass().getMethod("noResponse", MyType.class);
|
||||
MethodEndpoint methodEndpoint = new MethodEndpoint(this, noResponse);
|
||||
|
||||
replay(this.marshallerMock, this.unmarshallerMock);
|
||||
|
||||
assertThat(this.noResponseInvoked).isFalse();
|
||||
|
||||
this.adapter.invoke(this.messageContext, methodEndpoint);
|
||||
assertThat(this.noResponseInvoked).isTrue();
|
||||
|
||||
verify(this.marshallerMock, this.unmarshallerMock);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testResponse() throws Exception {
|
||||
|
||||
Method response = getClass().getMethod("response", MyType.class);
|
||||
MethodEndpoint methodEndpoint = new MethodEndpoint(this, response);
|
||||
expect(this.unmarshallerMock.unmarshal(isA(Source.class))).andReturn(new MyType());
|
||||
this.marshallerMock.marshal(isA(MyType.class), isA(Result.class));
|
||||
|
||||
replay(this.marshallerMock, this.unmarshallerMock);
|
||||
|
||||
assertThat(this.responseInvoked).isFalse();
|
||||
|
||||
this.adapter.invoke(this.messageContext, methodEndpoint);
|
||||
|
||||
assertThat(this.responseInvoked).isTrue();
|
||||
|
||||
verify(this.marshallerMock, this.unmarshallerMock);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testSupportedNoResponse() throws NoSuchMethodException {
|
||||
|
||||
Method noResponse = getClass().getMethod("noResponse", MyType.class);
|
||||
MethodEndpoint methodEndpoint = new MethodEndpoint(this, noResponse);
|
||||
expect(this.unmarshallerMock.supports(MyType.class)).andReturn(true);
|
||||
|
||||
replay(this.marshallerMock, this.unmarshallerMock);
|
||||
|
||||
assertThat(this.adapter.supportsInternal(methodEndpoint)).isTrue();
|
||||
|
||||
verify(this.marshallerMock, this.unmarshallerMock);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testSupportedResponse() throws NoSuchMethodException {
|
||||
|
||||
Method response = getClass().getMethod("response", MyType.class);
|
||||
MethodEndpoint methodEndpoint = new MethodEndpoint(this, response);
|
||||
expect(this.unmarshallerMock.supports(MyType.class)).andReturn(true);
|
||||
expect(this.marshallerMock.supports(MyType.class)).andReturn(true);
|
||||
|
||||
replay(this.marshallerMock, this.unmarshallerMock);
|
||||
|
||||
assertThat(this.adapter.supportsInternal(methodEndpoint)).isTrue();
|
||||
|
||||
verify(this.marshallerMock, this.unmarshallerMock);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testUnsupportedMethodMultipleParams() throws NoSuchMethodException {
|
||||
|
||||
Method unsupported = getClass().getMethod("unsupportedMultipleParams", String.class, String.class);
|
||||
|
||||
replay(this.marshallerMock, this.unmarshallerMock);
|
||||
|
||||
assertThat(this.adapter.supportsInternal(new MethodEndpoint(this, unsupported))).isFalse();
|
||||
|
||||
verify(this.marshallerMock, this.unmarshallerMock);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testUnsupportedMethodWrongParam() throws NoSuchMethodException {
|
||||
|
||||
Method unsupported = getClass().getMethod("unsupportedWrongParam", String.class);
|
||||
expect(this.unmarshallerMock.supports(String.class)).andReturn(false);
|
||||
expect(this.marshallerMock.supports(String.class)).andReturn(true);
|
||||
|
||||
replay(this.marshallerMock, this.unmarshallerMock);
|
||||
|
||||
assertThat(this.adapter.supportsInternal(new MethodEndpoint(this, unsupported))).isFalse();
|
||||
|
||||
verify(this.marshallerMock, this.unmarshallerMock);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testUnsupportedMethodWrongReturnType() throws NoSuchMethodException {
|
||||
|
||||
Method unsupported = getClass().getMethod("unsupportedWrongParam", String.class);
|
||||
expect(this.marshallerMock.supports(String.class)).andReturn(false);
|
||||
|
||||
replay(this.marshallerMock, this.unmarshallerMock);
|
||||
|
||||
assertThat(this.adapter.supportsInternal(new MethodEndpoint(this, unsupported))).isFalse();
|
||||
|
||||
verify(this.marshallerMock, this.unmarshallerMock);
|
||||
}
|
||||
|
||||
public void noResponse(MyType type) {
|
||||
this.noResponseInvoked = true;
|
||||
|
||||
}
|
||||
|
||||
public MyType response(MyType type) {
|
||||
|
||||
this.responseInvoked = true;
|
||||
return new MyType();
|
||||
}
|
||||
|
||||
public void unsupportedMultipleParams(String s1, String s2) {
|
||||
}
|
||||
|
||||
public String unsupportedWrongParam(String s) {
|
||||
return s;
|
||||
}
|
||||
|
||||
private static final class MyType {
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
@@ -1,88 +0,0 @@
|
||||
/*
|
||||
* Copyright 2005-2025 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
|
||||
*
|
||||
* https://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.server.endpoint.adapter;
|
||||
|
||||
import org.junit.jupiter.api.BeforeEach;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
import org.springframework.ws.MockWebServiceMessageFactory;
|
||||
import org.springframework.ws.context.DefaultMessageContext;
|
||||
import org.springframework.ws.context.MessageContext;
|
||||
import org.springframework.ws.server.endpoint.MethodEndpoint;
|
||||
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
|
||||
@Deprecated
|
||||
public class MessageMethodEndpointAdapterTest {
|
||||
|
||||
private MessageMethodEndpointAdapter adapter;
|
||||
|
||||
private boolean supportedInvoked;
|
||||
|
||||
private MessageContext messageContext;
|
||||
|
||||
@BeforeEach
|
||||
public void setUp() {
|
||||
this.adapter = new MessageMethodEndpointAdapter();
|
||||
this.messageContext = new DefaultMessageContext(new MockWebServiceMessageFactory());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testSupported() throws NoSuchMethodException {
|
||||
|
||||
MethodEndpoint methodEndpoint = new MethodEndpoint(this, "supported", MessageContext.class);
|
||||
assertThat(this.adapter.supportsInternal(methodEndpoint)).isTrue();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testUnsupportedMethodMultipleParams() throws NoSuchMethodException {
|
||||
|
||||
assertThat(this.adapter.supportsInternal(
|
||||
new MethodEndpoint(this, "unsupportedMultipleParams", MessageContext.class, MessageContext.class)))
|
||||
.isFalse();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testUnsupportedMethodWrongParam() throws NoSuchMethodException {
|
||||
|
||||
assertThat(this.adapter.supportsInternal(new MethodEndpoint(this, "unsupportedWrongParam", String.class)))
|
||||
.isFalse();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testInvokeSupported() throws Exception {
|
||||
|
||||
MethodEndpoint methodEndpoint = new MethodEndpoint(this, "supported", MessageContext.class);
|
||||
|
||||
assertThat(this.supportedInvoked).isFalse();
|
||||
|
||||
this.adapter.invoke(this.messageContext, methodEndpoint);
|
||||
|
||||
assertThat(this.supportedInvoked).isTrue();
|
||||
}
|
||||
|
||||
public void supported(MessageContext context) {
|
||||
this.supportedInvoked = true;
|
||||
}
|
||||
|
||||
public void unsupportedMultipleParams(MessageContext s1, MessageContext s2) {
|
||||
}
|
||||
|
||||
public void unsupportedWrongParam(String request) {
|
||||
}
|
||||
|
||||
}
|
||||
@@ -1,136 +0,0 @@
|
||||
/*
|
||||
* Copyright 2005-2025 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
|
||||
*
|
||||
* https://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.server.endpoint.adapter;
|
||||
|
||||
import javax.xml.transform.Source;
|
||||
import javax.xml.transform.dom.DOMSource;
|
||||
import javax.xml.transform.stream.StreamSource;
|
||||
|
||||
import org.junit.jupiter.api.BeforeEach;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
import org.springframework.ws.MockWebServiceMessage;
|
||||
import org.springframework.ws.MockWebServiceMessageFactory;
|
||||
import org.springframework.ws.WebServiceMessage;
|
||||
import org.springframework.ws.context.DefaultMessageContext;
|
||||
import org.springframework.ws.context.MessageContext;
|
||||
import org.springframework.ws.server.endpoint.MethodEndpoint;
|
||||
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
|
||||
@Deprecated
|
||||
public class PayloadMethodEndpointAdapterTest {
|
||||
|
||||
private PayloadMethodEndpointAdapter adapter;
|
||||
|
||||
private boolean noResponseInvoked;
|
||||
|
||||
private boolean responseInvoked;
|
||||
|
||||
private MessageContext messageContext;
|
||||
|
||||
@BeforeEach
|
||||
public void setUp() {
|
||||
|
||||
this.adapter = new PayloadMethodEndpointAdapter();
|
||||
this.messageContext = new DefaultMessageContext(new MockWebServiceMessageFactory());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testSupportedNoResponse() throws NoSuchMethodException {
|
||||
|
||||
MethodEndpoint methodEndpoint = new MethodEndpoint(this, "noResponse", DOMSource.class);
|
||||
assertThat(this.adapter.supportsInternal(methodEndpoint)).isTrue();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testSupportedResponse() throws NoSuchMethodException {
|
||||
|
||||
MethodEndpoint methodEndpoint = new MethodEndpoint(this, "response", StreamSource.class);
|
||||
assertThat(this.adapter.supportsInternal(methodEndpoint)).isTrue();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testUnsupportedMethodMultipleParams() throws NoSuchMethodException {
|
||||
|
||||
assertThat(this.adapter
|
||||
.supportsInternal(new MethodEndpoint(this, "unsupportedMultipleParams", Source.class, Source.class)))
|
||||
.isFalse();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testUnsupportedMethodWrongReturnType() throws NoSuchMethodException {
|
||||
|
||||
assertThat(this.adapter.supportsInternal(new MethodEndpoint(this, "unsupportedWrongReturnType", Source.class)))
|
||||
.isFalse();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testUnsupportedMethodWrongParam() throws NoSuchMethodException {
|
||||
|
||||
assertThat(this.adapter.supportsInternal(new MethodEndpoint(this, "unsupportedWrongParam", String.class)))
|
||||
.isFalse();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testNoResponse() throws Exception {
|
||||
|
||||
MethodEndpoint methodEndpoint = new MethodEndpoint(this, "noResponse", DOMSource.class);
|
||||
|
||||
assertThat(this.noResponseInvoked).isFalse();
|
||||
|
||||
this.adapter.invoke(this.messageContext, methodEndpoint);
|
||||
|
||||
assertThat(this.noResponseInvoked).isTrue();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testResponse() throws Exception {
|
||||
|
||||
WebServiceMessage request = new MockWebServiceMessage("<request/>");
|
||||
this.messageContext = new DefaultMessageContext(request, new MockWebServiceMessageFactory());
|
||||
MethodEndpoint methodEndpoint = new MethodEndpoint(this, "response", StreamSource.class);
|
||||
|
||||
assertThat(this.responseInvoked).isFalse();
|
||||
|
||||
this.adapter.invoke(this.messageContext, methodEndpoint);
|
||||
|
||||
assertThat(this.responseInvoked).isTrue();
|
||||
}
|
||||
|
||||
public void noResponse(DOMSource request) {
|
||||
this.noResponseInvoked = true;
|
||||
}
|
||||
|
||||
public Source response(StreamSource request) {
|
||||
|
||||
this.responseInvoked = true;
|
||||
return request;
|
||||
}
|
||||
|
||||
public void unsupportedMultipleParams(Source s1, Source s2) {
|
||||
}
|
||||
|
||||
public Source unsupportedWrongParam(String request) {
|
||||
return null;
|
||||
}
|
||||
|
||||
public String unsupportedWrongReturnType(Source request) {
|
||||
return null;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -1,242 +0,0 @@
|
||||
/*
|
||||
* Copyright 2005-2025 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
|
||||
*
|
||||
* https://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.server.endpoint.adapter;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
|
||||
import javax.xml.parsers.DocumentBuilder;
|
||||
import javax.xml.parsers.DocumentBuilderFactory;
|
||||
import javax.xml.transform.Source;
|
||||
import javax.xml.transform.dom.DOMSource;
|
||||
|
||||
import org.junit.jupiter.api.BeforeEach;
|
||||
import org.junit.jupiter.api.Test;
|
||||
import org.w3c.dom.Document;
|
||||
import org.w3c.dom.Element;
|
||||
import org.w3c.dom.Node;
|
||||
import org.w3c.dom.NodeList;
|
||||
import org.w3c.dom.Text;
|
||||
|
||||
import org.springframework.ws.WebServiceMessage;
|
||||
import org.springframework.ws.WebServiceMessageFactory;
|
||||
import org.springframework.ws.context.DefaultMessageContext;
|
||||
import org.springframework.ws.context.MessageContext;
|
||||
import org.springframework.ws.server.endpoint.MethodEndpoint;
|
||||
import org.springframework.ws.server.endpoint.annotation.XPathParam;
|
||||
import org.springframework.xml.DocumentBuilderFactoryUtils;
|
||||
import org.springframework.xml.transform.StringResult;
|
||||
import org.springframework.xml.transform.StringSource;
|
||||
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
import static org.easymock.EasyMock.createMock;
|
||||
import static org.easymock.EasyMock.expect;
|
||||
import static org.easymock.EasyMock.replay;
|
||||
import static org.easymock.EasyMock.verify;
|
||||
|
||||
@Deprecated
|
||||
public class XPathParamAnnotationMethodEndpointAdapterTest {
|
||||
|
||||
private static final String CONTENTS = "<root><child><text>text</text><number>42.0</number></child></root>";
|
||||
|
||||
private XPathParamAnnotationMethodEndpointAdapter adapter;
|
||||
|
||||
private boolean supportedTypesInvoked = false;
|
||||
|
||||
private boolean supportedSourceInvoked;
|
||||
|
||||
private boolean namespacesInvoked;
|
||||
|
||||
@BeforeEach
|
||||
public void setUp() throws Exception {
|
||||
|
||||
this.adapter = new XPathParamAnnotationMethodEndpointAdapter();
|
||||
this.adapter.afterPropertiesSet();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testUnsupportedInvalidParam() throws NoSuchMethodException {
|
||||
|
||||
MethodEndpoint endpoint = new MethodEndpoint(this, "unsupportedInvalidParamType", Integer.TYPE);
|
||||
|
||||
assertThat(this.adapter.supports(endpoint)).isFalse();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testUnsupportedInvalidReturnType() throws NoSuchMethodException {
|
||||
|
||||
MethodEndpoint endpoint = new MethodEndpoint(this, "unsupportedInvalidReturnType", String.class);
|
||||
assertThat(this.adapter.supports(endpoint)).isFalse();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testUnsupportedInvalidParams() throws NoSuchMethodException {
|
||||
|
||||
MethodEndpoint endpoint = new MethodEndpoint(this, "unsupportedInvalidParams", String.class, String.class);
|
||||
assertThat(this.adapter.supports(endpoint)).isFalse();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testSupportedTypes() throws NoSuchMethodException {
|
||||
|
||||
MethodEndpoint endpoint = new MethodEndpoint(this, "supportedTypes", Boolean.TYPE, Double.TYPE, Node.class,
|
||||
NodeList.class, String.class);
|
||||
assertThat(this.adapter.supports(endpoint)).isTrue();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testSupportsStringSource() throws NoSuchMethodException {
|
||||
|
||||
MethodEndpoint endpoint = new MethodEndpoint(this, "supportedStringSource", String.class);
|
||||
assertThat(this.adapter.supports(endpoint)).isTrue();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testSupportsSource() throws NoSuchMethodException {
|
||||
|
||||
MethodEndpoint endpoint = new MethodEndpoint(this, "supportedSource", String.class);
|
||||
assertThat(this.adapter.supports(endpoint)).isTrue();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testSupportsVoid() throws NoSuchMethodException {
|
||||
|
||||
MethodEndpoint endpoint = new MethodEndpoint(this, "supportedVoid", String.class);
|
||||
assertThat(this.adapter.supports(endpoint)).isTrue();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testInvokeTypes() throws Exception {
|
||||
|
||||
WebServiceMessage messageMock = createMock(WebServiceMessage.class);
|
||||
expect(messageMock.getPayloadSource()).andReturn(new StringSource(CONTENTS));
|
||||
WebServiceMessageFactory factoryMock = createMock(WebServiceMessageFactory.class);
|
||||
replay(messageMock, factoryMock);
|
||||
|
||||
MessageContext messageContext = new DefaultMessageContext(messageMock, factoryMock);
|
||||
MethodEndpoint endpoint = new MethodEndpoint(this, "supportedTypes", Boolean.TYPE, Double.TYPE, Node.class,
|
||||
NodeList.class, String.class);
|
||||
this.adapter.invoke(messageContext, endpoint);
|
||||
|
||||
assertThat(this.supportedTypesInvoked).isTrue();
|
||||
|
||||
verify(messageMock, factoryMock);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testInvokeSource() throws Exception {
|
||||
|
||||
WebServiceMessage requestMock = createMock(WebServiceMessage.class);
|
||||
WebServiceMessage responseMock = createMock(WebServiceMessage.class);
|
||||
expect(requestMock.getPayloadSource()).andReturn(new StringSource(CONTENTS));
|
||||
expect(responseMock.getPayloadResult()).andReturn(new StringResult());
|
||||
WebServiceMessageFactory factoryMock = createMock(WebServiceMessageFactory.class);
|
||||
expect(factoryMock.createWebServiceMessage()).andReturn(responseMock);
|
||||
replay(requestMock, responseMock, factoryMock);
|
||||
|
||||
MessageContext messageContext = new DefaultMessageContext(requestMock, factoryMock);
|
||||
MethodEndpoint endpoint = new MethodEndpoint(this, "supportedSource", String.class);
|
||||
this.adapter.invoke(messageContext, endpoint);
|
||||
|
||||
assertThat(this.supportedSourceInvoked).isTrue();
|
||||
|
||||
verify(requestMock, responseMock, factoryMock);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testInvokeVoidDom() throws Exception {
|
||||
|
||||
DocumentBuilderFactory documentBuilderFactory = DocumentBuilderFactoryUtils.newInstance();
|
||||
DocumentBuilder documentBuilder = documentBuilderFactory.newDocumentBuilder();
|
||||
Document document = documentBuilder.newDocument();
|
||||
|
||||
String rootNamespace = "http://rootnamespace";
|
||||
Element rootElement = document.createElementNS(rootNamespace, "root");
|
||||
document.appendChild(rootElement);
|
||||
String childNamespace = "http://childnamespace";
|
||||
Element first = document.createElementNS(childNamespace, "child");
|
||||
rootElement.appendChild(first);
|
||||
Text text = document.createTextNode("value");
|
||||
first.appendChild(text);
|
||||
Element second = document.createElementNS(rootNamespace, "other-child");
|
||||
rootElement.appendChild(second);
|
||||
text = document.createTextNode("other-value");
|
||||
second.appendChild(text);
|
||||
|
||||
WebServiceMessage requestMock = createMock(WebServiceMessage.class);
|
||||
expect(requestMock.getPayloadSource()).andReturn(new DOMSource(first));
|
||||
WebServiceMessageFactory factoryMock = createMock(WebServiceMessageFactory.class);
|
||||
|
||||
replay(requestMock, factoryMock);
|
||||
|
||||
Map<String, String> namespaces = new HashMap<>();
|
||||
namespaces.put("root", rootNamespace);
|
||||
namespaces.put("child", childNamespace);
|
||||
this.adapter.setNamespaces(namespaces);
|
||||
|
||||
MessageContext messageContext = new DefaultMessageContext(requestMock, factoryMock);
|
||||
MethodEndpoint endpoint = new MethodEndpoint(this, "namespaces", Node.class);
|
||||
this.adapter.invoke(messageContext, endpoint);
|
||||
|
||||
assertThat(this.namespacesInvoked).isTrue();
|
||||
}
|
||||
|
||||
public void supportedVoid(@XPathParam("/") String param1) {
|
||||
}
|
||||
|
||||
public Source supportedSource(@XPathParam("/") String param1) {
|
||||
|
||||
this.supportedSourceInvoked = true;
|
||||
return new StringSource("<response/>");
|
||||
}
|
||||
|
||||
public StringSource supportedStringSource(@XPathParam("/") String param1) {
|
||||
return null;
|
||||
}
|
||||
|
||||
public void supportedTypes(@XPathParam("/root/child") boolean param1,
|
||||
@XPathParam("/root/child/number") double param2, @XPathParam("/root/child") Node param3,
|
||||
@XPathParam("/root/*") NodeList param4, @XPathParam("/root/child/text") String param5) {
|
||||
|
||||
this.supportedTypesInvoked = true;
|
||||
|
||||
assertThat(param1).isTrue();
|
||||
assertThat(param2).isEqualTo(42D);
|
||||
assertThat(param3.getLocalName()).isEqualTo("child");
|
||||
assertThat(param4.getLength()).isEqualTo(1);
|
||||
assertThat(param4.item(0).getLocalName()).isEqualTo("child");
|
||||
assertThat(param5).isEqualTo("text");
|
||||
}
|
||||
|
||||
public void unsupportedInvalidParams(@XPathParam("/") String param1, String param2) {
|
||||
|
||||
}
|
||||
|
||||
public String unsupportedInvalidReturnType(@XPathParam("/") String param1) {
|
||||
return null;
|
||||
}
|
||||
|
||||
public void unsupportedInvalidParamType(@XPathParam("/") int param1) {
|
||||
}
|
||||
|
||||
public void namespaces(@XPathParam(".") Node param) {
|
||||
|
||||
this.namespacesInvoked = true;
|
||||
assertThat(param.getLocalName()).isEqualTo("child");
|
||||
}
|
||||
|
||||
}
|
||||
@@ -1,227 +0,0 @@
|
||||
/*
|
||||
* Copyright 2005-2025 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
|
||||
*
|
||||
* https://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.server.endpoint;
|
||||
|
||||
import java.util.Iterator;
|
||||
|
||||
import javax.xml.namespace.QName;
|
||||
import javax.xml.transform.Result;
|
||||
import javax.xml.transform.Source;
|
||||
|
||||
import jakarta.xml.soap.Detail;
|
||||
import jakarta.xml.soap.DetailEntry;
|
||||
import jakarta.xml.soap.MessageFactory;
|
||||
import jakarta.xml.soap.SOAPFault;
|
||||
import jakarta.xml.soap.SOAPMessage;
|
||||
import org.junit.jupiter.api.BeforeEach;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
import org.springframework.context.support.ResourceBundleMessageSource;
|
||||
import org.springframework.oxm.Marshaller;
|
||||
import org.springframework.oxm.Unmarshaller;
|
||||
import org.springframework.oxm.XmlMappingException;
|
||||
import org.springframework.validation.Errors;
|
||||
import org.springframework.validation.ValidationUtils;
|
||||
import org.springframework.validation.Validator;
|
||||
import org.springframework.ws.context.DefaultMessageContext;
|
||||
import org.springframework.ws.context.MessageContext;
|
||||
import org.springframework.ws.soap.saaj.SaajSoapMessage;
|
||||
import org.springframework.ws.soap.saaj.SaajSoapMessageFactory;
|
||||
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
import static org.assertj.core.api.Assertions.fail;
|
||||
|
||||
@Deprecated
|
||||
public class FaultCreatingValidatingMarshallingPayloadEndpointTest {
|
||||
|
||||
private MessageContext messageContext;
|
||||
|
||||
private ResourceBundleMessageSource messageSource;
|
||||
|
||||
@BeforeEach
|
||||
public void setUp() throws Exception {
|
||||
|
||||
this.messageSource = new ResourceBundleMessageSource();
|
||||
this.messageSource.setBasename("org.springframework.ws.soap.server.endpoint.messages");
|
||||
MessageFactory messageFactory = MessageFactory.newInstance();
|
||||
SOAPMessage request = messageFactory.createMessage();
|
||||
request.getSOAPBody().addBodyElement(new QName("http://www.springframework.org/spring-ws", "request"));
|
||||
this.messageContext = new DefaultMessageContext(new SaajSoapMessage(request),
|
||||
new SaajSoapMessageFactory(messageFactory));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testValidationIncorrect() throws Exception {
|
||||
|
||||
Person p = new Person("", -1);
|
||||
PersonMarshaller marshaller = new PersonMarshaller(p);
|
||||
|
||||
AbstractFaultCreatingValidatingMarshallingPayloadEndpoint endpoint = new AbstractFaultCreatingValidatingMarshallingPayloadEndpoint() {
|
||||
|
||||
@Override
|
||||
protected Object invokeInternal(Object requestObject) {
|
||||
|
||||
fail("No expected");
|
||||
return null;
|
||||
}
|
||||
};
|
||||
endpoint.setValidator(new PersonValidator());
|
||||
endpoint.setMessageSource(this.messageSource);
|
||||
endpoint.setMarshaller(marshaller);
|
||||
endpoint.setUnmarshaller(marshaller);
|
||||
|
||||
endpoint.invoke(this.messageContext);
|
||||
|
||||
SOAPMessage response = ((SaajSoapMessage) this.messageContext.getResponse()).getSaajMessage();
|
||||
|
||||
assertThat(response.getSOAPBody().hasFault()).isTrue();
|
||||
|
||||
SOAPFault fault = response.getSOAPBody().getFault();
|
||||
|
||||
assertThat(fault.getFaultCodeAsQName())
|
||||
.isEqualTo(new QName("http://schemas.xmlsoap.org/soap/envelope/", "Client"));
|
||||
assertThat(fault.getFaultString()).isEqualTo(endpoint.getFaultStringOrReason());
|
||||
|
||||
Detail detail = fault.getDetail();
|
||||
|
||||
assertThat(detail).isNotNull();
|
||||
|
||||
Iterator<?> iterator = detail.getDetailEntries();
|
||||
|
||||
assertThat(iterator.hasNext()).isTrue();
|
||||
|
||||
DetailEntry detailEntry = (DetailEntry) iterator.next();
|
||||
|
||||
assertThat(detailEntry.getElementQName())
|
||||
.isEqualTo(new QName("http://springframework.org/spring-ws", "ValidationError"));
|
||||
assertThat(detailEntry.getTextContent()).isEqualTo("Name is required");
|
||||
assertThat(iterator.hasNext()).isTrue();
|
||||
|
||||
detailEntry = (DetailEntry) iterator.next();
|
||||
|
||||
assertThat(detailEntry.getElementQName())
|
||||
.isEqualTo(new QName("http://springframework.org/spring-ws", "ValidationError"));
|
||||
assertThat(detailEntry.getTextContent()).isEqualTo("Age Cannot be negative");
|
||||
assertThat(iterator.hasNext()).isFalse();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testValidationCorrect() throws Exception {
|
||||
|
||||
Person p = new Person("John", 42);
|
||||
PersonMarshaller marshaller = new PersonMarshaller(p);
|
||||
AbstractFaultCreatingValidatingMarshallingPayloadEndpoint endpoint = new AbstractFaultCreatingValidatingMarshallingPayloadEndpoint() {
|
||||
|
||||
@Override
|
||||
protected Object invokeInternal(Object requestObject) {
|
||||
return null;
|
||||
}
|
||||
};
|
||||
endpoint.setValidator(new PersonValidator());
|
||||
endpoint.setMessageSource(this.messageSource);
|
||||
endpoint.setMarshaller(marshaller);
|
||||
endpoint.setUnmarshaller(marshaller);
|
||||
|
||||
endpoint.invoke(this.messageContext);
|
||||
|
||||
SOAPMessage response = ((SaajSoapMessage) this.messageContext.getResponse()).getSaajMessage();
|
||||
|
||||
assertThat(response.getSOAPBody().hasFault()).isFalse();
|
||||
}
|
||||
|
||||
private static final class PersonValidator implements Validator {
|
||||
|
||||
@Override
|
||||
public boolean supports(Class<?> clazz) {
|
||||
return Person.class.equals(clazz);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void validate(Object obj, Errors e) {
|
||||
|
||||
ValidationUtils.rejectIfEmpty(e, "name", "name.empty");
|
||||
Person p = (Person) obj;
|
||||
|
||||
if (p.getAge() < 0) {
|
||||
e.rejectValue("age", "age.negativevalue");
|
||||
}
|
||||
else if (p.getAge() > 110) {
|
||||
e.rejectValue("age", "too.darn.old");
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
private static final class Person {
|
||||
|
||||
private String name;
|
||||
|
||||
private int age;
|
||||
|
||||
private Person(String name, int age) {
|
||||
|
||||
this.name = name;
|
||||
this.age = age;
|
||||
}
|
||||
|
||||
public String getName() {
|
||||
return this.name;
|
||||
}
|
||||
|
||||
public void setName(String name) {
|
||||
this.name = name;
|
||||
}
|
||||
|
||||
public int getAge() {
|
||||
return this.age;
|
||||
}
|
||||
|
||||
public void setAge(int age) {
|
||||
this.age = age;
|
||||
}
|
||||
|
||||
public String toString() {
|
||||
return "Person{" + this.name + "," + this.age + "}";
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
private static final class PersonMarshaller implements Unmarshaller, Marshaller {
|
||||
|
||||
private final Person person;
|
||||
|
||||
private PersonMarshaller(Person person) {
|
||||
this.person = person;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Object unmarshal(Source source) throws XmlMappingException {
|
||||
return this.person;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean supports(Class<?> clazz) {
|
||||
return Person.class.equals(clazz);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void marshal(Object graph, Result result) throws XmlMappingException {
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
@@ -1,14 +0,0 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<beans xmlns="http://www.springframework.org/schema/beans"
|
||||
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||
xmlns:sws="http://www.springframework.org/schema/web-services" xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-2.0.xsd
|
||||
|
||||
http://www.springframework.org/schema/web-services http://www.springframework.org/schema/web-services/web-services-1.5.xsd">
|
||||
|
||||
<sws:marshalling-endpoints/>
|
||||
|
||||
<bean id="marshaller" class="org.springframework.ws.config.DummyMarshaller"/>
|
||||
|
||||
</beans>
|
||||
|
||||
|
||||
@@ -1,18 +0,0 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<beans xmlns="http://www.springframework.org/schema/beans"
|
||||
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||
xmlns:sws="http://www.springframework.org/schema/web-services" xsi:schemaLocation="
|
||||
http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-2.0.xsd
|
||||
http://www.springframework.org/schema/web-services http://www.springframework.org/schema/web-services/web-services-1.5.xsd">
|
||||
|
||||
<sws:marshalling-endpoints/>
|
||||
|
||||
<bean id="marshaller" class="org.springframework.ws.config.DummyMarshaller"/>
|
||||
|
||||
<sws:xpath-endpoints>
|
||||
<sws:namespace prefix="sws" uri="http://www.springframework.org/spring-ws"/>
|
||||
</sws:xpath-endpoints>
|
||||
|
||||
</beans>
|
||||
|
||||
|
||||
Reference in New Issue
Block a user