Example usage for javax.xml.soap SOAPEnvelope getBody

List of usage examples for javax.xml.soap SOAPEnvelope getBody

Introduction

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

Prototype

public SOAPBody getBody() throws SOAPException;

Source Link

Document

Returns the SOAPBody object associated with this SOAPEnvelope object.

Usage

From source file:it.cnr.icar.eric.server.interfaces.soap.RegistrySAMLServlet.java

@SuppressWarnings("unchecked")
public SOAPMessage onMessage(SOAPMessage msg, HttpServletRequest req, HttpServletResponse resp) {

    SOAPMessage soapResponse = null;
    SOAPHeader soapHeader = null;

    try {/*from   w  w  w.j a  va 2s .  c  om*/

        // extract SOAP related parts from incoming SOAP message

        // set 'soapHeader' variable ASAP (before "firstly")
        SOAPPart soapPart = msg.getSOAPPart();
        SOAPEnvelope soapEnvelope = soapPart.getEnvelope();
        SOAPBody soapBody = soapEnvelope.getBody();
        soapHeader = soapEnvelope.getHeader();

        /****************************************************************
         * 
         * REPOSITORY ITEM HANDLING (IN) REPOSITORY ITEM HANDLING (IN)
         * 
         ***************************************************************/

        // Firstly we put save the attached repository items in a map

        HashMap<String, Object> idToRepositoryItemMap = new HashMap<String, Object>();
        Iterator<AttachmentPart> apIter = msg.getAttachments();

        while (apIter.hasNext()) {
            AttachmentPart ap = apIter.next();

            // Get the content for the attachment
            RepositoryItem ri = processIncomingAttachment(ap);
            idToRepositoryItemMap.put(ri.getId(), ri);
        }

        /****************************************************************
         * 
         * LOGGING (IN) LOGGING (IN) LOGGING (IN) LOGGING (IN)
         * 
         ***************************************************************/

        // Log received message

        if (log.isTraceEnabled()) {
            // Warning! BAOS.toString() uses platform's default encoding
            ByteArrayOutputStream msgOs = new ByteArrayOutputStream();
            msg.writeTo(msgOs);
            msgOs.close();
            log.trace("incoming message:\n" + msgOs.toString());
        }

        /****************************************************************
         * 
         * MESSAGE VERIFICATION (IN) MESSAGE VERIFICATION (IN)
         * 
         ***************************************************************/
        CredentialInfo credentialInfo = new CredentialInfo();

        WSS4JSecurityUtilSAML.verifySOAPEnvelopeOnServerSAML(soapEnvelope, credentialInfo);

        /****************************************************************
         * 
         * RS:REQUEST HANDLING RS:REQUEST HANDLING RS:REQUEST
         * 
         ***************************************************************/

        // The ebXML registry request is the only element in the SOAPBody

        StringWriter requestXML = new StringWriter(); // The request as an
        // XML String
        String requestRootElement = null;

        Iterator<?> iter = soapBody.getChildElements();
        int i = 0;

        while (iter.hasNext()) {
            Object obj = iter.next();

            if (!(obj instanceof SOAPElement)) {
                continue;
            }

            if (i++ == 0) {
                SOAPElement elem = (SOAPElement) obj;
                Name name = elem.getElementName();
                requestRootElement = name.getLocalName();

                StreamResult result = new StreamResult(requestXML);
                TransformerFactory tf = TransformerFactory.newInstance();
                Transformer trans = tf.newTransformer();
                trans.transform(new DOMSource(elem), result);
            } else {
                throw new RegistryException(
                        ServerResourceBundle.getInstance().getString("message.invalidRequest"));
            }
        }

        if (requestRootElement == null) {
            throw new RegistryException(
                    ServerResourceBundle.getInstance().getString("message.noebXMLRegistryRequest"));
        }

        // unmarshalling request to message
        Object message = bu.getRequestObject(requestRootElement, requestXML.toString());

        if (message instanceof JAXBElement<?>) {
            // If Element; take ComplexType from Element
            message = ((JAXBElement<?>) message).getValue();
        }

        SAMLRequest request = new SAMLRequest(req, credentialInfo.assertion, message, idToRepositoryItemMap);

        Response response = request.process();

        /****************************************************************
         * 
         * RESPONSE HANDLING RESPONSE HANDLING RESPONSE HANDLING
         * 
         ***************************************************************/

        soapResponse = createResponseSOAPMessage(response);

        if (response.getIdToRepositoryItemMap().size() > 0 && (response.getMessage().getStatus()
                .equals(BindingUtility.CANONICAL_RESPONSE_STATUS_TYPE_ID_Success))) {

            idToRepositoryItemMap = response.getIdToRepositoryItemMap();
            Iterator<String> mapKeysIter = idToRepositoryItemMap.keySet().iterator();

            while (mapKeysIter.hasNext()) {
                String id = mapKeysIter.next();
                RepositoryItem repositoryItem = (RepositoryItem) idToRepositoryItemMap.get(id);

                String cid = WSS4JSecurityUtilSAML.convertUUIDToContentId(id);
                DataHandler dh = repositoryItem.getDataHandler();
                AttachmentPart ap = soapResponse.createAttachmentPart(dh);
                ap.setContentId(cid);
                soapResponse.addAttachmentPart(ap);

                if (log.isTraceEnabled()) {
                    log.trace("adding attachment: contentId=" + id);
                }
            }
        }

    } catch (Throwable t) {
        // Do not log ObjectNotFoundException as it clutters the log
        if (!(t instanceof ObjectNotFoundException)) {
            log.error(ServerResourceBundle.getInstance().getString("message.CaughtException",
                    new Object[] { t.getMessage() }), t);
            Throwable cause = t.getCause();
            while (cause != null) {
                log.error(ServerResourceBundle.getInstance().getString("message.CausedBy",
                        new Object[] { cause.getMessage() }), cause);
                cause = cause.getCause();
            }
        }

        soapResponse = createFaultSOAPMessage(t, soapHeader);
    }

    if (log.isTraceEnabled()) {
        try {
            ByteArrayOutputStream rspOs = new ByteArrayOutputStream();
            soapResponse.writeTo(rspOs);
            rspOs.close();
            // Warning! BAOS.toString() uses platform's default encoding
            log.trace("response message:\n" + rspOs.toString());
        } catch (Exception e) {
            log.error(ServerResourceBundle.getInstance().getString("message.FailedToLogResponseMessage",
                    new Object[] { e.getMessage() }), e);
        }
    }
    return soapResponse;
}

