Example usage for javax.xml.soap SOAPBody detachNode

List of usage examples for javax.xml.soap SOAPBody detachNode

Introduction

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

Prototype

public void detachNode();

Source Link

Document

Removes this Node object from the tree.

Usage

From source file:org.apache.axis2.jaxws.message.util.impl.SAAJConverterImpl.java

public SOAPEnvelope toSAAJ(org.apache.axiom.soap.SOAPEnvelope omEnvelope) throws WebServiceException {
    if (log.isDebugEnabled()) {
        log.debug("Converting OM SOAPEnvelope to SAAJ SOAPEnvelope");
        log.debug("The conversion occurs due to " + JavaUtils.stackToString());
    }//from  w w w  . j ava2  s  . c om

    SOAPEnvelope soapEnvelope = null;
    try {
        // Build the default envelope
        OMNamespace ns = omEnvelope.getNamespace();
        MessageFactory mf = createMessageFactory(ns.getNamespaceURI());
        SOAPMessage sm = mf.createMessage();
        SOAPPart sp = sm.getSOAPPart();
        soapEnvelope = sp.getEnvelope();

        // The getSOAPEnvelope() call creates a default SOAPEnvelope with a SOAPHeader and SOAPBody.
        // The SOAPHeader and SOAPBody are removed (they will be added back in if they are present in the
        // OMEnvelope).
        SOAPBody soapBody = soapEnvelope.getBody();
        if (soapBody != null) {
            soapBody.detachNode();
        }
        SOAPHeader soapHeader = soapEnvelope.getHeader();
        if (soapHeader != null) {
            soapHeader.detachNode();
        }

        // We don't know if there is a real OM tree or just a backing XMLStreamReader.
        // The best way to walk the data is to get the XMLStreamReader and use this
        // to build the SOAPElements
        XMLStreamReader reader = omEnvelope.getXMLStreamReader();

        NameCreator nc = new NameCreator(soapEnvelope);
        buildSOAPTree(nc, soapEnvelope, null, reader, false);
    } catch (WebServiceException e) {
        throw e;
    } catch (SOAPException e) {
        throw ExceptionFactory.makeWebServiceException(e);
    }
    return soapEnvelope;
}

From source file:org.jbpm.bpel.integration.server.SoapHandler.java

public boolean handleResponse(MessageContext messageContext) throws JAXRPCException {
    Map parts = (Map) messageContext.getProperty(MESSAGE_PARTS_PROP);
    SOAPFaultException faultException = (SOAPFaultException) messageContext.getProperty(FAULT_EXCEPTION_PROP);

    // absence of both parts and fault means one-way operation
    if (parts == null && faultException == null)
        return true;

    String operationName = (String) messageContext.getProperty(OPERATION_NAME_PROP);
    SOAPMessage soapMessage = ((SOAPMessageContext) messageContext).getMessage();

    JbpmContext jbpmContext = integrationControl.getIntegrationServiceFactory().getJbpmConfiguration()
            .createJbpmContext();// w  ww  . j  ava 2 s .c  o m
    try {
        lookupEndpointMetadata(messageContext);

        SOAPEnvelope envelope = soapMessage.getSOAPPart().getEnvelope();
        // remove existing body, it might have undesirable content
        SOAPBody body = envelope.getBody();
        body.detachNode();
        // re-create body
        body = envelope.addBody();

        if (faultException == null)
            writeOutput(operationName, soapMessage, parts);
        else {
            String faultName = (String) messageContext.getProperty(FAULT_NAME_PROP);
            writeFault(operationName, soapMessage, faultName, parts, faultException);
        }
    }
    /*
     * NO need to set jbpm context as rollback only for any exception, since operations in try-block
     * only read definitions from database
     */
    catch (SOAPException e) {
        throw new JAXRPCException("could not compose outbound soap message", e);
    } finally {
        jbpmContext.close();
    }
    return true;
}