Example usage for javax.xml.soap SOAPMessage getMimeHeaders

List of usage examples for javax.xml.soap SOAPMessage getMimeHeaders

Introduction

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

Prototype

public abstract MimeHeaders getMimeHeaders();

Source Link

Document

Returns all the transport-specific MIME headers for this SOAPMessage object in a transport-independent fashion.

Usage

From source file:com.novartis.opensource.yada.adaptor.SOAPAdaptor.java

/**
 * Constructs and executes a SOAP message.  For {@code basic} authentication, YADA uses the 
 * java soap api, and the {@link SOAPConnection} object stored in the query object.  For 
 * NTLM, which was never successful using the java api, YADA calls out to {@link #CURL_EXEC}
 * in {@link #YADA_BIN}. /*  ww w  .jav a  2s  .co m*/
 * @see com.novartis.opensource.yada.adaptor.Adaptor#execute(com.novartis.opensource.yada.YADAQuery)
 */
@Override
public void execute(YADAQuery yq) throws YADAAdaptorExecutionException {
    String result = "";
    resetCountParameter(yq);
    SOAPConnection connection = (SOAPConnection) yq.getConnection();
    for (int row = 0; row < yq.getData().size(); row++) {
        yq.setResult();
        YADAQueryResult yqr = yq.getResult();
        String soapUrl = yq.getSoap(row);

        try {
            this.endpoint = new URL(soapUrl);
            MessageFactory factory = MessageFactory.newInstance();
            SOAPMessage message = factory.createMessage();

            byte[] authenticationToken = Base64.encodeBase64((this.soapUser + ":" + this.soapPass).getBytes());

            // Assume a SOAP message was built previously
            MimeHeaders mimeHeaders = message.getMimeHeaders();
            if ("basic".equals(this.soapAuth.toLowerCase())) {
                mimeHeaders.addHeader("Authorization", this.soapAuth + " " + new String(authenticationToken));
                mimeHeaders.addHeader("SOAPAction", this.soapAction);
                mimeHeaders.addHeader("Content-Type", "text/xml");
                SOAPHeader header = message.getSOAPHeader();
                SOAPBody body = message.getSOAPBody();
                header.detachNode();

                l.debug("query:\n" + this.queryString);

                try {
                    Document xml = DocumentBuilderFactory.newInstance().newDocumentBuilder()
                            .parse(new ByteArrayInputStream(this.soapData.getBytes()));

                    //SOAPBodyElement docElement = 
                    body.addDocument(xml);

                    Authenticator.setDefault(new YadaSoapAuthenticator(this.soapUser, this.soapPass));

                    SOAPMessage response = connection.call(message, this.endpoint);
                    try (ByteArrayOutputStream responseOutputStream = new ByteArrayOutputStream()) {
                        response.writeTo(responseOutputStream);
                        result = responseOutputStream.toString();
                    }
                } catch (IOException e) {
                    String msg = "Unable to process input or output stream for SOAP message with Basic Authentication. This is an I/O problem, not an authentication issue.";
                    throw new YADAAdaptorExecutionException(msg, e);
                }
                l.debug("SOAP Body:\n" + result);
            } else if (AUTH_NTLM.equals(this.soapAuth.toLowerCase())
                    || "negotiate".equals(this.soapAuth.toLowerCase())) {
                ArrayList<String> args = new ArrayList<>();
                args.add(Finder.getEnv(YADA_BIN) + CURL_EXEC);
                args.add("-X");
                args.add("-s");
                args.add(this.soapSource + this.soapPath);
                args.add("-u");
                args.add(this.soapDomain + "\\" + this.soapUser);
                args.add("-p");
                args.add(this.soapPass);
                args.add("-a");
                args.add(this.soapAuth);
                args.add("-q");
                args.add(this.soapData);
                args.add("-t");
                args.add(this.soapAction);
                String[] cmds = args.toArray(new String[0]);
                l.debug("Executing soap request via script: " + Arrays.toString(cmds));
                String s = null;
                try {
                    ProcessBuilder pb = new ProcessBuilder(args);
                    l.debug(pb.environment().toString());
                    pb.redirectErrorStream(true);
                    Process p = pb.start();
                    try (BufferedReader si = new BufferedReader(new InputStreamReader(p.getInputStream()))) {
                        while ((s = si.readLine()) != null) {
                            l.debug(s);
                            if (null == result) {
                                result = "";
                            }
                            result += s;
                        }
                    }
                } catch (IOException e) {
                    String msg = "Unable to execute NTLM-authenticated SOAP call using system call to 'curl'.  Make sure the curl executable is still accessible.";
                    throw new YADAAdaptorExecutionException(msg, e);
                }
            }
        } catch (SOAPException e) {
            String msg = "There was a problem creating or executing the SOAP message, or receiving the response.";
            throw new YADAAdaptorExecutionException(msg, e);
        } catch (SAXException e) {
            String msg = "Unable to parse SOAP message body.";
            throw new YADAAdaptorExecutionException(msg, e);
        } catch (ParserConfigurationException e) {
            String msg = "There was a problem creating the xml document for the SOAP message body.";
            throw new YADAAdaptorExecutionException(msg, e);
        } catch (YADAResourceException e) {
            String msg = "Cannot find 'curl' executable at specified JNDI path " + YADA_BIN + CURL_EXEC;
            throw new YADAAdaptorExecutionException(msg, e);
        } catch (MalformedURLException e) {
            String msg = "Can't create URL from provided source and path.";
            throw new YADAAdaptorExecutionException(msg, e);
        } finally {
            try {
                ConnectionFactory.releaseResources(connection, yq.getSoap().get(0));
            } catch (YADAConnectionException e) {
                l.error(e.getMessage());
            }
        }

        yqr.addResult(row, result);

    }

}

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

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

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

    try {
        MessageFactory mf = MessageFactory.newInstance();
        SOAPMessage message = mf.createMessage();

        MimeHeaders mh = message.getMimeHeaders();
        mh.setHeader("SOAPAction", "\"urn:schemas-microsoft-com:xml-analysis:Execute\"");

        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<String, String> paraList = new HashMap<String, String>();
        String datasource = (String) getParameterValue(JRXmlaQueryExecuterFactory.PARAMETER_XMLA_DATASOURCE);
        paraList.put("DataSourceInfo", datasource);
        String catalog = (String) getParameterValue(JRXmlaQueryExecuterFactory.PARAMETER_XMLA_CATALOG);
        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: \n" + prettyPrintSOAP(message.getSOAPPart().getEnvelope()));
        }

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