From source file:com.polivoto.networking.SoapClient.java

private SOAPMessage createSOAPRequest() throws SOAPException, IOException {
    MessageFactory messageFactory = MessageFactory.newInstance();
    SOAPMessage soapMessage = messageFactory.createMessage();
    SOAPPart soapPart = soapMessage.getSOAPPart();

    String serverURI = "http://votingservice.develops.capiz.org";

    // SOAP Envelope
    SOAPEnvelope envelope = soapPart.getEnvelope();
    envelope.addNamespaceDeclaration("example", serverURI);

    /* El siguiente es un ejemplo tomado de donde me bas para armar la solicitud.
    Constructed SOAP Request Message:/*  w  w w . j  a  v  a 2s .  co m*/
    <SOAP-ENV:Envelope xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/" xmlns:example="http://ws.cdyne.com/">
    <SOAP-ENV:Header/>
    <SOAP-ENV:Body>
        <example:VerifyEmail>
            <example:email>mutantninja@gmail.com</example:email>
            <example:LicenseKey>123</example:LicenseKey>
        </example:VerifyEmail>
    </SOAP-ENV:Body>
    </SOAP-ENV:Envelope>
     */

    // SOAP Body
    SOAPBody soapBody = envelope.getBody();
    SOAPElement soapBodyElem = soapBody.addChildElement("serviceChooser", "example");
    SOAPElement soapBodyElem1 = soapBodyElem.addChildElement("json", "example");
    soapBodyElem1.addTextNode(json.toString());
    MimeHeaders headers = soapMessage.getMimeHeaders();
    headers.addHeader("SOAPAction", serverURI + "serviceChooser");
    soapMessage.saveChanges();
    return soapMessage;
}

From source file:net.sf.jasperreports.olap.xmla.JRXmlaQueryExecuter.java

