Start line:  
End line:  

Snippet Preview

Snippet HTML Code

Stack Overflow Questions
   * Copyright 2005-2010 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
  * 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.
Abstract base class for endpoints that handle the message payload as dom4j elements. Offers the message payload as a dom4j Element, and allows subclasses to create a response by returning an Element.

An AbstractDom4JPayloadEndpoint only accept one payload element. Multiple payload elements are not in accordance with WS-I.

as of Spring Web Services 2.0, in favor of annotated endpoints
Arjen Poutsma
See also:
 public abstract class AbstractDom4jPayloadEndpoint extends TransformerObjectSupport implements PayloadEndpoint {
     private boolean alwaysTransform = false;

Set if the request javax.xml.transform.Source should always be transformed into a new

Default is false, which is faster.

     public void setAlwaysTransform(boolean alwaysTransform) {
         this. = alwaysTransform;
     public final Source invoke(Source requestthrows Exception {
         Element requestElement = null;
         if (request != null) {
             DocumentResult dom4jResult = new DocumentResult();
             requestElement = dom4jResult.getDocument().getRootElement();
         Document responseDocument = DocumentHelper.createDocument();
         Element responseElement = invokeInternal(requestElementresponseDocument);
         return responseElement != null ? new DocumentSource(responseElement) : null;

Returns the payload element of the given source.

Default implementation checks whether the source is a javax.xml.transform.dom.DOMSource, and uses a org.jdom.input.DOMBuilder to create a JDOM org.jdom.Element. In all other cases, or when alwaysTransform is true, the source is transformed into a org.jdom.transform.JDOMResult, which is more expensive. If the passed source is null, null is returned.

source the source to return the root element of; can be null
the document element
javax.xml.transform.TransformerException in case of errors
     protected Element getDocumentElement(Source sourcethrows TransformerException {
         if (source == null) {
             return null;
         if (! && source instanceof DOMSource) {
             Node node = ((DOMSourcesource).getNode();
             if (node.getNodeType() == .) {
                 DOMReader domReader = new DOMReader();
                 Document document =;
                 return document.getRootElement();
         // we have no other option than to transform
         DocumentResult dom4jResult = new DocumentResult();
        return dom4jResult.getDocument().getRootElement();

Template method. Subclasses must implement this. Offers the request payload as a dom4j Element, and allows subclasses to return a response Element.

The given dom4j Document is to be used for constructing a response element, by using addElement.

requestElement the contents of the SOAP message as dom4j elements
responseDocument a dom4j document to be used for constructing a response
the response element. Can be null to specify no response.
    protected abstract Element invokeInternal(Element requestElementDocument responseDocumentthrows Exception;
New to GrepCode? Check out our FAQ X