Example usage for javax.xml.soap SOAPException SOAPException

List of usage examples for javax.xml.soap SOAPException SOAPException

Introduction

In this page you can find the example usage for javax.xml.soap SOAPException SOAPException.

Prototype

public SOAPException(Throwable cause) 

Source Link

Document

Constructs a SOAPException object initialized with the given Throwable object.

Usage

From source file:org.apache.axis.message.SOAPBody.java

public void setParentElement(SOAPElement parent) throws SOAPException {
    if (parent == null) {
        throw new IllegalArgumentException(Messages.getMessage("nullParent00"));
    }/*from  w w w . j a  v  a 2  s. c  o m*/
    try {
        SOAPEnvelope env = (SOAPEnvelope) parent;
        super.setParentElement(env);
        setEnvelope(env);
    } catch (Throwable t) {
        throw new SOAPException(t);
    }
}

From source file:org.apache.axis.message.SOAPEnvelope.java

/**
 * Add a soap body if one does not exist
 * @return/*from www . ja v  a 2 s  .co m*/
 * @throws SOAPException
 */
public javax.xml.soap.SOAPBody addBody() throws SOAPException {
    if (body == null) {
        body = new SOAPBody(this, soapConstants);
        _isDirty = true;
        body.setOwnerDocument(getOwnerDocument());
        return body;
    } else {
        throw new SOAPException(Messages.getMessage("bodyPresent"));
    }
}

From source file:org.apache.axis.message.SOAPEnvelope.java

/**
 * Add a soap header if one does not exist
 * @return//  www.  j  av  a  2  s . c  o  m
 * @throws SOAPException
 */
public javax.xml.soap.SOAPHeader addHeader() throws SOAPException {
    if (header == null) {
        header = new SOAPHeader(this, soapConstants);
        header.setOwnerDocument(getOwnerDocument());
        return header;
    } else {
        throw new SOAPException(Messages.getMessage("headerPresent"));
    }
}

From source file:org.apache.axis.message.SOAPHeader.java

public void setParentElement(SOAPElement parent) throws SOAPException {
    if (parent == null) {
        throw new IllegalArgumentException(Messages.getMessage("nullParent00"));
    }/*from w  w w.jav a2 s. c  o m*/
    try {
        // cast to force exception if wrong type
        SOAPEnvelope env = (SOAPEnvelope) parent;
        super.setParentElement(env);
        setEnvelope(env);
    } catch (Throwable t) {
        throw new SOAPException(t);
    }
}

From source file:org.apache.axis.message.SOAPHeader.java

public void addChild(MessageElement element) throws SOAPException {
    if (!(element instanceof SOAPHeaderElement)) {
        throw new SOAPException(Messages.getMessage("badSOAPHeader00"));
    }//from   w w  w.  j  a  va 2s .c  o  m
    element.setEnvelope(getEnvelope());
    super.addChild(element);
}

From source file:org.apache.axis.message.SOAPHeader.java

public SOAPElement addChildElement(SOAPElement element) throws SOAPException {
    if (!(element instanceof SOAPHeaderElement)) {
        throw new SOAPException(Messages.getMessage("badSOAPHeader00"));
    }//from  ww  w . j  a v  a2s.c o  m
    SOAPElement child = super.addChildElement(element);
    setDirty();
    return child;
}

From source file:org.apache.axis.SOAPPart.java

/**
 * Sets the content of the <CODE>SOAPEnvelope</CODE> object
 * with the data from the given <CODE>Source</CODE> object.
 * @param   source javax.xml.transform.Source</CODE> object with the data to
 *     be set// w  ww . j  a  v  a  2  s .  c  om
 * @throws  SOAPException if there is a problem in
 *     setting the source
 * @see #getContent() getContent()
 */