/**
 * Parses the result-Message into this class's structure
 * /*w  w  w .  ja v  a 2 s  .  c  o m*/
 * @param reply
 *            The reply-Message from the Server
 */
protected void parseResult(SOAPMessage reply) throws SOAPException {
    SOAPPart soapPart = reply.getSOAPPart();
    SOAPEnvelope soapEnvelope = soapPart.getEnvelope();
    SOAPBody soapBody = soapEnvelope.getBody();
    SOAPElement eElement = null;

    if (log.isDebugEnabled()) {
        log.debug("XML/A result envelope: " + prettyPrintSOAP(soapEnvelope));
    }

    SOAPFault fault = soapBody.getFault();
    if (fault != null) {
        handleResultFault(fault);
    }

    Name eName = soapEnvelope.createName("ExecuteResponse", "", XMLA_URI);

    // Get the ExecuteResponse-Node
    Iterator<?> responseElements = soapBody.getChildElements(eName);
    if (responseElements.hasNext()) {
        Object eObj = responseElements.next();
        if (eObj == null) {
            throw new JRRuntimeException(EXCEPTION_MESSAGE_KEY_XMLA_NULL_ELEMENT,
                    new Object[] { "ExecuteResponse" });
        }
        eElement = (SOAPElement) eObj;
    } else {
        throw new JRRuntimeException(EXCEPTION_MESSAGE_KEY_XMLA_CANNOT_RETRIEVE_ELEMENT,
                new Object[] { "ExecuteResponse" });
    }

    // Get the return-Node
    Name rName = soapEnvelope.createName("return", "", XMLA_URI);
    Iterator<?> returnElements = eElement.getChildElements(rName);
    SOAPElement returnElement = null;
    if (returnElements.hasNext()) {
        Object eObj = returnElements.next();
        if (eObj == null) {
            throw new JRRuntimeException(EXCEPTION_MESSAGE_KEY_XMLA_NULL_ELEMENT, new Object[] { "return" });
        }
        returnElement = (SOAPElement) eObj;
    } else {
        // Should be old-Microsoft XMLA-SDK. Try without m-prefix
        Name rName2 = soapEnvelope.createName("return", "", "");
        returnElements = eElement.getChildElements(rName2);
        if (returnElements.hasNext()) {
            Object eObj = returnElements.next();
            if (eObj == null) {
                throw new JRRuntimeException(EXCEPTION_MESSAGE_KEY_XMLA_NULL_ELEMENT,
                        new Object[] { "return" });
            }
            returnElement = (SOAPElement) eObj;
        } else {
            throw new JRRuntimeException(EXCEPTION_MESSAGE_KEY_XMLA_CANNOT_RETRIEVE_ELEMENT,
                    new Object[] { "return" });
        }
    }

    // Get the root-Node
    Name rootName = soapEnvelope.createName("root", "", MDD_URI);
    SOAPElement rootElement = null;
    Iterator<?> rootElements = returnElement.getChildElements(rootName);
    if (rootElements.hasNext()) {
        Object eObj = rootElements.next();
        if (eObj == null) {
            throw new JRRuntimeException(EXCEPTION_MESSAGE_KEY_XMLA_NULL_ELEMENT, new Object[] { "root" });
        }
        rootElement = (SOAPElement) eObj;
    } else {
        throw new JRRuntimeException(EXCEPTION_MESSAGE_KEY_XMLA_CANNOT_RETRIEVE_ELEMENT,
                new Object[] { "root" });
    }
    // Get the OlapInfo-Node
    Name olapInfoName = soapEnvelope.createName("OlapInfo", "", MDD_URI);
    SOAPElement olapInfoElement = null;
    Iterator<?> olapInfoElements = rootElement.getChildElements(olapInfoName);
    if (olapInfoElements.hasNext()) {
        Object eObj = olapInfoElements.next();
        if (eObj == null) {
            throw new JRRuntimeException(EXCEPTION_MESSAGE_KEY_XMLA_NULL_ELEMENT, new Object[] { "OlapInfo" });
        }
        olapInfoElement = (SOAPElement) eObj;
    } else {
        throw new JRRuntimeException(EXCEPTION_MESSAGE_KEY_XMLA_CANNOT_RETRIEVE_ELEMENT,
                new Object[] { "OlapInfo" });
    }

    parseOLAPInfoElement(olapInfoElement);

    // Get the Axes Element
    Name axesName = soapEnvelope.createName("Axes", "", MDD_URI);
    SOAPElement axesElement = null;
    Iterator<?> axesElements = rootElement.getChildElements(axesName);
    if (axesElements.hasNext()) {
        Object eObj = axesElements.next();
        if (eObj == null) {
            throw new JRRuntimeException(EXCEPTION_MESSAGE_KEY_XMLA_NULL_ELEMENT, new Object[] { "Axes" });
        }
        axesElement = (SOAPElement) eObj;
    } else {
        throw new JRRuntimeException(EXCEPTION_MESSAGE_KEY_XMLA_CANNOT_RETRIEVE_ELEMENT,
                new Object[] { "Axes" });
    }

    parseAxesElement(axesElement);

    // Get the CellData Element
    Name cellDataName = soapEnvelope.createName("CellData", "", MDD_URI);
    SOAPElement cellDataElement = null;
    Iterator<?> cellDataElements = rootElement.getChildElements(cellDataName);
    if (cellDataElements.hasNext()) {
        Object eObj = cellDataElements.next();
        if (eObj == null) {
            throw new JRRuntimeException(EXCEPTION_MESSAGE_KEY_XMLA_NULL_ELEMENT, new Object[] { "CellData" });
        }
        cellDataElement = (SOAPElement) eObj;
    } else {
        throw new JRRuntimeException(EXCEPTION_MESSAGE_KEY_XMLA_CANNOT_RETRIEVE_ELEMENT,
                new Object[] { "CellData" });
    }
    parseCellDataElement(cellDataElement);
}

