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(String reason, Throwable cause) 

Source Link

Document

Constructs a SOAPException object with the given String as the reason for the exception being thrown and the given Throwable object as an embedded exception.

Usage

From source file:be.fedict.eid.idp.protocol.ws_federation.sts.WSSecuritySoapHandler.java

private void handleOutboundMessage(SOAPMessageContext context) throws SOAPException {
    SOAPMessage soapMessage = context.getMessage();
    SOAPPart soapPart = soapMessage.getSOAPPart();
    SOAPHeader soapHeader = soapMessage.getSOAPHeader();
    if (null == soapHeader) {
        SOAPEnvelope soapEnvelope = soapPart.getEnvelope();
        soapHeader = soapEnvelope.addHeader();
    }//from   ww  w  . j  av  a  2 s  .co m

    WSSecHeader wsSecHeader = new WSSecHeader();
    Element securityElement;
    try {
        securityElement = wsSecHeader.insertSecurityHeader(soapPart);
    } catch (WSSecurityException e) {
        throw new SOAPException("WS-Security error: " + e.getMessage(), e);
    }
    soapHeader.removeChild(securityElement);
    soapHeader.appendChild(securityElement);

    WSSecTimestamp wsSecTimeStamp = new WSSecTimestamp();
    wsSecTimeStamp.build(soapPart, wsSecHeader);
}

From source file:com.centurylink.mdw.hub.servlet.SoapServlet.java

/**
 * Allow version specific factory passed in TODO: allow specifying response
 * headers/*  www . j av a2s .c  o  m*/
 */
protected String createSoapResponse(String soapVersion, String xml) throws SOAPException {
    try {
        SOAPMessage soapMessage = getSoapMessageFactory(soapVersion).createMessage();
        SOAPBody soapBody = soapMessage.getSOAPBody();
        soapBody.addDocument(DomHelper.toDomDocument(xml));
        return DomHelper.toXml(soapMessage.getSOAPPart().getDocumentElement());
    } catch (Exception ex) {
        throw new SOAPException(ex.getMessage(), ex);
    }
}

From source file:com.centurylink.mdw.hub.servlet.SoapServlet.java

protected String createOldStyleSoapResponse(String soapVersion, String xml) throws SOAPException {
    try {//from w w  w .  jav  a  2 s .  c  om
        SOAPMessage soapMessage = getSoapMessageFactory(soapVersion).createMessage();
        SOAPBody soapBody = soapMessage.getSOAPBody();
        soapBody.addDocument(DomHelper.toDomDocument(xml));
        return DomHelper.toXmlNoWhiteSpace(soapMessage.getSOAPPart());
    } catch (Exception ex) {
        throw new SOAPException(ex.getMessage(), ex);
    }
}

From source file:org.apache.axis.attachments.AttachmentPart.java

/**
 * Returns the number of bytes in this <CODE>
 * AttachmentPart</CODE> object./*from   ww w . j a va 2s  . c  om*/
 * @return the size of this <CODE>AttachmentPart</CODE> object
 *     in bytes or -1 if the size cannot be determined
 * @throws  SOAPException  if the content of this
 *     attachment is corrupted of if there was an exception
 *     while trying to determine the size.
 */
public int getSize() throws SOAPException {
    if (datahandler == null) {
        return 0;
    }
    ByteArrayOutputStream bout = new ByteArrayOutputStream();
    try {
        datahandler.writeTo(bout);
    } catch (java.io.IOException ex) {
        log.error(Messages.getMessage("javaIOException00"), ex);
        throw new SOAPException(Messages.getMessage("javaIOException01", ex.getMessage()), ex);
    }
    return bout.size();
}

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

/**
 * Returns the content of the SOAPEnvelope as a JAXP <CODE>
 * Source</CODE> object./*from  www. java2s.  c  om*/
 * @return the content as a <CODE>
 *     javax.xml.transform.Source</CODE> object
 * @throws  SOAPException  if the implementation cannot
 *     convert the specified <CODE>Source</CODE> object
 * @see #setContent(javax.xml.transform.Source) setContent(javax.xml.transform.Source)
 */
public Source getContent() throws SOAPException {
    if (contentSource == null) {
        switch (currentForm) {
        case FORM_STRING:
            String s = (String) currentMessage;
            contentSource = new StreamSource(new StringReader(s));
            break;
        case FORM_INPUTSTREAM:
            contentSource = new StreamSource((InputStream) currentMessage);
            break;
        case FORM_SOAPENVELOPE:
            SOAPEnvelope se = (SOAPEnvelope) currentMessage;
            try {
                contentSource = new DOMSource(se.getAsDocument());
            } catch (Exception e) {
                throw new SOAPException(Messages.getMessage("errorGetDocFromSOAPEnvelope"), e);
            }
            break;
        case FORM_OPTIMIZED:
            try {
                ByteArrayInputStream baos = new ByteArrayInputStream(
                        ((ByteArray) currentMessage).toByteArray());
                contentSource = new StreamSource(baos);
            } catch (IOException e) {
                throw new SOAPException(Messages.getMessage("errorGetDocFromSOAPEnvelope"), e);
            }
            break;
        case FORM_BYTES:
            byte[] bytes = (byte[]) currentMessage;
            contentSource = new StreamSource(new ByteArrayInputStream(bytes));
            break;
        case FORM_BODYINSTREAM:
            contentSource = new StreamSource((InputStream) currentMessage);
            break;
        }
    }
    return contentSource;
}