From source file:com.googlecode.ddom.saaj.SOAPMessageTest.java

@Validated
@Test/*  www .j ava 2s .co  m*/
public void testAddAttachmentPart() throws Exception {
    SOAPMessage message = getFactory().createMessage();
    AttachmentPart attachment = message.createAttachmentPart();
    message.addAttachmentPart(attachment);
    Iterator it = message.getAttachments();
    assertTrue(it.hasNext());
    assertSame(attachment, it.next());
    assertFalse(it.hasNext());
    // Check that the content type automatically changes to SwA
    if (message.saveRequired()) {
        message.saveChanges();
    }
    String[] contentTypeArray = message.getMimeHeaders().getHeader("Content-Type");
    assertNotNull(contentTypeArray);
    assertEquals(1, contentTypeArray.length);
    MimeType contentType = new MimeType(contentTypeArray[0]);
    assertEquals("multipart/related", contentType.getBaseType());
    assertEquals(messageSet.getVersion().getContentType(), contentType.getParameter("type"));
    assertNotNull(contentType.getParameter("boundary"));
}

From source file:cl.nic.dte.net.ConexionSii.java

@SuppressWarnings("unchecked")
private String getSemilla()
        throws UnsupportedOperationException, SOAPException, IOException, XmlException, ConexionSiiException {
    SOAPConnectionFactory scFactory = SOAPConnectionFactory.newInstance();
    SOAPConnection con = scFactory.createConnection();
    MessageFactory factory = MessageFactory.newInstance();
    SOAPMessage message = factory.createMessage();
    SOAPPart soapPart = message.getSOAPPart();
    SOAPEnvelope envelope = soapPart.getEnvelope();
    SOAPHeader header = envelope.getHeader();
    SOAPBody body = envelope.getBody();
    header.detachNode();//from ww  w  .j  a  v  a2  s . c  om

    String urlSolicitud = Utilities.netLabels.getString("URL_SOLICITUD_SEMILLA");

    Name bodyName = envelope.createName("getSeed", "m", urlSolicitud);

    message.getMimeHeaders().addHeader("SOAPAction", "");

    body.addBodyElement(bodyName);

    URL endpoint = new URL(urlSolicitud);

    SOAPMessage responseSII = con.call(message, endpoint);

    SOAPPart sp = responseSII.getSOAPPart();
    SOAPBody b = sp.getEnvelope().getBody();

    cl.sii.xmlSchema.RESPUESTADocument resp = null;
    for (Iterator<SOAPBodyElement> res = b.getChildElements(
            sp.getEnvelope().createName("getSeedResponse", "ns1", urlSolicitud)); res.hasNext();) {
        for (Iterator<SOAPBodyElement> ret = res.next().getChildElements(
                sp.getEnvelope().createName("getSeedReturn", "ns1", urlSolicitud)); ret.hasNext();) {

            HashMap<String, String> namespaces = new HashMap<String, String>();
            namespaces.put("", "http://www.sii.cl/XMLSchema");
            XmlOptions opts = new XmlOptions();
            opts.setLoadSubstituteNamespaces(namespaces);

            resp = RESPUESTADocument.Factory.parse(ret.next().getValue(), opts);

        }
    }

    if (resp != null && resp.getRESPUESTA().getRESPHDR().getESTADO() == 0) {
        return resp.getRESPUESTA().getRESPBODY().getSEMILLA();
    } else {
        throw new ConexionSiiException(
                "No obtuvo Semilla: Codigo: " + resp.getRESPUESTA().getRESPHDR().getESTADO() + "; Glosa: "
                        + resp.getRESPUESTA().getRESPHDR().getGLOSA());
    }
}

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 va 2s  .  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.betfair.testing.utils.cougar.helpers.CougarHelpers.java