public void setContent(Source source) throws SOAPException {
    if (source == null)
        throw new SOAPException(Messages.getMessage("illegalArgumentException00"));

    // override the checks in HandlerChainImpl for JAXRPCHandler kludge
    MessageContext ctx = getMessage().getMessageContext();
    if (ctx != null) {
        ctx.setProperty(org.apache.axis.SOAPPart.ALLOW_FORM_OPTIMIZATION, Boolean.TRUE);
    }

    contentSource = source;
    InputSource in = org.apache.axis.utils.XMLUtils.sourceToInputSource(contentSource);
    InputStream is = in.getByteStream();
    if (is != null) {
        setCurrentMessage(is, FORM_INPUTSTREAM);
    } else {
        Reader r = in.getCharacterStream();
        if (r == null) {
            throw new SOAPException(Messages.getMessage("noCharacterOrByteStream"));
        }
        BufferedReader br = new BufferedReader(r);
        String line = null;
        StringBuffer sb = new StringBuffer();
        try {
            while ((line = br.readLine()) != null) {
                sb.append(line);
            }
        } catch (IOException e) {
            throw new SOAPException(Messages.getMessage("couldNotReadFromCharStream"), e);
        }
        setCurrentMessage(sb.toString(), FORM_STRING);
    }
}

From source file:org.apache.axis.SOAPPart.java

/**
 * Gets the <CODE>SOAPEnvelope</CODE> object associated with
 * this <CODE>SOAPPart</CODE> object. Once the SOAP envelope is
 * obtained, it can be used to get its contents.
 * @return the <CODE>SOAPEnvelope</CODE> object for this <CODE>
 *     SOAPPart</CODE> object//from  w w  w  .j  a v  a2 s. c  o m
 * @throws  SOAPException if there is a SOAP error
 */
public javax.xml.soap.SOAPEnvelope getEnvelope() throws SOAPException {
    try {
        return getAsSOAPEnvelope();
    } catch (AxisFault af) {
        throw new SOAPException(af);
    }
}

From source file:org.apache.axis2.saaj.SOAPPartImpl.java

/**
 * Construct a SOAP part from the given input stream.
 * The content type (as provided by the MIME headers) must be SOAP 1.1, SOAP 1.2
 * or XOP (MTOM). MIME packages (multipart/related) are not supported and should be
 * parsed using {@link SOAPMessageImpl#SOAPMessageImpl(InputStream, MimeHeaders).
 * <p>//from   w w w. jav  a  2  s. c  o  m
 * If the content type is XOP, xop:Include elements will only be replaced if
 * the <code>attachments</code> parameter is not null.
 *
 * @see MessageFactoryImpl#setProcessMTOM(boolean)
 * 
 * @param parentSoapMsg the parent SOAP message
 * @param inputStream the input stream with the content of the SOAP part
 * @param mimeHeaders the MIME headers
 * @param attachments the set of attachments to be used to substitute xop:Include elements
 * @throws SOAPException
 */
