static public URLConnection build_soap_request(Node xml) throws Exception {
    String sUrl = null;
    String method = "POST";
    String charset = ((Element) xml).getAttribute("charset").equals("") ? ((Element) xml)
            .getAttribute("charset") : "UTF-8";
    String version = ((Element) xml).getAttribute("version");
    String action = "";
    String contentType = "";
    Element body = null;

    // Read in the test information (from CTL)
    NodeList nl = xml.getChildNodes();
    for (int i = 0; i < nl.getLength(); i++) {
      Node n = nl.item(i);
      if (n.getNodeType() == Node.ELEMENT_NODE) {
        if (n.getLocalName().equals("url")) {
          sUrl = n.getTextContent();
        } else if (n.getLocalName().equals("action")) {
          action = n.getTextContent();
        } // else if (n.getLocalName().equals("header")) {
        // header = (org.w3c.dom.Element) n;
        /*
         * }
                 */else if (n.getLocalName().equals("body")) {
          body = (org.w3c.dom.Element) n;
        }
      }
    }

    // Get the list of the header blocks needed to build the SOAP Header
    // section
    List<Element> headerBloks = DomUtils.getElementsByTagNameNS(xml,
                CTL_NS, HEADER_BLOCKS);
    // Open the URLConnection
    URLConnection uc = new URL(sUrl).openConnection();
    if (uc instanceof HttpURLConnection) {
      ((HttpURLConnection) uc).setRequestMethod(method);
    }

    uc.setDoOutput(true);
    byte[] bytes = null;

    // SOAP POST
    bytes = SoapUtils.getSoapMessageAsByte(version, headerBloks, body,
            charset);
    // System.out.println("SOAP MESSAGE  " + new String(bytes));

    uc.setRequestProperty("User-Agent", "Team Engine 1.2");
    uc.setRequestProperty("Cache-Control", "no-cache");
    uc.setRequestProperty("Pragma", "no-cache");
    uc.setRequestProperty("charset", charset);
    uc.setRequestProperty("Content-Length", Integer.toString(bytes.length));

        if (version.equals(SOAP_V_1_1)) {
      // Handle HTTP binding for SOAP 1.1
      // uc.setRequestProperty("Accept", "application/soap+xml");
      uc.setRequestProperty("Accept", "text/xml");
      uc.setRequestProperty("SOAPAction", action);
      contentType = "text/xml";
      if (!charset.equals("")) {
        contentType = contentType + "; charset=" + charset;
      }
      uc.setRequestProperty("Content-Type", contentType);
    } else {
      // Handle HTTP binding for SOAP 1.2
      uc.setRequestProperty("Accept", "application/soap+xml");
      contentType = "application/soap+xml";
      if (!charset.equals("")) {
        contentType = contentType + "; charset=" + charset;
      }
      if (!action.equals("")) {
        contentType = contentType + "; action=" + action;
      }
      uc.setRequestProperty("Content-Type", contentType);
    }
    OutputStream os = uc.getOutputStream();
    os.write(bytes);
    return uc;

  }
static public URLConnection build_soap_request ( Node xml ) throws Exception { String sUrl = null ; String method = "POST" ; String charset = ( ( Element ) xml ) . getAttribute ( "charset" ) . equals ( "" ) ? ( ( Element ) xml ) . getAttribute ( "charset" ) : "UTF-8" ; String version = ( ( Element ) xml ) . getAttribute ( "version" ) ; String action = "" ; String contentType = "" ; Element body = null ; NodeList nl = xml . getChildNodes ( ) ; for ( int i = 0 ; i < nl . getLength ( ) ; i ++ ) { Node n = nl . item ( i ) ; if ( n . getNodeType ( ) == Node . ELEMENT_NODE ) { if ( n . getLocalName ( ) . equals ( "url" ) ) { sUrl = n . getTextContent ( ) ; } else if ( n . getLocalName ( ) . equals ( "action" ) ) { action = n . getTextContent ( ) ; } else if ( n . getLocalName ( ) . equals ( "body" ) ) { body = ( org . w3c . dom . Element ) n ; } } } List < Element > headerBloks = DomUtils . getElementsByTagNameNS ( xml , CTL_NS , HEADER_BLOCKS ) ; URLConnection uc = new URL ( sUrl ) . openConnection ( ) ; if ( uc instanceof HttpURLConnection ) { ( ( HttpURLConnection ) uc ) . setRequestMethod ( method ) ; } uc . setDoOutput ( true ) ; byte [ ] bytes = null ; bytes = SoapUtils . getSoapMessageAsByte ( version , headerBloks , body , charset ) ; uc . setRequestProperty ( "User-Agent" , "Team Engine 1.2" ) ; uc . setRequestProperty ( "Cache-Control" , "no-cache" ) ; uc . setRequestProperty ( "Pragma" , "no-cache" ) ; uc . setRequestProperty ( "charset" , charset ) ; uc . setRequestProperty ( "Content-Length" , Integer . toString ( bytes . length ) ) ; if ( version . equals ( SOAP_V_1_1 ) ) { uc . setRequestProperty ( "Accept" , "text/xml" ) ; uc . setRequestProperty ( "SOAPAction" , action ) ; contentType = "text/xml" ; if ( ! charset . equals ( "" ) ) { contentType = contentType + "; charset=" + charset ; } uc . setRequestProperty ( "Content-Type" , contentType ) ; } else { uc . setRequestProperty ( "Accept" , "application/soap+xml" ) ; contentType = "application/soap+xml" ; if ( ! charset . equals ( "" ) ) { contentType = contentType + "; charset=" + charset ; } if ( ! action . equals ( "" ) ) { contentType = contentType + "; action=" + action ; } uc . setRequestProperty ( "Content-Type" , contentType ) ; } OutputStream os = uc . getOutputStream ( ) ; os . write ( bytes ) ; return uc ; }
Create SOAP request, sends it and return an URL Connection ready to be
parsed.

@param xml
the soap-request node (from CTL)

@return The URL Connection

@throws Exception
the exception

<soap-request version="1.1|1.2" charset="UTF-8">
<url>http://blah</url> <action>Some-URI</action> <headers>
<header MutUnderstand="true" rely="true" role="http://etc">
<t:Transaction xmlns:t="some-URI" >5</t:Transaction>
</header> </headers> <body> <m:GetLastTradePrice
xmlns:m="Some-URI"> <symbol>DEF</symbol>
</m:GetLastTradePrice> </body> <parsers:SOAPParser
return="content"> <parsers:XMLValidatingParser>
<parsers:schemas> <parsers:schema
type="url">http://blah/schema.xsd</parsers:schema>
</parsers:schemas> </parsers:XMLValidatingParser>
</parsers:SOAPParser> </soap-request>