Start line:  
End line:  

Snippet Preview

Snippet HTML Code

Stack Overflow Questions
  /*
   * Copyright 2005-2012 the original author or authors.
   *
   * Licensed under the Apache License, Version 2.0 (the "License");
   * you may not use this file except in compliance with the License.
   * You may obtain a copy of the License at
   *
   *     http://www.apache.org/licenses/LICENSE-2.0
   *
  * Unless required by applicable law or agreed to in writing, software
  * distributed under the License is distributed on an "AS IS" BASIS,
  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  * See the License for the specific language governing permissions and
  * limitations under the License.
  */
 
 package org.springframework.ws.soap.axiom;
 
 
 
AXIOM-specific implementation of the org.springframework.ws.soap.SoapMessage interface. Created via the AxiomSoapMessageFactory, wraps a org.apache.axiom.soap.SOAPMessage.

Author(s):
Arjen Poutsma
Since:
1.0.0
See also:
org.apache.axiom.soap.SOAPMessage
 
 public class AxiomSoapMessage extends AbstractSoapMessage implements StreamingWebServiceMessage {
 
     private static final String EMPTY_SOAP_ACTION = "\"\"";
 
     private SOAPMessage axiomMessage;
 
     private final SOAPFactory axiomFactory;
 
     private final Attachments attachments;
 
     private final boolean payloadCaching;
 
     private AxiomSoapEnvelope envelope;
 
     private String soapAction;
 
     private final boolean langAttributeOnSoap11FaultString;
 
     private OMOutputFormat outputFormat;

    
Create a new, empty AxiomSoapMessage.

Parameters:
soapFactory the AXIOM SOAPFactory
 
     public AxiomSoapMessage(SOAPFactory soapFactory) {
         this(soapFactorytruetrue);
     }

    
Create a new, empty AxiomSoapMessage.

Parameters:
soapFactory the AXIOM SOAPFactory
 
     public AxiomSoapMessage(SOAPFactory soapFactoryboolean payloadCachingboolean langAttributeOnSoap11FaultString) {
         SOAPEnvelope soapEnvelope = soapFactory.getDefaultEnvelope();
          = soapFactory;
          = .createSOAPMessage(soapEnvelope.getBuilder());
        .setSOAPEnvelope(soapEnvelope);
         = new Attachments();
        this. = payloadCaching;
        this. = langAttributeOnSoap11FaultString;
         = ;
    }

    
Create a new AxiomSoapMessage based on the given AXIOM SOAPMessage.

Parameters:
soapMessage the AXIOM SOAPMessage
soapAction the value of the SOAP Action header
payloadCaching whether the contents of the SOAP body should be cached or not
    public AxiomSoapMessage(SOAPMessage soapMessage,
                            String soapAction,
                            boolean payloadCaching,
                            boolean langAttributeOnSoap11FaultString) {
        this(soapMessagenew Attachments(), soapActionpayloadCachinglangAttributeOnSoap11FaultString);
    }

    
Create a new AxiomSoapMessage based on the given AXIOM SOAPMessage and attachments.

Parameters:
soapMessage the AXIOM SOAPMessage
attachments the attachments
soapAction the value of the SOAP Action header
payloadCaching whether the contents of the SOAP body should be cached or not
    public AxiomSoapMessage(SOAPMessage soapMessage,
                            Attachments attachments,
                            String soapAction,
                            boolean payloadCaching,
                            boolean langAttributeOnSoap11FaultString) {
        Assert.notNull(soapMessage"'soapMessage' must not be null");
        Assert.notNull(attachments"'attachments' must not be null");
         = soapMessage;
         = (SOAPFactorysoapMessage.getSOAPEnvelope().getOMFactory();
        this. = attachments;
        if (!StringUtils.hasLength(soapAction)) {
            soapAction = ;
        }
        this. = soapAction;
        this. = payloadCaching;
        this. = langAttributeOnSoap11FaultString;
    }

    
Return the AXIOM SOAPMessage that this AxiomSoapMessage is based on.
    public final SOAPMessage getAxiomMessage() {
        return ;
    }

    
Sets the AXIOM SOAPMessage that this AxiomSoapMessage is based on.

Calling this method also clears the SOAP Action property.

    public final void setAxiomMessage(SOAPMessage axiomMessage) {
        Assert.notNull(axiomMessage"'axiomMessage' must not be null");
        this. = axiomMessage;
        this. = null;
        this. = ;
    }

    
Sets the org.apache.axiom.om.OMOutputFormat to be used when writing the message.

    public void setOutputFormat(OMOutputFormat outputFormat) {
        this. = outputFormat;
    }
    public void setStreamingPayload(StreamingPayload payload) {
        AxiomSoapBody soapBody = (AxiomSoapBodygetSoapBody();
        soapBody.setStreamingPayload(payload);
    }
    public SoapEnvelope getEnvelope() {
        if ( == null) {
            try {
                        );
            }
            catch (SOAPProcessingException ex) {
                throw new AxiomSoapEnvelopeException(ex);
            }
        }
        return ;
    }
    public String getSoapAction() {
        return ;
    }
    public void setSoapAction(String soapAction) {
        soapAction = SoapUtils.escapeAction(soapAction);
        this. = soapAction;
    }
    public Document getDocument() {
        return AxiomUtils.toDocument(.getSOAPEnvelope());
    }
    public void setDocument(Document document) {
        // save the Soap Action
        String soapAction = getSoapAction();
        SOAPEnvelope envelope = AxiomUtils.toEnvelope(document);
        SOAPMessage newMessage = .createSOAPMessage();
        newMessage.setSOAPEnvelope(envelope);
        // replace the Axiom message
        setAxiomMessage(newMessage);
        // restore the Soap Action
        setSoapAction(soapAction);
    }
    public boolean isXopPackage() {
        try {
        }
        catch (OMException ex) {
            return false;
        }
        catch (NullPointerException ex) {
            // gotta love Axis2
            return false;
        }
    }
    public boolean convertToXopPackage() {
        return false;
    }
    public Attachment getAttachment(String contentId) {
        Assert.hasLength(contentId"contentId must not be empty");
        if (contentId.startsWith("<") && contentId.endsWith(">")) {
            contentId = contentId.substring(1, contentId.length() - 1);
        }
        DataHandler dataHandler = .getDataHandler(contentId);
        return dataHandler != null ? new AxiomAttachment(contentIddataHandler) : null;
    }
    public Iterator<AttachmentgetAttachments() {
        return new AxiomAttachmentIterator();
    }
    public Attachment addAttachment(String contentIdDataHandler dataHandler) {
        Assert.hasLength(contentId"contentId must not be empty");
        Assert.notNull(dataHandler"dataHandler must not be null");
        .addDataHandler(contentIddataHandler);
        return new AxiomAttachment(contentIddataHandler);
    }
    public void writeTo(OutputStream outputStreamthrows IOException {
        try {
            OMOutputFormat outputFormat = getOutputFormat();
            if (outputStream instanceof TransportOutputStream) {
                TransportOutputStream transportOutputStream = (TransportOutputStreamoutputStream;
                String contentType = outputFormat.getContentType();
                if (!(outputFormat.isDoingSWA() || outputFormat.isOptimized())) {
                    String charsetEncoding = .getCharsetEncoding();
                    contentType += "; charset=" + charsetEncoding;
                }
                SoapVersion version = getVersion();
                if (. == version) {
                    transportOutputStream.addHeader(.);
                    transportOutputStream.addHeader(.version.getContentType());
                }
                else if (. == version) {
                    contentType += "; action=" + ;
                    transportOutputStream.addHeader(.version.getContentType());
                }
                transportOutputStream.addHeader(.contentType);
            }
            if (!(outputFormat.isOptimized()) & outputFormat.isDoingSWA()) {
                writeSwAMessage(outputStreamoutputFormat);
            }
            else {
                if () {
                    .serialize(outputStreamoutputFormat);
                }
                else {
                    .serializeAndConsume(outputStreamoutputFormat);
                }
            }
            outputStream.flush();
        }
        catch (XMLStreamException ex) {
            throw new AxiomSoapMessageException("Could not write message to OutputStream: " + ex.getMessage(), ex);
        }
        catch (OMException ex) {
            throw new AxiomSoapMessageException("Could not write message to OutputStream: " + ex.getMessage(), ex);
        }
    }
    private OMOutputFormat getOutputFormat() {
        if ( != null) {
            return ;
        }
        else {
            String charsetEncoding = .getCharsetEncoding();
            OMOutputFormat outputFormat = new OMOutputFormat();
            outputFormat.setCharSetEncoding(charsetEncoding);
            outputFormat.setSOAP11(getVersion() == .);
            if (isXopPackage()) {
                outputFormat.setDoOptimize(true);
            }
            else if (!.getContentIDSet().isEmpty()) {
                outputFormat.setDoingSWA(true);
            }
            return outputFormat;
        }
    }
    private void writeSwAMessage(OutputStream outputStreamOMOutputFormat format)
            throws XMLStreamExceptionUnsupportedEncodingException {
        StringWriter writer = new StringWriter();
        SOAPEnvelope envelope = .getSOAPEnvelope();
        if () {
            envelope.serialize(writerformat);
        }
        else {
            envelope.serializeAndConsume(writerformat);
        }
        MIMEOutputUtils.writeSOAPWithAttachmentsMessage(writeroutputStreamformat);
    }
    public String toString() {
        StringBuilder builder = new StringBuilder("AxiomSoapMessage");
        if () {
            try {
                SOAPEnvelope envelope = .getSOAPEnvelope();
                if (envelope != null) {
                    SOAPBody body = envelope.getBody();
                    if (body != null) {
                        OMElement bodyElement = body.getFirstElement();
                        if (bodyElement != null) {
                            builder.append(' ');
                            builder.append(bodyElement.getQName());
                        }
                    }
                }
            }
            catch (OMException ex) {
                // ignore
            }
        }
        return builder.toString();
    }
    private class AxiomAttachmentIterator implements Iterator<Attachment> {
        private final Iterator<Stringiterator;
        @SuppressWarnings("unchecked")
        private AxiomAttachmentIterator() {
             = .getContentIDSet().iterator();
        }
        public boolean hasNext() {
            return .hasNext();
        }
        public Attachment next() {
            String contentId = .next();
            DataHandler dataHandler = .getDataHandler(contentId);
            return new AxiomAttachment(contentIddataHandler);
        }
        public void remove() {
            .remove();
        }
    }
New to GrepCode? Check out our FAQ X