public SOAPPartImpl(SOAPMessageImpl parentSoapMsg, InputStream inputStream, MimeHeaders mimeHeaders,
        Attachments attachments) throws SOAPException {
    ContentType contentType = null;
    if (mimeHeaders == null) {
        //TODO : read string from constants
        this.mimeHeaders = new MimeHeaders();
        this.mimeHeaders.addHeader("Content-ID", IDGenerator.generateID());
        this.mimeHeaders.addHeader("content-type", HTTPConstants.MEDIA_TYPE_APPLICATION_SOAP_XML);
    } else {
        String contentTypes[] = mimeHeaders.getHeader(HTTPConstants.CONTENT_TYPE);
        if (contentTypes != null && contentTypes.length > 0) {
            try {
                contentType = new ContentType(contentTypes[0]);
            } catch (ParseException ex) {
                throw new SOAPException("Invalid content type '" + contentTypes[0] + "'");
            }
        }
        this.mimeHeaders = SAAJUtil.copyMimeHeaders(mimeHeaders);
    }

    soapMessage = parentSoapMsg;

    String charset;
    boolean isMTOM;
    String soapEnvelopeNamespaceURI;
    SOAPFactory soapFactory;
    if (contentType == null) {
        charset = null;
        isMTOM = false;
        soapFactory = new SOAP11Factory();
        soapEnvelopeNamespaceURI = null;
    } else {
        String baseType = contentType.getBaseType().toLowerCase();
        String soapContentType;
        if (baseType.equals(MTOMConstants.MTOM_TYPE)) {
            isMTOM = true;
            String typeParam = contentType.getParameter("type");
            if (typeParam == null) {
                throw new SOAPException("Missing 'type' parameter in XOP content type");
            } else {
                soapContentType = typeParam.toLowerCase();
            }
        } else {
            isMTOM = false;
            soapContentType = baseType;
        }

        if (soapContentType.equals(HTTPConstants.MEDIA_TYPE_TEXT_XML)) {
            soapEnvelopeNamespaceURI = SOAP11Constants.SOAP_ENVELOPE_NAMESPACE_URI;
            soapFactory = new SOAP11Factory();
        } else if (soapContentType.equals(HTTPConstants.MEDIA_TYPE_APPLICATION_SOAP_XML)) {
            soapEnvelopeNamespaceURI = SOAP12Constants.SOAP_ENVELOPE_NAMESPACE_URI;
            soapFactory = new SOAP12Factory();
        } else {
            throw new SOAPException("Unrecognized content type '" + soapContentType + "'");
        }

        charset = contentType.getParameter("charset");
    }

    XMLStreamReader streamReader;
    try {
        if (charset != null) {
            streamReader = StAXUtils.createXMLStreamReader(inputStream, charset);
        } else {
            streamReader = StAXUtils.createXMLStreamReader(inputStream);
        }
    } catch (XMLStreamException e) {
        throw new SOAPException(e);
    }

    StAXSOAPModelBuilder builder;
    if (isMTOM && attachments != null) {
        builder = new MTOMStAXSOAPModelBuilder(streamReader, soapFactory, attachments,
                soapEnvelopeNamespaceURI);
    } else {
        builder = new StAXSOAPModelBuilder(streamReader, soapFactory, soapEnvelopeNamespaceURI);
    }

    try {
        org.apache.axiom.soap.SOAPEnvelope soapEnvelope = builder.getSOAPEnvelope();
        envelope = new SOAPEnvelopeImpl((org.apache.axiom.soap.impl.dom.SOAPEnvelopeImpl) soapEnvelope);
        envelope.element.build();
        this.document = envelope.getOwnerDocument();
        envelope.setSOAPPartParent(this);
    } catch (Exception e) {
        throw new SOAPException(e);
    }
}

From source file:org.apache.axis2.saaj.SOAPPartImpl.java

public void setContent(Source source) throws SOAPException {
    try {//from w  w  w .  j ava  2 s .c  o  m
        ByteArrayOutputStream baos = new ByteArrayOutputStream();

        XMLInputFactory inputFactory = XMLInputFactory.newInstance();
        XMLStreamReader reader;

        if (source instanceof StreamSource) {
            reader = inputFactory.createXMLStreamReader(source);
        } else {
            Result result = new StreamResult(baos);
            Transformer xformer = TransformerFactory.newInstance().newTransformer();
            xformer.transform(source, result);
            InputStream is = new ByteArrayInputStream(baos.toByteArray());
            reader = inputFactory.createXMLStreamReader(is);
        }

        StAXSOAPModelBuilder builder1 = null;
        if (this.envelope.element.getOMFactory() instanceof SOAP11Factory) {
            builder1 = new StAXSOAPModelBuilder(reader, (SOAP11Factory) this.envelope.element.getOMFactory(),
                    null);
        } else if (this.envelope.element.getOMFactory() instanceof SOAP12Factory) {
            builder1 = new StAXSOAPModelBuilder(reader, (SOAP12Factory) this.envelope.element.getOMFactory(),
                    null);
        }

        org.apache.axiom.soap.SOAPEnvelope soapEnvelope = builder1.getSOAPEnvelope();
        envelope = new SOAPEnvelopeImpl((org.apache.axiom.soap.impl.dom.SOAPEnvelopeImpl) soapEnvelope);
        envelope.element.build();
        this.document = envelope.getOwnerDocument();
        envelope.setSOAPPartParent(this);
    } catch (TransformerFactoryConfigurationError e) {
        log.error(e);
        throw new SOAPException(e);
    } catch (Exception e) {
        log.error(e);
        throw new SOAPException(e);
    }
}