From source file:com.usps.UspsServlet.java

private SOAPMessage createSOAPRequest(String parameter) {
    SOAPMessage soapMessage = null;
    try {//w  w w. ja  v  a  2s. c om
        MessageFactory messageFactory = MessageFactory.newInstance();
        soapMessage = messageFactory.createMessage();
        SOAPPart soapPart = soapMessage.getSOAPPart();

        // SOAP Envelope
        SOAPEnvelope envelope = soapPart.getEnvelope();
        envelope.addNamespaceDeclaration("xsd", "http://www.w3.org/2001/XMLSchema");
        envelope.addNamespaceDeclaration("upss", "http://www.ups.com/XMLSchema/XOLTWS/UPSS/v1.0");
        envelope.addNamespaceDeclaration("wsf", "http://www.ups.com/schema/wsf");
        envelope.addNamespaceDeclaration("xsi", "http://www.w3.org/2001/XMLSchema-instance");
        envelope.addNamespaceDeclaration("common", "http://www.ups.com/XMLSchema/XOLTWS/Common/v1.0");

        // SOAP Body Generated Here
        // all of the nodes below are mandatory
        // if any optional nodes are desired refer to the ECHO API or SOAPUI for
        // exact Node names
        SOAPBody soapBody = envelope.getBody();

        MimeHeaders headers = soapMessage.getMimeHeaders();
        headers.addHeader("Security", "wsse");

        soapMessage.saveChanges();

        /* Print the request message */
        System.out.print("Request SOAP Message:");
        soapMessage.writeTo(System.out);

    } catch (SOAPException | IOException ex) {
        Logger.getLogger(UspsServlet.class.getName()).log(Level.SEVERE, null, ex);
    }
    return soapMessage;
}

From source file:com.twinsoft.convertigo.engine.translators.WebServiceTranslator.java