private void extractHeaderDataSOAP(SOAPMessage response, HttpResponseBean responseBean) throws SOAPException {
    //extract MimeHeaders
    MimeHeaders mime = response.getMimeHeaders();
    Iterator<MimeHeader> iter = mime.getAllHeaders();

    while (iter.hasNext()) {
        MimeHeader mimeH = iter.next();
        responseBean.addEntryToResponseHeaders(mimeH.getName(), mimeH.getValue());

    }/*from  w ww .  ja v a2 s .c om*/

    //extract SOAPHeaders from the envelope and a them to the mimeHeaders
    if (response.getSOAPHeader() != null) {
        javax.xml.soap.SOAPHeader header = response.getSOAPHeader();

        NodeList nodes = header.getChildNodes();

        for (int x = 0; x < nodes.getLength(); x++) {
            //if the header entry contains child nodes - write them with the node names
            if (nodes.item(x).hasChildNodes()) {
                NodeList childnodes = nodes.item(x).getChildNodes();
                for (int y = 0; y < childnodes.getLength(); y++) {
                    responseBean.addEntryToResponseHeaders(nodes.item(x).getLocalName(),
                            childnodes.item(y).getLocalName() + ":" + childnodes.item(y).getTextContent());
                }
            } else {
                responseBean.addEntryToResponseHeaders(nodes.item(x).getLocalName(),
                        nodes.item(x).getTextContent());
            }
        }
    }
}

From source file:it.cnr.icar.eric.common.SOAPMessenger.java

SOAPMessage send(SOAPMessage msg) throws SOAPException {

    SOAPConnectionFactory scf = SOAPConnectionFactory.newInstance();
    SOAPConnection connection = scf.createConnection();

    dumpMessage("Request=", msg);

    long t1 = System.currentTimeMillis();

    // if the sessionId exists, set it as a Mime header
    // This header will be used by the server to track authenticated
    // sessions//from   ww  w .j  a  v  a  2  s .  c  om
    if (credentialInfo != null) {
        if (credentialInfo.sessionId != null) {
            msg.getMimeHeaders().addHeader("Cookie", credentialInfo.sessionId);
        }
    }

    SOAPMessage reply = connection.call(msg, endpoint);

    // if the credentialInfo.sessionId is not null, cache the sessionId
    if (credentialInfo != null) {
        cacheSessionId(reply);
    }

    long t2 = System.currentTimeMillis();

    dumpMessage("Response=", reply);

    double secs = ((double) t2 - t1) / 1000;
    log.debug("Call elapsed time in seconds: " + secs);

    return reply;
}

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  va  2 s  .  co 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 {//from ww  w. j  ava 2  s.com
        // 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 {//w  w  w . j a va2s  .co  m
        // 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();
    }
}