Example usage for javax.xml.soap SOAPPart getEnvelope

List of usage examples for javax.xml.soap SOAPPart getEnvelope

Introduction

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

Prototype

public abstract SOAPEnvelope getEnvelope() throws SOAPException;

Source Link

Document

Gets the SOAPEnvelope object associated with this SOAPPart object.

Usage

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

/**
 * Parses the result-Message into this class's structure
 * //from w  w  w .  j  a va  2s  .c  om
 * @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: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);//ww w . ja  v a  2  s  .  com
    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.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  ww w  . j  av a  2s  .  co  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: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  ww. 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  2s .  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//from   w  ww  .ja  v  a  2 s.c o m
 *            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.maxl.java.aips2sqlite.AllDown.java

public void downRefdataPharmaXml(String file_refdata_pharma_xml) {
    boolean disp = false;
    ProgressBar pb = new ProgressBar();

    try {/*from  w  w  w  .  j  a v a 2  s  .c  o m*/
        // Start timer 
        long startTime = System.currentTimeMillis();
        if (disp)
            System.out.print("- Downloading Refdatabase pharma file... ");
        else {
            pb.init("- Downloading Refdatabase pharma file... ");
            pb.start();
        }

        // Create soaprequest
        SOAPMessage soapRequest = MessageFactory.newInstance().createMessage();
        // Set SOAPAction header line
        MimeHeaders headers = soapRequest.getMimeHeaders();
        headers.addHeader("SOAPAction", "http://refdatabase.refdata.ch/Pharma/Download");
        // Set SOAP main request part
        SOAPPart soapPart = soapRequest.getSOAPPart();
        SOAPEnvelope envelope = soapPart.getEnvelope();
        SOAPBody soapBody = envelope.getBody();
        // Construct SOAP request message
        SOAPElement soapBodyElement1 = soapBody.addChildElement("DownloadArticleInput");
        soapBodyElement1.addNamespaceDeclaration("", "http://refdatabase.refdata.ch/");
        SOAPElement soapBodyElement2 = soapBodyElement1.addChildElement("ATYPE");
        soapBodyElement2.addNamespaceDeclaration("", "http://refdatabase.refdata.ch/Article_in");
        soapBodyElement2.addTextNode("ALL");
        soapRequest.saveChanges();
        // If needed print out soapRequest in a pretty format
        // System.out.println(prettyFormatSoapXml(soapRequest));
        // Create connection to SOAP server
        SOAPConnectionFactory soapConnectionFactory = SOAPConnectionFactory.newInstance();
        SOAPConnection connection = soapConnectionFactory.createConnection();
        // wsURL contains service end point
        String wsURL = "http://refdatabase.refdata.ch/Service/Article.asmx?WSDL";
        SOAPMessage soapResponse = connection.call(soapRequest, wsURL);
        // Extract response
        Document doc = soapResponse.getSOAPBody().extractContentAsDocument();
        String strBody = getStringFromDoc(doc);
        String xmlBody = prettyFormat(strBody);
        // Note: parsing the Document tree and using the removeAttribute function is hopeless!          
        xmlBody = xmlBody.replaceAll("xmlns.*?\".*?\" ", "");

        long len = writeToFile(xmlBody, file_refdata_pharma_xml);

        if (!disp)
            pb.stopp();
        long stopTime = System.currentTimeMillis();
        System.out.println("\r- Downloading Refdata pharma file... " + len / 1024 + " kB in "
                + (stopTime - startTime) / 1000.0f + " sec");

        connection.close();

    } catch (Exception e) {
        if (!disp)
            pb.stopp();
        System.err.println(" Exception: in 'downRefdataPharmaXml'");
        e.printStackTrace();
    }
}

From source file:com.maxl.java.aips2sqlite.AllDown.java