public Object buildOutputData(Context context, Object convertigoResponse) throws Exception {
    Engine.logBeans.debug("[WebServiceTranslator] Encoding the SOAP response...");

    SOAPMessage responseMessage = null;
    String sResponseMessage = "";
    String encodingCharSet = "UTF-8";
    if (context.requestedObject != null)
        encodingCharSet = context.requestedObject.getEncodingCharSet();

    if (convertigoResponse instanceof Document) {
        Engine.logBeans.debug("[WebServiceTranslator] The Convertigo response is a XML document.");
        Document document = Engine.theApp.schemaManager.makeResponse((Document) convertigoResponse);

        //MessageFactory messageFactory = MessageFactory.newInstance(SOAPConstants.SOAP_1_1_PROTOCOL);
        MessageFactory messageFactory = MessageFactory.newInstance();
        responseMessage = messageFactory.createMessage();

        responseMessage.setProperty(SOAPMessage.CHARACTER_SET_ENCODING, encodingCharSet);

        SOAPPart sp = responseMessage.getSOAPPart();
        SOAPEnvelope se = sp.getEnvelope();
        SOAPBody sb = se.getBody();

        sb.setEncodingStyle("http://schemas.xmlsoap.org/soap/encoding/");

        //se.addNamespaceDeclaration(prefix, targetNameSpace);
        se.addNamespaceDeclaration("soapenc", "http://schemas.xmlsoap.org/soap/encoding/");
        se.addNamespaceDeclaration("xsi", "http://www.w3.org/2001/XMLSchema-instance");
        se.addNamespaceDeclaration("xsd", "http://www.w3.org/2001/XMLSchema");

        // Remove header as it not used. Seems that empty headers causes the WS client of Flex 4 to fail 
        se.getHeader().detachNode();/*from  w w  w  . j  a v  a2 s  .  c o  m*/

        addSoapElement(context, se, sb, document.getDocumentElement());

        sResponseMessage = SOAPUtils.toString(responseMessage, encodingCharSet);

        // Correct missing "xmlns" (Bug AXA POC client .NET)
        //sResponseMessage = sResponseMessage.replaceAll("<soapenv:Envelope", "<soapenv:Envelope xmlns=\""+targetNameSpace+"\"");
    } else {
        Engine.logBeans.debug("[WebServiceTranslator] The Convertigo response is not a XML document.");
        sResponseMessage = convertigoResponse.toString();
    }

    if (Engine.logBeans.isDebugEnabled()) {
        Engine.logBeans.debug("[WebServiceTranslator] SOAP response:\n" + sResponseMessage);
    }

    return responseMessage == null ? sResponseMessage.getBytes(encodingCharSet) : responseMessage;
}

From source file:org.jasig.portal.security.provider.saml.SAMLDelegatedAuthenticationService.java

private Document createSOAPFaultDocument(String faultString) throws SOAPException {
    MessageFactory factory = MessageFactory.newInstance();
    SOAPMessage message = factory.createMessage();
    SOAPPart sp = message.getSOAPPart();
    SOAPEnvelope se = sp.getEnvelope();
    se.setPrefix(SOAP_PREFIX);// w w w. ja  v a 2s.c o m
    se.getHeader().detachNode();
    se.addHeader();
    se.getBody().detachNode();
    SOAPBody body = se.addBody();
    SOAPFault fault = body.addFault();
    Name faultCode = se.createName("Client", null, SOAPConstants.URI_NS_SOAP_ENVELOPE);
    fault.setFaultCode(faultCode);
    fault.setFaultString(faultString);
    return se.getOwnerDocument();
}

From source file:com.jaspersoft.ireport.designer.data.fieldsproviders.olap.OLAPQueryExecuter.java

protected SOAPMessage createQueryMessage(JRXMLADataSourceConnection xmlaConnection) {
    String queryStr = getQueryString();

    if (log.isDebugEnabled()) {
        log.debug("MDX query: " + queryStr);
    }//from  w  w w  .  j a v  a 2 s .c  o m

    try {
        // Force the use of Axis as message factory...

        MessageFactory mf = MessageFactory.newInstance();

        SOAPMessage message = mf.createMessage();

        MimeHeaders mh = message.getMimeHeaders();
        mh.setHeader("SOAPAction", "\"urn:schemas-microsoft-com:xml-analysis:Execute\"");
        //mh.setHeader("Content-Type", "text/xml; charset=utf-8");

        SOAPPart soapPart = message.getSOAPPart();
        SOAPEnvelope envelope = soapPart.getEnvelope();
        SOAPBody body = envelope.getBody();
        Name nEx = envelope.createName("Execute", "", XMLA_URI);

        SOAPElement eEx = body.addChildElement(nEx);

        // add the parameters

        // COMMAND parameter
        // <Command>
        // <Statement>queryStr</Statement>
        // </Command>
        Name nCom = envelope.createName("Command", "", XMLA_URI);
        SOAPElement eCommand = eEx.addChildElement(nCom);
        Name nSta = envelope.createName("Statement", "", XMLA_URI);
        SOAPElement eStatement = eCommand.addChildElement(nSta);
        eStatement.addTextNode(queryStr);

        // <Properties>
        // <PropertyList>
        // <DataSourceInfo>dataSource</DataSourceInfo>
        // <Catalog>catalog</Catalog>
        // <Format>Multidimensional</Format>
        // <AxisFormat>TupleFormat</AxisFormat>
        // </PropertyList>
        // </Properties>
        Map paraList = new HashMap();
        String datasource = xmlaConnection.getDatasource();
        paraList.put("DataSourceInfo", datasource);
        String catalog = xmlaConnection.getCatalog();
        paraList.put("Catalog", catalog);
        paraList.put("Format", "Multidimensional");
        paraList.put("AxisFormat", "TupleFormat");
        addParameterList(envelope, eEx, "Properties", "PropertyList", paraList);
        message.saveChanges();

        if (log.isDebugEnabled()) {
            log.debug("XML/A query message: " + message.toString());
        }

        return message;
    } catch (SOAPException e) {
        log.error(e);
        throw new JRRuntimeException(e);
    }
}

From source file:com.twinsoft.convertigo.engine.translators.WebServiceTranslator.java

public Object __buildOutputData(Context context, Object convertigoResponse) throws Exception {
    Engine.logBeans.debug("[WebServiceTranslator] Encoding the SOAP response...");

    SOAPMessage responseMessage = null;
    String sResponseMessage = "";
    String encodingCharSet = "UTF-8";
    if (context.requestedObject != null)
        encodingCharSet = context.requestedObject.getEncodingCharSet();

    if (convertigoResponse instanceof Document) {
        Engine.logBeans.debug("[WebServiceTranslator] The Convertigo response is a XML document.");
        Document document = (Document) convertigoResponse;

        //MessageFactory messageFactory = MessageFactory.newInstance(SOAPConstants.SOAP_1_1_PROTOCOL);
        MessageFactory messageFactory = MessageFactory.newInstance();
        responseMessage = messageFactory.createMessage();

        responseMessage.setProperty(SOAPMessage.CHARACTER_SET_ENCODING, encodingCharSet);

        SOAPPart sp = responseMessage.getSOAPPart();
        SOAPEnvelope se = sp.getEnvelope();
        SOAPBody sb = se.getBody();

        sb.setEncodingStyle("http://schemas.xmlsoap.org/soap/encoding/");

        String targetNamespace = context.project.getTargetNamespace();
        String prefix = getPrefix(context.projectName, targetNamespace);

        //se.addNamespaceDeclaration(prefix, targetNameSpace);
        se.addNamespaceDeclaration("soapenc", "http://schemas.xmlsoap.org/soap/encoding/");
        se.addNamespaceDeclaration("xsi", "http://www.w3.org/2001/XMLSchema-instance");
        se.addNamespaceDeclaration("xsd", "http://www.w3.org/2001/XMLSchema");

        // Remove header as it not used. Seems that empty headers causes the WS client of Flex 4 to fail 
        se.getHeader().detachNode();//w  w  w.j  a v  a  2 s  . co  m

        // Add the method response element
        SOAPElement soapMethodResponseElement = null;
        String soapElementName = context.sequenceName != null ? context.sequenceName
                : context.connectorName + "__" + context.transactionName;
        soapElementName += "Response";

        soapMethodResponseElement = sb.addChildElement(se.createName(soapElementName, prefix, targetNamespace));

        if (XsdForm.qualified == context.project.getSchemaElementForm()) {
            soapMethodResponseElement.addAttribute(se.createName("xmlns"), targetNamespace);
        }

        // Add a 'response' root child element or not
        SOAPElement soapResponseElement;
        if (context.sequenceName != null) {
            Sequence sequence = (Sequence) context.requestedObject;
            if (sequence.isIncludeResponseElement()) {
                soapResponseElement = soapMethodResponseElement.addChildElement("response");
            } else {
                soapResponseElement = soapMethodResponseElement;
            }
        } else {
            soapResponseElement = soapMethodResponseElement.addChildElement("response");
        }

        if (soapResponseElement.getLocalName().equals("response")) {
            if (document.getDocumentElement().hasAttributes()) {
                addAttributes(responseMessage, se, context, document.getDocumentElement().getAttributes(),
                        soapResponseElement);
            }
        }

        NodeList childNodes = document.getDocumentElement().getChildNodes();
        int len = childNodes.getLength();
        org.w3c.dom.Node node;
        for (int i = 0; i < len; i++) {
            node = childNodes.item(i);
            if (node instanceof Element) {
                addElement(responseMessage, se, context, (Element) node, soapResponseElement);
            }
        }

        sResponseMessage = SOAPUtils.toString(responseMessage, encodingCharSet);

        // Correct missing "xmlns" (Bug AXA POC client .NET)
        //sResponseMessage = sResponseMessage.replaceAll("<soapenv:Envelope", "<soapenv:Envelope xmlns=\""+targetNameSpace+"\"");
    } else {
        Engine.logBeans.debug("[WebServiceTranslator] The Convertigo response is not a XML document.");
        sResponseMessage = convertigoResponse.toString();
    }

    if (Engine.logBeans.isDebugEnabled()) {
        Engine.logBeans.debug("[WebServiceTranslator] SOAP response:\n" + sResponseMessage);
    }

    return responseMessage == null ? sResponseMessage.getBytes(encodingCharSet) : responseMessage;
}