public void downRefdataPartnerXml(String file_refdata_partner_xml) {
    boolean disp = false;
    ProgressBar pb = new ProgressBar();

    try {/*w  w w  . jav a  2 s.  c om*/
        // Start timer 
        long startTime = System.currentTimeMillis();
        if (disp)
            System.out.print("- Downloading Refdata partner file... ");
        else {
            pb.init("- Downloading Refdata partner file... ");
            pb.start();
        }

        // Create soaprequest
        SOAPMessage soapRequest = MessageFactory.newInstance().createMessage();
        // Set SOAPAction header line
        MimeHeaders headers = soapRequest.getMimeHeaders();
        headers.addHeader("SOAPAction", "http://refdatabase.refdata.ch/Download");
        // Set SOAP main request part
        SOAPPart soapPart = soapRequest.getSOAPPart();
        SOAPEnvelope envelope = soapPart.getEnvelope();
        SOAPBody soapBody = envelope.getBody();
        // Construct SOAP request message
        SOAPElement soapBodyElement1 = soapBody.addChildElement("DownloadPartnerInput");
        soapBodyElement1.addNamespaceDeclaration("", "http://refdatabase.refdata.ch/");
        SOAPElement soapBodyElement2 = soapBodyElement1.addChildElement("PTYPE");
        soapBodyElement2.addNamespaceDeclaration("", "http://refdatabase.refdata.ch/Partner_in");
        soapBodyElement2.addTextNode("ALL");
        soapRequest.saveChanges();
        // If needed print out soapRequest in a pretty format
        // System.out.println(prettyFormatSoapXml(soapRequest));
        // Create connection to SOAP server
        SOAPConnectionFactory soapConnectionFactory = SOAPConnectionFactory.newInstance();
        SOAPConnection connection = soapConnectionFactory.createConnection();
        // wsURL contains service end point
        String wsURL = "http://refdatabase.refdata.ch/Service/Partner.asmx?WSDL";
        SOAPMessage soapResponse = connection.call(soapRequest, wsURL);
        // Extract response
        Document doc = soapResponse.getSOAPBody().extractContentAsDocument();
        String strBody = getStringFromDoc(doc);
        String xmlBody = prettyFormat(strBody);
        // Note: parsing the Document tree and using the removeAttribute function is hopeless!          
        xmlBody = xmlBody.replaceAll("xmlns.*?\".*?\" ", "");

        long len = writeToFile(xmlBody, file_refdata_partner_xml);

        if (!disp)
            pb.stopp();
        long stopTime = System.currentTimeMillis();
        System.out.println("\r- Downloading Refdata partner file... " + len / 1024 + " kB in "
                + (stopTime - startTime) / 1000.0f + " sec");

        connection.close();

    } catch (Exception e) {
        if (!disp)
            pb.stopp();
        System.err.println(" Exception: in 'downRefdataPartnerXml'");
        e.printStackTrace();
    }
}

From source file:com.maxl.java.aips2sqlite.AllDown.java

public void downSwissindexXml(String language, String file_refdata_pharma_xml) {
    boolean disp = false;
    ProgressBar pb = new ProgressBar();

    try {//  ww  w  . j  a v  a  2s.  c  om
        // Start timer 
        long startTime = System.currentTimeMillis();
        if (disp)
            System.out.print("- Downloading Swissindex (" + language + ") file... ");
        else {
            pb.init("- Downloading Swissindex (" + language + ") file... ");
            pb.start();
        }

        SOAPMessage soapRequest = MessageFactory.newInstance().createMessage();

        // Setting SOAPAction header line
        MimeHeaders headers = soapRequest.getMimeHeaders();
        headers.addHeader("SOAPAction", "http://swissindex.e-mediat.net/SwissindexPharma_out_V101/DownloadAll");

        SOAPPart soapPart = soapRequest.getSOAPPart();
        SOAPEnvelope envelope = soapPart.getEnvelope();
        SOAPBody soapBody = envelope.getBody();
        // Construct SOAP request message
        SOAPElement soapBodyElement1 = soapBody.addChildElement("pharmacode");
        soapBodyElement1.addNamespaceDeclaration("",
                "http://swissindex.e-mediat.net/SwissindexPharma_out_V101");
        soapBodyElement1.addTextNode("DownloadAll");
        SOAPElement soapBodyElement2 = soapBody.addChildElement("lang");
        soapBodyElement2.addNamespaceDeclaration("",
                "http://swissindex.e-mediat.net/SwissindexPharma_out_V101");
        if (language.equals("DE"))
            soapBodyElement2.addTextNode("DE");
        else if (language.equals("FR"))
            soapBodyElement2.addTextNode("FR");
        else {
            System.err.println("down_swissindex_xml: wrong language!");
            return;
        }
        soapRequest.saveChanges();

        SOAPConnectionFactory soapConnectionFactory = SOAPConnectionFactory.newInstance();
        SOAPConnection connection = soapConnectionFactory.createConnection();
        String wsURL = "https://swissindex.refdata.ch/Swissindex/Pharma/ws_Pharma_V101.asmx?WSDL";
        SOAPMessage soapResponse = connection.call(soapRequest, wsURL);

        Document doc = soapResponse.getSOAPBody().extractContentAsDocument();
        String strBody = getStringFromDoc(doc);
        String xmlBody = prettyFormat(strBody);
        // Note: parsing the Document tree and using the removeAttribute function is hopeless! 
        xmlBody = xmlBody.replaceAll("xmlns.*?\".*?\" ", "");
        long len = writeToFile(xmlBody, file_refdata_pharma_xml);

        if (!disp)
            pb.stopp();
        long stopTime = System.currentTimeMillis();
        System.out.println("\r- Downloading Swissindex (" + language + ") file... " + len / 1024 + " kB in "
                + (stopTime - startTime) / 1000.0f + " sec");

        connection.close();

    } catch (Exception e) {
        if (!disp)
            pb.stopp();
        System.err.println(" Exception: in 'downSwissindexXml'");
        e.printStackTrace();
    }
}

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