From source file:com.jaspersoft.ireport.designer.data.fieldsproviders.olap.OLAPQueryExecuter.java

/**
 * Parses the result-Message into this class's structure
 *
 * @param reply/*w w w.ja v  a 2  s.  c om*/
 *            The reply-Message from the Server
 */
protected void parseResult(SOAPMessage reply) throws SOAPException, JRRuntimeException {
    SOAPPart soapPart = reply.getSOAPPart();
    SOAPEnvelope soapEnvelope = soapPart.getEnvelope();
    SOAPBody soapBody = soapEnvelope.getBody();
    SOAPElement eElement = null;

    if (log.isDebugEnabled()) {
        log.debug("XML/A result envelope: " + soapEnvelope.toString());
    }

    SOAPFault fault = soapBody.getFault();
    if (fault != null) {
        handleResultFault(fault);
    }

    Name eName = soapEnvelope.createName("ExecuteResponse", "", XMLA_URI);

    // Get the ExecuteResponse-Node
    Iterator responseElements = soapBody.getChildElements(eName);
    if (responseElements.hasNext()) {
        Object eObj = responseElements.next();
        if (eObj == null) {
            log.error("ExecuteResponse Element is null.");
            throw new JRRuntimeException("ExecuteResponse Element is null.");
        }
        eElement = (SOAPElement) eObj;
    } else {
        log.error("Could not retrieve ExecuteResponse Element.");
        throw new JRRuntimeException("Could not retrieve ExecuteResponse Element.");
    }

    // Get the return-Node
    Name rName = soapEnvelope.createName("return", "", XMLA_URI);
    Iterator returnElements = eElement.getChildElements(rName);
    SOAPElement returnElement = null;
    if (returnElements.hasNext()) {
        Object eObj = returnElements.next();
        if (eObj == null) {
            log.error("return Element is null.");
            throw new JRRuntimeException("return Element is null.");
        }
        returnElement = (SOAPElement) eObj;
    } else {
        // Should be old-Microsoft XMLA-SDK. Try without m-prefix
        Name rName2 = soapEnvelope.createName("return", "", "");
        returnElements = eElement.getChildElements(rName2);
        if (returnElements.hasNext()) {
            Object eObj = returnElements.next();
            if (eObj == null) {
                log.error("return Element is null.");
                throw new JRRuntimeException("return Element is null.");
            }
            returnElement = (SOAPElement) eObj;
        } else {
            log.error("Could not retrieve return Element.");
            throw new JRRuntimeException("Could not retrieve return Element.");
        }
    }

    // Get the root-Node
    Name rootName = soapEnvelope.createName("root", "", MDD_URI);
    SOAPElement rootElement = null;
    Iterator rootElements = returnElement.getChildElements(rootName);
    if (rootElements.hasNext()) {
        Object eObj = rootElements.next();
        if (eObj == null) {
            log.error("root Element is null.");
            throw new JRRuntimeException("root Element is null.");
        }
        rootElement = (SOAPElement) eObj;
    } else {
        log.error("Could not retrieve root Element.");
        throw new JRRuntimeException("Could not retrieve root Element.");
    }
    // Get the OlapInfo-Node
    Name olapInfoName = soapEnvelope.createName("OlapInfo", "", MDD_URI);
    SOAPElement olapInfoElement = null;
    Iterator olapInfoElements = rootElement.getChildElements(olapInfoName);
    if (olapInfoElements.hasNext()) {
        Object eObj = olapInfoElements.next();
        if (eObj == null) {
            log.error("OlapInfo Element is null.");
            throw new JRRuntimeException("OlapInfo Element is null.");
        }
        olapInfoElement = (SOAPElement) eObj;
    } else {
        log.error("Could not retrieve OlapInfo Element.");
        throw new JRRuntimeException("Could not retrieve OlapInfo Element.");
    }

    parseOLAPInfoElement(olapInfoElement);

    // Get the Axes Element
    Name axesName = soapEnvelope.createName("Axes", "", MDD_URI);
    SOAPElement axesElement = null;
    Iterator axesElements = rootElement.getChildElements(axesName);
    if (axesElements.hasNext()) {
        Object eObj = axesElements.next();
        if (eObj == null) {
            log.error("Axes Element is null");
            throw new JRRuntimeException("Axes Element is null");
        }
        axesElement = (SOAPElement) eObj;
    } else {
        log.error("Could not retrieve Axes Element.");
        throw new JRRuntimeException("Could not retrieve Axes Element.");
    }

    parseAxesElement(axesElement);

    // Get the CellData Element
    Name cellDataName = soapEnvelope.createName("CellData", "", MDD_URI);
    SOAPElement cellDataElement = null;
    Iterator cellDataElements = rootElement.getChildElements(cellDataName);
    if (cellDataElements.hasNext()) {
        Object eObj = cellDataElements.next();
        if (eObj == null) {
            log.error("CellData element is null");
            throw new JRRuntimeException("CellData element is null");
        }
        cellDataElement = (SOAPElement) eObj;
    } else {
        log.error("Could not retrieve CellData Element.");
        throw new JRRuntimeException("Could not retrieve CellData Element.");
    }
    parseCellDataElement(cellDataElement);
}