public void buildInputDocument(Context context, Object inputData) throws Exception {
    Engine.logBeans.debug("[WebServiceTranslator] Making input document");

    HttpServletRequest request = (HttpServletRequest) inputData;

    SOAPMessage requestMessage = (SOAPMessage) request
            .getAttribute(WebServiceServlet.REQUEST_MESSAGE_ATTRIBUTE);

    SOAPPart sp = requestMessage.getSOAPPart();
    SOAPEnvelope se = sp.getEnvelope();
    SOAPBody sb = se.getBody();/*from   ww  w  .  j  av  a  2s .  c  o  m*/

    Iterator<?> iterator = sb.getChildElements();
    SOAPElement method, parameter;
    String methodName;

    InputDocumentBuilder inputDocumentBuilder = new InputDocumentBuilder(context);

    while (iterator.hasNext()) {
        List<RequestableVariable> variableList = null; // jmc 12/06/26

        Object element = iterator.next();
        if (element instanceof SOAPElement) {
            method = (SOAPElement) element;

            methodName = method.getElementName().getLocalName();
            Engine.logBeans.debug("[WebServiceTranslator] Requested web service name: " + methodName);

            int i = methodName.indexOf("__");

            // for statefull transaction, don't replace the project
            if (context.project == null || !context.project.getName().equals(context.projectName)) {
                context.project = Engine.theApp.databaseObjectsManager.getProjectByName(context.projectName);
            }

            String connectorName = null;
            if (i == -1) {
                context.connectorName = null;
                context.sequenceName = methodName;
            } else {
                connectorName = methodName.substring(0, i);
                context.transactionName = methodName.substring(i + 2);
            }

            if ((connectorName != null) && (!connectorName.equals(context.connectorName))) {
                Engine.logBeans.debug("Connector name differs from previous one; requiring new session");
                context.isNewSession = true;
                context.connectorName = connectorName;
                Engine.logBeans.debug("[WebServiceTranslator] The connector is overridden to \""
                        + context.connectorName + "\".");
            }

            Engine.logBeans.debug("[WebServiceTranslator] Connector: "
                    + (context.connectorName == null ? "(default)" : context.connectorName));
            Engine.logBeans.debug("[WebServiceTranslator] Transaction: " + context.transactionName);

            //Connector connector = (context.connectorName == null ? context.project.getDefaultConnector() : context.project.getConnectorByName(context.connectorName));
            //Transaction transaction = (context.transactionName == null ? connector.getDefaultTransaction() : connector.getTransactionByName(context.transactionName));
            RequestableObject requestable = null;
            if (context.sequenceName != null) {
                requestable = context.project.getSequenceByName(context.sequenceName);
                variableList = ((Sequence) requestable).getVariablesList();
            } else if (context.connectorName != null) {
                if (context.transactionName != null) {
                    requestable = context.project.getConnectorByName(context.connectorName)
                            .getTransactionByName(context.transactionName);
                    if (requestable instanceof TransactionWithVariables) {
                        variableList = ((TransactionWithVariables) requestable).getVariablesList();
                    }
                }
            }

            Iterator<?> iterator2 = method.getChildElements();
            String parameterName, parameterValue;

            while (iterator2.hasNext()) {
                element = iterator2.next();
                if (element instanceof SOAPElement) {
                    parameter = (SOAPElement) element;
                    parameterName = parameter.getElementName().getLocalName();
                    parameterValue = parameter.getValue();
                    if (parameterValue == null) {
                        parameterValue = "";
                    }

                    if (variableList != null) { // jmc 12/06/26 hide hidden variables in sequences
                        String str = (String) Visibility.Logs.replaceVariables(variableList,
                                "" + parameterName + "=\"" + parameterValue + "\"");
                        Engine.logBeans.debug("   Parameter: " + str);
                    } else
                        Engine.logBeans.debug("   Parameter: " + parameterName + "=\"" + parameterValue + "\"");

                    // Handle convertigo parameters
                    if (parameterName.startsWith("__")) {
                        webServiceServletRequester.handleParameter(parameterName, parameterValue);
                    }

                    // Common parameter handling
                    if (inputDocumentBuilder.handleSpecialParameter(parameterName, parameterValue)) {
                        // handled
                    }
                    // Compatibility for Convertigo 2.x
                    else if (parameterName.equals("context")) {
                        // Just ignore it
                    } else {
                        SOAPElement soapArrayElement = null;
                        Iterator<?> iterator3;

                        String href = parameter.getAttributeValue(se.createName("href"));

                        String arrayType = parameter.getAttributeValue(se.createName("soapenc:arrayType"));
                        if (arrayType == null) {
                            iterator3 = parameter.getAllAttributes();
                            while (iterator3.hasNext()) {
                                element = iterator3.next();
                                if (element instanceof Name) {
                                    String s = ((Name) element).getQualifiedName();
                                    if (s.equals("soapenc:arrayType")) {
                                        arrayType = s;
                                        break;
                                    }
                                }
                            }
                        }

                        // Array (Microsoft .net)
                        if (href != null) {
                            Engine.logBeans.debug("Deserializing Microsoft .net array");
                            iterator3 = sb.getChildElements();
                            while (iterator3.hasNext()) {
                                element = iterator3.next();
                                if (element instanceof SOAPElement) {
                                    soapArrayElement = (SOAPElement) element;
                                    String elementId = soapArrayElement.getAttributeValue(se.createName("id"));
                                    if (elementId != null) {
                                        if (href.equals("#" + elementId)) {
                                            iterator3 = soapArrayElement.getChildElements();
                                            while (iterator3.hasNext()) {
                                                element = iterator3.next();
                                                if (element instanceof SOAPElement) {
                                                    break;
                                                }
                                            }
                                            break;
                                        }
                                    }
                                }
                            }

                            // Find the element with href id
                            iterator3 = sb.getChildElements();
                            while (iterator3.hasNext()) {
                                element = iterator3.next();
                                if (element instanceof SOAPElement) {
                                    soapArrayElement = (SOAPElement) element;
                                    String elementId = soapArrayElement.getAttributeValue(se.createName("id"));
                                    if (elementId != null) {
                                        if (href.equals("#" + elementId)) {
                                            break;
                                        }
                                    }
                                }
                            }
                        }
                        // Array (Java/Axis)
                        else if (arrayType != null) {
                            Engine.logBeans.debug("Deserializing Java/Axis array");
                            soapArrayElement = parameter;
                        }
                        // If the node has children nodes, we assume it is an array.
                        else if (parameter.getChildElements().hasNext()) {
                            if (isSoapArray((IVariableContainer) requestable, parameterName)) {
                                Engine.logBeans.debug("Deserializing array");
                                soapArrayElement = parameter;
                            }
                        }

                        // Deserializing array
                        if (soapArrayElement != null) {
                            iterator3 = soapArrayElement.getChildElements();
                            while (iterator3.hasNext()) {
                                element = iterator3.next();
                                if (element instanceof SOAPElement) {
                                    soapArrayElement = (SOAPElement) element;
                                    parameterValue = soapArrayElement.getValue();
                                    if (parameterValue == null)
                                        parameterValue = "";
                                    handleSimpleVariable(context.inputDocument, soapArrayElement, parameterName,
                                            parameterValue, inputDocumentBuilder.transactionVariablesElement);
                                }
                            }
                        }
                        // Deserializing simple variable
                        else {
                            handleSimpleVariable(context.inputDocument, parameter, parameterName,
                                    parameterValue, inputDocumentBuilder.transactionVariablesElement);
                        }
                    }
                }
            }

            if (Engine.logBeans.isDebugEnabled()) {
                String soapMessage = SOAPUtils.toString(requestMessage, request.getCharacterEncoding());

                if (requestable instanceof TransactionWithVariables)
                    Engine.logBeans.debug("[WebServiceTranslator] SOAP message received:\n"
                            + Visibility.Logs.replaceVariables(
                                    ((TransactionWithVariables) (requestable)).getVariablesList(), request));
                else if (requestable instanceof Sequence)
                    Engine.logBeans.debug("[WebServiceTranslator] SOAP message received:\n" + Visibility.Logs
                            .replaceVariables(((Sequence) (requestable)).getVariablesList(), request));
                else
                    Engine.logBeans.debug("[WebServiceTranslator] SOAP message received:\n" + soapMessage);
            }

            break;
        }
    }

    Engine.logBeans.debug("[WebServiceTranslator] SOAP message analyzed");

    Engine.logBeans.debug("[WebServiceTranslator] Input document created");
}