From source file:com.twinsoft.convertigo.engine.translators.WebServiceTranslator.java

private void addAttributes(SOAPMessage responseMessage, SOAPEnvelope soapEnvelope, Context context,
        NamedNodeMap attributes, SOAPElement soapElement) throws SOAPException {
    SOAPElement soapMethodResponseElement = (SOAPElement) soapEnvelope.getBody().getFirstChild();
    String targetNamespace = soapMethodResponseElement.getNamespaceURI();
    String prefix = soapMethodResponseElement.getPrefix();

    int len = attributes.getLength();
    Attr attribute;//  ww  w .ja v a2s  .c om
    for (int i = 0; i < len; i++) {
        attribute = (Attr) attributes.item(i);
        String attributeName = attribute.getName();
        String attributeValue = attribute.getNodeValue();
        String attributeNsUri = attribute.getNamespaceURI();
        String attributePrefix = getPrefix(context.projectName, attributeNsUri);

        XmlSchemaAttribute xmlSchemaAttribute = getXmlSchemaAttributeByName(context.projectName, attributeName);
        boolean isGlobal = xmlSchemaAttribute != null;
        if (isGlobal) {
            attributeNsUri = xmlSchemaAttribute.getQName().getNamespaceURI();
            attributePrefix = getPrefix(context.projectName, attributeNsUri);
        }

        if (XsdForm.qualified == context.project.getSchemaElementForm() || isGlobal) {
            if (attributePrefix == null) {
                soapElement.addAttribute(soapEnvelope.createName(attributeName, prefix, targetNamespace),
                        attributeValue);
            } else {
                soapElement.addAttribute(
                        soapEnvelope.createName(attributeName, attributePrefix, attributeNsUri),
                        attributeValue);
            }
        } else {
            soapElement.addAttribute(soapEnvelope.createName(attributeName), attributeValue);
        }
    }
}